added clear video cache

This commit is contained in:
LagradOst 2022-03-16 22:54:58 +01:00
parent 5b02a37fc1
commit d19d293074
3 changed files with 49 additions and 1 deletions

View file

@ -204,6 +204,20 @@ class SettingsFragment : PreferenceFragmentCompat() {
} }
} }
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?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
hideKeyboard() hideKeyboard()
setPreferencesFromResource(R.xml.settings, rootKey) setPreferencesFromResource(R.xml.settings, rootKey)
@ -249,6 +263,31 @@ class SettingsFragment : PreferenceFragmentCompat() {
return@setOnPreferenceClickListener true 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 { getPref(R.string.video_buffer_disk_key)?.setOnPreferenceClickListener {
val prefNames = resources.getStringArray(R.array.video_buffer_size_names) val prefNames = resources.getStringArray(R.array.video_buffer_size_names)
val prefValues = resources.getIntArray(R.array.video_buffer_size_values) val prefValues = resources.getIntArray(R.array.video_buffer_size_values)

View file

@ -15,6 +15,7 @@
<string name="quality_pref_key" translatable="false">quality_pref_key</string> <string name="quality_pref_key" translatable="false">quality_pref_key</string>
<string name="video_buffer_size_key" translatable="false">video_buffer_size_key</string> <string name="video_buffer_size_key" translatable="false">video_buffer_size_key</string>
<string name="video_buffer_length_key" translatable="false">video_buffer_length_key</string> <string name="video_buffer_length_key" translatable="false">video_buffer_length_key</string>
<string name="video_buffer_clear_key" translatable="false">video_buffer_clear_key</string>
<string name="video_buffer_disk_key" translatable="false">video_buffer_disk_key</string> <string name="video_buffer_disk_key" translatable="false">video_buffer_disk_key</string>
<string name="prerelease_commit_hash" translatable="false">unknown_prerelease</string> <string name="prerelease_commit_hash" translatable="false">unknown_prerelease</string>
<string name="use_system_brightness_key" translatable="false">use_system_brightness_key</string> <string name="use_system_brightness_key" translatable="false">use_system_brightness_key</string>
@ -44,6 +45,7 @@
<string name="extra_info_format" translatable="false" formatted="true">%d %s | %sMB</string> <string name="extra_info_format" translatable="false" formatted="true">%d %s | %sMB</string>
<string name="storage_size_format" translatable="false" formatted="true">%s • %sGB</string> <string name="storage_size_format" translatable="false" formatted="true">%s • %sGB</string>
<string name="download_size_format" translatable="false" formatted="true">%sMB / %sMB</string> <string name="download_size_format" translatable="false" formatted="true">%sMB / %sMB</string>
<string name="mb_format" translatable="false" formatted="true">%dMB</string>
<string name="episode_name_format" translatable="false" formatted="true">%s %s</string> <string name="episode_name_format" translatable="false" formatted="true">%s %s</string>
<string name="ffw_text_format" translatable="false" formatted="true">+%d</string> <string name="ffw_text_format" translatable="false" formatted="true">+%d</string>
<string name="rew_text_format" translatable="false" formatted="true">-%d</string> <string name="rew_text_format" translatable="false" formatted="true">-%d</string>
@ -324,6 +326,8 @@
<string name="video_buffer_size_settings">Video buffer size</string> <string name="video_buffer_size_settings">Video buffer size</string>
<string name="video_buffer_length_settings">Video buffer length</string> <string name="video_buffer_length_settings">Video buffer length</string>
<string name="video_buffer_disk_settings">Video cache on disk</string> <string name="video_buffer_disk_settings">Video cache on disk</string>
<string name="video_buffer_clear_settings">Clear video and image cache</string>
<string name="video_buffer_description">May cause problems on systems with low ram or storage such as Android TV devices or old phones if you set it too high</string> <string name="video_buffer_description">May cause problems on systems with low ram or storage such as Android TV devices or old phones if you set it too high</string>
<string name="dns_pref">DNS over HTTPS</string> <string name="dns_pref">DNS over HTTPS</string>

View file

@ -80,6 +80,11 @@
android:title="@string/video_buffer_length_settings" android:title="@string/video_buffer_length_settings"
android:summary="@string/video_buffer_description" android:summary="@string/video_buffer_description"
android:icon="@drawable/ic_baseline_storage_24" /> android:icon="@drawable/ic_baseline_storage_24" />
<Preference
android:key="@string/video_buffer_clear_key"
android:title="@string/video_buffer_clear_settings"
android:icon="@drawable/ic_baseline_autorenew_24" />
<!-- <!--
<SwitchPreference <SwitchPreference
android:icon="@drawable/ic_baseline_brightness_7_24" android:icon="@drawable/ic_baseline_brightness_7_24"