com.trello.rxlifecycle2.android.FragmentEvent Java Examples

The following examples show how to use com.trello.rxlifecycle2.android.FragmentEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShotPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void checkLike() {
    if (likeChecked) {
        view.setLikeStatus(like);
        view.setLikeFabVisibility(true);
        return;
    }

    repository.checkLike(shotId)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(shotLikeResponse -> {
                likeChecked = true;
                ShotLike shotLike = shotLikeResponse.body();
                view.setLikeStatus(like = (shotLike != null));
                view.setLikeFabVisibility(true);
            }, throwable -> view.setLikeFabVisibility(true));
}
 
Example #2
Source File: AskOverwriteDialog.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
	super.onActivityCreated(savedInstanceState);
	_selectedPaths = savedInstanceState == null ?
			new SrcDstPlain()
			:
			(SrcDstPlain) savedInstanceState.getParcelable(ARG_SELECTED_PATHS);
	SrcDstCollection paths = getArguments().getParcelable(ARG_PATHS);
	if(paths == null)
		paths = new SrcDstPlain();
	_applyToAll = savedInstanceState != null && savedInstanceState.getBoolean(ARG_APPLY_TO_ALL);
	_numProc = savedInstanceState == null ? 0 : savedInstanceState.getInt(ARG_NUM_PROC);
	_pathsIter = paths.iterator();
	for(int i=0;i<_numProc;i++)
		_next = _pathsIter.next();

	lifecycle().
			filter(event -> event == FragmentEvent.RESUME).
			firstElement().
			subscribe(res -> askNextRecord(), err ->
			{
				if(!(err instanceof CancellationException))
					Logger.log(err);
			});
}
 
Example #3
Source File: FolloweeListPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchMoreData() {
    view.showLoadingMore(true);
    repository.listFolloweeOfNextPage(getNextPageUrl())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(listResponse -> {
                view.showLoadingMore(false);
                view.showMoreData(generateEpoxyModels(listResponse.body()));
                setNextPageUrl(new PageLinks(listResponse).getNext());
            }, throwable -> {
                view.showLoadingMore(false);
                view.showSnackbar(throwable.getMessage());
                throwable.printStackTrace();
            });
}
 
Example #4
Source File: ShotListPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchMoreData() {
    if (TextUtils.isEmpty(getNextPageUrl()))
        return;

    view.showLoadingMore(true);
    repository.getShotsOfNextPage(getNextPageUrl())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(response -> {
                view.showLoadingMore(false);
                view.showMoreData(generateEpoxyModels(response.body()));
                setNextPageUrl(new PageLinks(response).getNext());
            }, throwable -> {
                view.showLoadingMore(false);
                view.showSnackbar(throwable.getMessage());
                throwable.printStackTrace();
            });
}
 
Example #5
Source File: ShotLikeListPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchData() {
    view.showLoading(true);
    repository.listShotLikesForUser(user.id())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(listResponse -> {
                view.showLoading(false);
                firstPageShotLikes.addAll(listResponse.body());
                view.showData(generateEpoxyModels(listResponse.body()));
                if (listResponse.body().isEmpty()) {
                    view.showEmptyView();
                }
                setNextPageUrl(new PageLinks(listResponse).getNext());
            }, throwable -> {
                view.showLoading(false);
                view.showErrorView();
                throwable.printStackTrace();
            });
}
 
Example #6
Source File: ShotLikeListPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchMoreData() {
    if (TextUtils.isEmpty(getNextPageUrl()))
        return;

    view.showLoadingMore(true);
    repository.listShotLikesForUserOfNextPage(getNextPageUrl())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(listResponse -> {
                view.showLoadingMore(false);
                view.showMoreData(generateEpoxyModels(listResponse.body()));
                setNextPageUrl(new PageLinks(listResponse).getNext());
            }, throwable -> {
                view.showLoadingMore(false);
                view.showSnackbar(throwable.getMessage());
                throwable.printStackTrace();
            });
}
 
Example #7
Source File: FolloweeListPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchData() {
    view.showLoading(true);
    repository.listUserFollowing(user.id())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(listResponse -> {
                view.showLoading(false);
                firstPageFollowees.addAll(listResponse.body());
                view.showData(generateEpoxyModels(listResponse.body()));
                if (listResponse.body().isEmpty()) {
                    view.showEmptyView();
                }
                setNextPageUrl(new PageLinks(listResponse).getNext());
            }, throwable -> {
                view.showLoading(false);
                view.showErrorView();
                throwable.printStackTrace();
            });
}
 
Example #8
Source File: UserShotListPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchData() {
    view.showLoading(true);
    repository.getUserShots(user.id())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(response -> {
                view.showLoading(false);
                firstPageShots.addAll(response.body());
                view.showData(generateEpoxyModels(response.body()));
                if (response.body().isEmpty()) {
                    view.showEmptyView();
                }
                setNextPageUrl(new PageLinks(response).getNext());
            }, throwable -> {
                view.showLoading(false);
                view.showErrorView();
                throwable.printStackTrace();
            });
}
 
Example #9
Source File: FollowerListPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchData() {
    view.showLoading(true);
    repository.listUserFollowers(user.id())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(listResponse -> {
                view.showLoading(false);
                firstPageFollowers.addAll(listResponse.body());
                view.showData(generateEpoxyModels(listResponse.body()));
                if (listResponse.body().isEmpty()) {
                    view.showEmptyView();
                }
                setNextPageUrl(new PageLinks(listResponse).getNext());
            }, throwable -> {
                view.showLoading(false);
                view.showErrorView();
                throwable.printStackTrace();
            });
}
 
Example #10
Source File: UserShotListPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchMoreData() {
    if (TextUtils.isEmpty(getNextPageUrl()))
        return;

    view.showLoadingMore(true);
    repository.getShotsOfNextPage(getNextPageUrl())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(response -> {
                view.showLoadingMore(false);
                view.showMoreData(generateEpoxyModels(response.body()));
                setNextPageUrl(new PageLinks(response).getNext());
            }, throwable -> {
                view.showLoadingMore(false);
                view.showSnackbar(throwable.getMessage());
                throwable.printStackTrace();
            });
}
 
Example #11
Source File: FollowerListPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchMoreData() {
    view.showLoadingMore(true);
    repository.listFollowerOfNextPage(getNextPageUrl())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(listResponse -> {
                view.showLoadingMore(false);
                view.showMoreData(generateEpoxyModels(listResponse.body()));
                setNextPageUrl(new PageLinks(listResponse).getNext());
            }, throwable -> {
                view.showLoadingMore(false);
                view.showSnackbar(throwable.getMessage());
                throwable.printStackTrace();
            });
}
 
Example #12
Source File: CommentPostPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void postComment(String comment) {
    repository.createCommentForShot(shot.id(), comment)
            .observeOn(Schedulers.io())
            .subscribeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(commentResponse -> {
                if (commentResponse.code() == 201 && commentResponse.body() != null) {
                    view.fillInput("");
                    RxBus.getInstance().post(commentResponse.body());
                } else {
                    view.showSnackbar(R.string.shot_comment_send_failed);
                }
            }, throwable -> {
                throwable.printStackTrace();
                view.showSnackbar(R.string.shot_comment_send_failed);
            });
}
 
Example #13
Source File: CommentListPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchData() {
    view.showLoading(true);
    repository.getCommentsForShot(shot.id())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(commentListResponse -> {
                view.showLoading(false);
                firstPageComments.addAll(commentListResponse.body());
                view.showData(generateEpoxyModels(commentListResponse.body()));
                if (commentListResponse.body().isEmpty()) {
                    view.showEmptyView();
                }
                setNextPageUrl(new PageLinks(commentListResponse).getNext());
            }, throwable -> {
                view.showLoading(false);
                view.showErrorView();
                throwable.printStackTrace();
            });
}
 
Example #14
Source File: CommentListPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchMoreData() {
    if (TextUtils.isEmpty(getNextPageUrl()))
        return;

    view.showLoadingMore(true);
    repository.getCommentsOfNextPage(getNextPageUrl())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(listResponse -> {
                view.showLoadingMore(false);
                view.showMoreData(generateEpoxyModels(listResponse.body()));
                setNextPageUrl(new PageLinks(listResponse).getNext());
            }, throwable -> {
                view.showLoadingMore(false);
                view.showSnackbar(throwable.getMessage());
                throwable.printStackTrace();
            });
}
 
Example #15
Source File: ShotPresenter.java    From Protein with Apache License 2.0 6 votes vote down vote up
@Override
public void start() {
    if (isDeepLink) {
        if (shot == null) {
            repository.getShot(shotId)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
                    .subscribe(shotResponse -> {
                        shot = shotResponse.body();
                        view.show(shot);
                    }, throwable -> {

                    });
        } else {
            view.show(shot);
        }
    } else {
        view.show(shot);
    }
    if (AccountManager.getInstance().isLogin()) {
        checkLike();
    } else {
        view.setLikeFabVisibility(true);
    }
}
 
Example #16
Source File: FileListDataFragment.java    From edslite with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onActivityResult (int requestCode, int resultCode, Intent data)
{
	if(requestCode == REQUEST_CODE_OPEN_LOCATION)
       {
           if(resultCode != Activity.RESULT_OK)
               getActivity().setIntent(new Intent());
           lifecycle().
                   filter(event -> event == FragmentEvent.RESUME).
                   firstElement().
                   subscribe(isResumed ->
                           loadLocation(null, false),
                           err ->
                   {
                       if(!(err instanceof CancellationException))
                           Logger.log(err);
                   });

       }
	else
		super.onActivityResult(requestCode, resultCode, data);
}
 
Example #17
Source File: AuthPresenter.java    From Protein with Apache License 2.0 5 votes vote down vote up
@Override
public void getAccessToken(String code) {
    view.setProgressDialogVisibility(true);
    repository.getAccessToken(code)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .compose(((LifecycleProvider<FragmentEvent>) view).bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(accessTokenResponse -> {
                view.setProgressDialogVisibility(false);

                if (accessTokenResponse.isSuccessful()) {
                    AccessToken accessToken = accessTokenResponse.body();
                    AccountManager.getInstance().setAccessToken(accessToken);

                    SharedPreferences sp = view.getContext().getSharedPreferences(
                            Constants.DEFAULT_SHARED_PREFERENCES, Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = sp.edit();
                    String strRepre = new GsonBuilder()
                            .registerTypeAdapterFactory(ProteinAdapterFactory.create())
                            .create()
                            .toJson(accessToken);
                    editor.putString(Constants.ACCESS_TOKEN_KEY, strRepre);
                    editor.apply();

                    Intent intent = new Intent(view.getContext(), MainActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    view.getContext().startActivity(intent);
                } else {
                    view.setProgressDialogVisibility(false);
                    view.showSnackbar(ErrorUtils.parseError(accessTokenResponse).error());
                }
            }, throwable -> {
                view.setProgressDialogVisibility(false);
                view.showSnackbar(R.string.request_access_token_failed);
            });
}
 
Example #18
Source File: FileListViewFragmentBase.java    From edslite with GNU General Public License v2.0 5 votes vote down vote up
public TaskFragment.TaskCallbacks getOpenAsContainerTaskCallbacks()
{
    return new ProgressDialogTaskFragmentCallbacks(getActivity(), R.string.loading)
    {
        @Override
        public void onCompleted(Bundle args, TaskFragment.Result result)
        {
            try
            {
                final Location locToOpen = (Location) result.getResult();
                if(locToOpen != null)
                    lifecycle().
                            filter(event -> event == FragmentEvent.RESUME).
                            firstElement().
                            subscribe(res -> openLocation(locToOpen), err ->
                            {
                                if(!(err instanceof CancellationException))
                                    Logger.log(err);
                            });
            }
            catch (Throwable e)
            {
                Logger.showAndLog(getActivity(), e);
            }
        }
    };
}
 
Example #19
Source File: RxLifecycleUtils.java    From Aurora with Apache License 2.0 5 votes vote down vote up
/**
 * 绑定 Fragment 的指定生命周期
 *
 * @param view
 * @param event
 * @param <T>
 * @return
 */
public static <T> LifecycleTransformer<T> bindUntilEvent(@NonNull final IView view,
                                                         final FragmentEvent event) {
    Preconditions.checkNotNull(view, "view == null");
    if (view instanceof FragmentLifecycleable) {
        return bindUntilEvent((FragmentLifecycleable) view, event);
    } else {
        throw new IllegalArgumentException("view isn't FragmentLifecycleable");
    }
}
 
Example #20
Source File: SuperFragment.java    From AndroidBase with Apache License 2.0 4 votes vote down vote up
@Override
public void onDestroy() {
    mLifecycleSubject.onNext(FragmentEvent.DESTROY);
    super.onDestroy();
}
 
Example #21
Source File: FragmentLifecycleForRxLifecycle.java    From MVPArms with Apache License 2.0 4 votes vote down vote up
@Override
public void onFragmentViewCreated(@NotNull @NonNull FragmentManager fm, @NotNull @NonNull Fragment f, @NotNull @NonNull View v, Bundle savedInstanceState) {
    if (f instanceof FragmentLifecycleable) {
        obtainSubject(f).onNext(FragmentEvent.CREATE_VIEW);
    }
}
 
Example #22
Source File: FragmentLifecycleForRxLifecycle.java    From MVPArms with Apache License 2.0 4 votes vote down vote up
@Override
public void onFragmentCreated(@NotNull @NonNull FragmentManager fm, @NotNull @NonNull Fragment f, Bundle savedInstanceState) {
    if (f instanceof FragmentLifecycleable) {
        obtainSubject(f).onNext(FragmentEvent.CREATE);
    }
}
 
Example #23
Source File: FragmentLifecycleForRxLifecycle.java    From MVPArms with Apache License 2.0 4 votes vote down vote up
@Override
public void onFragmentAttached(@NotNull @NonNull FragmentManager fm, @NotNull @NonNull Fragment f, @NotNull @NonNull Context context) {
    if (f instanceof FragmentLifecycleable) {
        obtainSubject(f).onNext(FragmentEvent.ATTACH);
    }
}
 
Example #24
Source File: BaseFragment.java    From MVPArms with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public final Subject<FragmentEvent> provideLifecycleSubject() {
    return mLifecycleSubject;
}
 
Example #25
Source File: BaseFragment.java    From QuickDevFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void onDetach() {
    lifecycleSubject.onNext(FragmentEvent.DETACH);
    super.onDetach();
}
 
Example #26
Source File: BaseFragment.java    From QuickDevFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void onDestroy() {
    lifecycleSubject.onNext(FragmentEvent.DESTROY);
    super.onDestroy();
}
 
Example #27
Source File: BaseFragment.java    From QuickDevFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void onDestroyView() {
    lifecycleSubject.onNext(FragmentEvent.DESTROY_VIEW);
    super.onDestroyView();
}
 
Example #28
Source File: BaseFragment.java    From QuickDevFramework with Apache License 2.0 4 votes vote down vote up
@Override
@NonNull
@CheckResult
public final <T> LifecycleTransformer<T> bindUntilEvent(@NonNull FragmentEvent event) {
    return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
}
 
Example #29
Source File: BaseFragment.java    From QuickDevFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    lifecycleSubject.onNext(FragmentEvent.CREATE);
}
 
Example #30
Source File: BaseFragment.java    From QuickDevFramework with Apache License 2.0 4 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    lifecycleSubject.onNext(FragmentEvent.CREATE_VIEW);
}