SHARE
TWEET

Untitled

a guest Aug 25th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package io.eveno.view.activity;
  2.  
  3. import android.arch.lifecycle.Observer;
  4. import android.arch.lifecycle.ViewModelProviders;
  5. import android.databinding.DataBindingUtil;
  6. import android.support.annotation.Nullable;
  7. import android.os.Bundle;
  8. import android.support.v7.widget.LinearLayoutManager;
  9.  
  10. import java.util.List;
  11.  
  12. import io.eveno.R;
  13. import io.eveno.databinding.ActivityEventsBinding;
  14. import io.eveno.model.entity.Event;
  15. import io.eveno.view.adapter.EventsAdapter;
  16. import io.eveno.viewmodel.EventsViewModel;
  17.  
  18. public class EventsActivity extends BaseActivity {
  19.  
  20.     private ActivityEventsBinding activityEventsBinding;
  21.     private EventsViewModel eventsViewModel;
  22.     private EventsAdapter eventsAdapter;
  23.  
  24.     @Override
  25.     protected void onCreate(Bundle savedInstanceState) {
  26.         super.onCreate(savedInstanceState);
  27.         setContentView(R.layout.activity_events);
  28.  
  29.         configureDataBinding();
  30.         observeViewModel();
  31.     }
  32.  
  33.     private void configureDataBinding() {
  34.         activityEventsBinding = DataBindingUtil.setContentView(this, R.layout.activity_events);
  35.  
  36.         eventsViewModel = ViewModelProviders.of(this).get(EventsViewModel.class);
  37.         activityEventsBinding.setEventsViewModel(eventsViewModel);
  38.  
  39.         LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
  40.         activityEventsBinding.eventsRecyclerView.setLayoutManager(linearLayoutManager);
  41.  
  42.         eventsAdapter = new EventsAdapter();
  43.         activityEventsBinding.eventsRecyclerView.setAdapter(eventsAdapter);
  44.     }
  45.  
  46.     private void observeViewModel() {
  47.         eventsViewModel.getEventListObservable().observe(this, new Observer<List<Event>>() {
  48.             @Override
  49.             public void onChanged(@Nullable List<Event> events) {
  50.                 eventsAdapter.setEventList(events);
  51.             }
  52.         });
  53.     }
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top