Search in sources :

Example 1 with SwipeRefresher

use of com.kickstarter.libs.SwipeRefresher 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 SwipeRefresher

use of com.kickstarter.libs.SwipeRefresher 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)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerViewPaginator (com.kickstarter.libs.RecyclerViewPaginator)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 Nullable (android.support.annotation.Nullable)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 AlertDialog (android.support.v7.app.AlertDialog)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 RxView (com.jakewharton.rxbinding.view.RxView)1