Skip to content

Instantly share code, notes, and snippets.

View Diolor's full-sized avatar

Dionysis Lorentzos Diolor

View GitHub Profile
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(...)
/**
* 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 {
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()
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())
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())
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()),
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())
) { _, _ ->
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),
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())
)
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 {