From 5f1a89df6324a617e3594320d06ec85c499e7389 Mon Sep 17 00:00:00 2001 From: len Date: Fri, 8 Jul 2016 18:23:03 +0200 Subject: [PATCH] Remove newThread usages, it probably fixes random crashes --- .../eu/kanade/tachiyomi/data/download/DownloadManager.kt | 2 +- .../eu/kanade/tachiyomi/ui/download/DownloadFragment.kt | 3 +-- .../ui/reader/viewer/pager/PagerReaderFragment.kt | 3 +-- .../main/java/eu/kanade/tachiyomi/util/RetryWithDelay.kt | 7 +++++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index ce5968bdfb..483f06ba6b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -273,7 +273,7 @@ class DownloadManager( page } // Retry 3 times, waiting 2, 4 and 8 seconds between attempts. - .retryWhen(RetryWithDelay(3, { (2 shl it - 1) * 1000 })) + .retryWhen(RetryWithDelay(3, { (2 shl it - 1) * 1000 }, Schedulers.trampoline())) } // Public method to get the image from the filesystem. It does NOT provide any way to download the image diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.kt index 31f5c74a1d..ca0b70ab75 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadFragment.kt @@ -14,7 +14,6 @@ import nucleus.factory.RequiresPresenter import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers import rx.subscriptions.CompositeSubscription import java.util.* import java.util.concurrent.TimeUnit @@ -179,7 +178,7 @@ class DownloadFragment : BaseRxFragment() { * @param download the download to observe its progress. */ private fun observeProgress(download: Download) { - val subscription = Observable.interval(50, TimeUnit.MILLISECONDS, Schedulers.newThread()) + val subscription = Observable.interval(50, TimeUnit.MILLISECONDS) // Get the sum of percentages for all the pages. .flatMap { Observable.from(download.pages) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReaderFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReaderFragment.kt index b6c04c67e7..0c172a0863 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReaderFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReaderFragment.kt @@ -21,7 +21,6 @@ import kotlinx.android.synthetic.main.item_pager_reader.* import rx.Observable import rx.Subscription import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers import rx.subjects.PublishSubject import rx.subjects.SerializedSubject import java.io.File @@ -168,7 +167,7 @@ class PagerReaderFragment : BaseFragment() { val currentValue = AtomicInteger(-1) progressSubscription?.unsubscribe() - progressSubscription = Observable.interval(100, TimeUnit.MILLISECONDS, Schedulers.newThread()) + progressSubscription = Observable.interval(100, TimeUnit.MILLISECONDS) .onBackpressureLatest() .observeOn(AndroidSchedulers.mainThread()) .subscribe { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/RetryWithDelay.kt b/app/src/main/java/eu/kanade/tachiyomi/util/RetryWithDelay.kt index 237bfcbdc1..e2ef0d2a1b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/RetryWithDelay.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/RetryWithDelay.kt @@ -1,12 +1,15 @@ package eu.kanade.tachiyomi.util import rx.Observable +import rx.Scheduler import rx.functions.Func1 +import rx.schedulers.Schedulers import java.util.concurrent.TimeUnit.MILLISECONDS class RetryWithDelay( private val maxRetries: Int = 1, - private val retryStrategy: (Int) -> Int = { 1000 } + private val retryStrategy: (Int) -> Int = { 1000 }, + private val scheduler: Scheduler = Schedulers.computation() ) : Func1, Observable<*>> { private var retryCount = 0 @@ -14,7 +17,7 @@ class RetryWithDelay( override fun call(attempts: Observable) = attempts.flatMap { error -> val count = ++retryCount if (count <= maxRetries) { - Observable.timer(retryStrategy(count).toLong(), MILLISECONDS) + Observable.timer(retryStrategy(count).toLong(), MILLISECONDS, scheduler) } else { Observable.error(error as Throwable) }