Skip to content

Commit

Permalink
Support CustomerClean
Browse files Browse the repository at this point in the history
  • Loading branch information
KyuubiRan committed Nov 15, 2020
1 parent c550b7d commit 1eac1ae
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 32 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 10
versionName "1.0"
versionCode 11
versionName "1.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.kyuubiran.qqcleaner">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -19,5 +18,4 @@
android:name="xposedminversion"
android:value="54"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package me.kyuubiran.qqcleaner.activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.preference.MultiSelectListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import me.kyuubiran.qqcleaner.R
import me.kyuubiran.qqcleaner.dialog.CUSTOMER_MODE
import me.kyuubiran.qqcleaner.dialog.CleanDialog.showConfirmDialog
import me.kyuubiran.qqcleaner.dialog.FULL_MODE
import me.kyuubiran.qqcleaner.dialog.HALF_MODE
import me.kyuubiran.qqcleaner.utils.CleanManager
import me.kyuubiran.qqcleaner.utils.qqContext
import me.kyuubiran.qqcleaner.utils.showToastBySystem

Expand All @@ -31,7 +34,8 @@ class SettingsActivity : AppCompatTransferActivity() {
private lateinit var cleanedTime: Preference
private lateinit var halfClean: Preference
private lateinit var fullClean: Preference
private lateinit var customerClean: Preference
private lateinit var customerCleanList: MultiSelectListPreference
private lateinit var doCustomerClean: Preference
private lateinit var supportMe: Preference
private lateinit var gotoGithub: Preference

Expand All @@ -41,7 +45,8 @@ class SettingsActivity : AppCompatTransferActivity() {
cleanedTime = findPreference("CleanedTime")!!
halfClean = findPreference("HalfClean")!!
fullClean = findPreference("FullClean")!!
customerClean = findPreference("CustomerClean")!!
customerCleanList = findPreference("CustomerClean")!!
doCustomerClean = findPreference("DoCustomerClean")!!
gotoGithub = findPreference("GotoGithub")!!
supportMe = findPreference("SupportMe")!!
init()
Expand All @@ -61,8 +66,12 @@ class SettingsActivity : AppCompatTransferActivity() {
onClickCleanFull()
true
}
customerClean.setOnPreferenceClickListener {
onClickCustomer()
customerCleanList.setOnPreferenceChangeListener { _, _ ->
true
}
doCustomerClean.setOnPreferenceClickListener {
CleanManager.customerList = customerCleanList.values
showConfirmDialog(CUSTOMER_MODE, this.activity!!)
true
}
gotoGithub.setOnPreferenceClickListener {
Expand Down Expand Up @@ -94,11 +103,6 @@ class SettingsActivity : AppCompatTransferActivity() {
showConfirmDialog(FULL_MODE, this.activity!!)
}

private fun onClickCustomer() {
// showCustomerDialog(this.activity!!)
qqContext?.showToastBySystem("还在制作中> <")
}


private fun toggleCleanedTimeShow() {
cleanedTime.isVisible = autoClean.isChecked
Expand Down
12 changes: 2 additions & 10 deletions app/src/main/java/me/kyuubiran/qqcleaner/dialog/CleanDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import me.kyuubiran.qqcleaner.utils.CleanManager

const val HALF_MODE = 0
const val FULL_MODE = 1
const val CUSTOMER_MODE = 2

object CleanDialog {
fun showConfirmDialog(mode: Int, context: Context) {
Expand All @@ -17,19 +18,10 @@ object CleanDialog {
when (mode) {
HALF_MODE -> CleanManager.halfClean()
FULL_MODE -> CleanManager.fullClean()
CUSTOMER_MODE -> CleanManager.customerClean()
}
}
.create()
.show()
}

fun showCustomerDialog(context: Context) {
AlertDialog.Builder(context)
.setTitle("Tips")
.setMessage("你确定要清理吗?")
.setNegativeButton("取消") { _, _ -> }
.setPositiveButton("确定") { _, _ -> }
.create()
.show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ModuleEntryHook {
val vg = item?.parent as ViewGroup
vg.addView(entry, 2)
entry.setOnClickListener {
val intent = Intent(context, SettingsActivity::class.java)
val intent = Intent(qqContext, SettingsActivity::class.java)
context?.startActivity(intent)
}
} catch (e: Exception) {
Expand Down
25 changes: 21 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 @@ -4,6 +4,10 @@ import java.io.File
import kotlin.concurrent.thread

object CleanManager {
const val HALF_MODE = "half_mode"
const val FULL_MODE = "full_mode"
const val CUSTOMER_MODE = "customer_mode"

const val CACHES = "caches"
const val PICTURE = "picture"
const val SHORT_VIDEO = "short_video"
Expand All @@ -25,6 +29,8 @@ object CleanManager {
const val RECEIVE_FILE_CACHE = "receive_file_cache"
const val OTHERS = "others"

lateinit var customerList: Set<String>

private fun getFiles(item: String): ArrayList<File> {
val arr = ArrayList<File>()
when (item) {
Expand Down Expand Up @@ -147,9 +153,20 @@ object CleanManager {
return arr
}

private fun getCustomerList(): ArrayList<File> {
val arr = ArrayList<File>()
for (s in customerList) {
arr.addAll(getFiles(s))
}
return arr
}

fun autoClean() {

fun autoClean(mode: String) {
when (mode) {
HALF_MODE -> halfClean()
FULL_MODE -> fullClean()
CUSTOMER_MODE -> customerClean()
}
}

fun halfClean() {
Expand All @@ -161,10 +178,10 @@ object CleanManager {
}

fun customerClean() {

doClean(getCustomerList())
}

fun doClean(files: ArrayList<File>) {
private fun doClean(files: ArrayList<File>) {
thread {
try {
qqContext?.showToastBySystem("好耶 开始清理了")
Expand Down
21 changes: 19 additions & 2 deletions app/src/main/res/layout/settings_activity.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="horizontal">
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?android:actionBarSize"
android:id="@+id/toolbar"
android:background="?attr/themeColor"
android:elevation="0dp">
<TextView
android:id="@+id/title"
android:text="@string/title_activity_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title"
android:textColor="@android:color/white"/>

</androidx.appcompat.widget.Toolbar>
<FrameLayout
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
12 changes: 12 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
<resources>
<attr name="themeColor" format="color"/>
<string-array name="clean_method">
<item>一键瘦身</item>
<item>完全瘦身</item>
<item>自定义瘦身</item>
</string-array>

<string-array name="clean_method_value">
<item>half_mode</item>
<item>full_mode</item>
<item>customer_mode</item>
</string-array>

<string-array name="customer_clean_list">
<item>各类缓存</item>
<item>图片</item>
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<string name="auto_clean_switch_title">定时清理</string>
<string name="auto_clean_switch_key">启用定时清理</string>
<string name="auto_clean_time">上次清理时间</string>
<string name="auto_clean_method">清理方案</string>
<string name="auto_clean_time_hint">还没有记录哦~</string>
<string name="auto_clean_methodhint">三选一哦</string>
<string name="clean_title">清理缓存</string>

<string name="clean_half">一键瘦身</string>
Expand All @@ -15,10 +17,11 @@
<string name="clean_full_hint">把QQ能清理的都给他清理了</string>
<string name="clean_cus">自定义瘦身</string>
<string name="clean_cus_hint">我要自己选!</string>
<string name="do_clean_cus">执行自定义瘦身</string>

<string name="other_title">其他</string>
<string name="module_version">模块版本</string>
<string name="version_name">1.0</string>
<string name="version_name">1.1</string>
<string name="goto_github">点我前往项目地址</string>
<string name="author">模块作者:KyuubiRan</string>
<string name="support_me">扶贫</string>
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
<SwitchPreferenceCompat
app:key="AutoClean"
app:title="@string/auto_clean_switch_key"/>
<Preference
app:key="AutoCleanMethod"
app:title="@string/auto_clean_time"
app:summary="@string/auto_clean_time_hint"
app:isPreferenceVisible="false"/>
<Preference
app:key="CleanedTime"
app:title="@string/auto_clean_time"
Expand All @@ -22,10 +27,15 @@
app:key="FullClean"
app:title="@string/clean_full"
app:summary="@string/clean_full_hint"/>
<Preference
<MultiSelectListPreference
app:entries="@array/customer_clean_list"
app:entryValues="@array/customer_clean_list_value"
app:key="CustomerClean"
app:title="@string/clean_cus"
app:summary="@string/clean_cus_hint"/>
<Preference
app:key="DoCustomerClean"
app:title="@string/do_clean_cus"/>
</PreferenceCategory>
<PreferenceCategory
app:title="@string/other_title">
Expand Down

0 comments on commit 1eac1ae

Please sign in to comment.