add clear infojson preference

pull/1366/head
deniscerri 4 days ago
parent ba356d8a93
commit 0f16bece8f
No known key found for this signature in database
GPG Key ID: 95C43D517D830350

@ -345,6 +345,61 @@ object FolderSettingsModule: SettingModule {
}
}
}
"clear_info_jsons" -> {
pref.apply {
val infoJsonSize = File(FileUtil.getInfoJsonPath(context)).walkBottomUp().fold(0L) { acc, file -> acc + file.length() }
val filesize = if (infoJsonSize < 10000) {
"0B"
}else {
FileUtil.convertFileSize(infoJsonSize)
}
summary = "(${filesize})"
onPreferenceClickListener =
Preference.OnPreferenceClickListener {
host.hostLifecycleOwner.lifecycleScope.launch {
activeDownloadCount = withContext(Dispatchers.IO) {
downloadViewModel.getActiveDownloadsCount()
}
if (activeDownloadCount == 0){
fun clearInfoJsonFolder(folder: File) {
if (folder.exists() && folder.isDirectory) {
folder.listFiles()?.forEach { file ->
if (file.isDirectory) {
clearInfoJsonFolder(file)
file.delete()
} else {
file.delete()
}
}
}
}
clearInfoJsonFolder(File(FileUtil.getInfoJsonPath(context)))
if (host.hostView != null && host.hostView!!.isAttachedToWindow) {
Snackbar.make(host.hostView!!, context.getString(R.string.cache_cleared), Snackbar.LENGTH_SHORT).show()
}
}else{
if (host.hostView != null && host.hostView!!.isAttachedToWindow) {
Snackbar.make(host.hostView!!, context.getString(R.string.downloads_running_try_later), Snackbar.LENGTH_SHORT).show()
}
}
val infoJsonSize = File(FileUtil.getInfoJsonPath(context)).walkBottomUp().fold(0L) { acc, file -> acc + file.length() }
val filesize = if (infoJsonSize < 10000) {
"0B"
}else {
FileUtil.convertFileSize(infoJsonSize)
}
summary = "(${filesize})"
host.refreshUI()
}
true
}
}
}
"move_cache" -> {
pref.apply {
onPreferenceClickListener =

@ -587,6 +587,7 @@
<string name="check_clipboard">Check clipboard on app startup</string>
<string name="check_clipboard_home_summary">Automatically detect URLs in clipboard in the home screen</string>
<string name="check_clipboard_home">Check clipboard in the home screen</string>
<string name="clear_info_json">Clear infojsons</string>
<plurals name="every_hours"><item quantity="one">Every hour</item><item quantity="other">Every %d hours</item></plurals>
<plurals name="every_days"><item quantity="one">Every day</item><item quantity="other">Every %d days</item></plurals>
<plurals name="every_weeks"><item quantity="one">Every week</item><item quantity="other">Every %d weeks</item></plurals>

@ -118,6 +118,11 @@
android:summary="@string/clear_temporary_files_summary"
app:title="@string/clear_temporary_files" />
<Preference
app:icon="@drawable/ic_folder_delete"
app:key="clear_info_jsons"
app:title="@string/clear_info_json" />
<Preference
app:icon="@drawable/baseline_reset_tv_24"
app:key="reset_preferences"

Loading…
Cancel
Save