@Override public void getData(boolean isRefresh) { mDbDao.queryBuilder().rx().list() .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<NewsTypeInfo>>() { @Override public void call(List<NewsTypeInfo> newsTypeBeen) { mView.loadData(newsTypeBeen); } }); }
/** * 先进行初始化,把之前下载的图片记录下来 * @param dbDao */ public static void init(BeautyPhotoInfoDao dbDao) { dbDao.queryBuilder().rx().list() .subscribeOn(Schedulers.io()) .flatMap(new Func1<List<BeautyPhotoInfo>, Observable<BeautyPhotoInfo>>() { @Override public Observable<BeautyPhotoInfo> call(List<BeautyPhotoInfo> photoList) { return Observable.from(photoList); } }) .filter(new Func1<BeautyPhotoInfo, Boolean>() { @Override public Boolean call(BeautyPhotoInfo bean) { return bean.isDownload(); } }) .subscribe(new Action1<BeautyPhotoInfo>() { @Override public void call(BeautyPhotoInfo bean) { sDlPhotos.put(bean.getImgsrc().hashCode(), true); } }); }
@Override public void getData(boolean isRefresh) { mDbDao.queryBuilder().rx() .oneByOne() .filter(new Func1<VideoInfo, Boolean>() { @Override public Boolean call(VideoInfo info) { // 判断是否存于下载中 return (info.getDownloadStatus() != DownloadStatus.NORMAL && info.getDownloadStatus() != DownloadStatus.COMPLETE); } }) .toList() .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<VideoInfo>>() { @Override public void call(List<VideoInfo> videoList) { if (ListUtils.isEmpty(videoList)) { mView.noData(); } else { mView.loadData(videoList); } } }); }
@Override public void getData(boolean isRefresh) { mDbDao.queryBuilder().where(BeautyPhotoInfoDao.Properties.IsLove.eq(true)) .rx() .list() .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<BeautyPhotoInfo>>() { @Override public void call(List<BeautyPhotoInfo> list) { if (list.size() == 0) { mView.noData(); } else { mView.loadData(list); } } }); }
@Override public void getData(boolean isRefresh) { mDbDao.queryBuilder().where(VideoInfoDao.Properties.IsCollect.eq(true)) .rx() .list() .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<VideoInfo>>() { @Override public void call(List<VideoInfo> videoList) { if (ListUtils.isEmpty(videoList)) { mView.noData(); } else { mView.loadData(videoList); } } }); }
@Override public void getData(boolean isRefresh) { mDbDao.queryBuilder() .where(VideoInfoDao.Properties.DownloadStatus.eq(DownloadStatus.COMPLETE)) .rx() .list() .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<List<VideoInfo>>() { @Override public void call(List<VideoInfo> videoList) { if (ListUtils.isEmpty(videoList)) { mView.noData(); } else { mView.loadData(videoList); } } }); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setUpViews(); // get the Rx variant of the note DAO DaoSession daoSession = ((App) getApplication()).getDaoSession(); noteDao = daoSession.getNoteDao().rx(); // query all notes, sorted a-z by their text notesQuery = daoSession.getNoteDao().queryBuilder().orderAsc(NoteDao.Properties.Text).rx(); updateNotes(); }
@Override public void cleanDanmaku() { mDanmakuDao.queryBuilder().where(DanmakuInfoDao.Properties.Vid.eq(mVideoData.getVid())) .rx() .list() .compose(mView.<List<DanmakuInfo>>bindToLife()) .subscribe(new Action1<List<DanmakuInfo>>() { @Override public void call(List<DanmakuInfo> danmakuInfos) { mDanmakuDao.deleteInTx(danmakuInfos); } }); } }
public void testOneByOneUnsubscribe() { insertEntities(1000); RxQuery<TestEntity> bigQuery = daoSession.getTestEntityDao().queryBuilder().rx(); TestSubscriber<TestEntity> testSubscriber = new TestSubscriber<>(); Observable<TestEntity> observable = bigQuery.oneByOne(); Subscription subscription = observable.subscribe(testSubscriber); subscription.unsubscribe(); testSubscriber.assertUnsubscribed(); int count = testSubscriber.getValueCount(); testSubscriber.awaitTerminalEvent(100, TimeUnit.MILLISECONDS); int count2 = testSubscriber.getValueCount(); DaoLog.d("Count 1: " + count + " vs. count 2: " + count2); // Not strictly multi-threading correct, but anyway: assertTrue(count2 < 1000); }