|
@@ -11,8 +11,6 @@ import kotlinx.coroutines.flow.drop
|
|
|
import kotlinx.coroutines.flow.launchIn
|
|
|
import kotlinx.coroutines.flow.onEach
|
|
|
import kotlinx.coroutines.flow.onStart
|
|
|
-import rx.Observable
|
|
|
-import rx.Subscription
|
|
|
import uy.kohesive.injekt.Injekt
|
|
|
import uy.kohesive.injekt.api.get
|
|
|
import java.util.TreeMap
|
|
@@ -20,9 +18,6 @@ import java.util.TreeMap
|
|
|
/**
|
|
|
* Presenter of [SourceController]
|
|
|
* Function calls should be done from here. UI calls should be done from the controller.
|
|
|
- *
|
|
|
- * @param sourceManager manages the different sources.
|
|
|
- * @param preferences application preferences.
|
|
|
*/
|
|
|
class SourcePresenter(
|
|
|
val sourceManager: SourceManager = Injekt.get(),
|
|
@@ -31,17 +26,10 @@ class SourcePresenter(
|
|
|
|
|
|
var sources = getEnabledSources()
|
|
|
|
|
|
- /**
|
|
|
- * Subscription for retrieving enabled sources.
|
|
|
- */
|
|
|
- private var sourceSubscription: Subscription? = null
|
|
|
-
|
|
|
/**
|
|
|
* Unsubscribe and create a new subscription to fetch enabled sources.
|
|
|
*/
|
|
|
private fun loadSources() {
|
|
|
- sourceSubscription?.unsubscribe()
|
|
|
-
|
|
|
val pinnedSources = mutableListOf<SourceItem>()
|
|
|
val pinnedSourceIds = preferences.pinnedSources().get()
|
|
|
|
|
@@ -53,7 +41,7 @@ class SourcePresenter(
|
|
|
else -> d1.compareTo(d2)
|
|
|
}
|
|
|
}
|
|
|
- val byLang = sources.groupByTo(map, { it.lang })
|
|
|
+ val byLang = sources.groupByTo(map) { it.lang }
|
|
|
var sourceItems = byLang.flatMap {
|
|
|
val langItem = LangItem(it.key)
|
|
|
it.value.map { source ->
|
|
@@ -70,8 +58,7 @@ class SourcePresenter(
|
|
|
sourceItems = pinnedSources + sourceItems
|
|
|
}
|
|
|
|
|
|
- sourceSubscription = Observable.just(sourceItems)
|
|
|
- .subscribeLatestCache(SourceController::setSources)
|
|
|
+ view?.setSources(sourceItems)
|
|
|
}
|
|
|
|
|
|
private fun loadLastUsedSource() {
|