Skip to content

Instantly share code, notes, and snippets.

Avatar

Dionysis Lorentzos Diolor

View GitHub Profile
View JobsListAdapter2.kt
class JobsListAdapter : ListAdapter<JobListItem, JobViewHolder>() {
override fun getItemViewType(position: Int): Int {
return getItem(position).ordinal()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): JobViewHolder {
return when (viewType) {
Header.ordinal() -> HeaderViewHolder(...)
JobItem.ordinal() -> JobViewHolder(...)
View Adapter.kt
/**
* ListAdapter is a superclass of RecyclerView.Adapter.
* Check the d.android.com for more.
*/
class JobsAdapter : ListAdapter<JobListItem, JobViewHolder>() {
}
// items of 2 types
sealed class JobListItem {
View replayRefCountObserveOn.kt
fun printCurrentThread(tag: String) = println("$tag: ${Thread.currentThread().name.substringBefore("-")}")
fun main(args: Array<String>) {
printCurrentThread("main thread name")
val subject = BehaviorSubject.create(Unit)
val connectable = subject
.observeOn(io())
.replay().refCount()
View replayRefCountSubscribeOn.kt
fun printCurrentThread(tag: String) = println("$tag: ${Thread.currentThread().name.substringBefore("-")}")
fun main(args: Array<String>) {
printCurrentThread("main thread name")
val connectable = just(Unit)
.replay().refCount()
connectable
.subscribeOn(newThread())
View replayRefCount.kt
fun printCurrentThread(tag: String) = println("$tag: ${Thread.currentThread().name.substringBefore("-")}")
fun main(args: Array<String>) {
printCurrentThread("main thread name")
val connectable = just(Unit)
.replay().refCount()
connectable
.subscribeOn(computation())
View combineLatestAdvanced.kt
fun printCurrentThread(tag: String) = println("$tag: ${Thread.currentThread().name.substringBefore("-")}")
fun main(args: Array<String>) {
printCurrentThread("main thread name")
val subject = BehaviorSubject.create(Unit)
Observable
.combineLatest(
subject.subscribeOn(io()),
View combineLatest.kt
fun printCurrentThread(tag: String) = println("$tag: ${Thread.currentThread().name.substringBefore("-")}")
fun main(args: Array<String>) {
printCurrentThread("main thread name")
Observable
.combineLatest(
just(Unit).observeOn(io()),
just(Unit).observeOn(computation())
) { _, _ ->
View advancedMerge.kt
fun printCurrentThread(tag: String) = println("$tag: ${Thread.currentThread().name.substringBefore("-")}")
fun main(args: Array<String>) {
printCurrentThread("main thread name")
val subject = BehaviorSubject.create(Unit)
Observable
.merge(
just(Unit),
View merge.kt
fun printCurrentThread(tag: String) = println("$tag: ${Thread.currentThread().name.substringBefore("-")}")
fun main(args: Array<String>) {
printCurrentThread("main thread name")
Observable
.merge(
just(Unit).subscribeOn(Schedulers.computation()),
just(Unit).subscribeOn(Schedulers.io())
)
View advancedSubject.kt
fun printCurrentThread(tag: String) = println("$tag: ${Thread.currentThread().name.substringBefore("-")}")
fun main(args: Array<String>) {
printCurrentThread("main thread name")
val subject = BehaviorSubject.create(Unit)
subject
.subscribeOn(Schedulers.computation())
.subscribe {