This file contains 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
package ornoyman.com.colorbardrawable; | |
import android.graphics.Canvas; | |
import android.graphics.ColorFilter; | |
import android.graphics.Paint; | |
import android.graphics.PixelFormat; | |
import android.graphics.Rect; | |
import android.graphics.drawable.Drawable; | |
import android.support.annotation.IntRange; | |
import android.support.annotation.NonNull; |
This file contains 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
package android.graphics.drawable; | |
/* | |
* Copyright (C) 2008 The Android Open Source Project | |
* | |
* 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 |
This file contains 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
@file:JvmName("RecyclerViewUtils") | |
package com.ornoyman.core.ui.recyclerview | |
import android.support.v7.widget.RecyclerView | |
import io.reactivex.functions.Action | |
/** | |
* Allows safely updating the backing data and notifying recycler view. | |
* If adapter is currently in lockdown state, will post update action to avoid illegal state error. |
This file contains 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 io.reactivex.Single | |
import io.reactivex.schedulers.Schedulers | |
import java.util.* | |
fun <T> flatMapUntil_deferred_rec(seedState: T, flat: (T) -> Single<T>, until: (T) -> Boolean): Observable<T> { | |
fun flatMapUntil_rec(state: T): Observable<T> = | |
if (until(state)) Observable.empty() | |
else flat(state).flatMapObservable { next -> Observable.just(next).concatWith(flatMapUntil_deferred_rec(next)) } | |
return flatMapUntil_rec(seedState).replay().refCount() |
This file contains 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
private fun Context?.findActivity_iter(): Activity? { | |
var context = this | |
while (context is ContextWrapper) { | |
if (context is Activity) { | |
return context | |
} | |
context = context.baseContext | |
} | |
return null | |
} |
This file contains 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 verify(driver: TestDriver) { | |
// a switch case fallthrough-like recursive flow | |
tailrec fun verify(verification: Verification) { | |
when (verification) { | |
NO_VERIFICATION -> return // THE END | |
VERIFY_PHASE_1 -> verifyPhase1(driver) | |
VERIFY_PHASE_2 -> verifyPhase2(driver) | |
VERIFY_PHASE_3 -> verifyPhase3(driver) | |
VERIFY_PHASE_4 -> verifyPhase4(driver) | |
} |
This file contains 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
private fun prefetchData(): Completable = | |
Completable.mergeArray( | |
async1().concatWith(async2()).concatWith(async3().mergeWith(async4())), | |
async1().concatWith(async5()), | |
async6().concatWith(async7())) | |
fun async1(): Completable { TODO("not implemented") } | |
fun async2(): Completable { TODO("not implemented") } | |
fun async3(): Completable { TODO("not implemented") } | |
fun async4(): Completable { TODO("not implemented") } |
This file contains 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
class DebugCallAdapterFactory(private val callAdapterFactories: List<CallAdapter.Factory>) : CallAdapter.Factory() { | |
override fun get(returnType: Type, annotations: Array<Annotation>, retrofit: Retrofit): CallAdapter<out Any, out Any>? = | |
callAdapterFactories.asSequence() | |
.map { it.get(returnType, annotations, retrofit) } | |
.filterNotNull().firstOrNull()?.let { WrappingCallAdapter(it, retrofit) } | |
} | |
private class WrappingCallAdapter<R, T>(private val adapter: CallAdapter<R, T>, | |
private val retrofit: Retrofit) : CallAdapter<R, T> by adapter { |
This file contains 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
class RxErrorHandlingCallAdapterFactory private constructor(private val original: RxJava2CallAdapterFactory) : CallAdapter.Factory() { | |
override fun get(returnType: Type, annotations: Array<Annotation>, retrofit: Retrofit): CallAdapter<*, *>? = | |
original.get(returnType, annotations, retrofit)?.let { | |
RxCallAdapterWrapper(it as CallAdapter<Any, Any>) | |
} | |
private class RxCallAdapterWrapper(private val wrapped: CallAdapter<Any, Any>) : CallAdapter<Any, Any> by wrapped { | |
override fun adapt(call: Call<Any>): Any { |
This file contains 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
inline fun <reified T : Any> generate(): T = T::class.generate() | |
fun <T : Any> KClass<T>.generate(): T = | |
when { | |
isData -> generateDataClass() | |
isTopLevelAutoValue -> generateTopLevelAutoValue() | |
isNestedAutoValue -> generateNestedAutoValue() | |
java.isEnum -> java.enumConstants.first() | |
else -> doGenerate() as T | |
} |
OlderNewer