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
@@ -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
@@ -170,20 +190,116 @@ fun BaseNonOriginatingProSettingsScreen(
170
190
buttonText : String ,
171
191
dangerButton : Boolean ,
172
192
onButtonClick : () -> Unit ,
173
- title : String? = null,
174
- content : @Composable () -> Unit
193
+ headerTitle : String? ,
194
+ contentTitle : String? ,
195
+ contentDescription : CharSequence? ,
196
+ linkCellsInfo : String? ,
197
+ linkCells : List <NonOriginatingLinkCellData > = emptyList(),
175
198
) {
176
199
BaseCellButtonProSettingsScreen (
177
200
disabled = disabled,
178
201
onBack = onBack,
179
202
buttonText = buttonText,
180
203
dangerButton = dangerButton,
181
204
onButtonClick = onButtonClick,
182
- title = title,
183
- content = content
184
- )
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
+ }
185
293
}
186
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
+
187
303
@Preview
188
304
@Composable
189
305
private fun PreviewBaseNonOrig (
@@ -193,17 +309,26 @@ private fun PreviewBaseNonOrig(
193
309
BaseNonOriginatingProSettingsScreen (
194
310
disabled = false ,
195
311
onBack = {},
196
- title = " This is a title" ,
312
+ headerTitle = " This is a title" ,
197
313
buttonText = " This is a button" ,
198
- dangerButton = true ,
314
+ dangerButton = false ,
199
315
onButtonClick = {},
200
- content = {
201
- Box (
202
- modifier = Modifier .padding(LocalDimensions .current.smallSpacing)
203
- ) {
204
- Text (" This is a cell button content screen~" )
205
- }
206
- }
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
+
207
332
)
208
333
}
209
334
}
0 commit comments