@@ -33,11 +33,13 @@ import eu.kanade.tachiyomi.ui.source.filter.TriStateSectionItem
33
33
import eu.kanade.tachiyomi.util.lang.launchIO
34
34
import eu.kanade.tachiyomi.util.lang.launchUI
35
35
import eu.kanade.tachiyomi.util.removeCovers
36
+ import eu.kanade.tachiyomi.util.system.withUIContext
36
37
import exh.isEhBasedSource
37
38
import exh.savedsearches.EXHSavedSearch
38
39
import exh.savedsearches.JsonSavedSearch
39
40
import java.lang.RuntimeException
40
41
import java.util.Date
42
+ import kotlinx.coroutines.Job
41
43
import kotlinx.coroutines.flow.MutableStateFlow
42
44
import kotlinx.coroutines.flow.asFlow
43
45
import kotlinx.coroutines.flow.catch
@@ -49,7 +51,6 @@ import kotlinx.serialization.decodeFromString
49
51
import kotlinx.serialization.json.Json
50
52
import kotlinx.serialization.json.buildJsonObject
51
53
import kotlinx.serialization.json.put
52
- import rx.Observable
53
54
import rx.Subscription
54
55
import rx.android.schedulers.AndroidSchedulers
55
56
import rx.schedulers.Schedulers
@@ -113,6 +114,7 @@ open class BrowseSourcePresenter(
113
114
* Subscription for the pager.
114
115
*/
115
116
private var pagerSubscription: Subscription ? = null
117
+ private var nextPageJob: Job ? = null
116
118
117
119
/* *
118
120
* Subscription for one request from the pager.
@@ -184,14 +186,16 @@ open class BrowseSourcePresenter(
184
186
fun requestNext () {
185
187
if (! hasNextPage()) return
186
188
187
- pageSubscription?.let { remove(it) }
188
- pageSubscription = Observable .defer { pager.requestNext() }
189
- .subscribeFirst(
190
- { _, _ ->
191
- // Nothing to do when onNext is emitted.
192
- },
193
- BrowseSourceController ::onAddPageError
194
- )
189
+ nextPageJob?.cancel()
190
+ nextPageJob = launchIO {
191
+ try {
192
+ pager.requestNextPage()
193
+ } catch (e: Throwable ) {
194
+ withUIContext {
195
+ view().subscribe { view -> view?.onAddPageError(e) }
196
+ }
197
+ }
198
+ }
195
199
}
196
200
197
201
/* *
0 commit comments