-
Notifications
You must be signed in to change notification settings - Fork 19
/
WireActivityDialogs.kt
482 lines (442 loc) · 15.5 KB
/
WireActivityDialogs.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
/*
* Wire
* Copyright (C) 2024 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/.
*/
@file:Suppress("TooManyFunctions")
package com.wire.android.ui
import androidx.annotation.StringRes
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.window.DialogProperties
import com.wire.android.BuildConfig
import com.wire.android.R
import com.wire.android.appLogger
import com.wire.android.navigation.BackStackMode
import com.wire.android.navigation.NavigationCommand
import com.wire.android.ui.common.WireDialog
import com.wire.android.ui.common.WireDialogButtonProperties
import com.wire.android.ui.common.WireDialogButtonType
import com.wire.android.ui.common.dialogs.CustomServerDialog
import com.wire.android.ui.common.dialogs.CustomServerDialogState
import com.wire.android.ui.common.dialogs.MaxAccountAllowedDialogContent
import com.wire.android.ui.common.wireDialogPropertiesBuilder
import com.wire.android.ui.destinations.ConversationScreenDestination
import com.wire.android.ui.home.messagecomposer.SelfDeletionDuration
import com.wire.android.ui.joinConversation.JoinConversationViaCodeState
import com.wire.android.ui.joinConversation.JoinConversationViaDeepLinkDialog
import com.wire.android.ui.joinConversation.JoinConversationViaInviteLinkError
import com.wire.android.ui.theme.WireTheme
import com.wire.android.util.formatMediumDateTime
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.configuration.server.ServerConfig
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.conversation.CheckConversationInviteCodeUseCase
@Composable
fun FileRestrictionDialog(
isFileSharingEnabled: Boolean,
hideDialogStatus: () -> Unit,
) {
val text: String =
stringResource(id = if (isFileSharingEnabled) R.string.sharing_files_enabled else R.string.sharing_files_disabled)
WireDialog(
title = stringResource(id = R.string.team_settings_changed),
text = text,
onDismiss = hideDialogStatus,
optionButton1Properties = WireDialogButtonProperties(
onClick = hideDialogStatus,
text = stringResource(id = R.string.label_ok),
type = WireDialogButtonType.Primary,
)
)
}
@Composable
fun SelfDeletingMessagesDialog(
areSelfDeletingMessagesEnabled: Boolean,
enforcedTimeout: SelfDeletionDuration,
hideDialogStatus: () -> Unit,
) {
val formattedTimeout = enforcedTimeout.longLabel.asString()
val text: String = when {
areSelfDeletingMessagesEnabled && enforcedTimeout == SelfDeletionDuration.None -> {
stringResource(id = R.string.self_deleting_messages_team_setting_enabled)
}
areSelfDeletingMessagesEnabled -> {
stringResource(
R.string.self_deleting_messages_team_setting_enabled_enforced_timeout,
formattedTimeout
)
}
else -> {
stringResource(id = R.string.self_deleting_messages_team_setting_disabled)
}
}
WireDialog(
title = stringResource(id = R.string.team_settings_changed),
text = text,
onDismiss = hideDialogStatus,
optionButton1Properties = WireDialogButtonProperties(
onClick = hideDialogStatus,
text = stringResource(id = R.string.label_ok),
type = WireDialogButtonType.Primary,
)
)
}
@Composable
fun GuestRoomLinkFeatureFlagDialog(
isGuestRoomLinkEnabled: Boolean,
onDismiss: () -> Unit,
) {
val text: String =
stringResource(id = if (isGuestRoomLinkEnabled) R.string.guest_room_link_enabled else R.string.guest_room_link_disabled)
WireDialog(
title = stringResource(id = R.string.team_settings_changed),
text = text,
onDismiss = onDismiss,
optionButton1Properties = WireDialogButtonProperties(
onClick = onDismiss,
text = stringResource(id = R.string.label_ok),
type = WireDialogButtonType.Primary,
)
)
}
@Composable
fun TeamAppLockFeatureFlagDialog(
isTeamAppLockEnabled: Boolean,
onConfirm: () -> Unit,
) {
val text: String =
stringResource(id = if (isTeamAppLockEnabled) R.string.team_app_lock_enabled
else R.string.team_app_lock_disabled)
WireDialog(
title = stringResource(id = R.string.team_settings_changed),
text = text,
onDismiss = {},
optionButton1Properties = WireDialogButtonProperties(
onClick = onConfirm,
text = stringResource(id = R.string.label_ok),
type = WireDialogButtonType.Primary,
)
)
}
@Composable
fun UpdateAppDialog(shouldShow: Boolean, onUpdateClick: () -> Unit) {
if (shouldShow) {
WireDialog(
title = stringResource(id = R.string.update_app_dialog_title),
text = stringResource(id = R.string.update_app_dialog_body),
onDismiss = { },
optionButton1Properties = WireDialogButtonProperties(
text = stringResource(id = R.string.update_app_dialog_button),
onClick = onUpdateClick,
type = WireDialogButtonType.Primary
),
properties = wireDialogPropertiesBuilder(
dismissOnBackPress = false,
dismissOnClickOutside = false,
usePlatformDefaultWidth = true
)
)
}
}
@Composable
fun JoinConversationDialog(
joinedDialogState: JoinConversationViaCodeState?,
navigate: (NavigationCommand) -> Unit,
onJoinConversationFlowCompleted: () -> Unit
) {
joinedDialogState?.let { state ->
val onComplete: (convId: ConversationId?) -> Unit = remember {
{
onJoinConversationFlowCompleted()
it?.also {
navigate(
NavigationCommand(
ConversationScreenDestination(it),
BackStackMode.CLEAR_TILL_START
)
)
}
}
}
when (state) {
is JoinConversationViaCodeState.Error -> JoinConversationViaInviteLinkError(
errorState = state,
onCancel = { onComplete(null) }
)
is JoinConversationViaCodeState.Show -> {
JoinConversationViaDeepLinkDialog(
name = state.conversationName,
code = state.code,
domain = state.domain,
key = state.key,
requirePassword = state.passwordProtected,
onFlowCompleted = onComplete
)
}
}
}
}
@Composable
fun CustomBackendDialog(
globalAppState: GlobalAppState,
onDismiss: () -> Unit,
onConfirm: () -> Unit
) {
if (globalAppState.customBackendDialog != null) {
CustomServerDialog(
serverLinksTitle = globalAppState.customBackendDialog.serverLinks.title,
serverLinksApi = globalAppState.customBackendDialog.serverLinks.api,
onDismiss = onDismiss,
onConfirm = onConfirm
)
}
}
@Composable
fun MaxAccountDialog(shouldShow: Boolean, onConfirm: () -> Unit, onDismiss: () -> Unit) {
if (shouldShow) {
MaxAccountAllowedDialogContent(
onConfirm = onConfirm,
onDismiss = onDismiss,
buttonText = R.string.max_account_reached_dialog_button_open_profile
)
}
}
@Composable
fun AccountLoggedOutDialog(blockUserUI: CurrentSessionErrorState?, navigateAway: () -> Unit) {
blockUserUI?.let {
accountLoggedOutDialog(reason = it, navigateAway)
}
}
@Composable
fun GuestCallWasEndedBecauseOfVerificationDegradedDialog(onDismiss: () -> Unit) {
WireDialog(
title = stringResource(id = R.string.call_ended_because_of_verification_title),
text = stringResource(id = R.string.call_ended_because_of_verification_message),
onDismiss = onDismiss,
optionButton1Properties = WireDialogButtonProperties(
onClick = onDismiss,
text = stringResource(id = R.string.label_ok),
type = WireDialogButtonType.Primary,
)
)
}
@Composable
private fun accountLoggedOutDialog(reason: CurrentSessionErrorState, navigateAway: () -> Unit) {
appLogger.e("AccountLongedOutDialog: $reason")
val (@StringRes title: Int, text: String) = when (reason) {
CurrentSessionErrorState.SessionExpired -> {
if (BuildConfig.WIPE_ON_COOKIE_INVALID) {
R.string.session_expired_error_title to (
stringResource(id = R.string.session_expired_error_message)
+ "\n\n"
+ stringResource(id = R.string.conversation_history_wipe_explanation)
)
} else {
R.string.session_expired_error_title to stringResource(id = R.string.session_expired_error_message)
}
}
CurrentSessionErrorState.RemovedClient -> {
if (BuildConfig.WIPE_ON_DEVICE_REMOVAL) {
R.string.removed_client_error_title to (
stringResource(id = R.string.removed_client_error_message)
+ "\n\n"
+ stringResource(id = R.string.conversation_history_wipe_explanation)
)
} else {
R.string.removed_client_error_title to stringResource(R.string.removed_client_error_message)
}
}
CurrentSessionErrorState.DeletedAccount -> {
R.string.deleted_user_error_title to stringResource(R.string.deleted_user_error_message)
}
}
WireDialog(
title = stringResource(id = title),
text = text,
onDismiss = remember { { } },
properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false, usePlatformDefaultWidth = false),
optionButton1Properties = WireDialogButtonProperties(
text = stringResource(R.string.label_ok),
onClick = navigateAway,
type = WireDialogButtonType.Primary
)
)
}
@Composable
fun NewClientDialog(
data: NewClientsData?,
openDeviceManager: () -> Unit,
switchAccountAndOpenDeviceManager: (UserId) -> Unit,
dismiss: (UserId) -> Unit
) {
data?.let {
val title: String
val text: String
val btnText: String
val btnAction: () -> Unit
val dismissAction: () -> Unit = { dismiss(data.userId) }
val devicesList = data.clientsInfo.map {
stringResource(
R.string.new_device_dialog_message_defice_info,
it.date.formatMediumDateTime() ?: "",
it.deviceInfo.asString()
)
}.joinToString("")
when (data) {
is NewClientsData.OtherUser -> {
title = stringResource(
R.string.new_device_dialog_other_user_title,
data.userName ?: "",
data.userHandle ?: ""
)
text = stringResource(R.string.new_device_dialog_other_user_message, devicesList)
btnText = stringResource(R.string.new_device_dialog_other_user_btn)
btnAction = { switchAccountAndOpenDeviceManager(data.userId) }
}
is NewClientsData.CurrentUser -> {
title = stringResource(R.string.new_device_dialog_current_user_title)
text = stringResource(R.string.new_device_dialog_current_user_message, devicesList)
btnText = stringResource(R.string.new_device_dialog_current_user_btn)
btnAction = openDeviceManager
}
}
WireDialog(
title = title,
text = text,
onDismiss = dismissAction,
optionButton1Properties = WireDialogButtonProperties(
onClick = {
dismissAction()
btnAction()
},
text = btnText,
type = WireDialogButtonType.Secondary
),
optionButton2Properties = WireDialogButtonProperties(
text = stringResource(id = R.string.label_ok),
onClick = dismissAction,
type = WireDialogButtonType.Primary
)
)
}
}
@PreviewMultipleThemes
@Composable
fun previewFileRestrictionDialog() {
WireTheme {
FileRestrictionDialog(true) {}
}
}
@PreviewMultipleThemes
@Composable
fun previewGuestRoomLinkFeatureFlagDialog() {
WireTheme {
GuestRoomLinkFeatureFlagDialog(true) {}
}
}
@PreviewMultipleThemes
@Composable
fun previewTeamAppLockFeatureFlagDialog() {
WireTheme {
TeamAppLockFeatureFlagDialog(true) {}
}
}
@PreviewMultipleThemes
@Composable
fun previewUpdateAppDialog() {
WireTheme {
UpdateAppDialog(true) {}
}
}
@PreviewMultipleThemes
@Composable
fun previewJoinConversationDialogWithPassword() {
WireTheme {
JoinConversationDialog(
JoinConversationViaCodeState.Show("convName", "code", "key", "domain", true),
{}) {}
}
}
@PreviewMultipleThemes
@Composable
fun previewJoinConversationDialogWithoutPassword() {
WireTheme {
JoinConversationDialog(
JoinConversationViaCodeState.Show("convName", "code", "key", "domain", false),
{}) {}
}
}
@PreviewMultipleThemes
@Composable
fun previewJoinConversationDialogError() {
WireTheme {
JoinConversationDialog(
JoinConversationViaCodeState.Error(CheckConversationInviteCodeUseCase.Result.Failure.InvalidCodeOrKey),
{}) {}
}
}
@PreviewMultipleThemes
@Composable
fun previewCustomBackendDialog() {
WireTheme {
CustomBackendDialog(
GlobalAppState(
customBackendDialog = CustomServerDialogState(
ServerConfig.STAGING
)
), {}, {})
}
}
@PreviewMultipleThemes
@Composable
fun previewMaxAccountDialog() {
WireTheme {
MaxAccountDialog(true, {}, {})
}
}
@PreviewMultipleThemes
@Composable
fun previewAccountLoggedOutDialog() {
WireTheme {
AccountLoggedOutDialog(CurrentSessionErrorState.DeletedAccount) {}
}
}
@PreviewMultipleThemes
@Composable
fun previewGuestCallWasEndedBecauseOfVerificationDegradedDialog() {
WireTheme {
GuestCallWasEndedBecauseOfVerificationDegradedDialog {}
}
}
@PreviewMultipleThemes
@Composable
fun previewNewClientDialog() {
WireTheme {
NewClientDialog(
NewClientsData.CurrentUser(listOf(NewClientInfo("date", UIText.DynamicString("name"))), UserId("id", "domain")),
{}, {}, {})
}
}
@PreviewMultipleThemes
@Composable
fun previewTestDialog() {
WireTheme {
FileRestrictionDialog(true) {}
}
}