diff --git a/app/src/main/java/app/revanced/manager/data/room/apps/installed/InstalledAppDao.kt b/app/src/main/java/app/revanced/manager/data/room/apps/installed/InstalledAppDao.kt index 7117249323..90d40b9fbd 100644 --- a/app/src/main/java/app/revanced/manager/data/room/apps/installed/InstalledAppDao.kt +++ b/app/src/main/java/app/revanced/manager/data/room/apps/installed/InstalledAppDao.kt @@ -6,6 +6,7 @@ import androidx.room.Insert import androidx.room.MapInfo import androidx.room.Query import androidx.room.Transaction +import androidx.room.Upsert import kotlinx.coroutines.flow.Flow @Dao @@ -24,17 +25,21 @@ interface InstalledAppDao { suspend fun getPatchesSelection(packageName: String): Map> @Transaction - suspend fun insertApp(installedApp: InstalledApp, appliedPatches: List) { - insertApp(installedApp) + suspend fun upsertApp(installedApp: InstalledApp, appliedPatches: List) { + upsertApp(installedApp) + deleteAppliedPatches(installedApp.currentPackageName) insertAppliedPatches(appliedPatches) } - @Insert - suspend fun insertApp(installedApp: InstalledApp) + @Upsert + suspend fun upsertApp(installedApp: InstalledApp) @Insert suspend fun insertAppliedPatches(appliedPatches: List) + @Query("DELETE FROM applied_patch WHERE package_name = :packageName") + suspend fun deleteAppliedPatches(packageName: String) + @Delete suspend fun delete(installedApp: InstalledApp) } \ No newline at end of file diff --git a/app/src/main/java/app/revanced/manager/domain/repository/InstalledAppRepository.kt b/app/src/main/java/app/revanced/manager/domain/repository/InstalledAppRepository.kt index 99a37ed957..afba73ba88 100644 --- a/app/src/main/java/app/revanced/manager/domain/repository/InstalledAppRepository.kt +++ b/app/src/main/java/app/revanced/manager/domain/repository/InstalledAppRepository.kt @@ -19,14 +19,14 @@ class InstalledAppRepository( suspend fun getAppliedPatches(packageName: String): PatchesSelection = dao.getPatchesSelection(packageName).mapValues { (_, patches) -> patches.toSet() } - suspend fun add( + suspend fun addOrUpdate( currentPackageName: String, originalPackageName: String, version: String, installType: InstallType, patchesSelection: PatchesSelection ) { - dao.insertApp( + dao.upsertApp( InstalledApp( currentPackageName = currentPackageName, originalPackageName = originalPackageName, diff --git a/app/src/main/java/app/revanced/manager/ui/viewmodel/InstallerViewModel.kt b/app/src/main/java/app/revanced/manager/ui/viewmodel/InstallerViewModel.kt index c6e0d58647..e136eb38ef 100644 --- a/app/src/main/java/app/revanced/manager/ui/viewmodel/InstallerViewModel.kt +++ b/app/src/main/java/app/revanced/manager/ui/viewmodel/InstallerViewModel.kt @@ -142,7 +142,7 @@ class InstallerViewModel( installedPackageName = intent.getStringExtra(InstallService.EXTRA_PACKAGE_NAME) viewModelScope.launch { - installedAppRepository.add( + installedAppRepository.addOrUpdate( installedPackageName!!, packageName, input.selectedApp.version, @@ -277,7 +277,7 @@ class InstallerViewModel( installedApp?.let { installedAppRepository.delete(it) } - installedAppRepository.add( + installedAppRepository.addOrUpdate( packageName, packageName, input.selectedApp.version,