mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2024-11-10 01:01:56 +01:00
fix: use upsert when modifying installed apps
This commit is contained in:
parent
c3af6acb2c
commit
9df98edca5
3 changed files with 13 additions and 8 deletions
|
@ -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<Int, List<String>>
|
||||
|
||||
@Transaction
|
||||
suspend fun insertApp(installedApp: InstalledApp, appliedPatches: List<AppliedPatch>) {
|
||||
insertApp(installedApp)
|
||||
suspend fun upsertApp(installedApp: InstalledApp, appliedPatches: List<AppliedPatch>) {
|
||||
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<AppliedPatch>)
|
||||
|
||||
@Query("DELETE FROM applied_patch WHERE package_name = :packageName")
|
||||
suspend fun deleteAppliedPatches(packageName: String)
|
||||
|
||||
@Delete
|
||||
suspend fun delete(installedApp: InstalledApp)
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue