This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:app="http://schemas.android.com/apk/res-auto" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:orientation="vertical"> | |
| <android.support.v4.widget.NestedScrollView | |
| android:id="@+id/nested_scrollview" | |
| android:layout_width="match_parent" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MainActivity extends AppCompatActivity { | |
| private Toolbar toolbar; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| setupToolbar(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun <T1, T2, T3, R> asyncCombineLatest(o1: Observable<T1>, | |
| o2: Observable<T2>, | |
| o3: Observable<T3>, | |
| asyncCombineFunc: (T1, T2, T3) -> Observable<R>): Observable<R> = | |
| Observable.combineLatest(o1, o2, o3, | |
| Function3<T1, T2, T3, Observable<R>> { t1, t2, t3 -> asyncCombineFunc(t1, t2, t3) } | |
| ).flatMap { it } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun <T1, T2, R> asyncZip(source1: Single<T1>, | |
| source2: Single<T2>, | |
| zipper: (T1, T2) -> Single<R>): Single<R> = | |
| Single.zip( | |
| source1, source2, | |
| io.reactivex.functions.BiFunction<T1, T2, Single<R>> { t1, t2 -> zipper(t1, t2) } | |
| ).flatMap { it } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io.reactivex.Observable | |
| import okhttp3.* | |
| import okio.ByteString | |
| fun OkHttpClient.newWebSocketObservable(serverUrl: String): Observable<WebSocketEvent> { | |
| val request = Request.Builder().url(serverUrl).build() | |
| return newWebSocketObservable(request) | |
| } | |
| fun OkHttpClient.newWebSocketObservable(request: Request): Observable<WebSocketEvent> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun <T> Observable<T>.throttleMatchingItems( | |
| windowDuration: Long, | |
| unit: TimeUnit, | |
| predicate: (T) -> Boolean | |
| ): Observable<T> { | |
| return this.compose { stream -> | |
| val throttledItems = stream | |
| .filter(predicate) | |
| .throttleFirst(windowDuration, unit) | |
| val allOtherItems = stream.filter { !predicate(it) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Filters items emitted by an observable by only emitting those that satisfy the specified | |
| * predicate based on the latest and previous items emitted. | |
| * Note that this will always filter out the first item of the stream since in this case there | |
| * is as of yet no previous item to compare it to. | |
| * | |
| * @param bipredicate | |
| * a function that evaluates the current and previous item emitted by the source ObservableSource, returning {@code true} | |
| * if it passes the filter | |
| * @return an Observable that emits only those items emitted by the source ObservableSource that the filter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Find all instances of given substring in this string. | |
| * Results are in the form of a list of index pairs (start and end index of that particular match). | |
| */ | |
| fun String.findAllInstancesOf( | |
| subString: String, | |
| startIndex: Int = 0 | |
| ): List<Pair<Int, Int>> { | |
| val index = this.indexOf(subString, startIndex) | |
| if (index == -1) return emptyList() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * E.g. | |
| * cartesianProduct(listOf(1, 2, 3), listOf(true, false)) returns | |
| * [(1, true), (1, false), (2, true), (2, false), (3, true), (3, false)] | |
| */ | |
| fun <T, U> cartesianProduct(c1: Collection<T>, c2: Collection<U>): List<Pair<T, U>> { | |
| return c1.flatMap { lhsElem -> c2.map { rhsElem -> lhsElem to rhsElem } } | |
| } |