From ec3334db9e5bb4bee9be6082aeac921fef63afca Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Mon, 8 Jan 2024 14:40:13 -0300 Subject: [PATCH] add support development button, add source code text --- .../nostrsigner/ui/SettingsScreen.kt | 43 +++++++++++ .../ui/components/HyperlinkText.kt | 71 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 + 3 files changed, 116 insertions(+) create mode 100644 app/src/main/java/com/greenart7c3/nostrsigner/ui/components/HyperlinkText.kt diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/ui/SettingsScreen.kt b/app/src/main/java/com/greenart7c3/nostrsigner/ui/SettingsScreen.kt index a35e0b6c..155c949b 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/ui/SettingsScreen.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/ui/SettingsScreen.kt @@ -2,8 +2,11 @@ package com.greenart7c3.nostrsigner.ui import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.CurrencyBitcoin import androidx.compose.material.icons.filled.Key import androidx.compose.material.icons.filled.Person import androidx.compose.material.icons.filled.PhoneAndroid @@ -18,14 +21,20 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp import com.greenart7c3.nostrsigner.BuildConfig import com.greenart7c3.nostrsigner.R import com.greenart7c3.nostrsigner.models.Account import com.greenart7c3.nostrsigner.ui.actions.AccountBackupDialog import com.greenart7c3.nostrsigner.ui.actions.AccountsBottomSheet import com.greenart7c3.nostrsigner.ui.actions.LogoutDialog +import com.greenart7c3.nostrsigner.ui.components.HyperlinkText import com.greenart7c3.nostrsigner.ui.components.IconRow import com.vitorpamplona.quartz.encoders.toNpub import kotlinx.coroutines.launch @@ -40,6 +49,8 @@ fun SettingsScreen( var backupDialogOpen by remember { mutableStateOf(false) } var logoutDialog by remember { mutableStateOf(false) } var shouldShowBottomSheet by remember { mutableStateOf(false) } + val uriHandler = LocalUriHandler.current + val context = LocalContext.current val sheetState = rememberModalBottomSheetState( confirmValueChange = { it != SheetValue.PartiallyExpanded }, @@ -105,6 +116,21 @@ fun SettingsScreen( } ) } + + Box( + Modifier + .padding(16.dp) + ) { + IconRow( + title = stringResource(R.string.support_development), + icon = Icons.Default.CurrencyBitcoin, + tint = MaterialTheme.colorScheme.onBackground, + onClick = { + uriHandler.openUri(context.getString(R.string.support_development_uri)) + } + ) + } + Box( Modifier .padding(16.dp) @@ -116,6 +142,23 @@ fun SettingsScreen( onClick = { } ) } + Spacer(modifier = Modifier.weight(1f)) + + HyperlinkText( + Modifier + .fillMaxWidth() + .padding(vertical = 24.dp), + fullText = "Made possible by OpenSats \n\nSource code", + hyperLinks = mutableMapOf( + "OpenSats" to "https://opensats.org", + "Source code" to "https://github.com/greenart7c3/amber" + ), + textStyle = TextStyle( + textAlign = TextAlign.Center + ), + linkTextColor = MaterialTheme.colorScheme.primary, + fontSize = 18.sp + ) } if (backupDialogOpen) { diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/HyperlinkText.kt b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/HyperlinkText.kt new file mode 100644 index 00000000..753eed8f --- /dev/null +++ b/app/src/main/java/com/greenart7c3/nostrsigner/ui/components/HyperlinkText.kt @@ -0,0 +1,71 @@ +package com.greenart7c3.nostrsigner.ui.components + +import androidx.compose.foundation.text.ClickableText +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalUriHandler +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.buildAnnotatedString +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextDecoration +import androidx.compose.ui.unit.TextUnit + +@Composable +fun HyperlinkText( + modifier: Modifier = Modifier, + fullText: String, + hyperLinks: Map, + textStyle: TextStyle = TextStyle.Default, + linkTextColor: Color = Color.Blue, + linkTextFontWeight: FontWeight = FontWeight.Normal, + linkTextDecoration: TextDecoration = TextDecoration.None, + fontSize: TextUnit = TextUnit.Unspecified +) { + val annotatedString = buildAnnotatedString { + append(fullText) + for ((key, value) in hyperLinks) { + val startIndex = fullText.indexOf(key) + val endIndex = startIndex + key.length + addStyle( + style = SpanStyle( + color = linkTextColor, + fontSize = fontSize, + fontWeight = linkTextFontWeight, + textDecoration = linkTextDecoration + ), + start = startIndex, + end = endIndex + ) + addStringAnnotation( + tag = "URL", + annotation = value, + start = startIndex, + end = endIndex + ) + } + addStyle( + style = SpanStyle( + fontSize = fontSize + ), + start = 0, + end = fullText.length + ) + } + + val uriHandler = LocalUriHandler.current + + ClickableText( + modifier = modifier, + text = annotatedString, + style = textStyle, + onClick = { + annotatedString + .getStringAnnotations("URL", it, it) + .firstOrNull()?.let { stringAnnotation -> + uriHandler.openUri(stringAnnotation.item) + } + } + ) +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a2022368..72a5cf3d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -67,4 +67,6 @@ Event copied to the clipboard Select/Deselect all Decrypt content + https://donate.greenart7c3.com/apps/gubjiRzruRLo6hMviH2hmSrvJjt/pos/static + Support development \ No newline at end of file