use of com.kickstarter.ui.adapters.CommentsAdapter in project android-oss by kickstarter.
the class CommentsActivity method onCreate.
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.comments_layout);
ButterKnife.bind(this);
adapter = new CommentsAdapter(this);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerViewPaginator = new RecyclerViewPaginator(recyclerView, viewModel.inputs::nextPage);
swipeRefresher = new SwipeRefresher(this, swipeRefreshLayout, viewModel.inputs::refresh, viewModel.outputs::isFetchingComments);
final Observable<TextView> commentBodyEditText = alertDialog.map(a -> ButterKnife.findById(a, R.id.comment_body));
final Observable<TextView> postCommentButton = alertDialog.map(a -> ButterKnife.findById(a, R.id.post_button));
final Observable<TextView> cancelButton = alertDialog.map(a -> ButterKnife.findById(a, R.id.cancel_button));
cancelButton.switchMap(RxView::clicks).observeOn(AndroidSchedulers.mainThread()).compose(bindToLifecycle()).subscribe(__ -> viewModel.inputs.commentDialogDismissed());
postCommentButton.switchMap(RxView::clicks).compose(bindToLifecycle()).subscribe(__ -> viewModel.inputs.postCommentClicked());
commentBodyEditText.switchMap(t -> RxTextView.textChanges(t).skip(1)).map(CharSequence::toString).compose(bindToLifecycle()).subscribe(viewModel.inputs::commentBodyChanged);
viewModel.outputs.currentCommentBody().compose(Transformers.takePairWhen(commentBodyEditText)).observeOn(AndroidSchedulers.mainThread()).compose(bindToLifecycle()).subscribe(ce -> ce.second.append(ce.first));
viewModel.outputs.commentsData().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(adapter::takeData);
viewModel.outputs.enablePostButton().compose(Transformers.combineLatestPair(postCommentButton)).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(bb -> setPostButtonEnabled(bb.second, bb.first));
viewModel.outputs.showCommentButton().map(show -> show ? View.VISIBLE : View.GONE).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(commentButtonTextView::setVisibility);
viewModel.outputs.showCommentDialog().filter(projectAndShow -> projectAndShow != null).map(projectAndShow -> projectAndShow.first).compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::showCommentDialog);
alertDialog.compose(Transformers.takeWhen(viewModel.outputs.dismissCommentDialog())).observeOn(AndroidSchedulers.mainThread()).compose(bindToLifecycle()).subscribe(this::dismissCommentDialog);
lifecycle().compose(Transformers.combineLatestPair(alertDialog)).filter(ad -> ad.first == ActivityEvent.DESTROY).map(ad -> ad.second).observeOn(AndroidSchedulers.mainThread()).take(1).subscribe(this::dismissCommentDialog);
toastMessages().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(ViewUtils.showToast(this));
}
Aggregations