Skip to content

Commit 1507f93

Browse files
authored
Local Model delete confirmation (#144)
* Local Model delete confirmation modal * Update
1 parent 3a90781 commit 1507f93

File tree

10 files changed

+60
-27
lines changed

10 files changed

+60
-27
lines changed

presentation/src/main/java/com/shifthackz/aisdv1/presentation/modal/ModalRenderer.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fun ModalRenderer(
171171
)
172172
}
173173

174-
Modal.DeleteConfirm -> DecisionInteractiveDialog(
174+
Modal.DeleteImageConfirm -> DecisionInteractiveDialog(
175175
title = R.string.interaction_delete_generation_title.asUiText(),
176176
text = R.string.interaction_delete_generation_sub_title.asUiText(),
177177
confirmActionResId = R.string.yes,
@@ -211,5 +211,17 @@ fun ModalRenderer(
211211
) {
212212
LanguageBottomSheet(onDismissRequest = dismiss)
213213
}
214+
215+
is Modal.DeleteLocalModelConfirm -> DecisionInteractiveDialog(
216+
title = R.string.interaction_delete_local_model_title.asUiText(),
217+
text = UiText.Resource(
218+
R.string.interaction_delete_local_model_sub_title,
219+
screenModal.model.name,
220+
),
221+
confirmActionResId = R.string.yes,
222+
dismissActionResId = R.string.no,
223+
onConfirmAction = { processIntent(ServerSetupIntent.LocalModel.DeleteConfirm(screenModal.model)) },
224+
onDismissRequest = dismiss,
225+
)
214226
}
215227
}

presentation/src/main/java/com/shifthackz/aisdv1/presentation/model/Modal.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import com.shifthackz.aisdv1.core.model.UiText
55
import com.shifthackz.aisdv1.domain.entity.AiGenerationResult
66
import com.shifthackz.aisdv1.domain.entity.HordeProcessStatus
77
import com.shifthackz.aisdv1.domain.feature.diffusion.LocalDiffusion
8+
import com.shifthackz.aisdv1.presentation.screen.setup.ServerSetupState
89

910
sealed interface Modal {
1011

@@ -14,7 +15,7 @@ sealed interface Modal {
1415

1516
data object ClearAppCache : Modal
1617

17-
data object DeleteConfirm : Modal
18+
data object DeleteImageConfirm : Modal
1819

1920
data object ConfirmExport : Modal
2021

@@ -74,6 +75,9 @@ sealed interface Modal {
7475
}
7576
}
7677

78+
@Immutable
79+
data class DeleteLocalModelConfirm(val model: ServerSetupState.LocalModel) : Modal
80+
7781
@Immutable
7882
data class Error(val error: UiText) : Modal
7983

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/gallery/detail/GalleryDetailViewModel.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.shifthackz.aisdv1.presentation.screen.gallery.detail
22

3-
import com.shifthackz.aisdv1.core.common.log.debugLog
43
import com.shifthackz.aisdv1.core.common.log.errorLog
54
import com.shifthackz.aisdv1.core.common.schedulers.SchedulersProvider
65
import com.shifthackz.aisdv1.core.common.schedulers.subscribeOnMainThread
@@ -43,15 +42,12 @@ class GalleryDetailViewModel(
4342
}
4443

4544
override fun processIntent(intent: GalleryDetailIntent) {
46-
debugLog("INTENT : $intent")
4745
when (intent) {
4846
is GalleryDetailIntent.CopyToClipboard -> {
4947
emitEffect(GalleryDetailEffect.ShareClipBoard(intent.content.toString()))
5048
}
5149

52-
GalleryDetailIntent.Delete.Request -> {
53-
setActiveModal(Modal.DeleteConfirm)
54-
}
50+
GalleryDetailIntent.Delete.Request -> setActiveModal(Modal.DeleteImageConfirm)
5551

5652
GalleryDetailIntent.Delete.Confirm -> {
5753
setActiveModal(Modal.None)

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/setup/ServerSetupIntent.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ sealed interface ServerSetupIntent : MviIntent {
3232

3333
data class UpdateHordeDefaultApiKey(val value: Boolean) : ServerSetupIntent
3434

35-
data class DownloadCardButtonClick(val model: ServerSetupState.LocalModel) : ServerSetupIntent
36-
3735
data class SelectLocalModel(val model: ServerSetupState.LocalModel) : ServerSetupIntent
3836

3937
data class AllowLocalCustomModel(val allow: Boolean) : ServerSetupIntent
@@ -77,4 +75,13 @@ sealed interface ServerSetupIntent : MviIntent {
7775
get() = linksProvider.openAiInfoUrl
7876
}
7977
}
78+
79+
sealed interface LocalModel : ServerSetupIntent {
80+
81+
val model: ServerSetupState.LocalModel
82+
83+
data class ClickReduce(override val model: ServerSetupState.LocalModel) : LocalModel
84+
85+
data class DeleteConfirm(override val model: ServerSetupState.LocalModel) : LocalModel
86+
}
8087
}

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/setup/ServerSetupViewModel.kt

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.shifthackz.aisdv1.presentation.screen.setup
22

3-
import com.shifthackz.aisdv1.core.common.log.debugLog
43
import com.shifthackz.aisdv1.core.common.log.errorLog
54
import com.shifthackz.aisdv1.core.common.schedulers.SchedulersProvider
65
import com.shifthackz.aisdv1.core.common.schedulers.subscribeOnMainThread
@@ -94,7 +93,22 @@ class ServerSetupViewModel(
9493

9594
ServerSetupIntent.DismissDialog -> setScreenModal(Modal.None)
9695

97-
is ServerSetupIntent.DownloadCardButtonClick -> localModelDownloadClickReducer(intent.model)
96+
is ServerSetupIntent.LocalModel.ClickReduce -> localModelDownloadClickReducer(intent.model)
97+
98+
is ServerSetupIntent.LocalModel.DeleteConfirm -> updateState {
99+
!deleteModelUseCase(intent.model.id)
100+
.subscribeOnMainThread(schedulersProvider)
101+
.subscribeBy(::errorLog)
102+
it.copy(
103+
screenModal = Modal.None,
104+
localModels = currentState.localModels.withNewState(
105+
intent.model.copy(
106+
downloadState = DownloadState.Unknown,
107+
downloaded = false,
108+
),
109+
),
110+
)
111+
}
98112

99113
is ServerSetupIntent.SelectLocalModel -> {
100114
if (currentState.localModels.any { it.downloadState is DownloadState.Downloading }) {
@@ -319,19 +333,8 @@ class ServerSetupViewModel(
319333
}
320334
}
321335
// User deletes local model
322-
localModel.downloaded -> {
323-
updateState {
324-
it.copy(
325-
localModels = currentState.localModels.withNewState(
326-
localModel.copy(
327-
downloadState = DownloadState.Unknown,
328-
downloaded = false,
329-
),
330-
),
331-
)
332-
}
333-
!deleteModelUseCase(localModel.id).subscribeOnMainThread(schedulersProvider)
334-
.subscribeBy(::errorLog)
336+
localModel.downloaded -> updateState {
337+
it.copy(screenModal = Modal.DeleteLocalModelConfirm(localModel))
335338
}
336339
// User requested new download operation
337340
else -> {
@@ -364,7 +367,6 @@ class ServerSetupViewModel(
364367
setScreenModal(Modal.Error(message.asUiText()))
365368
},
366369
onNext = { downloadState ->
367-
debugLog("DOWNLOAD STATE : $downloadState")
368370
updateState {
369371
when (downloadState) {
370372
is DownloadState.Complete -> it.copy(

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/setup/forms/LocalDiffusionForm.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fun LocalDiffusionForm(
9999
if (model.id != LocalAiModel.CUSTOM.id) {
100100
Button(
101101
modifier = Modifier.padding(end = 8.dp),
102-
onClick = { processIntent(ServerSetupIntent.DownloadCardButtonClick(model)) },
102+
onClick = { processIntent(ServerSetupIntent.LocalModel.ClickReduce(model)) },
103103
) {
104104
Text(
105105
text = stringResource(

presentation/src/main/res/values-ru/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
<string name="interaction_delete_generation_title">Удалить изображение</string>
195195
<string name="interaction_delete_generation_sub_title">Вы уверены, что хотите окончательно удалить это изображение?</string>
196196

197+
<string name="interaction_delete_local_model_title">Удалить модель</string>
198+
<string name="interaction_delete_local_model_sub_title">Вы уверены, что хотите удалить модель "%1$s"?</string>
199+
197200
<string name="gallery_empty_title">Здесь еще ничего нет…</string>
198201
<string name="gallery_empty_sub_title">Попытайтесь создать что-то, и вы увидите свое изображение здесь!</string>
199202

presentation/src/main/res/values-tr/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
<string name="interaction_delete_generation_title">Resmi sil</string>
195195
<string name="interaction_delete_generation_sub_title">Kalıcı olarak bu resmi silmek istediğinize emin misiniz?</string>
196196

197+
<string name="interaction_delete_local_model_title">Modeli sil</string>
198+
<string name="interaction_delete_local_model_sub_title">Modeli silmek istediğinizden emin misiniz "%1$s"?</string>
199+
197200
<string name="gallery_empty_title">Burada henüz bir şey yok…</string>
198201
<string name="gallery_empty_sub_title">Bir şeyler üretmeyi deneyin! Ürettiğiniz resimler burada gözükecektir.</string>
199202

presentation/src/main/res/values-uk/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
<string name="interaction_delete_generation_title">Видалити зображення</string>
195195
<string name="interaction_delete_generation_sub_title">Ви впевнені, що хочете остаточно видалити це зображення?</string>
196196

197+
<string name="interaction_delete_local_model_title">Видалити модель</string>
198+
<string name="interaction_delete_local_model_sub_title">Ви впевнені, що хочете видалити модель "%1$s"?</string>
199+
197200
<string name="gallery_empty_title">Тут ще нічого немає…</string>
198201
<string name="gallery_empty_sub_title">Спробуйте створити щось, і ви побачите своє зображення тут!</string>
199202

presentation/src/main/res/values/strings.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@
210210
<string name="interaction_cache_sub_title">This will reset app settings and delete all the generated images. Do you want to proceed?</string>
211211

212212
<string name="interaction_delete_generation_title">Delete image</string>
213-
<string name="interaction_delete_generation_sub_title">Are you sure you want to permanently remove this image?</string>
213+
<string name="interaction_delete_generation_sub_title">Are you sure you want to permanently delete this image?</string>
214+
215+
<string name="interaction_delete_local_model_title">Delete model</string>
216+
<string name="interaction_delete_local_model_sub_title">Are you sure you want to delete model "%1$s"?</string>
214217

215218
<string name="gallery_empty_title">There is nothing here yet…</string>
216219
<string name="gallery_empty_sub_title">Try to generate something, and you will see your image here!</string>

0 commit comments

Comments
 (0)