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
// generates callback and method to handle that callback for better Java interop | |
annotation class JvmCallback | |
@JvmCallback | |
sealed class Result { | |
data class Success(val successId: String) : Result() | |
data class Error(val exception: Exception) : Result() | |
// would be automatically generated because of JvmCallback |
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:Suppress("unused", "FunctionName", "IllegalIdentifier") | |
import android.annotation.SuppressLint | |
import android.app.Activity | |
import android.content.Context | |
import android.content.Intent | |
import android.os.Bundle | |
/** | |
* The best way to launch yourself an activity. Your implementation should enable the following api: |
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 UserRepository{ | |
// note: hot observables that do not replay missed events | |
fun logins(): Observable<User> | |
fun logouts(): Observable<Unit> | |
} | |
/** | |
* An abstract user with two implementations: | |
* "LoggedIn" and "Logged out" | |
*/ |
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 com.example.taccardi.zak; | |
import android.support.annotation.NonNull; | |
import io.reactivex.Observable; | |
/** | |
* Use this class to lock (prevent charges to it) or unlock (allow charges) a card. | |
*/ | |
interface CardLockRepository { |
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 org.junit.Test; | |
import java.util.function.Consumer; | |
/** | |
* Note: no actual assertions are done here. | |
*/ | |
public class FizzBuzzTest { | |
static void defaultPrint(BaseFizzBuzz base) { |
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 class BetterApi { | |
fun login(credentials: Credentials): LoginResponse { | |
//login... | |
TODO() | |
} | |
class LoginResponse private constructor( | |
val user: User?, |
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 | |
} |
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
@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
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. |