Commit 002b35d0 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy
Browse files

Fix headers observations

parent d4f0aa7d
......@@ -42,6 +42,7 @@ import androidx.constraintlayout.widget.ConstraintSet
import androidx.databinding.BindingAdapter
import androidx.fragment.app.Fragment
import androidx.leanback.app.BackgroundManager
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
......@@ -52,6 +53,7 @@ import kotlinx.coroutines.yield
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.resources.util.HeadersIndex
import org.videolan.television.R
import org.videolan.television.databinding.SongBrowserBinding
import org.videolan.television.ui.*
......@@ -68,6 +70,7 @@ import org.videolan.vlc.viewmodels.SortableModel
import org.videolan.vlc.viewmodels.browser.TYPE_FILE
import org.videolan.vlc.viewmodels.browser.TYPE_NETWORK
import org.videolan.vlc.viewmodels.tv.TvBrowserModel
import java.util.ArrayList
private const val TAG = "MediaBrowserTvFragment"
......@@ -219,6 +222,18 @@ abstract class BaseBrowserTvFragment<T> : Fragment(), BrowserFragmentInterface,
binding.list.layoutManager = gridLayoutManager
}
fun updateHeaders(it: HeadersIndex) {
val headerItems = ArrayList<String>()
it.run {
for (i in 0 until size()) {
headerItems.add(valueAt(i))
}
}
headerAdapter.items = headerItems
headerAdapter.notifyDataSetChanged()
}
private fun changeDisplayMode() {
inGrid = !inGrid
Settings.getInstance(requireActivity()).putSingle(getDisplayPrefId(), inGrid)
......
......@@ -113,20 +113,15 @@ class FileBrowserTvFragment : BaseBrowserTvFragment<MediaLibraryItem>(), PathAda
binding.headerList.layoutManager = GridLayoutManager(requireActivity(), nbColumns)
headerAdapter.sortType = (viewModel as BrowserModel).sort
val headerItems = ArrayList<String>()
viewModel.provider.headers.run {
for (i in 0 until size()) headerItems.add(valueAt(i))
}
headerAdapter.items = headerItems
headerAdapter.notifyDataSetChanged()
})
(viewModel.provider as BrowserProvider).loading.observe(viewLifecycleOwner, Observer {
if (it) binding.emptyLoading.state = EmptyLoadingState.LOADING
viewModel.provider.liveHeaders.observe(viewLifecycleOwner, Observer {
updateHeaders(it)
binding.list.invalidateItemDecorations()
})
(viewModel as BrowserModel).provider.liveHeaders.observe(viewLifecycleOwner, Observer {
headerAdapter.notifyDataSetChanged()
(viewModel.provider as BrowserProvider).loading.observe(viewLifecycleOwner, Observer {
if (it) binding.emptyLoading.state = EmptyLoadingState.LOADING
})
(viewModel as BrowserModel).getDescriptionUpdate().observe(viewLifecycleOwner, Observer { pair ->
......
......@@ -6,12 +6,14 @@ import android.view.View
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.resources.*
import org.videolan.resources.util.HeadersIndex
import org.videolan.television.ui.MediaTvItemAdapter
import org.videolan.television.ui.TvItemAdapter
import org.videolan.television.ui.TvUtil
......@@ -40,7 +42,6 @@ class MediaBrowserTvFragment : BaseBrowserTvFragment<MediaLibraryItem>() {
override fun getDisplayPrefId() = "display_tv_media_${(viewModel as MediaBrowserViewModel).category}"
override lateinit var adapter: TvItemAdapter
override fun getTitle() = when ((viewModel as MediaBrowserViewModel).category) {
......@@ -71,7 +72,6 @@ class MediaBrowserTvFragment : BaseBrowserTvFragment<MediaLibraryItem>() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val currentItem = if (savedInstanceState != null) savedInstanceState.getParcelable<Parcelable>(ITEM) as? MediaLibraryItem
else requireActivity().intent.getParcelableExtra<Parcelable>(ITEM) as? MediaLibraryItem
......@@ -87,15 +87,13 @@ class MediaBrowserTvFragment : BaseBrowserTvFragment<MediaLibraryItem>() {
binding.headerList.layoutManager = GridLayoutManager(requireActivity(), nbColumns)
headerAdapter.sortType = (viewModel as MediaBrowserViewModel).sort
val headerItems = ArrayList<String>()
viewModel.provider.headers.run {
for (i in 0 until size()) {
headerItems.add(valueAt(i))
}
}
headerAdapter.items = headerItems
headerAdapter.notifyDataSetChanged()
})
viewModel.provider.liveHeaders.observe(this, Observer {
updateHeaders(it)
binding.list.invalidateItemDecorations()
})
(viewModel.provider as MedialibraryProvider<*>).loading.observe(this, Observer {
binding.emptyLoading.state = when {
it -> EmptyLoadingState.LOADING
......
......@@ -30,6 +30,7 @@ import android.view.View
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.medialibrary.interfaces.Medialibrary
......@@ -99,22 +100,17 @@ class MediaScrapingBrowserTvFragment : BaseBrowserTvFragment<MediaMetadataWithIm
binding.headerList.layoutManager = GridLayoutManager(requireActivity(), nbColumns)
headerAdapter.sortType = (viewModel as MediaScrapingBrowserViewModel).sort
val headerItems = ArrayList<String>()
viewModel.provider.headers.run {
for (i in 0 until size()) {
headerItems.add(valueAt(i))
}
}
headerAdapter.items = headerItems
headerAdapter.notifyDataSetChanged()
}
})
viewModel.provider.liveHeaders.observe(this, Observer {
updateHeaders(it)
binding.list.invalidateItemDecorations()
})
(viewModel.provider as MediaScrapingProvider).loading.observe(this, Observer {
if (it) binding.emptyLoading.state = EmptyLoadingState.LOADING
})
(viewModel.provider as MediaScrapingProvider).liveHeaders.observe(this, Observer {
headerAdapter.notifyDataSetChanged()
})
}
override fun onClick(v: View, position: Int, item: MediaMetadataWithImages) {
......
......@@ -109,6 +109,10 @@ class PlaylistFragment : BaseAudioBrowser<PlaylistsViewModel>(), SwipeRefreshLay
setRefreshing(loading) { }
})
viewModel.provider.liveHeaders.observe(requireActivity(), Observer {
playlists.invalidateItemDecorations()
})
fastScroller.setRecyclerView(getCurrentRV(), viewModel.provider)
}
......
......@@ -146,6 +146,13 @@ class AudioAlbumsSongsFragment : BaseAudioBrowser<AlbumSongsViewModel>(), SwipeR
}
setRefreshing(loading)
})
viewModel.albumsProvider.liveHeaders.observe(viewLifecycleOwner, Observer {
lists[0].invalidateItemDecorations()
})
viewModel.tracksProvider.liveHeaders.observe(viewLifecycleOwner, Observer {
lists[1].invalidateItemDecorations()
})
}
override fun sortBy(sort: Int) {
......
......@@ -211,6 +211,9 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
}
}
})
provider.liveHeaders.observe(viewLifecycleOwner, Observer {
lists[currentTab].invalidateItemDecorations()
})
}
override fun onStart() {
......
......@@ -58,7 +58,7 @@ class RecyclerSectionItemGridDecoration(private val headerOffset: Int, private v
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
super.onDrawOver(c, parent, state)
if (provider.headers.isEmpty) {
if (provider.liveHeaders.value?.isEmpty != false) {
return
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment