Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created August 27, 2019 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BetterProgramming/84e8f934896d52172ca7dd623abf0322 to your computer and use it in GitHub Desktop.
Save BetterProgramming/84e8f934896d52172ca7dd623abf0322 to your computer and use it in GitHub Desktop.
private fun startAnimate() {
RxJavaPlugins.setErrorHandler { /*Catch InterruptedException*/ }
compositeDisposable.add(Observable
.create<Int> { emitter ->
while (true) {
if (control == 1) {
for (x in 0 until image.size) {
emitter.onNext(x)
Thread.sleep(100)
}
} else {
for (x in (image.size - 1) downTo 0) {
emitter.onNext(x)
Thread.sleep(100)
}
}
control *= -1
Thread.sleep(300)
}
}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { showImage(it) })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment