diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt
index aa85c08f..05139957 100644
--- a/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt
+++ b/app/src/main/java/com/lagradost/cloudstream3/ui/settings/SettingsFragment.kt
@@ -198,12 +198,26 @@ class SettingsFragment : PreferenceFragmentCompat() {
private fun getPref(id: Int): Preference? {
return try {
findPreference(getString(id))
- } catch (e : Exception) {
+ } catch (e: Exception) {
logError(e)
null
}
}
+ fun getFolderSize(dir: File): Long {
+ var size: Long = 0
+ dir.listFiles()?.let {
+ for (file in it) {
+ size += if (file.isFile) {
+ // System.out.println(file.getName() + " " + file.length());
+ file.length()
+ } else getFolderSize(file)
+ }
+ }
+
+ return size
+ }
+
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
hideKeyboard()
setPreferencesFromResource(R.xml.settings, rootKey)
@@ -249,6 +263,31 @@ class SettingsFragment : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true
}
+ getPref(R.string.video_buffer_clear_key)?.let { pref ->
+ val cacheDir = context?.cacheDir ?: return@let
+
+ fun updateSummery() {
+ try {
+ pref.summary =
+ getString(R.string.mb_format).format(getFolderSize(cacheDir) / (1024L * 1024L))
+ } catch (e: Exception) {
+ logError(e)
+ }
+ }
+
+ updateSummery()
+
+ pref.setOnPreferenceClickListener {
+ try {
+ cacheDir.deleteRecursively()
+ updateSummery()
+ } catch (e: Exception) {
+ logError(e)
+ }
+ return@setOnPreferenceClickListener true
+ }
+ }
+
getPref(R.string.video_buffer_disk_key)?.setOnPreferenceClickListener {
val prefNames = resources.getStringArray(R.array.video_buffer_size_names)
val prefValues = resources.getIntArray(R.array.video_buffer_size_values)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index ae03e7b6..702c37d3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -15,6 +15,7 @@
quality_pref_key
video_buffer_size_key
video_buffer_length_key
+ video_buffer_clear_key
video_buffer_disk_key
unknown_prerelease
use_system_brightness_key
@@ -44,6 +45,7 @@
%d %s | %sMB
%s • %sGB
%sMB / %sMB
+ %dMB
%s %s
+%d
-%d
@@ -324,6 +326,8 @@
Video buffer size
Video buffer length
Video cache on disk
+ Clear video and image cache
+
May cause problems on systems with low ram or storage such as Android TV devices or old phones if you set it too high
DNS over HTTPS
diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml
index 4104e6d1..58eb7726 100644
--- a/app/src/main/res/xml/settings.xml
+++ b/app/src/main/res/xml/settings.xml
@@ -80,6 +80,11 @@
android:title="@string/video_buffer_length_settings"
android:summary="@string/video_buffer_description"
android:icon="@drawable/ic_baseline_storage_24" />
+
+