| package despotoski.nikola.appbarlayoutsamples.view; | |
| import android.animation.IntEvaluator; | |
| import android.animation.ValueAnimator; | |
| import android.content.Context; | |
| import android.content.res.TypedArray; | |
| import android.support.design.widget.AppBarLayout; | |
| import android.support.design.widget.CoordinatorLayout; | |
| import android.support.v4.view.ViewCompat; | |
| import android.support.v4.view.ViewPropertyAnimatorCompat; |
This guide is a first draft (that will end up in the official docs) on writing resilient code for production with the Couchbase Java SDK. At the end, the reader will be able to write code that withstands bugs, latency issues or anything else that can make their application fail.
Note that lots of concepts can be applied for both synchronous and asynchronous access. When necessary, both patterns are discussed separately. Also, the focus is on database interaction, but if you are using RxJava as part of your stack you can apply most of the principles there as well (and should!).
When working with Observables, it is important to understand the difference between cold and hot. Cold Observables will start to emit events once a Observer subscribes, and will do it "fresh" for each Observer. Hot Observables instead are starting to emit data as soon as it becomes available, and will return the same (or parts of the same)
| /* | |
| * Copyright (C) 2016 Jeff Gilfelt. | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software |
| import rx.Observable; | |
| import rx.subjects.PublishSubject; | |
| import rx.subjects.SerializedSubject; | |
| import rx.subjects.Subject; | |
| /** | |
| * Simple pass-thru event bus with error handling and reconnect. | |
| */ | |
| public class EventBus { |
| /* | |
| * Copyright (C) 2014 darnmason | |
| * | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software |
| /** | |
| * @param interval The base interval to start backing off from. The function is: attemptNum^2 * intervalTime | |
| * @param units The units for interval | |
| * @param retryAttempts The max number of attempts to retry this task or -1 to try MAX_INT times, | |
| */ | |
| public static <T> Observable.Transformer<T, T> backoff(final long interval, final TimeUnit units, final int retryAttempts) { | |
| return new Observable.Transformer<T, T>() { | |
| @Override | |
| public Observable<T> call(final Observable<T> observable) { | |
| return observable.retryWhen( |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd"> | |
| <!-- Generated by RHY @will_awoke --> | |
| <module name="Checker"> | |
| <property name="charset" value="UTF-8"/> | |
| <property name="severity" value="warning"/> |
| import android.media.AudioManager; | |
| import android.media.MediaPlayer; | |
| import android.util.Pair; | |
| import org.jetbrains.annotations.NotNull; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import java.util.concurrent.TimeUnit; | |
| import rx.Observable; | |
| import rx.subscriptions.Subscriptions; |
| import android.media.MediaRecorder; | |
| import android.support.annotation.NonNull; | |
| import com.f2prateek.rx.android.schedulers.AndroidSchedulers; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import java.util.concurrent.TimeUnit; | |
| import rx.Observable; | |
| import rx.subscriptions.Subscriptions; | |
| public class RxMediaRecorder { |