diff --git a/app/src/main/java/de/christinecoenen/code/zapp/app/mediathek/api/MediathekPagingSource.kt b/app/src/main/java/de/christinecoenen/code/zapp/app/mediathek/api/MediathekPagingSource.kt index 0055c99a..206b9796 100644 --- a/app/src/main/java/de/christinecoenen/code/zapp/app/mediathek/api/MediathekPagingSource.kt +++ b/app/src/main/java/de/christinecoenen/code/zapp/app/mediathek/api/MediathekPagingSource.kt @@ -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) } diff --git a/app/src/main/java/de/christinecoenen/code/zapp/app/mediathek/ui/list/MediathekListFragment.kt b/app/src/main/java/de/christinecoenen/code/zapp/app/mediathek/ui/list/MediathekListFragment.kt index 0a75939d..5d5220e6 100644 --- a/app/src/main/java/de/christinecoenen/code/zapp/app/mediathek/ui/list/MediathekListFragment.kt +++ b/app/src/main/java/de/christinecoenen/code/zapp/app/mediathek/ui/list/MediathekListFragment.kt @@ -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 { diff --git a/app/src/main/res/layout/fragment_mediathek_list.xml b/app/src/main/res/layout/fragment_mediathek_list.xml index 9ffb6e96..683d54ad 100644 --- a/app/src/main/res/layout/fragment_mediathek_list.xml +++ b/app/src/main/res/layout/fragment_mediathek_list.xml @@ -10,6 +10,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="48dp" + android:animateLayoutChanges="true" android:orientation="vertical"> + android:layout_height="0dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintTop_toBottomOf="@id/error">