Skip to content

Instantly share code, notes, and snippets.

// Enable inline classes
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions.freeCompilerArgs += ["-XXLanguage:+InlineClasses"]
}
import android.arch.lifecycle.LiveData
import android.arch.lifecycle.MutableLiveData
import android.arch.paging.PageKeyedDataSource
import android.arch.paging.PagedList
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.GlobalScope
import kotlinx.coroutines.experimental.android.Main
import kotlinx.coroutines.experimental.launch
import us.kostenko.architecturecomponentstmdb.details.model.Movie
import us.kostenko.architecturecomponentstmdb.details.repository.persistance.MovieDao
@oligazar
oligazar / ViewModelFactory.kt
Last active September 21, 2018 22:15
1#. ViewModelFactory
inline fun <VM : ViewModel> viewModelFactory(crossinline f: () -> VM) =
object : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(aClass: Class<T>):T = f() as T
}
// Usage
private val viewModel by lazy {
val factory = viewModelFactory { component.myViewModel() }
ViewModelProviders.of(this, factory)
package us.kostenko.architecturecomponentstmdb.details.viewmodel.netres
import retrofit2.Response
import timber.log.Timber
import java.util.regex.Pattern
/**
* Common class used by API responses.
* @param <T> the type of the response object
</T> */
package com.android.example.github.util
import android.arch.lifecycle.LiveData
import com.android.example.github.api.ApiResponse
import retrofit2.Call
import retrofit2.CallAdapter
import retrofit2.Callback
import retrofit2.Response
import java.lang.reflect.Type
import java.util.concurrent.atomic.AtomicBoolean
/**
* Lives in debug build variant
*/
object MyTimberImplementation: TimberLog {
override fun init() {
Timber.plant(object: Timber.DebugTree() {
override fun createStackElementTag(element: StackTraceElement): String? {
return String.format("(%s:%s)",
super.createStackElementTag(element),
@oligazar
oligazar / DaoQueriesExample.kt
Last active September 26, 2018 03:37
1. TypeConverters 2. DaoQueriesExamples Android Architecture Components: Room — Relationships https://android.jlelse.eu/android-architecture-components-room-relationships-bf473510c14a Defining data using Room entities https://developer.android.com/
@Dao
public abstract class ProductDao {
@Insert
public abstract void insert(Product product);
@Delete
public abstract void delete(Product product);
@Transaction
public void insertAndDeleteInTransaction(Product newProduct, Product oldProduct) {
Unit Testing of Cloud Functions
https://firebase.google.com/docs/functions/unit-testing
Using Firebase Test Lab to Improve the Quality of your Mobile Apps
https://codelabs.developers.google.com/codelabs/firebase-test-lab/index.html?index=..%2F..%2Findex#0
Recognize text in images with ML Kit for Firebase
https://codelabs.developers.google.com/codelabs/mlkit-android/index.html?index=..%2F..%2Findex#0
@oligazar
oligazar / CoroutinesInPractice.kt
Last active November 11, 2018 05:02
1#. Error handling with coroutines 2#. Suspending functions best practice: suspending functions do not block 3#. Testing problems 4#. Liks 5#. Coroutines in practice hint: \!h - highlites the line
import android.location.Location
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.Job
import kotlinx.coroutines.experimental.android.Main
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.SendChannel
import kotlinx.coroutines.experimental.coroutineScope
import kotlinx.coroutines.experimental.launch
package ru.kometa.app.ticket.choose.view
import android.content.Context
import android.os.Bundle
import android.support.v4.view.ViewCompat
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import io.reactivex.disposables.CompositeDisposable