0
0
mirror of https://github.com/mediathekview/zapp.git synced 2024-09-20 12:22:15 +02:00

Display no items found message

This commit is contained in:
Christine Coenen 2021-11-03 20:00:59 +01:00
parent 3b74dd2749
commit e33f0f33e6
2 changed files with 17 additions and 11 deletions

View File

@ -5,7 +5,7 @@ import android.os.Bundle
import android.view.*
import android.widget.PopupMenu
import androidx.activity.OnBackPressedCallback
import androidx.core.widget.addTextChangedListener
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.paging.LoadState
@ -22,6 +22,7 @@ import de.christinecoenen.code.zapp.app.mediathek.ui.list.adapter.MediathekShowC
import de.christinecoenen.code.zapp.databinding.FragmentMediathekListBinding
import de.christinecoenen.code.zapp.models.shows.MediathekShow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.launch
import org.koin.androidx.viewmodel.ext.android.viewModel
import timber.log.Timber
@ -108,13 +109,13 @@ class MediathekListFragment : Fragment(), ListItemListener, OnRefreshListener {
viewLifecycleOwner.lifecycleScope.launch {
viewmodel.flow.collectLatest { pagingData ->
adapter.submitData(pagingData)
updateNoShowsMessage()
}
}
viewLifecycleOwner.lifecycleScope.launch {
adapter.loadStateFlow.collectLatest { loadStates ->
adapter.loadStateFlow.drop(1).collectLatest { loadStates ->
binding.refreshLayout.isRefreshing = loadStates.refresh is LoadState.Loading
updateNoShowsMessage(loadStates.refresh)
// TODO: display errors
if (loadStates.refresh is LoadState.Error) {
@ -234,10 +235,14 @@ class MediathekListFragment : Fragment(), ListItemListener, OnRefreshListener {
binding.error.visibility = View.VISIBLE
}
// FIXME
private fun updateNoShowsMessage() {
val isAdapterEmpty = adapter.itemCount == 1
//binding.noShows.isVisible = isAdapterEmpty
private fun updateNoShowsMessage(loadState: LoadState) {
Timber.d(
"updateNoShowsMessage: adapter.itemCount %d - loadState %s",
adapter.itemCount,
loadState
)
val isAdapterEmpty = adapter.itemCount == 0 && loadState is LoadState.NotLoading
binding.noShows.isVisible = isAdapterEmpty
}
private fun createChannelFilterView(inflater: LayoutInflater) {

View File

@ -9,8 +9,8 @@
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginBottom="48dp">
android:layout_marginBottom="48dp"
android:orientation="vertical">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/error"
@ -31,12 +31,13 @@
tools:ignore="UnusedAttribute"
tools:visibility="visible" />
<!--androidx.appcompat.widget.LinearLayoutCompat
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/no_shows"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
tools:ignore="UseCompoundDrawables">
<androidx.appcompat.widget.AppCompatImageView
@ -53,7 +54,7 @@
android:gravity="center"
android:text="@string/fragment_mediathek_no_results" />
</androidx.appcompat.widget.LinearLayoutCompat-->
</androidx.appcompat.widget.LinearLayoutCompat>
<FrameLayout
android:layout_width="match_parent"