[Android] TV: Improve browsing display
Geoffrey Métais
git at videolan.org
Fri Dec 20 16:54:41 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Dec 20 12:30:41 2019 +0100| [d32fd7104e130f491954a7ed47b5919bdfad030e] | committer: Geoffrey Métais
TV: Improve browsing display
> https://code.videolan.org/videolan/vlc-android/commit/d32fd7104e130f491954a7ed47b5919bdfad030e
---
.../vlc/gui/tv/browser/BaseBrowserTvFragment.kt | 7 +++
.../vlc/gui/tv/browser/FileBrowserTvFragment.kt | 52 +++++++++++-----------
2 files changed, 34 insertions(+), 25 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt
index b48f49935..f8ef40b97 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseBrowserTvFragment.kt
@@ -92,6 +92,8 @@ abstract class BaseBrowserTvFragment<T> : Fragment(), BrowserFragmentInterface,
private lateinit var backgroundManager: BackgroundManager
internal lateinit var animationDelegate: MediaBrowserAnimatorDelegate
private var setFocus = true
+ protected var restarted = false
+ private set
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = SongBrowserBinding.inflate(inflater, container, false)
@@ -202,6 +204,11 @@ abstract class BaseBrowserTvFragment<T> : Fragment(), BrowserFragmentInterface,
setFocus = true
}
+ override fun onStop() {
+ super.onStop()
+ restarted = true
+ }
+
private fun calculateNbColumns() {
viewModel.nbColumns = getColumnNumber()
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt
index 9410c4e61..aaea6b128 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt
@@ -73,8 +73,12 @@ class FileBrowserTvFragment : BaseBrowserTvFragment<MediaLibraryItem>(), PathAda
viewModel.currentItem = item
browserFavRepository = BrowserFavRepository.getInstance(requireContext())
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
- (viewModel.provider as BrowserProvider).dataset.observe(this, Observer { items ->
+ (viewModel.provider as BrowserProvider).dataset.observe(viewLifecycleOwner, Observer { items ->
val lm = binding.list.layoutManager as LinearLayoutManager
val selectedItem = lm.focusedChild
submitList(items)
@@ -95,23 +99,21 @@ class FileBrowserTvFragment : BaseBrowserTvFragment<MediaLibraryItem>(), PathAda
headerAdapter.sortType = (viewModel as BrowserModel).sort
val headerItems = ArrayList<String>()
viewModel.provider.headers.run {
- for (i in 0 until size()) {
- headerItems.add(valueAt(i))
- }
+ for (i in 0 until size()) headerItems.add(valueAt(i))
}
headerAdapter.items = headerItems
headerAdapter.notifyDataSetChanged()
})
- (viewModel.provider as BrowserProvider).loading.observe(this, Observer {
+ (viewModel.provider as BrowserProvider).loading.observe(viewLifecycleOwner, Observer {
if (it) binding.emptyLoading.state = EmptyLoadingState.LOADING
})
- (viewModel as BrowserModel).provider.liveHeaders.observe(this, Observer {
+ (viewModel as BrowserModel).provider.liveHeaders.observe(viewLifecycleOwner, Observer {
headerAdapter.notifyDataSetChanged()
})
- (viewModel as BrowserModel).getDescriptionUpdate().observe(this, Observer { pair ->
+ (viewModel as BrowserModel).getDescriptionUpdate().observe(viewLifecycleOwner, Observer { pair ->
if (pair != null) (adapter as RecyclerView.Adapter<*>).notifyItemChanged(pair.first, pair.second)
})
}
@@ -185,27 +187,11 @@ class FileBrowserTvFragment : BaseBrowserTvFragment<MediaLibraryItem>(), PathAda
animationDelegate.setVisibility(binding.imageButtonFavorite, View.VISIBLE)
animationDelegate.setVisibility(binding.favoriteDescription, View.VISIBLE)
favExists = withContext(Dispatchers.IO) {
- (item as? MediaWrapper)?.let { browserFavRepository.browserFavExists(it.uri) }
- ?: false
+ (item as? MediaWrapper)?.let { browserFavRepository.browserFavExists(it.uri) } ?: false
}
binding.favoriteButton.setImageResource(if (favExists) R.drawable.ic_menu_fav_tv else R.drawable.ic_menu_not_fav_tv)
binding.imageButtonFavorite.setImageResource(if (favExists) R.drawable.ic_menu_fav_tv_normal else R.drawable.ic_menu_not_fav_tv_normal)
}
- val favoriteClickListener: (View) -> Unit = {
- lifecycleScope.launch {
- withContext(Dispatchers.IO) {
- val mw = (item as MediaWrapper)
- when {
- browserFavRepository.browserFavExists(mw.uri) -> browserFavRepository.deleteBrowserFav(mw.uri)
- mw.uri.scheme == "file" -> browserFavRepository.addLocalFavItem(mw.uri, mw.title, mw.artworkURL)
- else -> browserFavRepository.addNetworkFavItem(mw.uri, mw.title, mw.artworkURL)
- }
- favExists = !favExists
- }
- if (!isRootLevel) binding.favoriteButton.setImageResource(if (favExists) R.drawable.ic_menu_fav_tv else R.drawable.ic_menu_not_fav_tv)
- binding.imageButtonFavorite.setImageResource(if (favExists) R.drawable.ic_menu_fav_tv_normal else R.drawable.ic_menu_not_fav_tv_normal)
- }
- }
if (!isRootLevel) binding.favoriteButton.setOnClickListener(favoriteClickListener)
binding.imageButtonFavorite.setOnClickListener(favoriteClickListener)
binding.emptyLoading.showNoMedia = false
@@ -214,7 +200,7 @@ class FileBrowserTvFragment : BaseBrowserTvFragment<MediaLibraryItem>(), PathAda
override fun onResume() {
super.onResume()
if (item == null) (viewModel.provider as BrowserProvider).browseRoot()
- else refresh()
+ else if (restarted) refresh()
(viewModel as IPathOperationDelegate).getAndRemoveDestination()?.let {
browse(it, true)
}
@@ -253,6 +239,22 @@ class FileBrowserTvFragment : BaseBrowserTvFragment<MediaLibraryItem>(), PathAda
ft.commit()
}
+ private val favoriteClickListener: (View) -> Unit = {
+ lifecycleScope.launch {
+ withContext(Dispatchers.IO) {
+ val mw = (item as MediaWrapper)
+ when {
+ browserFavRepository.browserFavExists(mw.uri) -> browserFavRepository.deleteBrowserFav(mw.uri)
+ mw.uri.scheme == "file" -> browserFavRepository.addLocalFavItem(mw.uri, mw.title, mw.artworkURL)
+ else -> browserFavRepository.addNetworkFavItem(mw.uri, mw.title, mw.artworkURL)
+ }
+ favExists = !favExists
+ }
+ if (!isRootLevel) binding.favoriteButton.setImageResource(if (favExists) R.drawable.ic_menu_fav_tv else R.drawable.ic_menu_not_fav_tv)
+ binding.imageButtonFavorite.setImageResource(if (favExists) R.drawable.ic_menu_fav_tv_normal else R.drawable.ic_menu_not_fav_tv_normal)
+ }
+ }
+
companion object {
fun newInstance(type: Long, item: MediaLibraryItem?, root: Boolean = false) =
FileBrowserTvFragment().apply {
More information about the Android
mailing list