From 857b2befd0e2ff76247ab5e8f943c890071cd2be Mon Sep 17 00:00:00 2001 From: KyuubiRan Date: Tue, 30 Mar 2021 11:51:16 +0800 Subject: [PATCH] Bug fix: Switching auto clean mode not working --- app/build.gradle | 4 +-- .../qqcleaner/activity/SettingsActivity.kt | 25 ++++++++++++++----- .../kyuubiran/qqcleaner/dialog/CleanDialog.kt | 18 ++++++------- .../kyuubiran/qqcleaner/utils/CleanManager.kt | 13 +++++++--- .../qqcleaner/utils/ConfigManager.kt | 2 +- app/src/main/res/values/strings.xml | 4 +-- 6 files changed, 42 insertions(+), 24 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0c7880a..19a6e79 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "me.kyuubiran.qqcleaner" minSdkVersion 21 targetSdkVersion 30 - versionCode 31 - versionName "1.6.1" + versionCode 32 + versionName "1.6.2" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/me/kyuubiran/qqcleaner/activity/SettingsActivity.kt b/app/src/main/java/me/kyuubiran/qqcleaner/activity/SettingsActivity.kt index a31c6d4..cd23388 100644 --- a/app/src/main/java/me/kyuubiran/qqcleaner/activity/SettingsActivity.kt +++ b/app/src/main/java/me/kyuubiran/qqcleaner/activity/SettingsActivity.kt @@ -16,7 +16,11 @@ import me.kyuubiran.qqcleaner.data.hostInfo import me.kyuubiran.qqcleaner.dialog.* import me.kyuubiran.qqcleaner.dialog.CleanDialog.showConfirmDialog import me.kyuubiran.qqcleaner.dialog.CleanDialog.showSetFileDateLimitDialog +import me.kyuubiran.qqcleaner.utils.CleanManager.CUSTOMER_MODE +import me.kyuubiran.qqcleaner.utils.CleanManager.FULL_MODE +import me.kyuubiran.qqcleaner.utils.CleanManager.HALF_MODE import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_AUTO_CLEAN_ENABLED +import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_AUTO_CLEAN_MODE import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_CLEAN_DELAY import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_CURRENT_CLEANED_TIME import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_CUSTOMER_CLEAN_LIST @@ -38,7 +42,8 @@ class SettingsActivity : AppCompatTransferActivity() { @SuppressLint("SetTextI18n") override fun onCreate(savedInstanceState: Bundle?) { setTheme(R.style.AppTheme_Ftb) - val mode = if (isInNightMode()) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM + val mode = + if (isInNightMode()) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM AppCompatDelegate.setDefaultNightMode(mode) super.onCreate(savedInstanceState) setContentView(R.layout.settings_activity) @@ -132,11 +137,11 @@ class SettingsActivity : AppCompatTransferActivity() { //设置Item点击事件 private fun setClickable() { halfClean.setOnPreferenceClickListener { - showConfirmDialog(HALF_MODE, this.requireContext()) + showConfirmDialog(HALF_MODE_INT, this.requireContext()) true } fullClean.setOnPreferenceClickListener { - showConfirmDialog(FULL_MODE, this.requireContext()) + showConfirmDialog(FULL_MODE_INT, this.requireContext()) true } customerCleanList.setOnPreferenceChangeListener { _, newValue -> @@ -154,7 +159,7 @@ class SettingsActivity : AppCompatTransferActivity() { } doCustomerClean.setOnPreferenceClickListener { - showConfirmDialog(CUSTOMER_MODE, this.requireContext()) + showConfirmDialog(CUSTOMER_MODE_INT, this.requireContext()) true } gotoGithub.setOnPreferenceClickListener { @@ -163,7 +168,7 @@ class SettingsActivity : AppCompatTransferActivity() { true } joinQQGroup.setOnPreferenceClickListener { - openQQGroup("827356240") + openQQGroup() true } joinTelegram.setOnPreferenceClickListener { @@ -199,6 +204,14 @@ class SettingsActivity : AppCompatTransferActivity() { CleanDialog.showCleanDelayDialog(this.requireContext(), autoClean) true } + autoCleanMode.setOnPreferenceChangeListener { _, newValue -> + when (newValue) { + HALF_MODE -> setConfig(CFG_AUTO_CLEAN_MODE, HALF_MODE) + FULL_MODE -> setConfig(CFG_AUTO_CLEAN_MODE, FULL_MODE) + CUSTOMER_MODE -> setConfig(CFG_AUTO_CLEAN_MODE, CUSTOMER_MODE) + } + true + } } private fun openUrl(url: String) { @@ -207,7 +220,7 @@ class SettingsActivity : AppCompatTransferActivity() { startActivity(intent) } - private fun openQQGroup(uin: String) { + private fun openQQGroup(uin: String = "827356240") { val uri = Uri.parse("mqqapi://card/show_pslcard?src_type=internal&version=1&uin=$uin&card_type=group&source=qrcode") val intent = Intent(Intent.ACTION_VIEW, uri) diff --git a/app/src/main/java/me/kyuubiran/qqcleaner/dialog/CleanDialog.kt b/app/src/main/java/me/kyuubiran/qqcleaner/dialog/CleanDialog.kt index 384b3b5..989230b 100644 --- a/app/src/main/java/me/kyuubiran/qqcleaner/dialog/CleanDialog.kt +++ b/app/src/main/java/me/kyuubiran/qqcleaner/dialog/CleanDialog.kt @@ -13,16 +13,16 @@ import me.kyuubiran.qqcleaner.utils.ConfigManager import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_CLEAN_DELAY import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_DATE_LIMIT -const val HALF_MODE = 0 -const val FULL_MODE = 1 -const val CUSTOMER_MODE = 2 +const val HALF_MODE_INT = 0 +const val FULL_MODE_INT = 1 +const val CUSTOMER_MODE_INT = 2 object CleanDialog { private fun getMessage(mode: Int): String { return when (mode) { - HALF_MODE -> "一键瘦身" - FULL_MODE -> "完全瘦身" - CUSTOMER_MODE -> "自定义瘦身" + HALF_MODE_INT -> "一键瘦身" + FULL_MODE_INT -> "完全瘦身" + CUSTOMER_MODE_INT -> "自定义瘦身" else -> "" } } @@ -37,9 +37,9 @@ object CleanDialog { .setNegativeButton("取消") { _, _ -> } .setPositiveButton("确定") { _, _ -> when (mode) { - HALF_MODE -> CleanManager.halfClean() - FULL_MODE -> CleanManager.fullClean() - CUSTOMER_MODE -> CleanManager.customerClean() + HALF_MODE_INT -> CleanManager.halfClean() + FULL_MODE_INT -> CleanManager.fullClean() + CUSTOMER_MODE_INT -> CleanManager.customerClean() } } .create() diff --git a/app/src/main/java/me/kyuubiran/qqcleaner/utils/CleanManager.kt b/app/src/main/java/me/kyuubiran/qqcleaner/utils/CleanManager.kt index afede0a..62f9104 100644 --- a/app/src/main/java/me/kyuubiran/qqcleaner/utils/CleanManager.kt +++ b/app/src/main/java/me/kyuubiran/qqcleaner/utils/CleanManager.kt @@ -8,9 +8,9 @@ import com.github.kyuubiran.ezxhelper.utils.runtimeProcess import com.github.kyuubiran.ezxhelper.utils.showToast import me.kyuubiran.qqcleaner.data.hostApp import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_AUTO_CLEAN_ENABLED +import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_AUTO_CLEAN_MODE import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_CLEAN_DELAY import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_CURRENT_CLEANED_TIME -import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_CUSTOMER_CLEAN_MODE import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_DATE_LIMIT import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_DATE_LIMIT_ENABLED import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_POWER_MODE_ENABLED @@ -19,6 +19,7 @@ import me.kyuubiran.qqcleaner.utils.ConfigManager.getBool import me.kyuubiran.qqcleaner.utils.ConfigManager.getConfig import me.kyuubiran.qqcleaner.utils.ConfigManager.getInt import me.kyuubiran.qqcleaner.utils.ConfigManager.getLong +import me.kyuubiran.qqcleaner.utils.ConfigManager.getString import me.kyuubiran.qqcleaner.utils.clean.CleanQQ import me.kyuubiran.qqcleaner.utils.clean.CleanWeChat import java.io.File @@ -171,7 +172,7 @@ object CleanManager { class AutoClean { private var time = 0L - private val delay = ConfigManager.getInt(CFG_CLEAN_DELAY, 24) * 3600L * 1000L + private val delay = getInt(CFG_CLEAN_DELAY, 24) * 3600L * 1000L private var mode = "" //在加载模块的时候会检测并执行一次 @@ -180,7 +181,8 @@ object CleanManager { //判断间隔 if (getBool(CFG_AUTO_CLEAN_ENABLED) && System.currentTimeMillis() - time > if (delay < 3600_000L) 24 * 3600L * 1000L else delay ) { - mode = getConfig(CFG_CUSTOMER_CLEAN_MODE).toString() + mode = getString(CFG_AUTO_CLEAN_MODE) + if (mode.isEmpty()) mode = HALF_MODE autoClean() time = System.currentTimeMillis() ConfigManager.setConfig(CFG_CURRENT_CLEANED_TIME, time) @@ -191,6 +193,9 @@ object CleanManager { private fun autoClean() { appContext.showToast("好耶 开始自动清理了!") when (mode) { + HALF_MODE -> { + halfClean(false) + } FULL_MODE -> { fullClean(false) } @@ -198,7 +203,7 @@ object CleanManager { customerClean(false) } else -> { - halfClean(false) + appContext.showToast("坏耶 自动瘦身列表有误 请重新选择") } } } diff --git a/app/src/main/java/me/kyuubiran/qqcleaner/utils/ConfigManager.kt b/app/src/main/java/me/kyuubiran/qqcleaner/utils/ConfigManager.kt index 522d2dc..e7596f9 100644 --- a/app/src/main/java/me/kyuubiran/qqcleaner/utils/ConfigManager.kt +++ b/app/src/main/java/me/kyuubiran/qqcleaner/utils/ConfigManager.kt @@ -12,9 +12,9 @@ object ConfigManager { private val config = File("${appContext.filesDir.absolutePath}/qqcleaner.json") const val CFG_AUTO_CLEAN_ENABLED = "autoCleanEnabled" + const val CFG_AUTO_CLEAN_MODE = "autoCleanMode" const val CFG_CURRENT_CLEANED_TIME = "cleanedTime" const val CFG_CUSTOMER_CLEAN_LIST = "customerList" - const val CFG_CUSTOMER_CLEAN_MODE = "customerCleanMode" const val CFG_TOTAL_CLEANED_SIZE = "totalCleanedSize" const val CFG_CLEAN_DELAY = "cleanDelay" const val CFG_POWER_MODE_ENABLED = "powerModeEnabled" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1de71d1..6ec25ec 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -41,8 +41,8 @@ 点我扶贫 本模块完全免费开源 一切开发旨在学习 请勿用于非法用途 喜欢本模块的可以捐赠支持我 谢谢~ 更新日志 - -1.6.1(31)\n - 1.修复某些情况下微信入口打不开的问题 + -1.6.2(32)\n + 1.修复自动瘦身模式永远为普通模式的bug 点击加入QQ群 有问题可以来群里反馈哦~