diff --git a/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt b/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt index 4ecf0bda4e915c29b550f70cc795cf4b39f778db..00a02f1a86d5628868b9f824079fb8fc2e1be924 100644 --- a/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt +++ b/app/src/main/java/foundation/e/apps/AppLoungeApplication.kt @@ -24,6 +24,7 @@ import androidx.work.Configuration import dagger.hilt.android.HiltAndroidApp import foundation.e.apps.manager.pkg.PkgManagerBR import foundation.e.apps.manager.pkg.PkgManagerModule +import foundation.e.apps.manager.workmanager.InstallWorkManager import kotlinx.coroutines.DelicateCoroutinesApi import java.util.concurrent.Executors import javax.inject.Inject @@ -40,6 +41,7 @@ class AppLoungeApplication : Application(), Configuration.Provider { override fun onCreate() { super.onCreate() + InstallWorkManager.context = this // Register broadcast receiver for package manager val pkgManagerBR = object : PkgManagerBR() {} registerReceiver(pkgManagerBR, pkgManagerModule.getFilter()) diff --git a/app/src/main/java/foundation/e/apps/MainActivity.kt b/app/src/main/java/foundation/e/apps/MainActivity.kt index ba46db295e62351273ee71c2912bba0017ba5b99..3c6d100cd5540830cdc0578529feb535999bd281 100644 --- a/app/src/main/java/foundation/e/apps/MainActivity.kt +++ b/app/src/main/java/foundation/e/apps/MainActivity.kt @@ -239,7 +239,7 @@ class MainActivity : AppCompatActivity() { return@launch } viewModel.updateAwaiting(it) - InstallWorkManager.enqueueWork(applicationContext, it) + InstallWorkManager.enqueueWork(it) Log.d(TAG, "===> onCreate: AWAITING ${it.name}") } } @@ -251,7 +251,7 @@ class MainActivity : AppCompatActivity() { lifecycleScope.launch { val fusedDownload = viewModel.updateAwaitingForPurchasedApp(it) if (fusedDownload != null) { - InstallWorkManager.enqueueWork(applicationContext, fusedDownload) + InstallWorkManager.enqueueWork(fusedDownload) } else { showSnackbarMessage(getString(R.string.paid_app_anonymous_message)) } diff --git a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt index 73ff6297200efcf070d5e8ea163be57835c13e5e..32abd84e9b2d977277168cb3cb24dbd8b7d25336 100644 --- a/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt +++ b/app/src/main/java/foundation/e/apps/MainActivityViewModel.kt @@ -40,6 +40,7 @@ import foundation.e.apps.api.fused.data.FusedApp import foundation.e.apps.manager.database.fusedDownload.FusedDownload import foundation.e.apps.manager.fused.FusedManagerRepository import foundation.e.apps.manager.pkg.PkgManagerModule +import foundation.e.apps.manager.workmanager.InstallWorkManager import foundation.e.apps.utils.enums.Origin import foundation.e.apps.utils.enums.Status import foundation.e.apps.utils.enums.Type @@ -271,6 +272,7 @@ class MainActivityViewModel @Inject constructor( val fusedDownload = fusedManagerRepository.getFusedDownload(packageName = app.package_name) fusedManagerRepository.cancelDownload(fusedDownload) + InstallWorkManager.cancelWork(app.name) } } diff --git a/app/src/main/java/foundation/e/apps/manager/database/fusedDownload/FusedDownloadDAO.kt b/app/src/main/java/foundation/e/apps/manager/database/fusedDownload/FusedDownloadDAO.kt index cdb83411bf89b0128ed8f16b7d7d1bda40f1cd22..a5311262b6bfdfe126e528145765f4fe7d844afd 100644 --- a/app/src/main/java/foundation/e/apps/manager/database/fusedDownload/FusedDownloadDAO.kt +++ b/app/src/main/java/foundation/e/apps/manager/database/fusedDownload/FusedDownloadDAO.kt @@ -11,7 +11,7 @@ import androidx.room.Update @Dao interface FusedDownloadDAO { - @Insert(onConflict = OnConflictStrategy.IGNORE) + @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun addDownload(fusedDownload: FusedDownload) @Query("SELECT * FROM fuseddownload") diff --git a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallWorkManager.kt b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallWorkManager.kt index b94135fbdb7ff72c2c3cf5b22b51f2d19f14d798..809884ed014acea8f217b9640c7d9dc64941b619 100644 --- a/app/src/main/java/foundation/e/apps/manager/workmanager/InstallWorkManager.kt +++ b/app/src/main/java/foundation/e/apps/manager/workmanager/InstallWorkManager.kt @@ -1,6 +1,6 @@ package foundation.e.apps.manager.workmanager -import android.content.Context +import android.app.Application import androidx.work.Data import androidx.work.ExistingWorkPolicy import androidx.work.OneTimeWorkRequestBuilder @@ -9,7 +9,9 @@ import foundation.e.apps.manager.database.fusedDownload.FusedDownload object InstallWorkManager { const val INSTALL_WORK_NAME = "APP_LOUNGE_INSTALL_APP" - fun enqueueWork(context: Context, fusedDownload: FusedDownload) { + lateinit var context: Application + + fun enqueueWork(fusedDownload: FusedDownload) { WorkManager.getInstance(context).enqueueUniqueWork( INSTALL_WORK_NAME, ExistingWorkPolicy.APPEND_OR_REPLACE, @@ -21,4 +23,8 @@ object InstallWorkManager { .build() ) } + + fun cancelWork(tag: String) { + WorkManager.getInstance(context).cancelAllWorkByTag(tag) + } } diff --git a/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt b/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt index 2aa21aa8a9d3111f1096a288b33d6faef3b8952c..2244d136e88c18f68baed7c7a51dc9a8a96e77a6 100644 --- a/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt +++ b/app/src/main/java/foundation/e/apps/updates/manager/UpdatesWorker.kt @@ -146,7 +146,7 @@ class UpdatesWorker @AssistedInject constructor( TAG, "startUpdateProcess: Enqueued for update: ${fusedDownload.name} ${fusedDownload.id} ${fusedDownload.status}" ) - InstallWorkManager.enqueueWork(context, fusedDownload) + InstallWorkManager.enqueueWork(fusedDownload) } }