[Android] Display network protocol and network icon on TV
Nicolas Pomepuy
git at videolan.org
Thu Aug 8 13:35:03 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Thu Aug 8 09:44:03 2019 +0200| [b16176ed50deb6e9c25ea1578150222f0318fadd] | committer: Geoffrey Métais
Display network protocol and network icon on TV
> https://code.videolan.org/videolan/vlc-android/commit/b16176ed50deb6e9c25ea1578150222f0318fadd
---
vlc-android/res/layout/media_browser_tv_item.xml | 22 ++++++++++++++++++++++
.../org/videolan/vlc/gui/tv/FileTvItemAdapter.kt | 8 +++++++-
vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt | 4 ++--
.../vlc/gui/tv/browser/FileBrowserTvFragment.kt | 2 +-
4 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/vlc-android/res/layout/media_browser_tv_item.xml b/vlc-android/res/layout/media_browser_tv_item.xml
index 8b96ce1ee..648bf046f 100644
--- a/vlc-android/res/layout/media_browser_tv_item.xml
+++ b/vlc-android/res/layout/media_browser_tv_item.xml
@@ -45,6 +45,10 @@
name="isSquare"
type="Boolean" />
+ <variable
+ name="protocol"
+ type="String"/>
+
<variable
name="scaleType"
type="android.widget.ImageView.ScaleType"/>
@@ -99,6 +103,24 @@
vlc:layout_constraintTop_toTopOf="parent"/>
+ <TextView
+ android:id="@+id/dvi_icon_tv"
+ android:layout_width="wrap_content"
+ android:layout_height="0dp"
+ android:gravity="center"
+ android:text="@{protocol}"
+ android:textColor="@color/whitetransparent"
+ android:background="@drawable/rounded_corners"
+ android:padding="4dp"
+ android:visibility="@{ TextUtils.isEmpty(protocol) ? View.GONE : View.VISIBLE, default=gone}"
+ vlc:layout_constraintBottom_toBottomOf="@+id/media_cover"
+ android:layout_marginBottom="8dp"
+ tools:visibility="visible"
+ tools:text="smb"
+ vlc:layout_constraintStart_toStartOf="parent"
+ android:layout_marginLeft="8dp"
+ android:layout_marginStart="8dp"/>
+
<TextView
android:id="@+id/badgeTV"
android:layout_width="wrap_content"
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/FileTvItemAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/tv/FileTvItemAdapter.kt
index 533cd6b12..9537c3274 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/FileTvItemAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/FileTvItemAdapter.kt
@@ -24,10 +24,11 @@ import org.videolan.vlc.gui.view.FastScroller
import org.videolan.vlc.interfaces.IEventsHandler
import org.videolan.vlc.util.UPDATE_PAYLOAD
import org.videolan.vlc.util.generateResolutionClass
+import org.videolan.vlc.viewmodels.browser.TYPE_NETWORK
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
-class FileTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, var itemSize: Int) : DiffUtilAdapter<AbstractMediaWrapper, MediaTvItemAdapter.AbstractMediaItemViewHolder<MediaBrowserTvItemBinding>>(), FastScroller.SeparatedAdapter, TvItemAdapter {
+class FileTvItemAdapter(private val type: Int, private val eventsHandler: IEventsHandler, var itemSize: Int) : DiffUtilAdapter<AbstractMediaWrapper, MediaTvItemAdapter.AbstractMediaItemViewHolder<MediaBrowserTvItemBinding>>(), FastScroller.SeparatedAdapter, TvItemAdapter {
override fun submitList(pagedList: Any?) {
if (pagedList is List<*>) {
@@ -94,6 +95,10 @@ class FileTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, va
}
}
+ private fun getProtocol(media: AbstractMediaWrapper): String? {
+ return if (media.type != AbstractMediaWrapper.TYPE_DIR) null else media.uri.scheme
+ }
+
inner class MediaItemTVViewHolder @TargetApi(Build.VERSION_CODES.M)
internal constructor(binding: MediaBrowserTvItemBinding, override val eventsHandler: IEventsHandler) : MediaTvItemAdapter.AbstractMediaItemViewHolder<MediaBrowserTvItemBinding>(binding), View.OnFocusChangeListener {
@@ -165,6 +170,7 @@ class FileTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, va
binding.isSquare = isSquare
binding.seen = seen
binding.description = description
+ if (type == TYPE_NETWORK && item is AbstractMediaWrapper) binding.protocol = getProtocol(item)
val cover = if (item is AbstractMediaWrapper) getMediaIconDrawable(binding.root.context, item.type, true) else defaultCover
cover?.let { binding.cover = it }
if (seen == 0L) binding.mlItemSeen.visibility = View.GONE
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt b/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt
index 3a54331e8..67012f1db 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt
@@ -43,7 +43,6 @@ import org.videolan.medialibrary.media.DummyItem
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.tools.getposition
import org.videolan.vlc.R
-import org.videolan.vlc.VLCApplication
import org.videolan.vlc.gui.DialogActivity
import org.videolan.vlc.gui.helpers.AudioUtil
import org.videolan.vlc.gui.helpers.BitmapUtil
@@ -57,6 +56,7 @@ import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
import org.videolan.vlc.util.*
import org.videolan.vlc.viewmodels.BaseModel
import org.videolan.vlc.viewmodels.browser.BrowserModel
+
@ExperimentalCoroutinesApi
@ObsoleteCoroutinesApi
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@@ -326,7 +326,7 @@ object TvUtil {
return when {
mw.type == AbstractMediaWrapper.TYPE_VIDEO -> R.drawable.ic_browser_video_big_normal
else -> if (mw.type == AbstractMediaWrapper.TYPE_DIR)
- R.drawable.ic_menu_folder_big
+ if (mw.uri.scheme == "file") R.drawable.ic_menu_folder_big else R.drawable.ic_menu_network_big
else
R.drawable.ic_song_big
}
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 ef4b75995..ded303828 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
@@ -53,7 +53,7 @@ class FileBrowserTvFragment : BaseBrowserTvFragment() {
}
override fun provideAdapter(eventsHandler: IEventsHandler, itemSize: Int): TvItemAdapter {
- return FileTvItemAdapter(MediaLibraryItem.TYPE_MEDIA, this, itemSize)
+ return FileTvItemAdapter(getCategory(), this, itemSize)
}
override fun onCreate(savedInstanceState: Bundle?) {
More information about the Android
mailing list