[Android] Medialibrary: Call reload in service actor

Geoffrey Métais git at videolan.org
Tue Apr 2 12:04:16 CEST 2019


vlc-android | branch: 3.1.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Apr  2 11:39:52 2019 +0200| [cc139ab425d2caf805671930a85a23db0002683e] | committer: Geoffrey Métais

Medialibrary: Call reload in service actor

(cherry picked from commit 3a6b017babb25a5c98f5bb4f4633538133882230)

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

 vlc-android/src/org/videolan/vlc/MediaParsingService.kt        | 10 +++++++---
 vlc-android/src/org/videolan/vlc/gui/MainActivity.java         |  4 ++--
 vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt       |  4 ++--
 vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java    |  2 +-
 .../src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java   |  2 +-
 .../src/org/videolan/vlc/gui/folders/FoldersFragment.kt        |  4 ++--
 vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java    |  4 ++--
 .../src/org/videolan/vlc/gui/video/VideoGridFragment.java      |  2 +-
 8 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 566c045c8..d45600c62 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -126,8 +126,8 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope {
                 val parse = intent.getBooleanExtra(EXTRA_PARSE, true)
                 setupMedialibrary(upgrade, parse)
             }
-            ACTION_RELOAD -> reload(intent.getStringExtra(EXTRA_PATH))
-            ACTION_FORCE_RELOAD -> medialibrary.forceRescan()
+            ACTION_RELOAD -> actions.offer(Reload(intent.getStringExtra(EXTRA_PATH)))
+            ACTION_FORCE_RELOAD -> actions.offer(ForceReload)
             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()
@@ -388,6 +388,8 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope {
                 startScan(false, action.upgrade)
             }
             UpdateStorages -> updateStorages()
+            is Reload -> reload(action.path)
+            ForceReload -> medialibrary.forceRescan()
         }
     }
 
@@ -432,7 +434,7 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope {
 
 data class ScanProgress(val parsing: Int, val discovery: String)
 
-fun Context.reload() {
+fun Context.reloadLibrary() {
     ContextCompat.startForegroundService(this, Intent(ACTION_RELOAD, null, this, MediaParsingService::class.java))
 }
 
@@ -464,6 +466,8 @@ private class DiscoverFolder(val path: String) : MLAction()
 private class Init(val upgrade: Boolean, val parse: Boolean) : MLAction()
 private class StartScan(val upgrade: Boolean) : MLAction()
 private object UpdateStorages : MLAction()
+private class Reload(val path: String?) : MLAction()
+private object ForceReload : MLAction()
 
 private sealed class Notification
 private object Show : Notification()
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index e523a1c79..2fff634be 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -153,7 +153,7 @@ public class MainActivity extends ContentActivity implements ExtensionManagerSer
         super.onStart();
         if (mMediaLibrary.isInitiated()) {
             /* Load media items from database and storage */
-            if (mScanNeeded && Permissions.canReadStorage(this)) MediaParsingServiceKt.reload(this);
+            if (mScanNeeded && Permissions.canReadStorage(this)) MediaParsingServiceKt.reloadLibrary(this);
         }
         if (BuildConfig.DEBUG) createExtensionServiceConnection();
     }
@@ -344,7 +344,7 @@ public class MainActivity extends ContentActivity implements ExtensionManagerSer
         if (requestCode == Constants.ACTIVITY_RESULT_PREFERENCES) {
             switch (resultCode) {
                 case PreferencesActivity.RESULT_RESCAN:
-                    MediaParsingServiceKt.reload(this);
+                    MediaParsingServiceKt.reloadLibrary(this);
                     break;
                 case PreferencesActivity.RESULT_RESTART:
                 case PreferencesActivity.RESULT_RESTART_APP:
diff --git a/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt b/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
index a7f55396b..6489e444d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/PlaylistFragment.kt
@@ -46,7 +46,7 @@ import org.videolan.vlc.gui.audio.AudioBrowserFragment
 import org.videolan.vlc.gui.audio.BaseAudioBrowser
 import org.videolan.vlc.gui.view.FastScroller
 import org.videolan.vlc.gui.view.RecyclerSectionItemDecoration
-import org.videolan.vlc.reload
+import org.videolan.vlc.reloadLibrary
 import org.videolan.vlc.util.AppScope
 import org.videolan.vlc.viewmodels.paged.PagedPlaylistsModel
 
@@ -112,7 +112,7 @@ class PlaylistFragment : BaseAudioBrowser(), Observer<PagedList<MediaLibraryItem
     }
 
     override fun onRefresh() {
-        activity?.reload()
+        activity?.reloadLibrary()
     }
 
     override fun getTitle() = getString(R.string.playlists)
diff --git a/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java b/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
index 96d72446c..343598022 100644
--- a/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/SecondaryActivity.java
@@ -110,7 +110,7 @@ public class SecondaryActivity extends ContentActivity {
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
         if (requestCode == ACTIVITY_RESULT_SECONDARY) {
-            if (resultCode == PreferencesActivity.RESULT_RESCAN) MediaParsingServiceKt.reload(this);
+            if (resultCode == PreferencesActivity.RESULT_RESCAN) MediaParsingServiceKt.reloadLibrary(this);
         }
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index 65efcdff6..92e2fb3d7 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -252,7 +252,7 @@ public class AudioBrowserFragment extends BaseAudioBrowser implements SwipeRefre
     @Override
     public void onRefresh() {
         mActivity.closeSearchView();
-        MediaParsingServiceKt.reload(requireContext());
+        MediaParsingServiceKt.reloadLibrary(requireContext());
     }
 
     @Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/folders/FoldersFragment.kt b/vlc-android/src/org/videolan/vlc/gui/folders/FoldersFragment.kt
index cc7badf6f..bafc73d08 100644
--- a/vlc-android/src/org/videolan/vlc/gui/folders/FoldersFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/folders/FoldersFragment.kt
@@ -21,7 +21,7 @@ import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.media.MediaUtils
 import org.videolan.vlc.media.PlaylistManager
 import org.videolan.vlc.media.getAll
-import org.videolan.vlc.reload
+import org.videolan.vlc.reloadLibrary
 import org.videolan.vlc.util.*
 import org.videolan.vlc.viewmodels.paged.PagedFoldersModel
 import kotlin.coroutines.CoroutineContext
@@ -80,7 +80,7 @@ class FoldersFragment : MediaBrowserFragment<PagedFoldersModel>(), CoroutineScop
         super.onViewCreated(view, savedInstanceState)
         folders_list.layoutManager = LinearLayoutManager(view.context, RecyclerView.VERTICAL, false)
         folders_list.adapter = adapter
-        mSwipeRefreshLayout.setOnRefreshListener { activity?.reload() }
+        mSwipeRefreshLayout.setOnRefreshListener { activity?.reloadLibrary() }
     }
 
     override fun onStart() {
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 36b9363b9..8886c4fb0 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -80,7 +80,7 @@ public class MainTvActivity extends BaseTvActivity {
         if (requestCode == ACTIVITY_RESULT_PREFERENCES) {
             switch (resultCode) {
                 case PreferencesActivity.RESULT_RESCAN:
-                    MediaParsingServiceKt.reload(this);
+                    MediaParsingServiceKt.reloadLibrary(this);
                     break;
                 case PreferencesActivity.RESULT_RESTART:
                 case PreferencesActivity.RESULT_RESTART_APP:
@@ -139,6 +139,6 @@ public class MainTvActivity extends BaseTvActivity {
 
     @Override
     protected void refresh() {
-        mMediaLibrary.reload();
+        MediaParsingServiceKt.reloadLibrary(this);
     }
 }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 51eb263d4..2de5b389f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -260,7 +260,7 @@ public class VideoGridFragment extends MediaBrowserFragment<VideosModel> impleme
     @Override
     public void onRefresh() {
         final Activity activity = getActivity();
-        if (activity != null) MediaParsingServiceKt.reload(activity);
+        if (activity != null) MediaParsingServiceKt.reloadLibrary(activity);
     }
 
     @Override



More information about the Android mailing list