Commit af1617ec authored by Nicolas Pomepuy's avatar Nicolas Pomepuy

Fix icons on TV browser + set the right scale types

parent 92741540
......@@ -97,6 +97,16 @@ fun getAudioIconDrawable(context: Context?, type: Int, big: Boolean = false): Bi
}
}
fun getMediaIconDrawable(context: Context?, type: Int, big: Boolean = false): BitmapDrawable? = context?.let {
when (type) {
AbstractMediaWrapper.TYPE_ALBUM -> if (big) UiTools.getDefaultAlbumDrawableBig(it) else UiTools.getDefaultAlbumDrawable(it)
AbstractMediaWrapper.TYPE_ARTIST -> if (big) UiTools.getDefaultArtistDrawableBig(it) else UiTools.getDefaultArtistDrawable(it)
AbstractMediaWrapper.TYPE_AUDIO -> if (big) UiTools.getDefaultAudioDrawableBig(it) else UiTools.getDefaultAudioDrawable(it)
AbstractMediaWrapper.TYPE_VIDEO -> if (big) UiTools.getDefaultVideoDrawableBig(it) else UiTools.getDefaultAudioDrawable(it)
else -> null
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
fun getBitmapFromDrawable(context: Context, @DrawableRes drawableId: Int): Bitmap {
val drawable = AppCompatResources.getDrawable(context, drawableId)
......@@ -197,7 +207,7 @@ private suspend fun getImage(v: View, item: MediaLibraryItem, binding: ViewDataB
if (image == null && isForTV(binding)) {
val imageTV = BitmapFactory.decodeResource(v.resources, TvUtil.getIconRes(item))
// binding is set to null to be sure to set the src and not the cover (background)
if (!bindChanged) updateImageView(imageTV, v, null)
if (!bindChanged) updateImageView(imageTV, v, null, false)
binding?.removeOnRebindCallback(rebindCallbacks!!)
return
}
......@@ -236,7 +246,7 @@ private suspend fun getPlaylistImage(v: View, item: MediaLibraryItem, binding: V
}
@MainThread
fun updateImageView(bitmap: Bitmap?, target: View, vdb: ViewDataBinding?) {
fun updateImageView(bitmap: Bitmap?, target: View, vdb: ViewDataBinding?, updateScaleType: Boolean = true) {
if (bitmap === null || bitmap.width <= 1 || bitmap.height <= 1) return
if (vdb !== null && !isForTV(vdb)) {
vdb.setVariable(BR.scaleType, if (isCard(vdb)) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER)
......@@ -244,7 +254,7 @@ fun updateImageView(bitmap: Bitmap?, target: View, vdb: ViewDataBinding?) {
vdb.setVariable(BR.protocol, null)
} else when (target) {
is ImageView -> {
target.scaleType = if (isForTV(vdb)) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER
if (updateScaleType) target.scaleType = if (isForTV(vdb)) ImageView.ScaleType.CENTER_CROP else ImageView.ScaleType.FIT_CENTER
target.setImageBitmap(bitmap)
target.visibility = View.VISIBLE
}
......
......@@ -134,7 +134,7 @@ object UiTools {
fun getDefaultVideoDrawableBig(context: Context): BitmapDrawable {
if (DEFAULT_COVER_VIDEO_DRAWABLE_BIG == null) {
val DEFAULT_COVER_VIDEO = getBitmapFromDrawable(context, R.drawable.ic_no_thumbnail_1610)
val DEFAULT_COVER_VIDEO = getBitmapFromDrawable(context, R.drawable.ic_browser_video_big_normal)
DEFAULT_COVER_VIDEO_DRAWABLE_BIG = BitmapDrawable(context.resources, DEFAULT_COVER_VIDEO)
}
return DEFAULT_COVER_VIDEO_DRAWABLE_BIG!!
......
......@@ -15,9 +15,10 @@ import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.Tools
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.R
import org.videolan.vlc.databinding.MediaBrowserTvItemBinding
import org.videolan.vlc.gui.DiffUtilAdapter
import org.videolan.vlc.gui.helpers.getAudioIconDrawable
import org.videolan.vlc.gui.helpers.getBitmapFromDrawable
import org.videolan.vlc.gui.view.FastScroller
import org.videolan.vlc.interfaces.IEventsHandler
import org.videolan.vlc.util.UPDATE_PAYLOAD
......@@ -44,7 +45,7 @@ class FileTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, va
is Fragment -> eventsHandler.context
else -> null
}
defaultCover = ctx?.let { getAudioIconDrawable(it, type) }
defaultCover = ctx?.let { BitmapDrawable(it.resources, getBitmapFromDrawable(it, R.drawable.ic_browser_unknown_big_normal)) }
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MediaTvItemAdapter.AbstractMediaItemViewHolder<MediaBrowserTvItemBinding> {
......@@ -84,9 +85,9 @@ class FileTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, va
return object : DiffCallback<AbstractMediaWrapper>() {
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int) = try {
oldList[oldItemPosition] == newList[newItemPosition]
} catch (e: IndexOutOfBoundsException) {
false
}
} catch (e: IndexOutOfBoundsException) {
false
}
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
return oldList[oldItemPosition].description == newList[newItemPosition].description
......@@ -100,7 +101,7 @@ class FileTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, va
inner class MediaItemTVViewHolder @TargetApi(Build.VERSION_CODES.M)
internal constructor(binding: MediaBrowserTvItemBinding, override val eventsHandler: IEventsHandler) : MediaTvItemAdapter.AbstractMediaItemViewHolder<MediaBrowserTvItemBinding>(binding), View.OnFocusChangeListener {
override fun getItem(layoutPosition: Int) = this@FileTvItemAdapter.getItem(layoutPosition)
override fun getItem(layoutPosition: Int) = this@FileTvItemAdapter.getItem(layoutPosition)
init {
binding.holder = this
......@@ -123,13 +124,11 @@ class FileTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, va
eventsHandler.onItemFocused(binding.root, getItem(layoutPosition))
focusListener?.onFocusChanged(layoutPosition)
} else {
binding.container.animate().scaleX(1f).scaleY(1f).translationZ(1f)
}
}
binding.container.clipToOutline = true
}
override fun recycle() {
......@@ -169,12 +168,14 @@ class FileTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, va
binding.isSquare = isSquare
binding.seen = seen
binding.description = description
if (defaultCover != null) binding.cover = defaultCover
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
override fun setCoverlay(selected: Boolean) {}
override fun setCoverlay(selected: Boolean) {
}
}
}
......@@ -21,7 +21,7 @@ import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.databinding.MediaBrowserTvItemBinding
import org.videolan.vlc.gui.helpers.SelectorViewHolder
import org.videolan.vlc.gui.helpers.getAudioIconDrawable
import org.videolan.vlc.gui.helpers.getMediaIconDrawable
import org.videolan.vlc.gui.view.FastScroller
import org.videolan.vlc.interfaces.IEventsHandler
import org.videolan.vlc.util.UPDATE_PAYLOAD
......@@ -41,7 +41,7 @@ class MediaTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, v
is Fragment -> (eventsHandler as Fragment).context
else -> null
}
defaultCover = ctx?.let { getAudioIconDrawable(it, type, true) }
defaultCover = ctx?.let { getMediaIconDrawable(it, type, true) }
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AbstractMediaItemViewHolder<ViewDataBinding> {
......@@ -154,7 +154,6 @@ class MediaTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, v
init {
binding.holder = this
binding.scaleType = ImageView.ScaleType.CENTER_INSIDE
if (defaultCover != null) binding.cover = defaultCover
if (AndroidUtil.isMarshMallowOrLater)
itemView.setOnContextClickListener { v ->
......@@ -220,6 +219,7 @@ class MediaTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, v
binding.isSquare = isSquare
binding.seen = seen
binding.description = description
binding.scaleType = ImageView.ScaleType.CENTER_INSIDE
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
......
......@@ -27,7 +27,13 @@ import java.util.*
@ExperimentalCoroutinesApi
class MediaBrowserTvFragment : BaseBrowserTvFragment() {
override fun provideAdapter(eventsHandler: IEventsHandler, itemSize: Int): TvItemAdapter {
return MediaTvItemAdapter(MediaLibraryItem.TYPE_MEDIA, this, itemSize)
return MediaTvItemAdapter(when ((viewModel as MediaBrowserViewModel).category) {
CATEGORY_SONGS -> AbstractMediaWrapper.TYPE_AUDIO
CATEGORY_ALBUMS -> AbstractMediaWrapper.TYPE_ALBUM
CATEGORY_ARTISTS -> AbstractMediaWrapper.TYPE_ARTIST
CATEGORY_GENRES -> AbstractMediaWrapper.TYPE_GENRE
else -> AbstractMediaWrapper.TYPE_VIDEO
}, this, itemSize)
}
override lateinit var adapter: TvItemAdapter
......
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