Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup"
android:layout_width="match_parent"
// RecyclerView Adapter implemented as ListAdapter and DiffCallback
class Mydapter(
private val clickListener: (String) -> Unit
) :
ListAdapter<MyUiModel, MyViewHolder>(MyDiffCallback()) {
override fun onCreateViewHolder(
parent: ViewGroup,
position: Int
@jshvarts
jshvarts / DaggerParentChildExample.kt
Created October 14, 2020 16:02 — forked from arkivanov/DaggerParentChildExample.kt
Dagger parent-child example
// Deps
interface Database
interface Network
// Child
interface ChildRepository
class Child(dependencies: Dependencies) {
// In ViewModel:
private val error = ConflatedBroadcastChannel<ErrorType>()
fun errorEffect(): Flow<ErrorType> = error.asFlow()
val errorType = if (connectionHelper.isConnected()) {
ErrorType.GENERIC
} else {
ErrorType.CONNECTION
fun logCoroutine(message: String) = "[${Thread.currentThread().name}] $message"
// call with
Timber.d(logCoroutine("Initial coroutine launched"))
fun logCoroutine(message: String, coroutineContext: CoroutineContext) {
println("coroutine is executing on thread : ${Thread.currentThread().name} : $message : $coroutineContext")
}
fun logCoroutine(message: String) {
println("coroutineå is executing on thread : ${Thread.currentThread().name}: $message")
}
@jshvarts
jshvarts / .java
Last active October 13, 2019 19:50
Basic subscribeOn and observeOn case
Observable.just("long", "longer", "longest")
.subscribeOn(Schedulers.io())
.map(String::length)
.observeOn(Schedulers.computation())
.filter { it > 6 }
.subscribe { length -> println("item length $length") }
}
@jshvarts
jshvarts / .java
Created October 13, 2019 19:33
Default RxJava threading
Observable.just("long", "longer", "longest")
.map(String::length)
.filter { it > 6 }
.subscribe { length -> println("item length $length") }
apply plugin: 'androidx.navigation.safeargs.kotlin'