mirror of
https://github.com/mediathekview/zapp.git
synced 2024-09-20 04:12:14 +02:00
Display error message when refreshing fails
This commit is contained in:
parent
6c9828392d
commit
1fe22d5f81
@ -4,8 +4,8 @@ import androidx.paging.PagingSource
|
||||
import androidx.paging.PagingState
|
||||
import de.christinecoenen.code.zapp.app.mediathek.api.request.QueryRequest
|
||||
import de.christinecoenen.code.zapp.models.shows.MediathekShow
|
||||
import kotlinx.coroutines.delay
|
||||
import retrofit2.HttpException
|
||||
import timber.log.Timber
|
||||
import java.io.IOException
|
||||
|
||||
class MediathekPagingSource(
|
||||
@ -39,8 +39,6 @@ class MediathekPagingSource(
|
||||
val showList = response.result?.results ?: throw Error(response.err)
|
||||
val nextKey = if (showList.isEmpty()) null else nextPageNumber.plus(1)
|
||||
|
||||
delay(2000)
|
||||
|
||||
LoadResult.Page(
|
||||
data = showList,
|
||||
prevKey = null, // Only paging forward.
|
||||
@ -48,9 +46,11 @@ class MediathekPagingSource(
|
||||
)
|
||||
} catch (e: IOException) {
|
||||
// IOException for network failures.
|
||||
Timber.e(e)
|
||||
return LoadResult.Error(e)
|
||||
} catch (e: HttpException) {
|
||||
// HttpException for any non-2xx HTTP status codes.
|
||||
Timber.e(e)
|
||||
return LoadResult.Error(e)
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,7 @@ import de.christinecoenen.code.zapp.app.mediathek.ui.list.adapter.MediathekItemA
|
||||
import de.christinecoenen.code.zapp.app.mediathek.ui.list.adapter.MediathekShowComparator
|
||||
import de.christinecoenen.code.zapp.databinding.FragmentMediathekListBinding
|
||||
import de.christinecoenen.code.zapp.models.shows.MediathekShow
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.distinctUntilChangedBy
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import timber.log.Timber
|
||||
@ -118,18 +116,17 @@ class MediathekListFragment : Fragment(), ListItemListener, OnRefreshListener {
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
adapter.loadStateFlow
|
||||
.drop(1)
|
||||
.distinctUntilChangedBy { it.refresh }
|
||||
.collectLatest { loadStates ->
|
||||
binding.refreshLayout.isRefreshing = loadStates.refresh is LoadState.Loading
|
||||
updateNoShowsMessage(loadStates.refresh)
|
||||
.map { it.refresh }
|
||||
.distinctUntilChanged()
|
||||
.collectLatest { refreshState ->
|
||||
binding.refreshLayout.isRefreshing = refreshState is LoadState.Loading
|
||||
binding.error.isVisible = refreshState is LoadState.Error
|
||||
updateNoShowsMessage(refreshState)
|
||||
|
||||
when (loadStates.refresh) {
|
||||
is LoadState.Error -> {
|
||||
// TODO: display errors for refresh actions
|
||||
}
|
||||
when (refreshState) {
|
||||
is LoadState.Error -> onMediathekLoadErrorChanged(refreshState.error)
|
||||
is LoadState.NotLoading -> binding.list.scrollToPosition(0)
|
||||
is LoadState.Loading -> {
|
||||
}
|
||||
is LoadState.Loading -> Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -217,14 +214,7 @@ class MediathekListFragment : Fragment(), ListItemListener, OnRefreshListener {
|
||||
requireActivity().invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
private fun onMediathekLoadErrorChanged(e: Throwable?) {
|
||||
if (e == null) {
|
||||
binding.error.visibility = View.GONE
|
||||
return
|
||||
}
|
||||
|
||||
Timber.e(e)
|
||||
|
||||
private fun onMediathekLoadErrorChanged(e: Throwable) {
|
||||
if (e is SSLHandshakeException || e is UnknownServiceException) {
|
||||
showError(R.string.error_mediathek_ssl_error)
|
||||
} else {
|
||||
|
@ -10,6 +10,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="48dp"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
@ -60,7 +61,9 @@
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/refresh_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/error">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
|
Loading…
Reference in New Issue
Block a user