rx.schedulers.Timestamped Java Examples

The following examples show how to use rx.schedulers.Timestamped. 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: FlickrDomainService.java    From chaining-rxjava with Apache License 2.0 6 votes vote down vote up
private Func1<Timestamped<RecentPhotosResponse>, Boolean> getRecentPhotosFilter(final ITimestampedView timestampedView) {
    return new Func1<Timestamped<RecentPhotosResponse>, Boolean>() {
        @Override
        public Boolean call(Timestamped<RecentPhotosResponse> recentPhotosResponseTimestamped) {

            StringBuilder logMessage = new StringBuilder("getMergedPhotos().filter() - Filtering results");
            if (recentPhotosResponseTimestamped == null) {
                logMessage.append(", recentPhotosResponseTimestamped is null");
            } else {
                logMessage.append(", timestamps=").append(recentPhotosResponseTimestamped.getTimestampMillis()).append(">").append(timestampedView.getViewDataTimestampMillis()).append("?");
            }
            logMessage.append(", thread=").append(Thread.currentThread().getName());
            Log.d(CLASSNAME, logMessage.toString());

            // filter it
            // if result is null - ignore it
            // if timestamp of new arrived (emission) data is less than timestamp of already displayed data — ignore it.
            return recentPhotosResponseTimestamped != null
                    && recentPhotosResponseTimestamped.getValue() != null
                    && recentPhotosResponseTimestamped.getValue().photos != null
                    && recentPhotosResponseTimestamped.getTimestampMillis() > timestampedView.getViewDataTimestampMillis();
        }
    };
}
 
Example #2
Source File: UtilityOperatorsIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenObservables_whenDelay_thenEventsStartAppearAfterATime() throws InterruptedException {

    Observable<Timestamped<Long>> source = Observable.interval(1, TimeUnit.SECONDS)
      .take(5)
      .timestamp();

    Observable<Timestamped<Long>> delay = source.delaySubscription(2, TimeUnit.SECONDS);

    source.<Long>subscribe(
      value -> System.out.println("source :" + value),
      t -> System.out.println("source error"),
      () -> System.out.println("source completed"));

    delay.subscribe(
      value -> System.out.println("delay : " + value),
      t -> System.out.println("delay error"),
      () -> System.out.println("delay completed"));
    //Thread.sleep(8000);
}
 
Example #3
Source File: FlickrDomainService.java    From chaining-rxjava with Apache License 2.0 5 votes vote down vote up
@RxLogObservable
private Observable<Timestamped<RecentPhotosResponse>> getMergedPhotos() {
    return Observable.mergeDelayError(
            flickrDiskRepository.getRecentPhotos().subscribeOn(Schedulers.io()),
            flickrNetworkRepository.getRecentPhotos().timestamp().doOnNext(new Action1<Timestamped<RecentPhotosResponse>>() {
                @Override
                public void call(Timestamped<RecentPhotosResponse> recentPhotosResponse) {
                    Log.d(CLASSNAME, "flickrApiRepository.getRecentPhotos().doOnNext() - Saving photos to disk - thread=" + Thread.currentThread().getName());
                    flickrDiskRepository.savePhotos(recentPhotosResponse);
                }
            }).subscribeOn(Schedulers.io())
    );
}
 
Example #4
Source File: FlickrDiskRepository.java    From chaining-rxjava with Apache License 2.0 5 votes vote down vote up
@RxLogObservable
    public Observable<Timestamped<RecentPhotosResponse>> getRecentPhotos() {
        return Observable.fromCallable(new Callable<Timestamped<RecentPhotosResponse>>() {
            @Override
            public Timestamped<RecentPhotosResponse> call() throws Exception {
//                if (true) throw new RuntimeException("DISK.getRecentPhotos() fake Exception!");
                String serializedPhotoList = sharedPreferences.getString(RECENT_PHOTOS_RESPONSE_KEY, "");
                Timestamped<RecentPhotosResponse> photos = null;
                if (!TextUtils.isEmpty(serializedPhotoList)) {
                    photos = flickrPhotosJsonAdapter.fromJson(serializedPhotoList);
                }
                return photos;
            }
        });
    }
 
Example #5
Source File: FlickrListFragment.java    From chaining-rxjava with Apache License 2.0 5 votes vote down vote up
private void setupView(View view) {
    swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.flickr_swipe_refresh);
    swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_orange_dark);
    swipeRefreshLayout.setOnRefreshListener(this);

    recyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view);
    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    recyclerView.setHasFixedSize(true);
    // use a linear layout manager
    recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
    // specify an adapter
    recyclerView.setAdapter(flickrListAdapter = new FlickrListAdapter(new Timestamped<>(getViewDataTimestampMillis(), Collections.<FlickrCardVM>emptyList())));
}
 
Example #6
Source File: FlickrListFragment.java    From chaining-rxjava with Apache License 2.0 5 votes vote down vote up
private void fetchFlickrItems() {
    isRefreshing(true);
    unsubscribe();
    Observable<Timestamped<List<FlickrCardVM>>> recentPhotosObservable = flickrDomainService
            .getRecentPhotos(this)
            .observeOn(AndroidSchedulers.mainThread(), true); // delayError = true

    flickrListSubscription = recentPhotosObservable.subscribe(flickrRecentPhotosOnNext, flickrRecentPhotosOnError, flickrRecenPhotosOnComplete);
}
 
Example #7
Source File: Observable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Observable<Timestamped<T>> timestamp() {
    return timestamp(Schedulers.immediate());
}
 
Example #8
Source File: Observable.java    From letv with Apache License 2.0 4 votes vote down vote up
public final Observable<Timestamped<T>> timestamp(Scheduler scheduler) {
    return lift(new OperatorTimestamp(scheduler));
}
 
Example #9
Source File: FlickrDomainService.java    From chaining-rxjava with Apache License 2.0 4 votes vote down vote up
@RxLogObservable
public Observable<Timestamped<List<FlickrCardVM>>> getRecentPhotos(ITimestampedView timestampedView) {
    return getMergedPhotos()
            .filter(getRecentPhotosFilter(timestampedView))
            .map(FlickrModelToVmMapping.instance());
}
 
Example #10
Source File: FlickrDiskRepository.java    From chaining-rxjava with Apache License 2.0 4 votes vote down vote up
public FlickrDiskRepository(Context context) {
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    Moshi moshi = new Moshi.Builder().build();
    Type adapterType = Types.newParameterizedType(Timestamped.class, RecentPhotosResponse.class);
    flickrPhotosJsonAdapter = moshi.adapter(adapterType);
}
 
Example #11
Source File: FlickrDiskRepository.java    From chaining-rxjava with Apache License 2.0 4 votes vote down vote up
public void savePhotos(Timestamped<RecentPhotosResponse> photos) {
    String serializedPhotoList = flickrPhotosJsonAdapter.toJson(photos);
    sharedPreferences.edit().putString(RECENT_PHOTOS_RESPONSE_KEY, serializedPhotoList).apply();
}
 
Example #12
Source File: FlickrListFragment.java    From chaining-rxjava with Apache License 2.0 4 votes vote down vote up
@Override
public void call(Timestamped<List<FlickrCardVM>> flickrCardVMs) {
    Log.d(CLASSNAME, "flickrRecentPhotosOnNext.call() - Displaying card VMs in Adapter");
    // refresh the list adapter
    recyclerView.swapAdapter(flickrListAdapter = new FlickrListAdapter(flickrCardVMs), false);
}
 
Example #13
Source File: FlickrListAdapter.java    From chaining-rxjava with Apache License 2.0 4 votes vote down vote up
public FlickrListAdapter(Timestamped<List<FlickrCardVM>> dataSet) {
    this.dataSet = dataSet;
}