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
/** | |
* Custom implementation of the Either monad. | |
* | |
* @param F Type of a Left (Failure) | |
* @param S Type of a Right (Success) | |
*/ | |
sealed class Either<out F, out S> { | |
data class Left<out F>(val left: F) : Either<F, 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
import java.io.ByteArrayOutputStream | |
fun runCommand(command: String): String { | |
return runCatching { | |
val stdout = ByteArrayOutputStream() | |
exec { | |
commandLine(*command.split(' ').toTypedArray()) | |
standardOutput = stdout | |
} |
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 refreshUi(refresh: UiStateType.() -> UiStateType) { | |
val newState = uiState.run(refresh) | |
check(!(newState === uiState)) { "BaseUiState is the same object. Use .copy" } | |
_uiStateLiveData.value = newState | |
} |
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 Project.setupAsKotlinLibrary() { | |
println("\tKotlin library") | |
apply(plugin = "kotlin") | |
} |
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 Project.setupAsAndroidLibrary() { | |
println("\tAndroid Library") | |
apply(plugin = "com.android.library") | |
apply(plugin = "org.jetbrains.kotlin.android") | |
apply(plugin = "org.jetbrains.kotlin.android.extensions") | |
apply(plugin = "org.jetbrains.kotlin.kapt") | |
configure<com.android.build.gradle.LibraryExtension> { | |
compileOptions { |
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
plugins { | |
`kotlin-dsl` | |
} | |
buildscript { | |
repositories { | |
google() | |
jcenter() | |
} | |
dependencies { |
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.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion | |
dependencies { | |
implementation("org.jetbrains.kotlin:kotlin-stdlib:${getKotlinPluginVersion()}") | |
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5") | |
implementation("com.jakewharton.threetenabp:threetenabp:1.2.3") | |
implementation("com.squareup.okhttp3:okhttp:4.5.0") | |
testImplementation("junit:junit:4.13") | |
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.5") |
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 val viewModelClass = | |
(javaClass | |
.genericSuperclass as ParameterizedType) | |
.actualTypeArguments[0] as Class<ViewModelType> | |
val viewModel: ViewModelType by lazy { getViewModel(clazz = viewModelClass.kotlin) } |
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 MainDispatcher: CoroutineDispatcher() { | |
override fun dispatch(context: CoroutineContext, block: Runnable) { | |
dispatch_async(dispatch_get_main_queue()) { block.run() } // This line gets highlighted when the error happens | |
} | |
} | |
internal class MainScope: CoroutineScope { | |
private val dispatcher = MainDispatcher() | |
private val job = Job() |
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.ktor.client.HttpClient | |
import io.ktor.client.features.json.JsonFeature | |
import io.ktor.client.features.json.serializer.KotlinxSerializer | |
import io.ktor.client.request.get | |
import io.ktor.client.request.parameter | |
import io.ktor.client.statement.HttpResponse | |
import io.ktor.client.statement.readText | |
import io.ktor.http.URLProtocol.Companion.HTTPS | |
import kotlinx.coroutines.GlobalScope | |
import kotlinx.coroutines.launch |
NewerOlder