Skip to content

Instantly share code, notes, and snippets.

@Augusent
Created May 17, 2017 18:05
Show Gist options
  • Save Augusent/57dc6c30eeebb2ba1a7c83f84a432e7c to your computer and use it in GitHub Desktop.
Save Augusent/57dc6c30eeebb2ba1a7c83f84a432e7c to your computer and use it in GitHub Desktop.
View (list, pagination) Example
public class MyAvailabilityActivity
extends BaseMviActivity<MyAvailabilityView, MyAvailabilityModel, MyAvailabilityPresenter>
implements MyAvailabilityView {
@Inject Router router;
private ActivityMyAvailabilityBinding binding;
private AvailabilitiesAdapter adapter;
private CompositeDisposable disposables = new CompositeDisposable();
public static Intent getIntent(Context context) {
return new Intent(context, MyAvailabilityActivity.class);
}
@NonNull @Override public MyAvailabilityPresenter createPresenter() {
return new MyAvailabilityPresenter();
}
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
App.get().getAppComponent().inject(this);
binding = DataBindingUtil.setContentView(this, R.layout.activity_my_availability);
binding.calendarAppBarLayout.collapsingLayout.setExpandedTitleTypeface(Typeface.DEFAULT_BOLD);
setTitle(R.string.my_availability);
setSupportActionBar(binding.calendarAppBarLayout.toolbar);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
adapter = new AvailabilitiesAdapter();
binding.recycler.setAdapter(adapter);
calendarClicks()
.doOnSubscribe(disposables::add)
.subscribe(click -> router.startAvailabilityCalendar(this));
// TODO: handle click action
binding.fabActionsLayout.setOnActionsClickListener(view -> {
switch (view.getId()) {
case R.id.recurrent_button:
// TBD
Toast.makeText(this, "Recurrent", Toast.LENGTH_SHORT).show();
return true;
case R.id.range_button:
// TBD
Toast.makeText(this, "Ranged", Toast.LENGTH_SHORT).show();
return true;
case R.id.single_button:
// TBD
Toast.makeText(this, "Single", Toast.LENGTH_SHORT).show();
return true;
default:
throw new IllegalStateException("Action view with id " + view.getId() + " is not handled");
}
});
}
@Override protected void onDestroy() {
disposables.clear();
super.onDestroy();
}
@Override public void render(MyAvailabilityModel model) {
super.render(model);
binding.setModel(model);
binding.refreshLayout.setRefreshing(model.loadingRefresh());
if (model.data() != null) adapter.setData(model.data());
}
@Override public Observable<Object> refresh() {
return RxSwipeRefreshLayout.refreshes(binding.refreshLayout);
}
@Override public Observable<Object> loadFirstPage() {
return Observable.just(true);
}
@Override public Observable<Integer> loadNextPage() {
return RxPagination.paging(binding.recycler);
}
@Override public Observable<Object> calendarClicks() {
return RxView.clicks(binding.calendarAppBarLayout.calendarButton);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment