-
Notifications
You must be signed in to change notification settings - Fork 19
/
CreateBackupDialogFlow.kt
111 lines (102 loc) 路 4.11 KB
/
CreateBackupDialogFlow.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*
*/
package com.wire.android.ui.home.settings.backup.dialog.create
import android.net.Uri
import androidx.activity.compose.BackHandler
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.TextFieldValue
import com.wire.android.R
import com.wire.android.ui.home.settings.backup.BackupAndRestoreState
import com.wire.android.ui.home.settings.backup.BackupCreationProgress
import com.wire.android.ui.home.settings.backup.dialog.common.FailureDialog
@Composable
fun CreateBackupDialogFlow(
backUpAndRestoreState: BackupAndRestoreState,
onValidateBackupPassword: (TextFieldValue) -> Unit,
onCreateBackup: (String) -> Unit,
onSaveBackup: (Uri) -> Unit,
onShareBackup: () -> Unit,
onCancelCreateBackup: () -> Unit
) {
val backupDialogStateHolder = rememberBackUpDialogState()
with(backupDialogStateHolder) {
when (currentBackupDialogStep) {
BackUpDialogStep.SetPassword -> {
SetBackupPasswordDialog(
passwordValidation = backUpAndRestoreState.passwordValidation,
onBackupPasswordChanged = onValidateBackupPassword,
onCreateBackup = { password ->
toCreatingBackup()
onCreateBackup(password)
},
onDismissDialog = onCancelCreateBackup
)
}
is BackUpDialogStep.CreatingBackup,
is BackUpDialogStep.Finished -> {
CreateBackupStep(
backUpAndRestoreState = backUpAndRestoreState,
backupDialogStateHolder = backupDialogStateHolder,
onSaveBackup = onSaveBackup,
onShareBackup = onShareBackup,
onCancelCreateBackup = onCancelCreateBackup
)
}
BackUpDialogStep.Failure -> {
FailureDialog(
title = stringResource(R.string.backup_dialog_create_error_title),
message = stringResource(R.string.backup_dialog_create_error_subtitle),
onDismiss = onCancelCreateBackup
)
}
}
}
BackHandler(backupDialogStateHolder.currentBackupDialogStep !is BackUpDialogStep.CreatingBackup) {
onCancelCreateBackup()
}
}
@Composable
private fun CreateBackupStep(
backUpAndRestoreState: BackupAndRestoreState,
backupDialogStateHolder: CreateBackupDialogStateHolder,
onSaveBackup: (Uri) -> Unit,
onShareBackup: () -> Unit,
onCancelCreateBackup: () -> Unit
) {
with(backupDialogStateHolder) {
LaunchedEffect(backUpAndRestoreState.backupCreationProgress) {
when (val progress = backUpAndRestoreState.backupCreationProgress) {
BackupCreationProgress.Failed -> toBackupFailure()
is BackupCreationProgress.Finished -> toFinished(progress.fileName)
is BackupCreationProgress.InProgress -> toCreatingBackup(progress.value)
}
}
CreateBackupDialog(
isBackupCreationCompleted = isBackupFinished,
createBackupProgress = backupProgress,
onSaveBackup = onSaveBackup,
onShareBackup = onShareBackup,
backupFileName = backupFileName,
onDismissDialog = onCancelCreateBackup
)
}
}