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 kotlinx.coroutines.flow.Flow | |
import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.StateFlow | |
/** | |
* A variant of [StateFlow] that allows an initial state | |
*/ | |
interface NoInitialStateFlow<T> : Flow<T> { | |
/** |
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 i_love_companion_objects | |
suspend fun main() { | |
// Discoverability is easy with the companion object | |
// (although autocomplete could use some performance improvements...) | |
doStuff(SomeInterface.createWithDefaults()) | |
val someInstance: SomeInterface = SomeInterface.create( | |
parameterOne = 0, | |
parameterTwo = 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
sealed class Try<T> { | |
companion object { | |
operator fun <T> invoke(func: () -> T): Try<T> = | |
try { | |
Success(func()) | |
} catch (error: Exception) { | |
Failure(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
ext { | |
compileSDKVersionValue = 29 | |
minSDKVersionValue = 22 | |
targetSDKVersionValue = 29 | |
libraries = [ | |
cardView : 'androidx.cardview:cardview:1.0.0', | |
androidXLegacySupport : 'androidx.legacy:legacy-support-v4:1.0.0', | |
androidXAppCompat : 'androidx.appcompat:appcompat:1.1.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
@Scope | |
@Retention(AnnotationRetention.RUNTIME) | |
annotation class ActivityScope |
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
/** | |
* Let's say we want to display a list of Animals in a RecyclerView. | |
* The list can contain items of type Dog, Cat and Snake. | |
*/ | |
// AdapterDelegate for Dog. | |
fun dogAdapterDelegate(picasso : Picasso) = adapterDelegate<Dog, Animal>(R.layout.item_dog){ // Generics Types means this AdapterDelegate is used if item is instanceof Dog (whole list is List<Anmial>) | |
// this block is run once in onCreateViewHolder. Think of it as an intializer for a ViewHolder. | |
val name = findViewById(R.id.name) | |
val image = findViewById(R.id.image) |
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
open class BaseRepository{ | |
suspend fun <T : Any> safeApiCall(call: suspend () -> Response<T>, errorMessage: String): T? { | |
val result : Result<T> = safeApiResult(call,errorMessage) | |
var data : T? = null | |
when(result) { | |
is Result.Success -> | |
data = result.data |
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
sealed class Result<out T: Any> { | |
data class Success<out T : Any>(val data: T) : Result<T>() | |
data class Error(val exception: Exception) : Result<Nothing>() | |
} |
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
/** | |
* Copyright 2019 Coinbase, Inc. | |
* | |
* 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, |