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
//build.gradle for "server" module | |
buildscript { | |
repositories { | |
maven { | |
url "https://plugins.gradle.org/m2/" | |
} | |
} | |
} |
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
/** | |
* A reactive map implementation that allows you to observe a key and its value. | |
*/ | |
class RxMap<K, V>( | |
private val map: AbstractMap<K, V> = HashMap(), | |
private val rxMap: AbstractMap<K, Relay<V, V>> = HashMap() | |
) : Map<K, V> { | |
/** | |
* @return a hot observable that emits the value for the specified key. When you subscribe, |
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
public final class ControllerChangeEvent { | |
@Nullable final Controller to; | |
@Nullable final Controller from; | |
final boolean isPush; | |
@Nullable final ViewGroup container; | |
@Nullable final ControllerChangeHandler handler; | |
final boolean isComplete; | |
@Override |
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
/** | |
* Observe the activity events! | |
*/ | |
class RxActivityDelegate : RxActivity { | |
private val relay = BehaviorRelay.create<ActivityLifecycleEvent>().toSerialized() | |
fun onCreate() { | |
relay.call(CREATE) | |
log("onCreate") |
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
/** | |
* Handles checking when data should be considered stale, and invokes a function to refresh data. | |
* | |
*/ | |
@DataScope class StaleDataObservatory( | |
/** | |
* Duration the data is considered "fresh" | |
*/ | |
syncInterval: Long, |
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 <T, R> Observable<T>.scanMap(func2: (T?, T) -> R): Observable<R> { | |
return this.startWith(null as T?) //emit a null value first, otherwise the .buffer() below won't emit at first (needs 2 emissions to emit) | |
.buffer(2, 1) //buffer the previous and current emission | |
.filter { it.size >= 2 } | |
.map { func2.invoke(it[0], it[1]) } | |
} | |
fun <T, R> Observable<T>.scanMap(initialValue: T, func2: (T, T) -> R): Observable<R> { | |
return this.startWith(initialValue) //use initially provided value instead of null | |
.buffer(2, 1) |
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 android.animation.Animator | |
import android.animation.AnimatorListenerAdapter | |
import android.content.Context | |
import android.view.View | |
import android.view.ViewGroup | |
/** | |
* Animates a view between its states. | |
* | |
* Currently only supports crossfading. |
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
@Test | |
fun testClear() { | |
clickNumber(1) | |
clickNumber(2) | |
clickNumber(3) | |
state.assertValue(123) | |
longPressClear() | |
state.assertValue(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
/** | |
* The user interface for dealing cards. | |
* | |
* @see DealCardsActivity | |
*/ | |
interface DealCardsUi : StateRenderer<DealCardsUi.State> { | |
val state: State | |
override fun render(state: State) |
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 TemporalCoupling { | |
fun incorrectUsageOfBadApi() { | |
val badApi: BadApi = BadApi() | |
badApi.username = "Zak" | |
badApi.password = "temporalCouplingIsBad_123" | |
badApi.login() //throws an NullPointerException | |
} |