当前位置: 首页>>代码示例>>Java>>正文


Java LifecycleProvider类代码示例

本文整理汇总了Java中com.trello.rxlifecycle2.LifecycleProvider的典型用法代码示例。如果您正苦于以下问题:Java LifecycleProvider类的具体用法?Java LifecycleProvider怎么用?Java LifecycleProvider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LifecycleProvider类属于com.trello.rxlifecycle2包,在下文中一共展示了LifecycleProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testBindUntilEvent

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
private void testBindUntilEvent(LifecycleProvider<FragmentEvent> provider) {
    Fragment fragment = (Fragment) provider;
    startFragment(fragment);

    TestObserver<Object> testObserver = observable.compose(provider.bindUntilEvent(STOP)).test();

    fragment.onAttach(null);
    testObserver.assertNotComplete();
    fragment.onCreate(null);
    testObserver.assertNotComplete();
    fragment.onViewCreated(null, null);
    testObserver.assertNotComplete();
    fragment.onStart();
    testObserver.assertNotComplete();
    fragment.onResume();
    testObserver.assertNotComplete();
    fragment.onPause();
    testObserver.assertNotComplete();
    fragment.onStop();
    testObserver.assertComplete();
}
 
开发者ID:xufreshman,项目名称:RxLifeCycle,代码行数:22,代码来源:RxFragmentLifecycleTest.java

示例2: getObservable

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
/**
 * 获取被监听者
 * 备注:网络请求Observable构建
 * data:网络请求参数
 * <h1>补充说明</h1>
 * 传入LifecycleProvider自动管理生命周期,避免内存溢出
 * 备注:需要继承RxActivity.../RxFragment...
 *
 * @author ZhongDaFeng
 */
public static Observable getObservable(Observable<HttpResponse> apiObservable, LifecycleProvider lifecycle) {
    //showLog(request);
    Observable observable;

    if (lifecycle != null) {
        //随生命周期自动管理.eg:onCreate(start)->onStop(end)
        observable =apiObservable
                .map(new ServerResultFunction())
                .compose(lifecycle.bindToLifecycle())//需要在这个位置添加
                .onErrorResumeNext(new HttpResultFunction<>())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    } else {
        observable = getObservable(apiObservable);
    }
    return observable;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:HttpRxObservable.java

示例3: fetchMoreData

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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();
            });
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:21,代码来源:ShotListPresenter.java

示例4: fetchData

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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();
            });
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:22,代码来源:ShotLikeListPresenter.java

示例5: fetchMoreData

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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();
            });
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:21,代码来源:ShotLikeListPresenter.java

示例6: fetchData

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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();
            });
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:22,代码来源:FolloweeListPresenter.java

示例7: fetchMoreData

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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();
            });
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:18,代码来源:FolloweeListPresenter.java

示例8: fetchData

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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();
            });
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:22,代码来源:UserShotListPresenter.java

示例9: fetchData

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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();
            });
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:22,代码来源:FollowerListPresenter.java

示例10: fetchMoreData

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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();
            });
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:18,代码来源:FollowerListPresenter.java

示例11: postComment

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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);
            });
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:19,代码来源:CommentPostPresenter.java

示例12: fetchData

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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();
            });
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:22,代码来源:CommentListPresenter.java

示例13: fetchMoreData

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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();
            });
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:21,代码来源:CommentListPresenter.java

示例14: start

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:27,代码来源:ShotPresenter.java

示例15: checkLike

import com.trello.rxlifecycle2.LifecycleProvider; //导入依赖的package包/类
@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));
}
 
开发者ID:gejiaheng,项目名称:Protein,代码行数:20,代码来源:ShotPresenter.java


注:本文中的com.trello.rxlifecycle2.LifecycleProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。