Skip to content

Instantly share code, notes, and snippets.

View gildor's full-sized avatar

Andrey Mischenko gildor

View GitHub Profile
@gildor
gildor / OnViewWithTimeout.kt
Last active March 17, 2022 02:29
Simple implementation of Android Espresso onView with timeout
import android.view.View
import androidx.test.espresso.Espresso
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.ViewAssertion
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility
import org.hamcrest.Matcher
@gildor
gildor / BorderModifier.kt
Last active October 7, 2024 11:56
Example of border modifier for Jetpack Compose
import androidx.compose.runtime.Stable
import androidx.compose.ui.Modifier
import androidx.compose.ui.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.unit.Dp
/**
* Border definition can be extended to provide border style or [androidx.compose.ui.graphics.Brush]
@gildor
gildor / JetpackComposeScaffoldSnackbar.kt
Created August 25, 2020 07:39
Jetpack Compose Scaffold with snackbar example
package ru.gildor.compose.sandbox
import android.app.Activity
import android.util.Log
import android.view.inputmethod.InputMethodManager
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.Text
@gildor
gildor / GoogleMapsServicesCoroutineAdapter.kt
Created August 15, 2020 03:31
Kotlin coroutines adapter for google-maps-services-java (Google Maps API client)
import com.google.maps.GeoApiContext
import com.google.maps.GeocodingApi
import com.google.maps.PendingResult
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
/**
* Coroutine adapter for Google Maps API future type [PendingResult]
*
@gildor
gildor / build.gradle
Last active August 17, 2019 03:53
Assert for Gradle to check that configuration is not resolved on configuration time
def afterEvaluation = false
gradle.projectsEvaluated {
afterEvaluation = true
}
allprojects { project ->
configurations.all { configuration ->
configuration.incoming.beforeResolve {
if (!afterEvaluation) {
throw new Exception("Configuration $configuration.name of project $project.name is being resolved at configuration time.")
@gildor
gildor / build.gradle.kts
Last active January 28, 2022 12:03
Protobuf Gradle Plugin + Kotlin DSL
import com.google.protobuf.gradle.protobuf
import com.google.protobuf.gradle.protoc
plugins {
java
idea
id("com.google.protobuf") version "0.8.7"
}
repositories {
@gildor
gildor / HelloWorld.kt
Created June 5, 2018 03:45
Minimal TornadoFX setup with Gradle
//File src/main/kotlin/HelloWorld.kt
import tornadofx.*
class HelloWorld : View() {
override val root = hbox {
label("Hello world")
}
}
class MyApp : App(HelloWorld::class)
@gildor
gildor / OkHttpDownloader.kt
Last active June 19, 2021 07:35
Simple non-blocking extension function for OkHttp Call that wraps request to Kotlin Coroutine and saves response to File
import kotlinx.coroutines.experimental.*
import okhttp3.*
import okio.Buffer
import okio.Okio
import java.io.File
import java.io.IOException
/**
* Custom coroutine dispatcher for blocking calls
*/
@gildor
gildor / coroutine-delay.kt
Last active July 23, 2020 02:38
Proof of concept for Kotlin JS coroutines delay()
import kotlin.coroutines.experimental.*
import kotlin.js.Date
fun main(args: Array<String>) {
println("before launch")
launch {
println("hello: ${Date()}")
delay(3000)
println("bye: ${Date()}")
}
@gildor
gildor / RetrofitCoroutines.kt
Last active June 22, 2021 19:09
Example of usage kotlin-coroutines-retrofit with awaitResponse()
import kotlinx.coroutines.experimental.runBlocking
import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.GET
import retrofit2.http.Path
import ru.gildor.coroutines.retrofit.awaitResponse
/**
dependencies {