Skip to content

Instantly share code, notes, and snippets.

@gastonmorixe
Created August 4, 2014 21:11
Show Gist options
  • Save gastonmorixe/ee74249fabff5ac95b16 to your computer and use it in GitHub Desktop.
Save gastonmorixe/ee74249fabff5ac95b16 to your computer and use it in GitHub Desktop.
Android + RxJava + Kotlin / Double-Click detection
val cellStream = ViewObservable.clicks(newCell, false)
val doubleClickCellStream = cellStream
?.buffer(cellStream?.debounce(200,TimeUnit.MILLISECONDS))
?.map({ list ->
println("list ${list}")
listOf(list?.first, list?.count())
})
?.filter({ list ->
val x = list?.last as Int
x >= 2
})
doubleClickCellStream
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe{ list ->
println("asdfasdf ${list}")
val cell = list?.first as TextView
val cellParent = cell.getParent() as ViewGroup
cellParent.removeView(cell)
}
@beautifulSoup
Copy link

Hello. I have a problem with this code. The Observable don't support multicast. So the item it emits can only obtained by one subscriber. In my test, the cellStream.debounce can't get any thing. So does it need to add share() just as val cellStream = ViewObservable.clicks(newCell, false).share()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment