diff --git a/app/src/main/java/foundation/e/apps/MainActivity.kt b/app/src/main/java/foundation/e/apps/MainActivity.kt index 22e12c86741d233ec19f9bdee5ec4f31634d915f..882cb4581ebb18dae04b112c4ebbdf409f9434ea 100644 --- a/app/src/main/java/foundation/e/apps/MainActivity.kt +++ b/app/src/main/java/foundation/e/apps/MainActivity.kt @@ -49,7 +49,6 @@ import foundation.e.apps.utils.modules.CommonUtilsModule import kotlinx.coroutines.launch import java.io.File import java.util.UUID -import javax.inject.Inject @AndroidEntryPoint class MainActivity : AppCompatActivity() { diff --git a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt index f2570cbcf7e4946317783f4e739813fa4a5b927d..4763401939b1ca29c8ec75c815b603c4d368757d 100644 --- a/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt +++ b/app/src/main/java/foundation/e/apps/api/fused/FusedAPIImpl.kt @@ -647,8 +647,7 @@ class FusedAPIImpl @Inject constructor( if (this.status != Status.INSTALLATION_ISSUE) { this.status = if (this.is_pwa) { pwaManagerModule.getPwaStatus(this) - } - else { + } else { pkgManagerModule.getPackageStatus(this.package_name, this.latest_version_code) } } diff --git a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt index e1116823617c715070935d46d568e694f35209e0..d17d965944f4f3078d3d64d585a6d3324acd2d9e 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationFragment.kt @@ -132,11 +132,7 @@ class ApplicationFragment : Fragment(R.layout.fragment_application) { binding.applicationLayout.visibility = View.INVISIBLE mainActivityViewModel.downloadList.observe(viewLifecycleOwner) { list -> - list.forEach { - if (it.origin == args.origin && (it.packageName == args.packageName || it.id == args.id)) { - applicationViewModel.appStatus.value = it.status - } - } + applicationViewModel.updateApplicationStatus(list) } applicationViewModel.fusedApp.observe(viewLifecycleOwner) { diff --git a/app/src/main/java/foundation/e/apps/application/ApplicationViewModel.kt b/app/src/main/java/foundation/e/apps/application/ApplicationViewModel.kt index 01c201d33b19bdf5b019638f9f3b63a8b184c930..83c42a5f8faf0687203ff9a81dd4237824b71168 100644 --- a/app/src/main/java/foundation/e/apps/application/ApplicationViewModel.kt +++ b/app/src/main/java/foundation/e/apps/application/ApplicationViewModel.kt @@ -25,9 +25,11 @@ import com.aurora.gplayapi.data.models.AuthData import dagger.hilt.android.lifecycle.HiltViewModel import foundation.e.apps.api.fused.FusedAPIRepository import foundation.e.apps.api.fused.data.FusedApp +import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.download.data.DownloadProgress import foundation.e.apps.manager.download.data.DownloadProgressLD import foundation.e.apps.manager.fused.FusedManagerRepository +import foundation.e.apps.manager.pkg.PkgManagerModule import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import kotlinx.coroutines.Dispatchers @@ -38,7 +40,8 @@ import javax.inject.Inject class ApplicationViewModel @Inject constructor( downloadProgressLD: DownloadProgressLD, private val fusedAPIRepository: FusedAPIRepository, - private val fusedManagerRepository: FusedManagerRepository + private val fusedManagerRepository: FusedManagerRepository, + private val pkgManagerModule: PkgManagerModule ) : ViewModel() { val fusedApp: MutableLiveData = MutableLiveData() @@ -99,4 +102,15 @@ class ApplicationViewModel @Inject constructor( } return Pair(1, 0) } + + fun updateApplicationStatus(downloadList: List) { + fusedApp.value?.let { app -> + val downloadingItem = + downloadList.find { it.origin == app.origin && (it.packageName == app.package_name || it.id == app.package_name) } + appStatus.value = downloadingItem?.status ?: pkgManagerModule.getPackageStatus( + app.package_name, + app.latest_version_code + ) + } + } } diff --git a/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt b/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt index 264213926f2891827a6f348136ee5b26a598daad..23b340ec18852dbb151889f3af4b4865bf48c5d7 100644 --- a/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt +++ b/app/src/main/java/foundation/e/apps/receiver/PWAPlayerStatusReceiver.kt @@ -23,7 +23,9 @@ import android.content.Intent import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.manager.database.DatabaseRepository import foundation.e.apps.utils.enums.Status -import kotlinx.coroutines.* +import kotlinx.coroutines.DelicateCoroutinesApi +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.launch import javax.inject.Inject /** @@ -37,7 +39,7 @@ import javax.inject.Inject */ @AndroidEntryPoint @DelicateCoroutinesApi -class PWAPlayerStatusReceiver: BroadcastReceiver() { +class PWAPlayerStatusReceiver : BroadcastReceiver() { companion object { const val ACTION_PWA_ADDED = "foundation.e.pwaplayer.PWA_ADDED" @@ -53,7 +55,7 @@ class PWAPlayerStatusReceiver: BroadcastReceiver() { intent?.getStringExtra("SHORTCUT_ID")?.let { shortcutId -> databaseRepository.getDownloadById(shortcutId)?.let { fusedDownload -> when (intent.action) { - ACTION_PWA_ADDED -> { + ACTION_PWA_ADDED -> { fusedDownload.status = Status.INSTALLED databaseRepository.updateDownload(fusedDownload) } @@ -68,4 +70,4 @@ class PWAPlayerStatusReceiver: BroadcastReceiver() { } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt b/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt index 643298bf88649b13fd01144997bc003c38667e05..a9fcd823993ee46cb64c7bc035b2bb7667a10163 100644 --- a/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt +++ b/app/src/main/java/foundation/e/apps/utils/modules/PWAManagerModule.kt @@ -53,8 +53,10 @@ class PWAManagerModule @Inject constructor( * As there is no concept of version, we cannot send [Status.UPDATABLE]. */ fun getPwaStatus(fusedApp: FusedApp): Status { - context.contentResolver.query(Uri.parse(PWA_PLAYER), - null, null, null, null)?.let { cursor -> + context.contentResolver.query( + Uri.parse(PWA_PLAYER), + null, null, null, null + )?.let { cursor -> if (cursor.count > 0) { if (cursor.moveToFirst()) { do { @@ -65,8 +67,7 @@ class PWAManagerModule @Inject constructor( fusedApp.pwaPlayerDbId = pwaItemDbId return Status.INSTALLED } - } - catch (e: Exception) { + } catch (e: Exception) { e.printStackTrace() } } while (cursor.moveToNext())