Skip to content

Commit

Permalink
fix: Duplicated app list items
Browse files Browse the repository at this point in the history
Change-Id: I8a7ab96022321eea3267aec0fe35e597adbfe24c
  • Loading branch information
XayahSuSuSu committed Sep 14, 2024
1 parent 9cf0e5a commit a94ae6c
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ListViewModel @Inject constructor(
Success.Apps(
opType = opType,
selected = listData.selected,
isUpdating = listData.isUpdating,
cloudName = cloudName,
backupDir = backupDir,
)
Expand All @@ -59,6 +60,7 @@ class ListViewModel @Inject constructor(
Success.Files(
opType = opType,
selected = listData.selected,
isUpdating = listData.isUpdating,
cloudName = cloudName,
backupDir = backupDir,
)
Expand All @@ -71,26 +73,34 @@ class ListViewModel @Inject constructor(

fun onResume() {
viewModelScope.launch {
when (target) {
Target.Apps -> {
when (uiState.value) {
is Success.Apps -> {
when (opType) {
OpType.BACKUP -> {
WorkManagerInitializer.fastInitializeAndUpdateApps(context)
val state = uiState.value.castTo<Success.Apps>()
if (state.isUpdating.not()) {
WorkManagerInitializer.fastInitializeAndUpdateApps(context)
}
}

OpType.RESTORE -> {}
}
}

Target.Files -> {
is Success.Files -> {
when (opType) {
OpType.BACKUP -> {
WorkManagerInitializer.fastInitializeAndUpdateFiles(context)
val state = uiState.value.castTo<Success.Files>()
if (state.isUpdating.not()) {
WorkManagerInitializer.fastInitializeAndUpdateFiles(context)
}
}

OpType.RESTORE -> {}
}
}

else -> {}
}
}
}
Expand Down Expand Up @@ -139,21 +149,24 @@ sealed interface ListUiState {
sealed class Success(
open val opType: OpType,
open val selected: Long,
open val isUpdating: Boolean,
open val cloudName: String,
open val backupDir: String,
) : ListUiState {
data class Apps(
override val opType: OpType,
override val selected: Long,
override val isUpdating: Boolean,
override val cloudName: String,
override val backupDir: String,
) : Success(opType, selected, cloudName, backupDir)
) : Success(opType, selected, isUpdating, cloudName, backupDir)

data class Files(
override val opType: OpType,
override val selected: Long,
override val isUpdating: Boolean,
override val cloudName: String,
override val backupDir: String,
) : Success(opType, selected, cloudName, backupDir)
) : Success(opType, selected, isUpdating, cloudName, backupDir)
}
}

0 comments on commit a94ae6c

Please sign in to comment.