[Android] Delete the thumbnails generated by Android on clear ML db

Nicolas Pomepuy git at videolan.org
Thu Jun 10 11:24:08 UTC 2021


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Jun  1 11:44:11 2021 +0200| [1af1ba8417ba110c48e124a1f318260a4159f5c4] | committer: Nicolas Pomepuy

Delete the thumbnails generated by Android on clear ML db

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

 .../television/ui/preferences/PreferencesAdvanced.kt    | 17 ++++++++++++++++-
 .../videolan/vlc/gui/preferences/PreferencesAdvanced.kt | 17 ++++++++++++++++-
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
index ef153a537..a6c0ba401 100644
--- a/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/preferences/PreferencesAdvanced.kt
@@ -32,6 +32,7 @@ import android.content.SharedPreferences
 import android.net.Uri
 import android.os.Build
 import android.os.Bundle
+import android.util.Log
 import android.widget.Toast
 import androidx.core.content.edit
 import androidx.fragment.app.FragmentActivity
@@ -41,6 +42,7 @@ import kotlinx.coroutines.*
 import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.resources.AndroidDevices
 import org.videolan.resources.VLCInstance
+import org.videolan.tools.BitmapCache
 import org.videolan.tools.putSingle
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.MediaParsingService
@@ -52,6 +54,7 @@ import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getW
 import org.videolan.vlc.util.FeatureFlag
 import org.videolan.vlc.util.FileUtils
 import java.io.File
+import java.io.IOException
 
 @ExperimentalCoroutinesApi
 @ObsoleteCoroutinesApi
@@ -125,7 +128,19 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
                         val medialibrary = Medialibrary.getInstance()
                         activity.stopService(Intent(activity, MediaParsingService::class.java))
                         withContext((Dispatchers.IO)) {
-                            medialibrary.clearDatabase(true)
+                            medialibrary.clearDatabase(false)
+                            //delete thumbnails
+                            try {
+                                activity.getExternalFilesDir(null)?. let {
+                                    val files = File(it.absolutePath + Medialibrary.MEDIALIB_FOLDER_NAME).listFiles()
+                                    files?.forEach { file ->
+                                        if (file.isFile) FileUtils.deleteFile(file)
+                                    }
+                                }
+                                BitmapCache.clear()
+                            } catch (e: IOException) {
+                                Log.e(this::class.java.simpleName, e.message, e)
+                            }
                         }
                         medialibrary.discover(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
                     }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
index df1e7ddb6..5337d4d03 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesAdvanced.kt
@@ -31,6 +31,7 @@ import android.content.SharedPreferences
 import android.net.Uri
 import android.os.Build
 import android.os.Bundle
+import android.util.Log
 import android.widget.Toast
 import androidx.appcompat.app.AlertDialog
 import androidx.core.content.edit
@@ -43,6 +44,7 @@ import org.videolan.resources.AndroidDevices
 import org.videolan.resources.KEY_AUDIO_LAST_PLAYLIST
 import org.videolan.resources.KEY_MEDIA_LAST_PLAYLIST
 import org.videolan.resources.VLCInstance
+import org.videolan.tools.BitmapCache
 import org.videolan.tools.Settings
 import org.videolan.tools.putSingle
 import org.videolan.vlc.BuildConfig
@@ -56,6 +58,7 @@ import org.videolan.vlc.gui.helpers.hf.StoragePermissionsDelegate.Companion.getW
 import org.videolan.vlc.util.FeatureFlag
 import org.videolan.vlc.util.FileUtils
 import java.io.File
+import java.io.IOException
 
 @ExperimentalCoroutinesApi
 @ObsoleteCoroutinesApi
@@ -116,7 +119,19 @@ class PreferencesAdvanced : BasePreferenceFragment(), SharedPreferences.OnShared
                         val medialibrary = Medialibrary.getInstance()
                         requireActivity().stopService(Intent(requireActivity(), MediaParsingService::class.java))
                         withContext((Dispatchers.IO)) {
-                            medialibrary.clearDatabase(true)
+                            medialibrary.clearDatabase(false)
+                            //delete thumbnails
+                            try {
+                                requireActivity().getExternalFilesDir(null)?. let {
+                                    val files = File(it.absolutePath + Medialibrary.MEDIALIB_FOLDER_NAME).listFiles()
+                                    files?.forEach { file ->
+                                        if (file.isFile) FileUtils.deleteFile(file)
+                                    }
+                                }
+                                BitmapCache.clear()
+                            } catch (e: IOException) {
+                                Log.e(this::class.java.simpleName, e.message, e)
+                            }
                         }
                         medialibrary.discover(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
                     }



More information about the Android mailing list