[Android] Properly clear the thumbnail DB when media is removed

Nicolas Pomepuy git at videolan.org
Tue Jul 18 13:10:07 UTC 2023


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jul 18 08:15:55 2023 +0200| [59bc13ed9c43a345b5fed47e497e9bde30f8bfb5] | committer: Duncan McNamara

Properly clear the thumbnail DB when media is removed

Fixes #2726

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

 .../videolan/vlc/viewmodels/CallBackDelegate.kt    | 24 ++++++++++++----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/CallBackDelegate.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/CallBackDelegate.kt
index 92ab681695..ee6b2efb6e 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/CallBackDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/CallBackDelegate.kt
@@ -111,21 +111,12 @@ class CallBackDelegate : ICallBackHandler,
             for (action in channel) when (action) {
                 is MediaDeletedAction -> {
                     action.ids.forEach {mediaId ->
-                        AppContextProvider.appContext.getExternalFilesDir(null)?. let {
-                            FileUtils.deleteFile(it.absolutePath + Medialibrary.MEDIALIB_FOLDER_NAME + "/$mediaId.jpg" )
-                        }
+                        deleteThumbnail(mediaId)
                     }
                 }
                 is MediaConvertedExternalAction -> {
                     action.ids.forEach {mediaId ->
-                        AppContextProvider.appContext.getExternalFilesDir(null)?. let {
-                            val file = File(it.absolutePath + Medialibrary.MEDIALIB_FOLDER_NAME + "/$mediaId.jpg")
-                            if (file.exists()) {
-                                val media = medialibrary.getMedia(mediaId)
-                                media.removeThumbnail()
-                            }
-                            FileUtils.deleteFile(file)
-                        }
+                        deleteThumbnail(mediaId)
                     }
                 }
             }
@@ -134,6 +125,17 @@ class CallBackDelegate : ICallBackHandler,
         medialibrary.addOnDeviceChangeListener(this at CallBackDelegate)
     }
 
+    private fun deleteThumbnail(mediaId: Long) {
+        AppContextProvider.appContext.getExternalFilesDir(null)?.let {
+            val file = File(it.absolutePath + Medialibrary.MEDIALIB_FOLDER_NAME + "/$mediaId.jpg")
+            if (file.exists()) {
+                val media = medialibrary.getMedia(mediaId)
+                media.removeThumbnail()
+            }
+            FileUtils.deleteFile(file)
+        }
+    }
+
     override fun watchMedia() {
         medialibrary.addMediaCb(this)
         mediaCb = true



More information about the Android mailing list