mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-05 06:50:31 +00:00
Extract actual feed loading code into separate method
Increase readability
This commit is contained in:
parent
5c7c382323
commit
6ab8716e69
@ -1,6 +1,7 @@
|
|||||||
package org.schabi.newpipe.local.feed.service
|
package org.schabi.newpipe.local.feed.service
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
||||||
import io.reactivex.rxjava3.core.Completable
|
import io.reactivex.rxjava3.core.Completable
|
||||||
@ -13,6 +14,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers
|
|||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
||||||
import org.schabi.newpipe.database.subscription.NotificationMode
|
import org.schabi.newpipe.database.subscription.NotificationMode
|
||||||
|
import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
||||||
import org.schabi.newpipe.extractor.Info
|
import org.schabi.newpipe.extractor.Info
|
||||||
import org.schabi.newpipe.extractor.NewPipe
|
import org.schabi.newpipe.extractor.NewPipe
|
||||||
import org.schabi.newpipe.extractor.feed.FeedInfo
|
import org.schabi.newpipe.extractor.feed.FeedInfo
|
||||||
@ -108,6 +110,38 @@ class FeedLoadManager(private val context: Context) {
|
|||||||
.runOn(Schedulers.io(), PARALLEL_EXTRACTIONS * 2)
|
.runOn(Schedulers.io(), PARALLEL_EXTRACTIONS * 2)
|
||||||
.filter { !cancelSignal.get() }
|
.filter { !cancelSignal.get() }
|
||||||
.map { subscriptionEntity ->
|
.map { subscriptionEntity ->
|
||||||
|
loadStreams(subscriptionEntity, useFeedExtractor, defaultSharedPreferences)
|
||||||
|
}
|
||||||
|
.sequential()
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.doOnNext(NotificationConsumer())
|
||||||
|
.observeOn(Schedulers.io())
|
||||||
|
.buffer(BUFFER_COUNT_BEFORE_INSERT)
|
||||||
|
.doOnNext(DatabaseConsumer())
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.toList()
|
||||||
|
.flatMap { x -> postProcessFeed().toSingleDefault(x.flatten()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun cancel() {
|
||||||
|
cancelSignal.set(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun broadcastProgress() {
|
||||||
|
FeedEventManager.postEvent(
|
||||||
|
FeedEventManager.Event.ProgressEvent(
|
||||||
|
currentProgress.get(),
|
||||||
|
maxProgress.get()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadStreams(
|
||||||
|
subscriptionEntity: SubscriptionEntity,
|
||||||
|
useFeedExtractor: Boolean,
|
||||||
|
defaultSharedPreferences: SharedPreferences
|
||||||
|
):
|
||||||
|
Notification<FeedUpdateInfo> {
|
||||||
var error: Throwable? = null
|
var error: Throwable? = null
|
||||||
val storeOriginalErrorAndRethrow = { e: Throwable ->
|
val storeOriginalErrorAndRethrow = { e: Throwable ->
|
||||||
// keep original to prevent blockingGet() from wrapping it into RuntimeException
|
// keep original to prevent blockingGet() from wrapping it into RuntimeException
|
||||||
@ -183,7 +217,7 @@ class FeedLoadManager(private val context: Context) {
|
|||||||
.filterIsInstance<StreamInfoItem>()
|
.filterIsInstance<StreamInfoItem>()
|
||||||
}
|
}
|
||||||
|
|
||||||
return@map Notification.createOnNext(
|
return Notification.createOnNext(
|
||||||
FeedUpdateInfo(
|
FeedUpdateInfo(
|
||||||
subscriptionEntity,
|
subscriptionEntity,
|
||||||
originalInfo!!,
|
originalInfo!!,
|
||||||
@ -199,32 +233,9 @@ class FeedLoadManager(private val context: Context) {
|
|||||||
// do this to prevent blockingGet() from wrapping into RuntimeException
|
// do this to prevent blockingGet() from wrapping into RuntimeException
|
||||||
error ?: e
|
error ?: e
|
||||||
)
|
)
|
||||||
return@map Notification.createOnError<FeedUpdateInfo>(wrapper)
|
return Notification.createOnError(wrapper)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sequential()
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.doOnNext(NotificationConsumer())
|
|
||||||
.observeOn(Schedulers.io())
|
|
||||||
.buffer(BUFFER_COUNT_BEFORE_INSERT)
|
|
||||||
.doOnNext(DatabaseConsumer())
|
|
||||||
.subscribeOn(Schedulers.io())
|
|
||||||
.toList()
|
|
||||||
.flatMap { x -> postProcessFeed().toSingleDefault(x.flatten()) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun cancel() {
|
|
||||||
cancelSignal.set(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun broadcastProgress() {
|
|
||||||
FeedEventManager.postEvent(
|
|
||||||
FeedEventManager.Event.ProgressEvent(
|
|
||||||
currentProgress.get(),
|
|
||||||
maxProgress.get()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep the feed and the stream tables small
|
* Keep the feed and the stream tables small
|
||||||
|
Loading…
Reference in New Issue
Block a user