mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-03 14:00:32 +00:00
Show snackbar with feed loading errors
This commit is contained in:
parent
604419dd1f
commit
6b3a178f2a
@ -60,6 +60,7 @@ import org.schabi.newpipe.database.feed.model.FeedGroupEntity
|
|||||||
import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
import org.schabi.newpipe.database.subscription.SubscriptionEntity
|
||||||
import org.schabi.newpipe.databinding.FragmentFeedBinding
|
import org.schabi.newpipe.databinding.FragmentFeedBinding
|
||||||
import org.schabi.newpipe.error.ErrorInfo
|
import org.schabi.newpipe.error.ErrorInfo
|
||||||
|
import org.schabi.newpipe.error.ErrorUtil
|
||||||
import org.schabi.newpipe.error.UserAction
|
import org.schabi.newpipe.error.UserAction
|
||||||
import org.schabi.newpipe.extractor.exceptions.AccountTerminatedException
|
import org.schabi.newpipe.extractor.exceptions.AccountTerminatedException
|
||||||
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
|
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException
|
||||||
@ -453,24 +454,33 @@ class FeedFragment : BaseStateFragment<FeedState>() {
|
|||||||
if (t is FeedLoadService.RequestException &&
|
if (t is FeedLoadService.RequestException &&
|
||||||
t.cause is ContentNotAvailableException
|
t.cause is ContentNotAvailableException
|
||||||
) {
|
) {
|
||||||
Single.fromCallable {
|
disposables.add(
|
||||||
NewPipeDatabase.getInstance(requireContext()).subscriptionDAO()
|
Single.fromCallable {
|
||||||
.getSubscription(t.subscriptionId)
|
NewPipeDatabase.getInstance(requireContext()).subscriptionDAO()
|
||||||
}.subscribeOn(Schedulers.io())
|
.getSubscription(t.subscriptionId)
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
}
|
||||||
.subscribe(
|
.subscribeOn(Schedulers.io())
|
||||||
{ subscriptionEntity ->
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
handleFeedNotAvailable(
|
.subscribe(
|
||||||
subscriptionEntity,
|
{ subscriptionEntity ->
|
||||||
t.cause,
|
handleFeedNotAvailable(
|
||||||
errors.subList(i + 1, errors.size)
|
subscriptionEntity,
|
||||||
)
|
t.cause,
|
||||||
},
|
errors.subList(i + 1, errors.size)
|
||||||
{ throwable -> Log.e(TAG, "Unable to process", throwable) }
|
)
|
||||||
)
|
},
|
||||||
return // this will be called on the remaining errors by handleFeedNotAvailable()
|
{ throwable -> Log.e(TAG, "Unable to process", throwable) }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
// this will be called on the remaining errors by handleFeedNotAvailable()
|
||||||
|
return@handleItemsErrors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (errors.isNotEmpty()) {
|
||||||
|
// if no error was a ContentNotAvailableException, show a general error snackbar
|
||||||
|
ErrorUtil.showSnackbar(this, ErrorInfo(errors, UserAction.REQUESTED_FEED, ""))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleFeedNotAvailable(
|
private fun handleFeedNotAvailable(
|
||||||
|
@ -13,9 +13,9 @@ sealed class FeedState {
|
|||||||
|
|
||||||
data class LoadedState(
|
data class LoadedState(
|
||||||
val items: List<StreamItem>,
|
val items: List<StreamItem>,
|
||||||
val oldestUpdate: OffsetDateTime? = null,
|
val oldestUpdate: OffsetDateTime?,
|
||||||
val notLoadedCount: Long,
|
val notLoadedCount: Long,
|
||||||
val itemsErrors: List<Throwable> = emptyList()
|
val itemsErrors: List<Throwable>
|
||||||
) : FeedState()
|
) : FeedState()
|
||||||
|
|
||||||
data class ErrorState(
|
data class ErrorState(
|
||||||
|
@ -86,7 +86,7 @@ class FeedViewModel(
|
|||||||
.subscribe { (event, listFromDB, notLoadedCount, oldestUpdate) ->
|
.subscribe { (event, listFromDB, notLoadedCount, oldestUpdate) ->
|
||||||
mutableStateLiveData.postValue(
|
mutableStateLiveData.postValue(
|
||||||
when (event) {
|
when (event) {
|
||||||
is IdleEvent -> FeedState.LoadedState(listFromDB.map { e -> StreamItem(e) }, oldestUpdate, notLoadedCount)
|
is IdleEvent -> FeedState.LoadedState(listFromDB.map { e -> StreamItem(e) }, oldestUpdate, notLoadedCount, listOf())
|
||||||
is ProgressEvent -> FeedState.ProgressState(event.currentProgress, event.maxProgress, event.progressMessage)
|
is ProgressEvent -> FeedState.ProgressState(event.currentProgress, event.maxProgress, event.progressMessage)
|
||||||
is SuccessResultEvent -> FeedState.LoadedState(listFromDB.map { e -> StreamItem(e) }, oldestUpdate, notLoadedCount, event.itemsErrors)
|
is SuccessResultEvent -> FeedState.LoadedState(listFromDB.map { e -> StreamItem(e) }, oldestUpdate, notLoadedCount, event.itemsErrors)
|
||||||
is ErrorResultEvent -> FeedState.ErrorState(event.error)
|
is ErrorResultEvent -> FeedState.ErrorState(event.error)
|
||||||
|
Loading…
Reference in New Issue
Block a user