added clear temporary files
This commit is contained in:
parent
b86c7a616e
commit
4c56042123
5 changed files with 44 additions and 3 deletions
|
|
@ -320,7 +320,7 @@
|
||||||
<PersistentState>
|
<PersistentState>
|
||||||
<option name="values">
|
<option name="values">
|
||||||
<map>
|
<map>
|
||||||
<entry key="url" value="file:/$USER_HOME$/AppData/Local/Android/Sdk/icons/material/materialicons/video_file/baseline_video_file_24.xml" />
|
<entry key="url" value="file:/$USER_HOME$/AppData/Local/Android/Sdk/icons/material/materialicons/folder_delete/baseline_folder_delete_24.xml" />
|
||||||
</map>
|
</map>
|
||||||
</option>
|
</option>
|
||||||
</PersistentState>
|
</PersistentState>
|
||||||
|
|
@ -330,8 +330,7 @@
|
||||||
</option>
|
</option>
|
||||||
<option name="values">
|
<option name="values">
|
||||||
<map>
|
<map>
|
||||||
<entry key="assetSourceType" value="FILE" />
|
<entry key="outputName" value="ic_folder_delete" />
|
||||||
<entry key="outputName" value="ic_translate" />
|
|
||||||
<entry key="sourceFile" value="C:\Users\denis\Desktop\FREKUENCA\icons8-google-translate.svg" />
|
<entry key="sourceFile" value="C:\Users\denis\Desktop\FREKUENCA\icons8-google-translate.svg" />
|
||||||
</map>
|
</map>
|
||||||
</option>
|
</option>
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.core.os.LocaleListCompat
|
import androidx.core.os.LocaleListCompat
|
||||||
import androidx.preference.*
|
import androidx.preference.*
|
||||||
|
import androidx.work.WorkInfo
|
||||||
|
import androidx.work.WorkManager
|
||||||
import com.deniscerri.ytdlnis.BuildConfig
|
import com.deniscerri.ytdlnis.BuildConfig
|
||||||
import com.deniscerri.ytdlnis.R
|
import com.deniscerri.ytdlnis.R
|
||||||
import com.deniscerri.ytdlnis.util.FileUtil
|
import com.deniscerri.ytdlnis.util.FileUtil
|
||||||
|
|
@ -26,6 +28,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||||
private var videoPath: Preference? = null
|
private var videoPath: Preference? = null
|
||||||
private var commandPath: Preference? = null
|
private var commandPath: Preference? = null
|
||||||
private var accessAllFiles : Preference? = null
|
private var accessAllFiles : Preference? = null
|
||||||
|
private var clearCache: Preference? = null
|
||||||
private var incognito: SwitchPreferenceCompat? = null
|
private var incognito: SwitchPreferenceCompat? = null
|
||||||
private var preferredDownloadType : ListPreference? = null
|
private var preferredDownloadType : ListPreference? = null
|
||||||
private var downloadCard: SwitchPreferenceCompat? = null
|
private var downloadCard: SwitchPreferenceCompat? = null
|
||||||
|
|
@ -56,12 +59,21 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||||
|
|
||||||
private var updateUtil: UpdateUtil? = null
|
private var updateUtil: UpdateUtil? = null
|
||||||
private var fileUtil: FileUtil? = null
|
private var fileUtil: FileUtil? = null
|
||||||
|
private var activeDownloadCount = 0
|
||||||
|
|
||||||
private val jsonFormat = Json { prettyPrint = true }
|
private val jsonFormat = Json { prettyPrint = true }
|
||||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||||
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
||||||
updateUtil = UpdateUtil(requireContext())
|
updateUtil = UpdateUtil(requireContext())
|
||||||
fileUtil = FileUtil()
|
fileUtil = FileUtil()
|
||||||
|
|
||||||
|
WorkManager.getInstance(requireContext()).getWorkInfosByTagLiveData("download").observe(this){
|
||||||
|
activeDownloadCount = 0
|
||||||
|
it.forEach {w ->
|
||||||
|
if (w.state == WorkInfo.State.RUNNING) activeDownloadCount++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initPreferences()
|
initPreferences()
|
||||||
initListeners()
|
initListeners()
|
||||||
}
|
}
|
||||||
|
|
@ -75,6 +87,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||||
videoPath = findPreference("video_path")
|
videoPath = findPreference("video_path")
|
||||||
commandPath = findPreference("command_path")
|
commandPath = findPreference("command_path")
|
||||||
accessAllFiles = findPreference("access_all_files")
|
accessAllFiles = findPreference("access_all_files")
|
||||||
|
clearCache = findPreference("clear_cache")
|
||||||
incognito = findPreference("incognito")
|
incognito = findPreference("incognito")
|
||||||
preferredDownloadType = findPreference("preferred_download_type")
|
preferredDownloadType = findPreference("preferred_download_type")
|
||||||
downloadCard = findPreference("download_card")
|
downloadCard = findPreference("download_card")
|
||||||
|
|
@ -210,6 +223,20 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cacheSize = requireContext().cacheDir.walkBottomUp().fold(0L) { acc, file -> acc + file.length() }
|
||||||
|
clearCache!!.summary = "(${fileUtil!!.convertFileSize(cacheSize)}) ${resources.getString(R.string.clear_temporary_files_summary)}"
|
||||||
|
clearCache!!.onPreferenceClickListener =
|
||||||
|
Preference.OnPreferenceClickListener {
|
||||||
|
if (activeDownloadCount == 0){
|
||||||
|
requireContext().cacheDir.deleteRecursively()
|
||||||
|
Toast.makeText(requireContext(), getString(R.string.cache_cleared), Toast.LENGTH_SHORT).show()
|
||||||
|
cacheSize = requireContext().cacheDir.walkBottomUp().fold(0L) { acc, file -> acc + file.length() }
|
||||||
|
clearCache!!.summary = "(${fileUtil!!.convertFileSize(cacheSize)}) ${resources.getString(R.string.clear_temporary_files_summary)}"
|
||||||
|
}else{
|
||||||
|
Toast.makeText(requireContext(), getString(R.string.downloads_running_try_later), Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
incognito!!.onPreferenceChangeListener =
|
incognito!!.onPreferenceChangeListener =
|
||||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||||
val enable = newValue as Boolean
|
val enable = newValue as Boolean
|
||||||
|
|
|
||||||
5
app/src/main/res/drawable/ic_folder_delete.xml
Normal file
5
app/src/main/res/drawable/ic_folder_delete.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
<vector android:height="24dp"
|
||||||
|
android:viewportHeight="24" android:viewportWidth="24"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="?android:colorAccent" android:pathData="M22,8v10c0,1.1 -0.9,2 -2,2H4c-1.1,0 -2,-0.9 -2,-2L2.01,6C2.01,4.9 2.9,4 4,4h6l2,2h8C21.1,6 22,6.9 22,8zM16.5,10V9h-2v1H12v1.5h1v4c0,0.83 0.67,1.5 1.5,1.5h2c0.83,0 1.5,-0.67 1.5,-1.5v-4h1V10H16.5zM16.5,15.5h-2v-4h2V15.5z"/>
|
||||||
|
</vector>
|
||||||
|
|
@ -221,4 +221,8 @@
|
||||||
<string name="restart">Restart</string>
|
<string name="restart">Restart</string>
|
||||||
<string name="download_rescheduled_to">Download rescheduled to:</string>
|
<string name="download_rescheduled_to">Download rescheduled to:</string>
|
||||||
<string name="file_size">File size</string>
|
<string name="file_size">File size</string>
|
||||||
|
<string name="clear_temporary_files">Clear temporary files</string>
|
||||||
|
<string name="clear_temporary_files_summary">Delete cached files from crashed/errored/cancelled downloads</string>
|
||||||
|
<string name="cache_cleared">Temporary files cleared</string>
|
||||||
|
<string name="downloads_running_try_later">Download worker is running. Try again later</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -36,6 +36,12 @@
|
||||||
android:summary="@string/access_all_directories_summary"
|
android:summary="@string/access_all_directories_summary"
|
||||||
app:title="@string/access_all_directories" />
|
app:title="@string/access_all_directories" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
app:icon="@drawable/ic_folder_delete"
|
||||||
|
app:key="clear_cache"
|
||||||
|
android:summary="@string/clear_temporary_files_summary"
|
||||||
|
app:title="@string/clear_temporary_files" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory app:title="@string/downloading">
|
<PreferenceCategory app:title="@string/downloading">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue