Skip to content

Commit

Permalink
Bug fix: Switching auto clean mode not working
Browse files Browse the repository at this point in the history
  • Loading branch information
KyuubiRan committed Mar 30, 2021
1 parent 14512a4 commit 857b2be
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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 ->
Expand All @@ -154,7 +159,7 @@ class SettingsActivity : AppCompatTransferActivity() {
}

doCustomerClean.setOnPreferenceClickListener {
showConfirmDialog(CUSTOMER_MODE, this.requireContext())
showConfirmDialog(CUSTOMER_MODE_INT, this.requireContext())
true
}
gotoGithub.setOnPreferenceClickListener {
Expand All @@ -163,7 +168,7 @@ class SettingsActivity : AppCompatTransferActivity() {
true
}
joinQQGroup.setOnPreferenceClickListener {
openQQGroup("827356240")
openQQGroup()
true
}
joinTelegram.setOnPreferenceClickListener {
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/me/kyuubiran/qqcleaner/dialog/CleanDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> ""
}
}
Expand All @@ -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()
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/me/kyuubiran/qqcleaner/utils/CleanManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = ""

//在加载模块的时候会检测并执行一次
Expand All @@ -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)
Expand All @@ -191,14 +193,17 @@ object CleanManager {
private fun autoClean() {
appContext.showToast("好耶 开始自动清理了!")
when (mode) {
HALF_MODE -> {
halfClean(false)
}
FULL_MODE -> {
fullClean(false)
}
CUSTOMER_MODE -> {
customerClean(false)
}
else -> {
halfClean(false)
appContext.showToast("坏耶 自动瘦身列表有误 请重新选择")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<string name="support_me">点我扶贫</string>
<string name="support_me_hint">本模块完全免费开源 一切开发旨在学习 请勿用于非法用途 喜欢本模块的可以捐赠支持我 谢谢~</string>
<string name="update_info">更新日志</string>
<string name="update_info_content">-1.6.1(31)\n
1.修复某些情况下微信入口打不开的问题
<string name="update_info_content">-1.6.2(32)\n
1.修复自动瘦身模式永远为普通模式的bug
</string>
<string name="join_qq_group">点击加入QQ群</string>
<string name="join_qq_group_hint">有问题可以来群里反馈哦~</string>
Expand Down

0 comments on commit 857b2be

Please sign in to comment.