[Android] Add a refresh card on TV

Nicolas Pomepuy git at videolan.org
Fri Apr 12 10:20:57 CEST 2019


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

Add a refresh card on TV

> https://code.videolan.org/videolan/vlc-android/commit/9e8a7348cc3a5e1f28b446bb880cb8ef263dc241
---

 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 ++++++++-------
 .../org/videolan/vlc/gui/tv/browser/BaseTvActivity.java |   6 ++++--
 vlc-android/src/org/videolan/vlc/util/Constants.kt      |   1 +
 10 files changed, 27 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 9a6c6030c..a41d395b2 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(GenericCardItem(ID_SETTINGS, getString(R.string.preferences), "", R.drawable.ic_menu_preferences_big, R.color.tv_card_content))
+        otherAdapter.add(GenericCardItem(ID_REFRESH, getString(R.string.refresh), "", R.drawable.ic_menu_scan, R.color.tv_card_content))
         otherAdapter.add(GenericCardItem(ID_ABOUT_TV, getString(R.string.about), "${getString(R.string.app_name_full)} ${BuildConfig.VERSION_NAME}", R.drawable.ic_menu_info_big, R.color.tv_card_content))
         otherAdapter.add(GenericCardItem(ID_LICENCE, getString(R.string.licence), "", R.drawable.ic_menu_open_source, R.color.tv_card_content))
         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 GenericCardItem).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/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 8b46df5c7..d84bd9e96 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