[Android] Force reload from 'refresh' menu

Geoffrey Métais git at videolan.org
Thu Nov 15 18:12:17 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Nov 15 18:12:00 2018 +0100| [8f9da6cdbf64a497a61ff795bfe72b3e44bbce3f] | committer: Geoffrey Métais

Force reload from 'refresh' menu

> https://code.videolan.org/videolan/vlc-android/commit/8f9da6cdbf64a497a61ff795bfe72b3e44bbce3f
---

 vlc-android/src/org/videolan/vlc/MediaParsingService.kt     |  9 +++++++--
 vlc-android/src/org/videolan/vlc/gui/MainActivity.java      |  2 +-
 vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java | 10 ++++++----
 vlc-android/src/org/videolan/vlc/util/Constants.kt          |  1 +
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index fc3170412..15ee4f564 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -125,6 +125,7 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope {
                 setupMedialibrary(upgrade, parse)
             }
             ACTION_RELOAD -> reload(intent.getStringExtra(EXTRA_PATH))
+            ACTION_FORCE_RELOAD -> medialibrary.forceRescan()
             ACTION_DISCOVER -> discover(intent.getStringExtra(EXTRA_PATH))
             ACTION_DISCOVER_DEVICE -> discoverStorage(intent.getStringExtra(EXTRA_PATH))
             ACTION_CHECK_STORAGES -> if (scanActivated) actions.offer(UpdateStorages) else exitCommand()
@@ -416,8 +417,12 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope {
 
 data class ScanProgress(val parsing: Int, val discovery: String)
 
-fun reload(ctx: Context) {
-    ContextCompat.startForegroundService(ctx, Intent(ACTION_RELOAD, null, ctx, MediaParsingService::class.java))
+fun Context.reload() {
+    ContextCompat.startForegroundService(this, Intent(ACTION_RELOAD, null, this, MediaParsingService::class.java))
+}
+
+fun Context.rescan() {
+    ContextCompat.startForegroundService(this, Intent(ACTION_FORCE_RELOAD, null, this, MediaParsingService::class.java))
 }
 
 fun Context.startMedialibrary(firstRun: Boolean = false, upgrade: Boolean = false, parse: Boolean = true) = AppScope.launch {
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 6a55a871b..bc359197a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -333,7 +333,7 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
             if(current != null && current instanceof IRefreshable)
                 ((IRefreshable) current).refresh();
             else
-                MediaParsingServiceKt.reload(this);
+                MediaParsingServiceKt.rescan(this);
         }
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java b/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
index 0424f5a4d..d764069bf 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
@@ -25,12 +25,11 @@ package org.videolan.vlc.gui;
 
 import android.content.Intent;
 import android.os.Bundle;
-import com.google.android.material.appbar.AppBarLayout;
-import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import androidx.fragment.app.Fragment;
 import android.view.MenuItem;
 import android.view.View;
 
+import com.google.android.material.appbar.AppBarLayout;
+
 import org.videolan.medialibrary.Medialibrary;
 import org.videolan.vlc.MediaParsingServiceKt;
 import org.videolan.vlc.R;
@@ -44,6 +43,9 @@ import org.videolan.vlc.gui.tv.TvUtil;
 import org.videolan.vlc.gui.video.VideoGridFragment;
 import org.videolan.vlc.util.AndroidDevices;
 
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.fragment.app.Fragment;
+
 public class SecondaryActivity extends ContentActivity {
     public final static String TAG = "VLC/SecondaryActivity";
 
@@ -117,7 +119,7 @@ public class SecondaryActivity extends ContentActivity {
         switch (item.getItemId()) {
             case R.id.ml_menu_refresh:
                 Medialibrary ml = VLCApplication.getMLInstance();
-                if (!ml.isWorking()) MediaParsingServiceKt.reload(this);
+                if (!ml.isWorking()) MediaParsingServiceKt.rescan(this);
                 return true;
         }
         return super.onOptionsItemSelected(item);
diff --git a/vlc-android/src/org/videolan/vlc/util/Constants.kt b/vlc-android/src/org/videolan/vlc/util/Constants.kt
index eabc7f491..be89e170d 100644
--- a/vlc-android/src/org/videolan/vlc/util/Constants.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Constants.kt
@@ -66,6 +66,7 @@ const val PLAYBACK_LOAD_SIZE = 500
 // MediaParsingService
 const val ACTION_INIT = "medialibrary_init"
 const val ACTION_RELOAD = "medialibrary_reload"
+const val ACTION_FORCE_RELOAD = "medialibrary_force_reload"
 const val ACTION_DISCOVER = "medialibrary_discover"
 const val ACTION_DISCOVER_DEVICE = "medialibrary_discover_device"
 const val ACTION_CHECK_STORAGES = "medialibrary_check_storages"



More information about the Android mailing list