Skip to content

Instantly share code, notes, and snippets.

View Diolor's full-sized avatar

Dionysis Lorentzos Diolor

View GitHub Profile
@Diolor
Diolor / BroadcastObservable.java
Last active January 13, 2021 09:26
Retry with Connection
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Looper;
import rx.Observable;
import rx.Scheduler;
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 {
@Diolor
Diolor / subject.kt
Last active December 30, 2018 17:49
Rx Puzzles
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 {
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)
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")
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
.combineLatest(
subject.subscribeOn(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)
Observable
.merge(
just(Unit),