io.reactivex.subscribers.ResourceSubscriber Java Examples

The following examples show how to use io.reactivex.subscribers.ResourceSubscriber. 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: ScheduleCollectionFragment.java    From AcgClub with MIT License 5 votes vote down vote up
/**
 * 获取收藏的所有番剧信息并显示出来
 */
private void getScheduleCollections() {
  ScheduleDAO dao = new ScheduleDAO(
      getMAppComponent()
          .repositoryManager()
          .obtainRealmConfig(SystemConstant.DB_NAME)
  );
  mDisposable = dao.getScheduleCollectCaches()
      .compose(RxUtil.<List<ScheduleCache>>rxSchedulerHelper())
      .subscribeWith(new ResourceSubscriber<List<ScheduleCache>>() {
        @Override
        public void onNext(List<ScheduleCache> scheduleCaches) {
          mAdapter.setList(scheduleCaches);
          if (scheduleCaches.size() > 0) {
            showPageContent();
          } else {
            showPageEmpty();
          }
        }

        @Override
        public void onError(Throwable t) {
          showError(R.string.msg_error_data_null);
          showPageError();
        }

        @Override
        public void onComplete() {

        }
      });
}
 
Example #2
Source File: DemoResourceSubscriber.java    From Reactive-Programming-With-Java-9 with MIT License 5 votes vote down vote up
public static void main(String[] args) {
	// TODO Auto-generated method stub
	
	ResourceSubscriber<Long> resourceSubscriber = new ResourceSubscriber<Long>() {

		@Override
		public void onComplete() {
			// TODO Auto-generated method stub
			System.out.println("Its Done!!!");
			dispose();
		}

		@Override
		public void onError(Throwable throwable) {
			// TODO Auto-generated method stub
			throwable.printStackTrace();
			dispose();
		}

		@Override
		public void onNext(Long value_long) {
			// TODO Auto-generated method stub
			if(value_long==7)
				dispose();
			System.out.println("value :-"+value_long);
		}
		
		@Override
		protected void onStart() {
			// TODO Auto-generated method stub
			request(Long.MAX_VALUE);
		}
	};
	
	Flowable.rangeLong(5, 4).subscribe(resourceSubscriber);
	resourceSubscriber.dispose();
	
}
 
Example #3
Source File: BeerClientFlowable.java    From rxjava2 with MIT License 5 votes vote down vote up
public static void main(String[] args) {

        Observable<Beer> beerData = BeerServer.getData(); // No streaming just yet


        ResourceSubscriber<Beer> beerSubscriber = new ResourceSubscriber<Beer>() {
            @Override
            public void onNext(Beer beer) {
                System.out.println("Got "+ beer);
            }

            @Override
            public void onError(Throwable throwable) {
                System.err.println("In Observer.onError(): " + throwable.getMessage());
            }

            @Override
            public void onComplete() {
                System.out.println("*** The stream is over ***");
            }
        };

        // Converting an Observable to Flowable
        beerData
             .toFlowable(BackpressureStrategy.BUFFER)
             .subscribe(beerSubscriber);   // Streaming starts here


        // If the subscriber is less than 21 year old, cancel subscription
         beerSubscriber.dispose();
    }
 
Example #4
Source File: ScheduleDetailPresenter.java    From AcgClub with MIT License 4 votes vote down vote up
/**
 * 查询该番剧的缓存信息
 *
 * @param isManualClick 是否主动点击
 */
public void getCurrentScheduleCache(final RxPermissions rxPermissions,
    final boolean isManualClick) {
  //如果播放记录还没加载成功,则先加载
  if (!TextUtils.isEmpty(curScheduleCache.getScheduleUrl()) && isManualClick) {
    checkPermission2ScheduleVideo(rxPermissions,
        getNextScheduleUrl(currentScheduleDetail, curScheduleCache.getLastWatchPos()));
  } else {
    addSubscribe(
        mModel.getScheduleCacheByUrl(currentScheduleUrl)
            .compose(RxUtil.<ScheduleCache>rxSchedulerHelper())
            .subscribeWith(new ResourceSubscriber<ScheduleCache>() {
              @Override
              public void onNext(ScheduleCache scheduleCache) {
                curScheduleCache.setCollect(scheduleCache.isCollect());
                curScheduleCache.setLastWatchPos(scheduleCache.getLastWatchPos());
              }

              @Override
              public void onError(Throwable t) {
                t.printStackTrace();
                mView.showError(R.string.msg_error_unknown);
              }

              @Override
              public void onComplete() {
                loadCache = true;
                if (!TextUtils.isEmpty(curScheduleCache.getScheduleUrl())) {
                  mView.showScheduleCacheStatus(curScheduleCache);
                }
                //手动点击,则在加载完记录后跳转到视频播放
                if (isManualClick) {
                  checkPermission2ScheduleVideo(
                      rxPermissions,
                      getNextScheduleUrl(currentScheduleDetail,
                          curScheduleCache.getLastWatchPos()));
                }
              }
            })
    );
  }
}