Skip to content

Commit 1d83201

Browse files
committed
Implement working Backup flow prototype (Create/Restore)
1 parent f9419b2 commit 1d83201

File tree

14 files changed

+359
-55
lines changed

14 files changed

+359
-55
lines changed

data/src/main/java/com/shifthackz/aisdv1/data/repository/BackupRepositoryImpl.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ internal class BackupRepositoryImpl(
145145
preferenceManager.localOnnxAllowCancel = value as Boolean
146146
}
147147
KEY_LOCAL_DIFFUSION_SCHEDULER_THREAD -> {
148-
preferenceManager.localOnnxSchedulerThread = value as SchedulersToken
148+
preferenceManager.localOnnxSchedulerThread = SchedulersToken.valueOf(value as String)
149149
}
150150
KEY_MONITOR_CONNECTIVITY -> {
151151
preferenceManager.monitorConnectivity = value as Boolean
@@ -163,7 +163,7 @@ internal class BackupRepositoryImpl(
163163
preferenceManager.formPromptTaggedInput = value as Boolean
164164
}
165165
KEY_SERVER_SOURCE -> {
166-
preferenceManager.source = value as ServerSource
166+
preferenceManager.source = ServerSource.valueOf(value as String)
167167
}
168168
KEY_SD_MODEL -> {
169169
preferenceManager.sdModel = value as String
@@ -217,7 +217,7 @@ internal class BackupRepositoryImpl(
217217
preferenceManager.backgroundGeneration = value as Boolean
218218
}
219219
KEY_GALLERY_GRID -> {
220-
preferenceManager.galleryGrid = value as Grid
220+
preferenceManager.galleryGrid = Grid.valueOf(value as String)
221221
}
222222
}
223223
}

domain/src/main/java/com/shifthackz/aisdv1/domain/di/DomainModule.kt

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import com.shifthackz.aisdv1.domain.interactor.wakelock.WakeLockInterActor
66
import com.shifthackz.aisdv1.domain.interactor.wakelock.WakeLockInterActorImpl
77
import com.shifthackz.aisdv1.domain.usecase.backup.CreateBackupUseCase
88
import com.shifthackz.aisdv1.domain.usecase.backup.CreateBackupUseCaseImpl
9+
import com.shifthackz.aisdv1.domain.usecase.backup.RestoreBackupUseCase
10+
import com.shifthackz.aisdv1.domain.usecase.backup.RestoreBackupUseCaseImpl
911
import com.shifthackz.aisdv1.domain.usecase.caching.ClearAppCacheUseCase
1012
import com.shifthackz.aisdv1.domain.usecase.caching.ClearAppCacheUseCaseImpl
1113
import com.shifthackz.aisdv1.domain.usecase.caching.DataPreLoaderUseCase
@@ -130,6 +132,7 @@ import org.koin.dsl.module
130132

131133
internal val useCasesModule = module {
132134
factoryOf(::CreateBackupUseCaseImpl) bind CreateBackupUseCase::class
135+
factoryOf(::RestoreBackupUseCaseImpl) bind RestoreBackupUseCase::class
133136
factoryOf(::TextToImageUseCaseImpl) bind TextToImageUseCase::class
134137
factoryOf(::ImageToImageUseCaseImpl) bind ImageToImageUseCase::class
135138
factoryOf(::PingStableDiffusionServiceUseCaseImpl) bind PingStableDiffusionServiceUseCase::class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.shifthackz.aisdv1.domain.usecase.backup
2+
3+
import io.reactivex.rxjava3.core.Completable
4+
5+
interface RestoreBackupUseCase {
6+
operator fun invoke(data: ByteArray): Completable
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.shifthackz.aisdv1.domain.usecase.backup
2+
3+
import com.shifthackz.aisdv1.domain.repository.BackupRepository
4+
5+
internal class RestoreBackupUseCaseImpl(
6+
private val backupRepository: BackupRepository,
7+
) : RestoreBackupUseCase {
8+
9+
override fun invoke(data: ByteArray) = backupRepository.restore(data)
10+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.shifthackz.aisdv1.presentation.modal.language.LanguageBottomSheet
3131
import com.shifthackz.aisdv1.presentation.modal.ldscheduler.LDSchedulerBottomSheet
3232
import com.shifthackz.aisdv1.presentation.modal.tag.EditTagDialog
3333
import com.shifthackz.aisdv1.presentation.model.Modal
34+
import com.shifthackz.aisdv1.presentation.screen.backup.BackupIntent
3435
import com.shifthackz.aisdv1.presentation.screen.debug.DebugMenuIntent
3536
import com.shifthackz.aisdv1.presentation.screen.gallery.detail.GalleryDetailIntent
3637
import com.shifthackz.aisdv1.presentation.screen.gallery.list.GalleryIntent
@@ -63,6 +64,7 @@ fun ModalRenderer(
6364
processIntent(InPaintIntent.ScreenModal.Dismiss)
6465
processIntent(DebugMenuIntent.DismissModal)
6566
processIntent(ReportIntent.DismissError)
67+
processIntent(BackupIntent.DismissModal)
6668
}
6769
val context = LocalContext.current
6870
when (screenModal) {

presentation/src/main/java/com/shifthackz/aisdv1/presentation/navigation/graph/DrawerNavGraph.kt

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.shifthackz.aisdv1.presentation.navigation.graph
22

33
import androidx.compose.material.icons.Icons
4+
import androidx.compose.material.icons.filled.Backup
45
import androidx.compose.material.icons.filled.DeveloperMode
56
import androidx.compose.material.icons.filled.SettingsEthernet
67
import androidx.compose.material.icons.filled.Web
@@ -24,6 +25,7 @@ fun mainDrawerNavItems(settings: Settings? = null): List<NavItem> = buildList {
2425
}
2526
add(settingsTab())
2627
add(configuration())
28+
add(backup())
2729
settings?.developerMode?.takeIf { it }?.let {
2830
add(developerMode())
2931
}
@@ -50,10 +52,18 @@ private fun configuration() = NavItem(
5052
),
5153
)
5254

55+
private fun backup() = NavItem(
56+
name = LocalizationR.string.title_backup.asUiText(),
57+
navRoute = NavigationRoute.Backup,
58+
icon = NavItem.Icon.Vector(
59+
vector = Icons.Default.Backup,
60+
),
61+
)
62+
5363
private fun developerMode() = NavItem(
5464
name = LocalizationR.string.title_debug_menu.asUiText(),
5565
navRoute = NavigationRoute.Debug,
5666
icon = NavItem.Icon.Vector(
5767
vector = Icons.Default.DeveloperMode,
58-
)
68+
),
5969
)

presentation/src/main/java/com/shifthackz/aisdv1/presentation/navigation/graph/MainNavGraph.kt

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.shifthackz.aisdv1.presentation.navigation.graph
22

3+
import androidx.compose.animation.core.tween
4+
import androidx.compose.animation.slideInVertically
5+
import androidx.compose.animation.slideOutVertically
36
import androidx.navigation.NavGraphBuilder
47
import androidx.navigation.NavType
58
import androidx.navigation.compose.composable
@@ -57,7 +60,20 @@ fun NavGraphBuilder.mainNavGraph() {
5760
GalleryDetailScreen(itemId = itemId)
5861
}
5962

60-
composable<NavigationRoute.ReportImage> { entry ->
63+
composable<NavigationRoute.ReportImage>(
64+
enterTransition = {
65+
slideInVertically(
66+
initialOffsetY = { it },
67+
animationSpec = tween(500),
68+
)
69+
},
70+
exitTransition = {
71+
slideOutVertically(
72+
targetOffsetY = { it },
73+
animationSpec = tween(500),
74+
)
75+
},
76+
) { entry ->
6177
val itemId = entry.toRoute<NavigationRoute.ReportImage>().itemId
6278
ReportScreen(
6379
viewModel = koinViewModel<ReportViewModel>(

presentation/src/main/java/com/shifthackz/aisdv1/presentation/screen/backup/BackupIntent.kt

+10
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,24 @@ import com.shifthackz.android.core.mvi.MviIntent
55

66
interface BackupIntent : MviIntent {
77

8+
data object DismissModal : BackupIntent
9+
810
data object NavigateBack : BackupIntent
911

1012
data object MainButtonClick : BackupIntent
1113

1214
data class SelectOperation(val value: String) : BackupIntent
1315

16+
@Suppress("ArrayInDataClass")
17+
data class SelectRestore(
18+
val path: String,
19+
val bytes: ByteArray,
20+
): BackupIntent
21+
1422
data class ToggleBackupEntry(
1523
val entry: BackupEntryToken,
1624
val checked: Boolean,
1725
) : BackupIntent
26+
27+
enum class OnResult : BackupIntent { Success, Fail }
1828
}

0 commit comments

Comments
 (0)