use of com.kickstarter.libs.RecyclerViewPaginator in project android-oss by kickstarter.
the class ActivityFeedActivity method onCreate.
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((KSApplication) getApplication()).component().inject(this);
setContentView(R.layout.activity_feed_layout);
ButterKnife.bind(this);
adapter = new ActivityFeedAdapter(viewModel.inputs);
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::isFetchingActivities);
// Only allow refreshing if there's a current user
currentUser.observable().map(ObjectUtils::isNotNull).compose(bindToLifecycle()).compose(observeForUI()).subscribe(swipeRefreshLayout::setEnabled);
viewModel.outputs.activities().compose(bindToLifecycle()).compose(observeForUI()).subscribe(this::showActivities);
viewModel.outputs.loggedOutEmptyStateIsVisible().compose(bindToLifecycle()).compose(observeForUI()).subscribe(adapter::showLoggedOutEmptyState);
viewModel.outputs.loggedInEmptyStateIsVisible().compose(bindToLifecycle()).compose(observeForUI()).subscribe(adapter::showLoggedInEmptyState);
viewModel.outputs.goToDiscovery().compose(bindToLifecycle()).compose(observeForUI()).subscribe(__ -> resumeDiscoveryActivity());
viewModel.outputs.goToLogin().compose(bindToLifecycle()).compose(observeForUI()).subscribe(__ -> startActivityFeedLogin());
viewModel.outputs.goToProject().compose(bindToLifecycle()).compose(observeForUI()).subscribe(this::startProjectActivity);
viewModel.outputs.goToProjectUpdate().compose(bindToLifecycle()).compose(observeForUI()).subscribe(this::startProjectUpdateActivity);
}
use of com.kickstarter.libs.RecyclerViewPaginator 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));
}
use of com.kickstarter.libs.RecyclerViewPaginator in project android-oss by kickstarter.
the class DiscoveryFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
recyclerView = (RecyclerView) inflater.inflate(R.layout.discovery_recycler_view, container, false);
final DiscoveryAdapter adapter = new DiscoveryAdapter(viewModel.inputs);
recyclerView.setAdapter(adapter);
final LinearLayoutManager layoutManager = new LinearLayoutManager(recyclerView.getContext());
recyclerView.setLayoutManager(layoutManager);
recyclerViewPaginator = new RecyclerViewPaginator(recyclerView, viewModel.inputs::nextPage);
viewModel.outputs.activity().compose(bindToLifecycle()).compose(observeForUI()).subscribe(adapter::takeActivity);
viewModel.outputs.projects().compose(bindToLifecycle()).compose(observeForUI()).subscribe(adapter::takeProjects);
viewModel.outputs.shouldShowOnboardingView().compose(bindToLifecycle()).compose(observeForUI()).subscribe(adapter::setShouldShowOnboardingView);
viewModel.outputs.showActivityFeed().compose(bindToLifecycle()).compose(observeForUI()).subscribe(__ -> startActivityFeedActivity());
viewModel.outputs.showActivityUpdate().compose(bindToLifecycle()).compose(observeForUI()).subscribe(this::startActivityUpdateActivity);
viewModel.outputs.showProject().compose(bindToLifecycle()).compose(observeForUI()).subscribe(projectAndRefTag -> this.startProjectActivity(projectAndRefTag.first, projectAndRefTag.second));
viewModel.outputs.showLoginTout().compose(bindToLifecycle()).compose(observeForUI()).subscribe(__ -> this.startLoginToutActivity());
return recyclerView;
}
use of com.kickstarter.libs.RecyclerViewPaginator in project android-oss by kickstarter.
the class SearchActivity method onCreate.
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search_layout);
ButterKnife.bind(this);
adapter = new SearchAdapter(this);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(adapter);
paginator = new RecyclerViewPaginator(recyclerView, viewModel.inputs::nextPage);
RxRecyclerView.scrollEvents(recyclerView).compose(bindToLifecycle()).filter(// Skip scroll events when y is 0, usually indicates new data
scrollEvent -> scrollEvent.dy() != 0).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> InputUtils.hideKeyboard(this, getCurrentFocus()));
viewModel.outputs.popularProjects().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(adapter::loadPopularProjects);
viewModel.outputs.searchProjects().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(adapter::loadSearchProjects);
}
use of com.kickstarter.libs.RecyclerViewPaginator in project android-oss by kickstarter.
the class ProfileActivity method onCreate.
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile_layout);
ButterKnife.bind(this);
adapter = new ProfileAdapter(viewModel);
final int spanCount = ViewUtils.isLandscape(this) ? 3 : 2;
recyclerView.setLayoutManager(new GridLayoutManager(this, spanCount));
recyclerView.setAdapter(adapter);
paginator = new RecyclerViewPaginator(recyclerView, viewModel.inputs::nextPage);
viewModel.outputs.avatarImageViewUrl().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(url -> Picasso.with(this).load(url).transform(new CircleTransformation()).into(avatarImageView));
viewModel.outputs.backedCountTextViewHidden().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(ViewUtils.setGone(this.backedCountTextView));
viewModel.outputs.backedCountTextViewText().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this.backedCountTextView::setText);
viewModel.outputs.backedTextViewHidden().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(ViewUtils.setGone(this.backedTextView));
viewModel.outputs.createdCountTextViewHidden().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(ViewUtils.setGone(this.createdCountTextView));
viewModel.outputs.createdCountTextViewText().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this.createdCountTextView::setText);
viewModel.outputs.createdTextViewHidden().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(ViewUtils.setGone(this.createdTextView));
viewModel.outputs.dividerViewHidden().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(ViewUtils.setGone(this.dividerView));
viewModel.outputs.projects().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::loadProjects);
viewModel.outputs.resumeDiscoveryActivity().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(__ -> resumeDiscoveryActivity());
viewModel.outputs.startProjectActivity().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this::startProjectActivity);
viewModel.outputs.userNameTextViewText().compose(bindToLifecycle()).observeOn(AndroidSchedulers.mainThread()).subscribe(this.userNameTextView::setText);
}
Aggregations