Skip to content

Commit

Permalink
Refresh app list when package change & Bump to 3.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-TSNG committed Sep 7, 2022
1 parent 70e75dd commit 8a56135
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/src/main/java/icu/nullptr/hidemyapplist/MyApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,6 +36,7 @@ class MyApp : Application() {
exitProcess(0)
}
hmaApp = this
AppChangeReceiver.register(this)

DayNightDelegate.setApplicationContext(this)
DayNightDelegate.setDefaultNightMode(PrefManager.darkTheme)
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 8a56135

Please sign in to comment.