From 10be21c87538e5f5e2895353e5649e49b4409d6a Mon Sep 17 00:00:00 2001 From: X1nto Date: Fri, 7 Aug 2020 11:07:49 +0400 Subject: [PATCH] added option to delete downloaded file --- .../manager/core/downloader/MicrogDownloadService.kt | 1 + .../manager/core/downloader/VancedDownloadService.kt | 1 + .../com/vanced/manager/ui/fragments/SettingsFragment.kt | 9 +++++++++ app/src/main/res/values/strings.xml | 4 +++- app/src/main/res/xml/preferences.xml | 4 ++++ 5 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloadService.kt b/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloadService.kt index 8e5151c5..b766ed03 100644 --- a/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloadService.kt +++ b/app/src/main/java/com/vanced/manager/core/downloader/MicrogDownloadService.kt @@ -33,6 +33,7 @@ class MicrogDownloadService: Service() { private fun downloadMicrog() { runBlocking { launch { + getExternalFilesDir("apk")?.delete() val url = getObjectFromJson( "${PreferenceManager.getDefaultSharedPreferences(this@MicrogDownloadService) .getString("install_url", baseUrl)}/microg.json", "url" diff --git a/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt b/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt index 225647e9..dd6c06ce 100644 --- a/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt +++ b/app/src/main/java/com/vanced/manager/core/downloader/VancedDownloadService.kt @@ -41,6 +41,7 @@ class VancedDownloadService: Service() { val context = this runBlocking { launch { + getExternalFilesDir("apks")?.delete() val defPrefs = PreferenceManager.getDefaultSharedPreferences(context) val installUrl = defPrefs.getString("install_url", baseUrl) val vancedVer = getObjectFromJson("$installUrl/vanced.json", "version") diff --git a/app/src/main/java/com/vanced/manager/ui/fragments/SettingsFragment.kt b/app/src/main/java/com/vanced/manager/ui/fragments/SettingsFragment.kt index 0c1aaed0..7986c446 100644 --- a/app/src/main/java/com/vanced/manager/ui/fragments/SettingsFragment.kt +++ b/app/src/main/java/com/vanced/manager/ui/fragments/SettingsFragment.kt @@ -91,6 +91,15 @@ class SettingsFragment : PreferenceFragmentCompat() { true } + findPreference("clear_files")?.setOnPreferenceClickListener { + with(requireActivity()) { + getExternalFilesDir("apk")?.delete() + getExternalFilesDir("apks")?.delete() + Toast.makeText(this, getString(R.string.cleared_files), Toast.LENGTH_SHORT) + } + true + } + } override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c148fb91..45a791dc 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -49,12 +49,14 @@ Purple Red Yellow - Check for updates Interface Manager + Check for updates Chosen installation preferences Language(s): %1$s Theme: %1$s + Clear downloaded files + Successfully cleared files Use Chrome Custom Tabs Links will open in Chrome Custom Tabs Links will open in an External Browser diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 57424920..135f1973 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -67,6 +67,10 @@ android:title="@string/update_url" android:key="install_url" /> + + \ No newline at end of file