Search in sources :

Example 1 with RecyclerViewPaginator

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);
}
Also used : RecyclerViewPaginator(com.kickstarter.libs.RecyclerViewPaginator) ActivityFeedAdapter(com.kickstarter.ui.adapters.ActivityFeedAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefresher(com.kickstarter.libs.SwipeRefresher)

Example 2 with RecyclerViewPaginator

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));
}
Also used : Transformers(com.kickstarter.libs.rx.transformers.Transformers) ViewUtils(com.kickstarter.libs.utils.ViewUtils) ProjectContextViewHolder(com.kickstarter.ui.viewholders.ProjectContextViewHolder) LoginReason(com.kickstarter.ui.data.LoginReason) EmptyCommentsViewHolder(com.kickstarter.ui.viewholders.EmptyCommentsViewHolder) Bundle(android.os.Bundle) ActivityRequestCodes(com.kickstarter.libs.ActivityRequestCodes) ButterKnife(butterknife.ButterKnife) Pair(android.util.Pair) WindowManager(android.view.WindowManager) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) CommentsViewModel(com.kickstarter.viewmodels.CommentsViewModel) OnClick(butterknife.OnClick) Observable(rx.Observable) RecyclerViewPaginator(com.kickstarter.libs.RecyclerViewPaginator) RequiresActivityViewModel(com.kickstarter.libs.qualifiers.RequiresActivityViewModel) RxView(com.jakewharton.rxbinding.view.RxView) CommentsAdapter(com.kickstarter.ui.adapters.CommentsAdapter) R(com.kickstarter.R) ActivityEvent(com.trello.rxlifecycle.ActivityEvent) View(android.view.View) Bind(butterknife.Bind) DialogInterface(android.content.DialogInterface) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SwipeRefresher(com.kickstarter.libs.SwipeRefresher) BaseActivity(com.kickstarter.libs.BaseActivity) Project(com.kickstarter.models.Project) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ObjectUtils(com.kickstarter.libs.utils.ObjectUtils) BindString(butterknife.BindString) RecyclerView(android.support.v7.widget.RecyclerView) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Nullable(android.support.annotation.Nullable) IntentKey(com.kickstarter.ui.IntentKey) PublishSubject(rx.subjects.PublishSubject) RxTextView(com.jakewharton.rxbinding.widget.RxTextView) TransitionUtils.slideInFromLeft(com.kickstarter.libs.utils.TransitionUtils.slideInFromLeft) CommentsAdapter(com.kickstarter.ui.adapters.CommentsAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SwipeRefresher(com.kickstarter.libs.SwipeRefresher) RecyclerViewPaginator(com.kickstarter.libs.RecyclerViewPaginator) TextView(android.widget.TextView) RxTextView(com.jakewharton.rxbinding.widget.RxTextView) RxView(com.jakewharton.rxbinding.view.RxView)

Example 3 with RecyclerViewPaginator

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;
}
Also used : RecyclerViewPaginator(com.kickstarter.libs.RecyclerViewPaginator) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DiscoveryAdapter(com.kickstarter.ui.adapters.DiscoveryAdapter) Nullable(android.support.annotation.Nullable)

Example 4 with RecyclerViewPaginator

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);
}
Also used : RecyclerViewPaginator(com.kickstarter.libs.RecyclerViewPaginator) SearchAdapter(com.kickstarter.ui.adapters.SearchAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 5 with RecyclerViewPaginator

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);
}
Also used : RecyclerViewPaginator(com.kickstarter.libs.RecyclerViewPaginator) ProfileAdapter(com.kickstarter.ui.adapters.ProfileAdapter) CircleTransformation(com.kickstarter.libs.transformations.CircleTransformation) GridLayoutManager(android.support.v7.widget.GridLayoutManager)

Aggregations

RecyclerViewPaginator (com.kickstarter.libs.RecyclerViewPaginator)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 Nullable (android.support.annotation.Nullable)2 SwipeRefresher (com.kickstarter.libs.SwipeRefresher)2 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 AlertDialog (android.support.v7.app.AlertDialog)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Pair (android.util.Pair)1 View (android.view.View)1 WindowManager (android.view.WindowManager)1 TextView (android.widget.TextView)1 Bind (butterknife.Bind)1 BindString (butterknife.BindString)1 ButterKnife (butterknife.ButterKnife)1 OnClick (butterknife.OnClick)1