add support development button, add source code text

This commit is contained in:
greenart7c3
2024-01-08 14:40:13 -03:00
parent a7c5cda407
commit ec3334db9e
3 changed files with 116 additions and 0 deletions
@@ -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) {
@@ -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<String, String>,
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)
}
}
)
}
+2
View File
@@ -67,4 +67,6 @@
<string name="event_copied_to_the_clipboard">Event copied to the clipboard</string>
<string name="select_deselect_all">Select/Deselect all</string>
<string name="decrypt_content">Decrypt content</string>
<string name="support_development_uri">https://donate.greenart7c3.com/apps/gubjiRzruRLo6hMviH2hmSrvJjt/pos/static</string>
<string name="support_development">Support development</string>
</resources>