Skip to content

Instantly share code, notes, and snippets.

import android.util.Log
import com.google.gson.Gson
import io.reactivex.Completable
import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.Single
const val TAG = "MyAppRx"
fun Completable.logEvents(hint: String? = null): Completable = this
@tomkoptel
tomkoptel / dashboar.json
Last active March 28, 2020 11:52
Sample Dashboard
{
"frameworks": [
{
"startDate": 1585388826446,
"endDate": 1585388826446,
"active": true,
"name": "Android"
},
{
"startDate": 1585388826446,
@tomkoptel
tomkoptel / RestApi.md
Last active April 15, 2019 12:41
Retrofit 2.0 converter for plain/text requests
  interface RestApi {
      @Multipart
      @Headers({"Accept:text/plain"})
      @POST(value = "/j_spring_security_check")
      Call<com.squareup.okhttp.Response> authenticate(
        @Part(value = "username") String username,
        @Part(value = "password") String password
        @PartMap Map<String, String> params);
 }
@tomkoptel
tomkoptel / AndroidTestOrchestrator.java
Created April 23, 2018 12:38
Extracted AndroidTestOrchestrator class from orchestrator-1.0.2-beta1.apk
package android.support.test.orchestrator;
import android.app.Instrumentation;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build.VERSION;
import android.os.Bundle;
@tomkoptel
tomkoptel / SugarVariantOutputDSL.kt
Last active April 22, 2018 18:01
Helper functions that introduce some sugar DSL around TestVariant and ApkVariantOutput instances.
/**
* Yields all available variants of type [TestVariant].
*/
internal fun DomainObjectCollection<out BaseVariant>.forEachTestVariant(block: (TestVariant) -> Unit) {
all { variant ->
when (variant) {
is ApplicationVariant -> variant.testVariant?.let(block)
is TestVariant -> block(variant)
is LibraryVariant -> variant.testVariant?.let(block)
}
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.InputFile
import java.io.File
/**
* Make sure the task is open. Otherwise the plugin will fail with exception:
* org.gradle.api.GradleException: Could not generate a proxy class for class com.sample.coolplugin.CoolTask.
*/
open class CoolTask : DefaultTask() {
// Represents path to the instrumentation task that get generated for the tests
package com.sample.coolplugin
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
class CoolPlugin : Plugin<Project> {
override fun apply(project: Project) {
validateAndroidPluginVersion3or31("Version of Android plugin should be >= 3.0")
@tomkoptel
tomkoptel / ListVariantsAndroidPlugin.kt
Created April 22, 2018 13:20
A shortcut API to list Android Gradle variants.
/**
* Returns the collection of Android variants on the basis of applied plugin. If the Android plugins are missing we
* are throwing build error.
*/
internal fun Project.getAndroidVariantsOrThrow(errorMessage: String): DomainObjectCollection<out BaseVariant> {
return when {
this.plugins.hasPlugin("com.android.application") -> {
val ext = project.extensions.findByType(AppExtension::class.java)
ext!!.applicationVariants
}
@tomkoptel
tomkoptel / ValidateAndroidPlugin.kt
Last active April 22, 2018 13:15
A shortcut API to validate Android Gradle plugin version validity.
package com.sample.coolplugin
import org.gradle.api.Plugin
import org.gradle.api.Project
/**
* Verifies if the plugin supports Android Gradle plugin of version 3.0 or 3.1.
*/
internal fun Plugin<Project>.validateAndroidPluginVersion3or31(errorMessage: String) {
var gradlePluginVersion: String? = null
@tomkoptel
tomkoptel / CoroutinesProvider.kt
Last active April 18, 2018 16:13
Wrapper factory API with a purpose to create a single entry point hook to later delegate Job instances.
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.CoroutineStart
import kotlinx.coroutines.experimental.DefaultDispatcher
import kotlinx.coroutines.experimental.Job
import kotlin.coroutines.experimental.CoroutineContext
import kotlinx.coroutines.experimental.launch as coroutineLaunch
/**
* Acts as dependency provider. Later used in the test env to provide suspendable UI tests.
*/