-
Notifications
You must be signed in to change notification settings - Fork 19
/
CustomServerDialog.kt
165 lines (159 loc) · 6.43 KB
/
CustomServerDialog.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
/*
* 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/.
*/
package com.wire.android.ui.common.dialogs
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextDecoration
import com.wire.android.R
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.button.WireButtonState
import com.wire.android.ui.common.colorsScheme
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.common.spacers.VerticalSpace
import com.wire.android.ui.common.wireDialogPropertiesBuilder
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.kalium.logic.configuration.server.ServerConfig
@Composable
internal fun CustomServerDialog(
serverLinks: ServerConfig.Links,
onDismiss: () -> Unit,
onConfirm: () -> Unit
) {
var showDetails by remember { mutableStateOf(false) }
WireDialog(
title = stringResource(R.string.custom_backend_dialog_title),
text = stringResource(R.string.custom_backend_dialog_body),
buttonsHorizontalAlignment = true,
properties = wireDialogPropertiesBuilder(
dismissOnBackPress = false,
dismissOnClickOutside = false
),
onDismiss = onDismiss,
dismissButtonProperties = WireDialogButtonProperties(
onClick = onDismiss,
text = stringResource(id = R.string.label_cancel),
state = WireButtonState.Default
),
optionButton1Properties = WireDialogButtonProperties(
onClick = onConfirm,
text = stringResource(id = R.string.label_proceed),
type = WireDialogButtonType.Primary,
state =
WireButtonState.Default
),
content = {
Column {
CustomServerPropertyInfo(
title = stringResource(id = R.string.custom_backend_dialog_body_backend_name),
value = serverLinks.title
)
CustomServerPropertyInfo(
title = stringResource(id = R.string.custom_backend_dialog_body_backend_api),
value = serverLinks.api
)
if (showDetails) {
CustomServerPropertyInfo(
title = stringResource(id = R.string.custom_backend_dialog_body_backend_websocket),
value = serverLinks.webSocket
)
CustomServerPropertyInfo(
title = stringResource(id = R.string.custom_backend_dialog_body_backend_blacklist),
value = serverLinks.blackList
)
CustomServerPropertyInfo(
title = stringResource(id = R.string.custom_backend_dialog_body_backend_teams),
value = serverLinks.teams
)
CustomServerPropertyInfo(
title = stringResource(id = R.string.custom_backend_dialog_body_backend_accounts),
value = serverLinks.accounts
)
CustomServerPropertyInfo(
title = stringResource(id = R.string.custom_backend_dialog_body_backend_website),
value = serverLinks.website
)
}
Column(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = dimensions().spacing8x)
) {
Text(
text = stringResource(id = if (showDetails) R.string.label_hide_details else R.string.label_show_details),
style = MaterialTheme.wireTypography.body02.copy(
textDecoration = TextDecoration.Underline,
color = MaterialTheme.colorScheme.primary
),
modifier = Modifier
.align(Alignment.Start)
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
onClick = { showDetails = !showDetails }
)
)
}
}
}
)
}
@Composable
private fun CustomServerPropertyInfo(
title: String,
value: String
) {
Text(
text = title,
style = MaterialTheme.wireTypography.body01,
color = colorsScheme().onBackground,
)
VerticalSpace.x4()
Text(
text = value,
style = MaterialTheme.wireTypography.body02,
color = colorsScheme().onBackground,
)
VerticalSpace.x16()
}
data class CustomServerDialogState(val serverLinks: ServerConfig.Links)
@PreviewMultipleThemes
@Composable
fun PreviewCustomServerDialog() = WireTheme {
CustomServerDialog(
serverLinks = ServerConfig.DEFAULT,
onConfirm = { },
onDismiss = { }
)
}