[Android] Add a refresh card on TV

Nicolas Pomepuy git at videolan.org
Fri Apr 12 11:05:10 CEST 2019


vlc-android | branch: 3.1.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Fri Apr 12 09:07:25 2019 +0200| [423e4338a7481064c95c4b16a9f6807be669312b] | committer: Geoffrey Métais

Add a refresh card on TV

(cherry picked from commit 9e8a7348cc3a5e1f28b446bb880cb8ef263dc241)

> https://code.videolan.org/videolan/vlc-android/commit/423e4338a7481064c95c4b16a9f6807be669312b
---

 vlc-android/res/drawable-hdpi/ic_menu_scan.png          | Bin 0 -> 4105 bytes
 vlc-android/res/drawable-mdpi/ic_menu_scan.png          | Bin 0 -> 2234 bytes
 vlc-android/res/drawable-xhdpi/ic_menu_scan.png         | Bin 0 -> 4913 bytes
 vlc-android/res/drawable-xxhdpi/ic_menu_scan.png        | Bin 0 -> 9446 bytes
 vlc-android/res/drawable-xxxhdpi/ic_menu_scan.png       | Bin 0 -> 11657 bytes
 vlc-android/res/layout/tv_main.xml                      |   9 +++++----
 .../src/org/videolan/vlc/gui/tv/MainTvActivity.java     |  14 +++++++++-----
 .../src/org/videolan/vlc/gui/tv/MainTvFragment.kt       |  15 ++++++++-------
 vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt       |   1 +
 .../org/videolan/vlc/gui/tv/browser/BaseTvActivity.java |   6 ++++--
 vlc-android/src/org/videolan/vlc/util/Constants.kt      |   1 +
 11 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/vlc-android/res/drawable-hdpi/ic_menu_scan.png b/vlc-android/res/drawable-hdpi/ic_menu_scan.png
new file mode 100644
index 000000000..35b07a93a
Binary files /dev/null and b/vlc-android/res/drawable-hdpi/ic_menu_scan.png differ
diff --git a/vlc-android/res/drawable-mdpi/ic_menu_scan.png b/vlc-android/res/drawable-mdpi/ic_menu_scan.png
new file mode 100644
index 000000000..f479b2b37
Binary files /dev/null and b/vlc-android/res/drawable-mdpi/ic_menu_scan.png differ
diff --git a/vlc-android/res/drawable-xhdpi/ic_menu_scan.png b/vlc-android/res/drawable-xhdpi/ic_menu_scan.png
new file mode 100644
index 000000000..c9598e0c4
Binary files /dev/null and b/vlc-android/res/drawable-xhdpi/ic_menu_scan.png differ
diff --git a/vlc-android/res/drawable-xxhdpi/ic_menu_scan.png b/vlc-android/res/drawable-xxhdpi/ic_menu_scan.png
new file mode 100644
index 000000000..120fe1d44
Binary files /dev/null and b/vlc-android/res/drawable-xxhdpi/ic_menu_scan.png differ
diff --git a/vlc-android/res/drawable-xxxhdpi/ic_menu_scan.png b/vlc-android/res/drawable-xxxhdpi/ic_menu_scan.png
new file mode 100644
index 000000000..67fba566b
Binary files /dev/null and b/vlc-android/res/drawable-xxxhdpi/ic_menu_scan.png differ
diff --git a/vlc-android/res/layout/tv_main.xml b/vlc-android/res/layout/tv_main.xml
index 85975d986..90847c996 100644
--- a/vlc-android/res/layout/tv_main.xml
+++ b/vlc-android/res/layout/tv_main.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/tv_container"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
@@ -16,11 +17,11 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="top|end"
-        android:layout_marginRight="128dp"
-        android:layout_marginEnd="128dp"
         android:layout_marginTop="32dp"
-        app:layout_constraintTop_toTopOf="parent"
+        android:layout_marginEnd="128dp"
+        android:visibility="gone"
         app:layout_constraintEnd_toEndOf="parent"
-        android:visibility="gone" />
+        app:layout_constraintTop_toTopOf="parent"
+        tools:visibility="visible" />
     <include layout="@layout/tv_time" />
 </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index 8886c4fb0..b2f4c0115 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -30,8 +30,10 @@ import android.view.KeyEvent;
 import android.view.View;
 import android.widget.ProgressBar;
 
+import org.videolan.medialibrary.Medialibrary;
 import org.videolan.vlc.MediaParsingServiceKt;
 import org.videolan.vlc.R;
+import org.videolan.vlc.ScanProgress;
 import org.videolan.vlc.StartActivity;
 import org.videolan.vlc.gui.preferences.PreferencesActivity;
 import org.videolan.vlc.gui.tv.browser.BaseTvActivity;
@@ -103,21 +105,23 @@ public class MainTvActivity extends BaseTvActivity {
 
     @Override
     protected void onParsingServiceStarted() {
-        mHandler.sendEmptyMessageDelayed(SHOW_LOADING, 300);
+        mHandler.sendEmptyMessage(SHOW_LOADING);
     }
 
     @Override
-    protected void onParsingServiceProgress() {
-        if (mProgressBar.getVisibility() == View.GONE) mHandler.sendEmptyMessage(SHOW_LOADING);
+    protected void onParsingServiceProgress(ScanProgress scanProgress) {
+        if (mProgressBar.getVisibility() == View.GONE && Medialibrary.getInstance().isWorking())
+            mHandler.sendEmptyMessage(SHOW_LOADING);
     }
 
     @Override
     protected void onParsingServiceFinished() {
-        mHandler.sendEmptyMessage(HIDE_LOADING);
+        if (!Medialibrary.getInstance().isWorking())
+            mHandler.sendEmptyMessageDelayed(HIDE_LOADING, 500);
     }
 
     public void hideLoading() {
-        mHandler.sendEmptyMessage(HIDE_LOADING);
+        mHandler.sendEmptyMessageDelayed(HIDE_LOADING, 500);
     }
     private static final int SHOW_LOADING = 0;
     private static final int HIDE_LOADING = 1;
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt
index e596a6e2c..96b01ec1b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvFragment.kt
@@ -45,14 +45,9 @@ import org.videolan.medialibrary.media.DummyItem
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.medialibrary.media.MediaWrapper
 import org.videolan.tools.coroutineScope
-import org.videolan.vlc.BuildConfig
-import org.videolan.vlc.ExternalMonitor
-import org.videolan.vlc.R
-import org.videolan.vlc.RecommendationsService
+import org.videolan.vlc.*
 import org.videolan.vlc.database.models.BrowserFav
 import org.videolan.vlc.gui.preferences.PreferencesFragment
-import org.videolan.vlc.gui.tv.MainTvActivity.ACTIVITY_RESULT_PREFERENCES
-import org.videolan.vlc.gui.tv.MainTvActivity.BROWSER_TYPE
 import org.videolan.vlc.gui.tv.TvUtil.diffCallback
 import org.videolan.vlc.gui.tv.audioplayer.AudioPlayerActivity
 import org.videolan.vlc.gui.tv.browser.VerticalGridActivity
@@ -151,6 +146,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
         val miscHeader = HeaderItem(HEADER_MISC, getString(R.string.other))
 
         otherAdapter.add(DummyItem(ID_SETTINGS, getString(R.string.preferences), ""))
+        otherAdapter.add(DummyItem(ID_REFRESH, getString(R.string.refresh), ""))
         otherAdapter.add(DummyItem(ID_ABOUT_TV, getString(R.string.about), "${getString(R.string.app_name_full)} ${BuildConfig.VERSION_NAME}"))
         otherAdapter.add(DummyItem(ID_LICENCE, getString(R.string.licence), ""))
         miscRow = ListRow(miscHeader, otherAdapter)
@@ -250,7 +246,7 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
                     return
                 }
                 val intent = Intent(activity, VerticalGridActivity::class.java)
-                intent.putExtra(BROWSER_TYPE, HEADER_CATEGORIES)
+                intent.putExtra(MainTvActivity.BROWSER_TYPE, HEADER_CATEGORIES)
                 intent.putExtra(AUDIO_CATEGORY, item.id)
                 activity.startActivity(intent)
             }
@@ -258,6 +254,11 @@ class MainTvFragment : BrowseSupportFragment(), OnItemViewSelectedListener, OnIt
                 val id = (item as DummyItem).id
                 when (id) {
                     ID_SETTINGS -> activity.startActivityForResult(Intent(activity, org.videolan.vlc.gui.tv.preferences.PreferencesActivity::class.java), ACTIVITY_RESULT_PREFERENCES)
+                    ID_REFRESH -> {
+                        if (!Medialibrary.getInstance().isWorking) {
+                            requireActivity().reloadLibrary()
+                        }
+                    }
                     ID_ABOUT_TV -> activity.startActivity(Intent(activity, org.videolan.vlc.gui.tv.AboutActivity::class.java))
                     ID_LICENCE -> startActivity(Intent(activity, org.videolan.vlc.gui.tv.LicenceActivity::class.java))
                 }
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 19c8c30fd..d84c0d950 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/TvUtil.kt
@@ -247,6 +247,7 @@ object TvUtil {
                     HEADER_SERVER -> R.drawable.ic_menu_network_add_big
                     HEADER_STREAM -> R.drawable.ic_menu_stream_big
                     ID_SETTINGS -> R.drawable.ic_menu_preferences_big
+                    ID_REFRESH -> R.drawable.ic_menu_scan
                     ID_ABOUT_TV, ID_LICENCE -> R.drawable.ic_default_cone
                     CATEGORY_ARTISTS -> R.drawable.ic_artist_big
                     CATEGORY_ALBUMS -> R.drawable.ic_album_big
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
index cdfad753e..55e4db268 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/BaseTvActivity.java
@@ -107,14 +107,16 @@ public abstract class BaseTvActivity extends FragmentActivity {
     }
 
     protected void onParsingServiceStarted() {}
-    protected void onParsingServiceProgress() {}
+
+    protected void onParsingServiceProgress(ScanProgress scanProgress) {
+    }
     protected void onParsingServiceFinished() {}
 
     private void registerLiveData() {
         MediaParsingService.Companion.getProgress().observe(this, new Observer<ScanProgress>() {
             @Override
             public void onChanged(@Nullable ScanProgress scanProgress) {
-                if (scanProgress != null) onParsingServiceProgress();
+                if (scanProgress != null) onParsingServiceProgress(scanProgress);
             }
         });
         Medialibrary.getState().observe(this, new Observer<Boolean>() {
diff --git a/vlc-android/src/org/videolan/vlc/util/Constants.kt b/vlc-android/src/org/videolan/vlc/util/Constants.kt
index c5c39c1bc..be7d01f92 100644
--- a/vlc-android/src/org/videolan/vlc/util/Constants.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Constants.kt
@@ -117,6 +117,7 @@ const val HEADER_SERVER = 7L
 const val ID_SETTINGS = 10L
 const val ID_ABOUT_TV = 11L
 const val ID_LICENCE = 12L
+const val ID_REFRESH = 13L
 const val CATEGORY_NOW_PLAYING = 20L
 const val CATEGORY_ARTISTS = 21L
 const val CATEGORY_ALBUMS = 22L



More information about the Android mailing list