mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-24 11:52:13 +00:00
Add: Receiving when apps get updated
This commit is contained in:
parent
ebb3ea7731
commit
285f417967
@ -16,7 +16,7 @@ import com.looker.droidify.index.RepositoryUpdater
|
|||||||
import com.looker.droidify.network.CoilDownloader
|
import com.looker.droidify.network.CoilDownloader
|
||||||
import com.looker.droidify.network.Downloader
|
import com.looker.droidify.network.Downloader
|
||||||
import com.looker.droidify.service.Connection
|
import com.looker.droidify.service.Connection
|
||||||
import com.looker.droidify.service.PackageChangeReciever
|
import com.looker.droidify.service.PackageChangedReceiver
|
||||||
import com.looker.droidify.service.SyncService
|
import com.looker.droidify.service.SyncService
|
||||||
import com.looker.droidify.ui.activities.MainActivityX
|
import com.looker.droidify.ui.activities.MainActivityX
|
||||||
import com.looker.droidify.utility.Utils.setLanguage
|
import com.looker.droidify.utility.Utils.setLanguage
|
||||||
@ -55,10 +55,11 @@ class MainApplication : Application(), ImageLoaderFactory {
|
|||||||
|
|
||||||
private fun listenApplications() {
|
private fun listenApplications() {
|
||||||
registerReceiver(
|
registerReceiver(
|
||||||
PackageChangeReciever(),
|
PackageChangedReceiver(),
|
||||||
IntentFilter().apply {
|
IntentFilter().apply {
|
||||||
addAction(Intent.ACTION_PACKAGE_ADDED)
|
addAction(Intent.ACTION_PACKAGE_ADDED)
|
||||||
addAction(Intent.ACTION_PACKAGE_REMOVED)
|
addAction(Intent.ACTION_PACKAGE_REMOVED)
|
||||||
|
addAction(Intent.ACTION_PACKAGE_REPLACED)
|
||||||
addDataScheme("package")
|
addDataScheme("package")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -10,7 +10,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class PackageChangeReciever : BroadcastReceiver() {
|
class PackageChangedReceiver : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
val db = DatabaseX.getInstance(context)
|
val db = DatabaseX.getInstance(context)
|
||||||
val packageName =
|
val packageName =
|
||||||
@ -19,6 +19,7 @@ class PackageChangeReciever : BroadcastReceiver() {
|
|||||||
when (intent.action.orEmpty()) {
|
when (intent.action.orEmpty()) {
|
||||||
Intent.ACTION_PACKAGE_ADDED,
|
Intent.ACTION_PACKAGE_ADDED,
|
||||||
Intent.ACTION_PACKAGE_REMOVED,
|
Intent.ACTION_PACKAGE_REMOVED,
|
||||||
|
Intent.ACTION_PACKAGE_REPLACED
|
||||||
-> {
|
-> {
|
||||||
val packageInfo = try {
|
val packageInfo = try {
|
||||||
context.packageManager.getPackageInfo(
|
context.packageManager.getPackageInfo(
|
||||||
@ -29,7 +30,7 @@ class PackageChangeReciever : BroadcastReceiver() {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
if (packageInfo != null) db.installedDao.put(packageInfo.toInstalledItem())
|
if (packageInfo != null) db.installedDao.insertReplace(packageInfo.toInstalledItem())
|
||||||
else db.installedDao.delete(packageName)
|
else db.installedDao.delete(packageName)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user