This file contains hidden or 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 <IN, OUT> Observable<IN>.filterMap(f: (IN) -> OUT?): Observable<OUT> { | |
| class Wrapper(val inner: OUT?) | |
| return this | |
| .map { Wrapper(f(it)) } | |
| .filter { it.inner != null } | |
| .map { it.inner } | |
| } | |
| private fun ResourcerManager.getScalableCBImageTask( |
This file contains hidden or 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 <IN, OUT> Observable<IN>.filterMap(f: (IN) -> OUT?): Observable<OUT> { | |
| class Wrapper(val inner: OUT?) | |
| return this | |
| .map { Wrapper(f(it)) } | |
| .filter { it.inner != null } | |
| .map { it.inner } | |
| } | |
| private fun ResourcerManager.getScalableCBImageTask( |
This file contains hidden or 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
| package com.yanbin.myapplication | |
| import android.content.Context | |
| import android.graphics.Canvas | |
| import android.graphics.Color | |
| import android.graphics.Paint | |
| import android.graphics.Rect | |
| import android.graphics.Typeface | |
| import android.text.TextPaint | |
| import android.util.AttributeSet |
This file contains hidden or 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 android.content.Context | |
| import android.content.DialogInterface | |
| import androidx.appcompat.app.AlertDialog | |
| context(Context) | |
| fun alertDialog2(execute: context(AlertDialogBuilder2) () -> Unit): AlertDialog { | |
| val builder = AlertDialogBuilder2().also(execute) | |
| return builder.build() | |
| } |
This file contains hidden or 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 android.content.Context | |
| import android.content.DialogInterface | |
| import androidx.appcompat.app.AlertDialog | |
| fun Context.alertDialog(execute: AlertDialogBuilder.() -> Unit): AlertDialog { | |
| val builder = AlertDialogBuilder() | |
| builder.execute() | |
| return builder.build(this) | |
| } |
This file contains hidden or 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
| class StreamTest { | |
| // Reactive programming is basically producer-consumer pattern | |
| @Test | |
| fun `producer consumer`() { | |
| val producer = Observable.create<Int> { emitter -> | |
| for (i in 0..5) { | |
| println("produce $i") | |
| emitter.onNext(i) | |
| } |
This file contains hidden or 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 androidx.compose.animation.core.* | |
| import androidx.compose.animation.core.rememberInfiniteTransition | |
| import androidx.compose.foundation.Canvas | |
| import androidx.compose.foundation.layout.size | |
| import androidx.compose.runtime.Composable | |
| import androidx.compose.runtime.getValue | |
| import androidx.compose.ui.Modifier | |
| import androidx.compose.ui.geometry.Offset | |
| import androidx.compose.ui.graphics.Color | |
| import androidx.compose.ui.graphics.PathEffect |
This file contains hidden or 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
| @Test | |
| fun parallelTest() { | |
| val subject = PublishSubject.create<Long>() | |
| subject.subscribe { | |
| println("subject.subscribe: ${it}, thread: ${Thread.currentThread().name}") | |
| } | |
| class ParallelSubscriber: Subscriber<Long> { | |
| override fun onSubscribe(s: Subscription) { | |
| s.request(1000) | |
| } |
This file contains hidden or 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
| class CountDown { | |
| fun execute(number: Int): Int { | |
| // (351, 2) -> 3 | |
| // (351, 1) -> 5 | |
| // (351, 0) -> 1 | |
| val digitExtractor: (Int, Int) -> Int = { number, digit -> | |
| if (number < 10 ) { | |
| number | |
| } else { |
This file contains hidden or 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
| class InMemoryNoteRepository: NoteRepository { | |
| private val notes = BehaviorSubject.createDefault(emptyList<Note>()) | |
| private val noteMap = ConcurrentHashMap<String, Note>() | |
| override fun getAllNotes(): Observable<List<Note>> = notes.hide() | |
| override fun putNote(note: Note) { | |
| noteMap[note.id] = note | |
| notes.onNext(noteMap.elements().toList()) |
NewerOlder