Skip to content
Snippets Groups Projects
Commit 42b3c034 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Geoffrey Métais
Browse files

Small reorganization and fix some states

parent 3d5964eb
No related branches found
No related tags found
1 merge request!108Tv media browser refactor
......@@ -71,15 +71,6 @@
<!-- Image loading is handled by org.videolan.vlc.gui.helpers.ImageLoader.loadImage() -->
<ImageView
android:id="@+id/ml_item_seen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_seen_normal"
android:visibility="@{seen == 0L ? View.GONE : View.VISIBLE}"
vlc:layout_constraintRight_toRightOf="@+id/ml_item_thumbnail"
vlc:layout_constraintTop_toTopOf="@+id/ml_item_thumbnail" />
<ImageView
android:id="@+id/media_cover"
android:layout_width="match_parent"
......@@ -93,6 +84,15 @@
vlc:layout_constraintTop_toTopOf="parent"
vlc:media="@{item}" />
<ImageView
android:id="@+id/ml_item_seen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_seen_normal"
android:visibility="@{seen == 0L ? View.GONE : View.VISIBLE}"
vlc:layout_constraintRight_toRightOf="parent"
vlc:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/badgeTV"
......@@ -101,11 +101,11 @@
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/rounded_corners"
android:padding="@dimen/kl_half"
android:text="@{badge}"
android:textSize="12sp"
tools:text="4K"
android:text="@{badge}"
android:background="@drawable/rounded_corners"
vlc:layout_constraintBottom_toBottomOf="@id/media_cover"
vlc:layout_constraintEnd_toEndOf="parent" />
......
......@@ -202,27 +202,26 @@ class TvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, var it
var progress = 0
var seen = 0L
var description = item?.description
var resolution = ""
if (item is MediaWrapper) {
if (item.type == MediaWrapper.TYPE_VIDEO) {
resolution = generateResolutionClass(item.width, item.height) ?: ""
isSquare = false
description = if (item.time == 0L) Tools.millisToString(item.length) else Tools.getProgressText(item)
}
seen = item.seen
val resolution = generateResolutionClass(item.width, item.height)
var max = 0
binding.badge = resolution
seen = item.seen
var max = 0
if (item.length > 0) {
val lastTime = item.displayTime
if (lastTime > 0) {
max = (item.length / 1000).toInt()
progress = (lastTime / 1000).toInt()
if (item.length > 0) {
val lastTime = item.displayTime
if (lastTime > 0) {
max = (item.length / 1000).toInt()
progress = (lastTime / 1000).toInt()
}
}
binding.max = max
}
binding.max = max
binding.badge = resolution
}
......@@ -231,6 +230,9 @@ class TvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, var it
binding.isSquare = isSquare
binding.seen = seen
binding.description = description
if (seen == 0L) binding.mlItemSeen.visibility = View.GONE
if (progress <= 0L) binding.progressBar.visibility = View.GONE
binding.badgeTV.visibility = if (resolution.isBlank()) View.GONE else View.VISIBLE
}
@ObsoleteCoroutinesApi
......
......@@ -24,6 +24,7 @@
package org.videolan.vlc.gui.tv.browser
import android.annotation.TargetApi
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Rect
import android.os.Build
......@@ -50,6 +51,7 @@ import kotlinx.android.synthetic.main.song_browser.*
import kotlinx.coroutines.*
import org.videolan.medialibrary.Medialibrary
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.medialibrary.media.MediaWrapper
import org.videolan.vlc.BuildConfig
import org.videolan.vlc.R
import org.videolan.vlc.gui.tv.*
......@@ -171,10 +173,10 @@ class MediaBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEventsHand
override fun requestChildRectangleOnScreen(parent: RecyclerView, child: View, rect: Rect, immediate: Boolean, focusedChildVisible: Boolean) = false
}
spacing = resources.getDimensionPixelSize(R.dimen.recycler_section_header_spacing)
spacing = resources.getDimensionPixelSize(R.dimen.kl_small)
//size of an item
val itemSize = (requireActivity().getScreenWidth() - list.paddingLeft - list.paddingRight) / viewModelnbColumns - spacing * 2
val itemSize = (requireActivity().getScreenWidth() - list.paddingLeft - list.paddingRight) / viewModel.nbColumns - spacing * 2
gridLayoutManager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
......@@ -188,7 +190,7 @@ class MediaBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEventsHand
val firstSection = viewModel.provider.getPositionForSection(position)
val nbItems = position - firstSection
if (BuildConfig.DEBUG)
Log.d("SongsBrowserFragment", "Position: " + position + " nb items: " + nbItems + " span: " + (viewModel.nbColumns - nbItems % nbColumns))
Log.d("SongsBrowserFragment", "Position: " + position + " nb items: " + nbItems + " span: " + (viewModel.nbColumns - nbItems % viewModel.nbColumns))
return viewModel.nbColumns - nbItems % viewModel.nbColumns
}
......@@ -233,6 +235,7 @@ class MediaBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEventsHand
calculateNbColumns()
gridLayoutManager.spanCount = viewModel.nbColumns
if (BuildConfig.DEBUG) Log.d(TAG, "${viewModel.nbColumns}");
list.layoutManager = gridLayoutManager
}
......@@ -249,7 +252,20 @@ class MediaBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEventsHand
launch { TvUtil.openMediaFromPaged(requireActivity(), item, viewModel.provider) }
}
override fun onLongClick(v: View, position: Int, item: MediaLibraryItem) = false
override fun onLongClick(v: View, position: Int, item: MediaLibraryItem): Boolean {
if (item is MediaWrapper) {
val intent = Intent(requireActivity(), DetailsActivity::class.java)
// pass the item information
intent.putExtra("media", item)
intent.putExtra("item", MediaItemDetails(item.title, item.artist, item.album, item.location, item.artworkURL))
startActivity(intent)
}
return true
}
override fun onCtxClick(v: View, position: Int, item: MediaLibraryItem) {}
......@@ -356,7 +372,7 @@ class MediaBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEventsHand
/**
* mitigate the perf issue when scrolling fast with d-pad
*/
KEYCODE_DPAD_DOWN, KEYCODE_DPAD_LEFT, KEYCODE_DPAD_RIGHT, KEYCODE_DPAD_UP -> {
KEYCODE_DPAD_DOWN, KEYCODE_DPAD_UP -> {
val now = System.currentTimeMillis()
if (now - lastDpadEventTime > 200) {
lastDpadEventTime = now
......
......@@ -55,14 +55,11 @@ class VerticalGridActivity : BaseTvActivity(), BrowserActivityInterface {
} else if (type == HEADER_CATEGORIES) {
val audioCategory = intent.getLongExtra(AUDIO_CATEGORY, CATEGORY_SONGS)
val item = intent.getParcelableExtra<MediaLibraryItem>(AUDIO_ITEM)
if (audioCategory == CATEGORY_SONGS) {
fragment = MediaBrowserTvFragment.newInstance(CATEGORY_SONGS, item)
} else if (audioCategory == CATEGORY_ALBUMS) {
fragment = MediaBrowserTvFragment.newInstance(CATEGORY_ALBUMS, item)
} else if (audioCategory == CATEGORY_ARTISTS) {
fragment = MediaBrowserTvFragment.newInstance(CATEGORY_ARTISTS, item)
} else if (audioCategory == CATEGORY_GENRES) {
fragment = MediaBrowserTvFragment.newInstance(CATEGORY_GENRES, item)
when (audioCategory) {
CATEGORY_SONGS -> fragment = MediaBrowserTvFragment.newInstance(CATEGORY_SONGS, item)
CATEGORY_ALBUMS -> fragment = MediaBrowserTvFragment.newInstance(CATEGORY_ALBUMS, item)
CATEGORY_ARTISTS -> fragment = MediaBrowserTvFragment.newInstance(CATEGORY_ARTISTS, item)
CATEGORY_GENRES -> fragment = MediaBrowserTvFragment.newInstance(CATEGORY_GENRES, item)
}
} else if (type == HEADER_NETWORK) {
var uri = intent.data
......
......@@ -17,12 +17,21 @@ import org.videolan.vlc.viewmodels.MedialibraryViewModel
@ExperimentalCoroutinesApi
class MediaBrowserViewModel(context: Context, category: Long) : MedialibraryViewModel(context) {
class MediaBrowserViewModel(context: Context, private val category: Long) : MedialibraryViewModel(context) {
val nbColumns = context.resources.getInteger(R.integer.tv_songs_col_count)
var nbColumns = 0
var currentItem: MediaLibraryItem? = null
val provider = when(category) {
fun updateColumns() {
nbColumns = when (category) {
CATEGORY_VIDEOS -> context.resources.getInteger(R.integer.tv_videos_col_count)
else -> context.resources.getInteger(R.integer.tv_songs_col_count)
}
}
val provider = when (category) {
CATEGORY_ALBUMS -> AlbumsProvider(null, context, this)
CATEGORY_ARTISTS -> ArtistsProvider(context, this, true)
CATEGORY_GENRES -> GenresProvider(context, this)
......@@ -31,7 +40,7 @@ class MediaBrowserViewModel(context: Context, category: Long) : MedialibraryView
}
override val providers = arrayOf(provider)
class Factory(private val context: Context, private val category: Long): ViewModelProvider.NewInstanceFactory() {
class Factory(private val context: Context, private val category: Long) : ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
return MediaBrowserViewModel(context.applicationContext, category) as T
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment