From 8a56135420670741702ee52afc290214aa660eef Mon Sep 17 00:00:00 2001 From: Nullptr Date: Wed, 7 Sep 2022 16:38:43 +0800 Subject: [PATCH] Refresh app list when package change & Bump to 3.0.5 --- .../java/icu/nullptr/hidemyapplist/MyApp.kt | 2 ++ .../ui/receiver/AppChangeReceiver.kt | 36 +++++++++++++++++++ build.gradle.kts | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/icu/nullptr/hidemyapplist/ui/receiver/AppChangeReceiver.kt diff --git a/app/src/main/java/icu/nullptr/hidemyapplist/MyApp.kt b/app/src/main/java/icu/nullptr/hidemyapplist/MyApp.kt index e2f4915b..eb877244 100644 --- a/app/src/main/java/icu/nullptr/hidemyapplist/MyApp.kt +++ b/app/src/main/java/icu/nullptr/hidemyapplist/MyApp.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.app.Application import com.tsng.hidemyapplist.R import icu.nullptr.hidemyapplist.service.PrefManager +import icu.nullptr.hidemyapplist.ui.receiver.AppChangeReceiver import icu.nullptr.hidemyapplist.ui.util.makeToast import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -35,6 +36,7 @@ class MyApp : Application() { exitProcess(0) } hmaApp = this + AppChangeReceiver.register(this) DayNightDelegate.setApplicationContext(this) DayNightDelegate.setDefaultNightMode(PrefManager.darkTheme) diff --git a/app/src/main/java/icu/nullptr/hidemyapplist/ui/receiver/AppChangeReceiver.kt b/app/src/main/java/icu/nullptr/hidemyapplist/ui/receiver/AppChangeReceiver.kt new file mode 100644 index 00000000..9700a44b --- /dev/null +++ b/app/src/main/java/icu/nullptr/hidemyapplist/ui/receiver/AppChangeReceiver.kt @@ -0,0 +1,36 @@ +package icu.nullptr.hidemyapplist.ui.receiver + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.util.Log +import icu.nullptr.hidemyapplist.util.PackageHelper + +class AppChangeReceiver : BroadcastReceiver() { + + companion object { + private const val TAG = "AppChangeReceiver" + + private val actions = setOf( + Intent.ACTION_PACKAGE_ADDED, + Intent.ACTION_PACKAGE_REMOVED, + Intent.ACTION_PACKAGE_REPLACED + ) + + fun register(context: Context) { + val filter = IntentFilter().apply { + actions.forEach(::addAction) + addDataScheme("package") + } + context.registerReceiver(AppChangeReceiver(), filter) + } + } + + override fun onReceive(context: Context, intent: Intent) { + if (intent.action in actions) { + Log.i(TAG, "Received intent: $intent") + PackageHelper.invalidateCache() + } + } +} diff --git a/build.gradle.kts b/build.gradle.kts index f3ae02fc..aadba5ee 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,7 +35,7 @@ fun String.execute(currentWorkingDir: File = file("./")): String { val minSdkVer by extra(24) val targetSdkVer by extra(33) -val appVerName by extra("3.0.4-Beta") +val appVerName by extra("3.0.5-Beta") val serviceVerCode by extra(87) val minBackupVerCode by extra(65)