Skip to content

Commit

Permalink
Bugfix:Change hint when user changed auto clean delay.
Browse files Browse the repository at this point in the history
  • Loading branch information
KyuubiRan committed Feb 17, 2021
1 parent 2903d1d commit 2da31b5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "me.kyuubiran.qqcleaner"
minSdkVersion 21
targetSdkVersion 30
versionCode 19
versionName "1.2.6"
versionCode 20
versionName "1.2.6.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import me.kyuubiran.qqcleaner.BuildConfig
import me.kyuubiran.qqcleaner.R
import me.kyuubiran.qqcleaner.dialog.*
import me.kyuubiran.qqcleaner.dialog.CleanDialog.showConfirmDialog
import me.kyuubiran.qqcleaner.utils.*
import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_AUTO_CLEAN_ENABLED
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
import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_TOTAL_CLEANED_SIZE
import me.kyuubiran.qqcleaner.utils.ConfigManager.checkCfg
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.setConfig
import me.kyuubiran.qqcleaner.utils.formatSize
import me.kyuubiran.qqcleaner.utils.loge
import me.kyuubiran.qqcleaner.utils.appContext
import me.kyuubiran.qqcleaner.utils.makeToast
import java.lang.annotation.Native
import java.text.SimpleDateFormat

class SettingsActivity : AppCompatTransferActivity() {
Expand Down Expand Up @@ -75,7 +75,7 @@ class SettingsActivity : AppCompatTransferActivity() {

//初始化函数
private fun init() {
setHistorySummary()
initSummary()
toggleCleanedTimeShow()
setClickable()
setVersionName()
Expand Down Expand Up @@ -140,11 +140,11 @@ class SettingsActivity : AppCompatTransferActivity() {
}
cleanedHistory.setOnPreferenceClickListener {
appContext?.makeToast("已刷新统计信息")
setHistorySummary()
initSummary()
true
}
cleanDelay.setOnPreferenceClickListener {
CleanDialog.showCleanDelayDialog(this.requireContext())
CleanDialog.showCleanDelayDialog(this.requireContext(), autoClean)
true
}
}
Expand Down Expand Up @@ -178,13 +178,16 @@ class SettingsActivity : AppCompatTransferActivity() {
}

//刷新总清理空间的函数
private fun setHistorySummary() {
private fun initSummary() {
if (getConfig(CFG_TOTAL_CLEANED_SIZE) != 0) {
cleanedHistory.summary =
"总共为您腾出:${formatSize(getLong(CFG_TOTAL_CLEANED_SIZE))}空间"
} else {
cleanedHistory.setSummary(R.string.no_cleaned_his_hint)
}

val delayTmp = getInt(CFG_CLEAN_DELAY)
autoClean.summary = if (delayTmp == 0) "当前清理的间隔为24小时" else "当前清理的间隔为${delayTmp}小时"
}

private fun setVersionName() {
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/me/kyuubiran/qqcleaner/dialog/CleanDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.text.InputFilter
import android.text.InputType
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import androidx.preference.SwitchPreference
import androidx.preference.SwitchPreferenceCompat
import me.kyuubiran.qqcleaner.utils.CleanManager
import me.kyuubiran.qqcleaner.utils.ConfigManager
import me.kyuubiran.qqcleaner.utils.ConfigManager.CFG_CLEAN_DELAY
Expand Down Expand Up @@ -44,7 +46,7 @@ object CleanDialog {
}

//设定瘦身延迟的对话框
fun showCleanDelayDialog(context: Context) {
fun showCleanDelayDialog(context: Context, spc: SwitchPreferenceCompat) {
val input = EditText(context)
input.setText(ConfigManager.getInt(CFG_CLEAN_DELAY, 24).toString())
input.inputType = InputType.TYPE_CLASS_NUMBER
Expand All @@ -53,9 +55,11 @@ object CleanDialog {
.setView(input)
.setTitle("设置瘦身延迟(小时)")
.setPositiveButton("确定") { _, _ ->
val num = input.text.toString().toInt()
ConfigManager.setConfig(CFG_CLEAN_DELAY, if (num < 1) 24 else num)
var num = input.text.toString().toInt()
num = if (num < 1) 24 else num
ConfigManager.setConfig(CFG_CLEAN_DELAY, num)
context.makeToast("保存成功!")
spc.summary = "当前清理的间隔为${num}小时"
}
.setNegativeButton("取消") { _, _ -> }
.create()
Expand Down
27 changes: 14 additions & 13 deletions app/src/main/java/me/kyuubiran/qqcleaner/utils/CleanManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ object CleanManager {
private const val DOU_TU = "dou_tu"
private const val VIDEO_BACKGROUND = "video_background"
private const val RECEIVE_FILE_CACHE = "receive_file_cache"
private const val TBS = "tbs"
private const val OTHERS = "others"

//计算清理完毕后的释放的空间
Expand Down Expand Up @@ -220,6 +221,7 @@ object CleanManager {
addAll(getFiles(VIP_ICON))
addAll(getFiles(DOU_TU))
addAll(getFiles(RECEIVE_FILE_CACHE))
addAll(getFiles(TBS))
addAll(getFiles(OTHERS))
}

Expand Down Expand Up @@ -276,7 +278,8 @@ object CleanManager {
if (showToast) appContext?.makeToast("好耶 开始清理了!")
try {
for (f in files) {
deleteAllFiles(f)
// appContext?.makeToast("开始清理${f.path}")
delFiles(f)
}
appContext?.makeToast("好耶 清理完毕了!腾出了${formatSize(size)}空间!")
saveSize()
Expand All @@ -289,24 +292,22 @@ object CleanManager {

/**
* @param file 文件/文件夹
* 递归删除文件
* 删除文件/文件夹的函数
*/
private fun deleteAllFiles(file: File) {
private fun delFiles(file: File) {
if (!file.exists()) return
if (file.isFile) {
size += file.length()
file.delete()
return
}
if (file.isDirectory) {
val childFile = file.listFiles()
if (childFile == null || childFile.isEmpty()) {
} else {
val list = file.listFiles()
if (list == null || list.isEmpty()) {
file.delete()
return
}
for (f in childFile) {
deleteAllFiles(f)
} else {
for (f in list) {
delFiles(f)
}
}
file.delete()
}
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<string name="auto_clean_switch_title">自动瘦身</string>

<string name="auto_clean_switch_hint">两次清理的间隔为24小时</string>
<string name="auto_clean_switch_key">启用自动瘦身</string>
<string name="auto_clean_time">上次自动瘦身时间</string>
<string name="auto_clean_mode">瘦身方案</string>
Expand Down Expand Up @@ -34,6 +33,8 @@
<string name="about">公告</string>
<string name="about_hint">注意:本模块不会清理聊天记录、接收文件、保存的图片、表情收藏等重要东西\n
[更新日志]\n
-1.2.6.1\n
1.修复自定义瘦身间隔后提示未改变的bug\n
-1.2.6\n
1.允许自定义瘦身间隔(单位小时) 最小为1小时 最大为99999小时 设为0时默认24小时
</string>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<PreferenceCategory app:title="@string/auto_clean_switch_title">
<SwitchPreferenceCompat
app:key="AutoClean"
app:title="@string/auto_clean_switch_key"
app:summary="@string/auto_clean_switch_hint" />
app:title="@string/auto_clean_switch_key" />
<ListPreference
app:entries="@array/auto_clean_mode"
app:entryValues="@array/auto_clean_mode_value"
Expand Down

0 comments on commit 2da31b5

Please sign in to comment.