1
1
package org.thoughtcrime.securesms.preferences.prosettings
2
2
3
+ import androidx.annotation.DrawableRes
4
+ import androidx.compose.foundation.background
5
+ import androidx.compose.foundation.layout.Arrangement
3
6
import androidx.compose.foundation.layout.Box
4
7
import androidx.compose.foundation.layout.Column
8
+ import androidx.compose.foundation.layout.Row
5
9
import androidx.compose.foundation.layout.Spacer
6
10
import androidx.compose.foundation.layout.WindowInsets
7
11
import androidx.compose.foundation.layout.WindowInsetsSides
@@ -11,17 +15,22 @@ import androidx.compose.foundation.layout.fillMaxWidth
11
15
import androidx.compose.foundation.layout.height
12
16
import androidx.compose.foundation.layout.only
13
17
import androidx.compose.foundation.layout.padding
18
+ import androidx.compose.foundation.layout.size
14
19
import androidx.compose.foundation.layout.systemBars
15
20
import androidx.compose.foundation.layout.widthIn
16
21
import androidx.compose.foundation.rememberScrollState
17
22
import androidx.compose.foundation.verticalScroll
18
23
import androidx.compose.material3.ExperimentalMaterial3Api
24
+ import androidx.compose.material3.Icon
25
+ import androidx.compose.material3.MaterialTheme
19
26
import androidx.compose.material3.Scaffold
20
27
import androidx.compose.material3.Text
21
28
import androidx.compose.runtime.Composable
29
+ import androidx.compose.ui.Alignment.Companion.Center
22
30
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
23
31
import androidx.compose.ui.Modifier
24
32
import androidx.compose.ui.graphics.Color
33
+ import androidx.compose.ui.res.painterResource
25
34
import androidx.compose.ui.text.style.TextAlign
26
35
import androidx.compose.ui.tooling.preview.Preview
27
36
import androidx.compose.ui.tooling.preview.PreviewParameter
@@ -31,12 +40,16 @@ import org.thoughtcrime.securesms.ui.SessionProSettingsHeader
31
40
import org.thoughtcrime.securesms.ui.components.AccentFillButtonRect
32
41
import org.thoughtcrime.securesms.ui.components.BackAppBar
33
42
import org.thoughtcrime.securesms.ui.components.DangerFillButtonRect
43
+ import org.thoughtcrime.securesms.ui.components.annotatedStringResource
34
44
import org.thoughtcrime.securesms.ui.theme.LocalColors
35
45
import org.thoughtcrime.securesms.ui.theme.LocalDimensions
36
46
import org.thoughtcrime.securesms.ui.theme.LocalType
37
47
import org.thoughtcrime.securesms.ui.theme.PreviewTheme
38
48
import org.thoughtcrime.securesms.ui.theme.SessionColorsParameterProvider
39
49
import org.thoughtcrime.securesms.ui.theme.ThemeColors
50
+ import org.thoughtcrime.securesms.ui.theme.bold
51
+ import network.loki.messenger.R
52
+ import org.thoughtcrime.securesms.ui.DialogBg
40
53
41
54
/* *
42
55
* Base structure used in most Pro Settings screen
@@ -92,7 +105,7 @@ fun BaseCellButtonProSettingsScreen(
92
105
buttonText : String ,
93
106
dangerButton : Boolean ,
94
107
onButtonClick : () -> Unit ,
95
- title : String ? = null,
108
+ title : CharSequence ? = null,
96
109
content : @Composable () -> Unit
97
110
) {
98
111
BaseProSettingsScreen (
@@ -104,7 +117,7 @@ fun BaseCellButtonProSettingsScreen(
104
117
if (! title.isNullOrEmpty()) {
105
118
Text (
106
119
modifier = Modifier .fillMaxWidth(),
107
- text = title,
120
+ text = annotatedStringResource( title) ,
108
121
textAlign = TextAlign .Center ,
109
122
style = LocalType .current.base,
110
123
color = LocalColors .current.text,
@@ -114,7 +127,14 @@ fun BaseCellButtonProSettingsScreen(
114
127
115
128
Spacer (Modifier .height(LocalDimensions .current.smallSpacing))
116
129
117
- Cell (content = content)
130
+ Cell {
131
+ Column (
132
+ modifier = Modifier .fillMaxWidth()
133
+ .padding(LocalDimensions .current.smallSpacing)
134
+ ) {
135
+ content()
136
+ }
137
+ }
118
138
119
139
Spacer (Modifier .height(LocalDimensions .current.smallSpacing))
120
140
@@ -159,3 +179,155 @@ private fun PreviewBaseCellButton(
159
179
)
160
180
}
161
181
}
182
+
183
+ /* *
184
+ * A reusable structure for Pro Settings screens for non originating steps
185
+ */
186
+ @Composable
187
+ fun BaseNonOriginatingProSettingsScreen (
188
+ disabled : Boolean ,
189
+ onBack : () -> Unit ,
190
+ buttonText : String ,
191
+ dangerButton : Boolean ,
192
+ onButtonClick : () -> Unit ,
193
+ headerTitle : CharSequence? ,
194
+ contentTitle : String? ,
195
+ contentDescription : CharSequence? ,
196
+ linkCellsInfo : String? ,
197
+ linkCells : List <NonOriginatingLinkCellData > = emptyList(),
198
+ ) {
199
+ BaseCellButtonProSettingsScreen (
200
+ disabled = disabled,
201
+ onBack = onBack,
202
+ buttonText = buttonText,
203
+ dangerButton = dangerButton,
204
+ onButtonClick = onButtonClick,
205
+ title = headerTitle,
206
+ ){
207
+ if (contentTitle != null ) {
208
+ Text (
209
+ text = contentTitle,
210
+ style = LocalType .current.h7,
211
+ color = LocalColors .current.text,
212
+ )
213
+ }
214
+
215
+ if (contentDescription != null ) {
216
+ Spacer (Modifier .height(LocalDimensions .current.xxxsSpacing))
217
+ Text (
218
+ text = annotatedStringResource(contentDescription),
219
+ style = LocalType .current.base,
220
+ color = LocalColors .current.text,
221
+ )
222
+ }
223
+
224
+ if (linkCellsInfo != null ) {
225
+ Spacer (Modifier .height(LocalDimensions .current.smallSpacing))
226
+ Text (
227
+ text = linkCellsInfo,
228
+ style = LocalType .current.base,
229
+ color = LocalColors .current.textSecondary,
230
+ )
231
+ }
232
+
233
+ Spacer (Modifier .height(LocalDimensions .current.xsSpacing))
234
+
235
+ linkCells.forEachIndexed { index, data ->
236
+ if (index > 0 ) {
237
+ Spacer (Modifier .height(LocalDimensions .current.xsSpacing))
238
+ }
239
+ NonOriginatingLinkCell (data)
240
+ }
241
+ }
242
+ }
243
+
244
+ @Composable
245
+ fun NonOriginatingLinkCell (
246
+ data : NonOriginatingLinkCellData
247
+ ) {
248
+ DialogBg (
249
+ bgColor = LocalColors .current.backgroundTertiary
250
+ ) {
251
+ Row (
252
+ modifier = Modifier .fillMaxWidth()
253
+ .padding(LocalDimensions .current.smallSpacing),
254
+ horizontalArrangement = Arrangement .spacedBy(LocalDimensions .current.smallSpacing)
255
+ ) {
256
+ // icon
257
+ Box (modifier = Modifier
258
+ .background(
259
+ color = LocalColors .current.accent.copy(alpha = 0.2f ),
260
+ shape = MaterialTheme .shapes.small
261
+ )
262
+ .padding(10 .dp)
263
+ ){
264
+ Icon (
265
+ modifier = Modifier .align(Center )
266
+ .size(LocalDimensions .current.iconMedium),
267
+ painter = painterResource(id = data.iconRes),
268
+ tint = LocalColors .current.accent,
269
+ contentDescription = null
270
+ )
271
+ }
272
+
273
+ // text content
274
+ Column (
275
+ modifier = Modifier .weight(1f )
276
+ ) {
277
+ Text (
278
+ text = annotatedStringResource(data.title),
279
+ style = LocalType .current.base.bold(),
280
+ color = LocalColors .current.text,
281
+ )
282
+
283
+ Spacer (Modifier .height(LocalDimensions .current.xxxsSpacing))
284
+
285
+ Text (
286
+ text = annotatedStringResource(data.info),
287
+ style = LocalType .current.base,
288
+ color = LocalColors .current.text,
289
+ )
290
+ }
291
+ }
292
+ }
293
+ }
294
+
295
+
296
+ data class NonOriginatingLinkCellData (
297
+ val title : CharSequence ,
298
+ val info : CharSequence ,
299
+ @DrawableRes val iconRes : Int ,
300
+ val onClick : (() -> Unit )? = null
301
+ )
302
+
303
+ @Preview
304
+ @Composable
305
+ private fun PreviewBaseNonOrig (
306
+ @PreviewParameter(SessionColorsParameterProvider ::class ) colors : ThemeColors
307
+ ) {
308
+ PreviewTheme (colors) {
309
+ BaseNonOriginatingProSettingsScreen (
310
+ disabled = false ,
311
+ onBack = {},
312
+ headerTitle = " This is a title" ,
313
+ buttonText = " This is a button" ,
314
+ dangerButton = false ,
315
+ onButtonClick = {},
316
+ contentTitle = " This is a content title" ,
317
+ contentDescription = " This is a content description" ,
318
+ linkCellsInfo = " This is a link cells info" ,
319
+ linkCells = listOf (
320
+ NonOriginatingLinkCellData (
321
+ title = " This is a title" ,
322
+ info = " This is some info" ,
323
+ iconRes = R .drawable.ic_globe
324
+ ),
325
+ NonOriginatingLinkCellData (
326
+ title = " This is another title" ,
327
+ info = " This is some different info" ,
328
+ iconRes = R .drawable.ic_phone
329
+ )
330
+ )
331
+ )
332
+ }
333
+ }
0 commit comments