mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-07-17 21:42:17 +00:00
name UI
This commit is contained in:
@@ -757,6 +757,17 @@ struct SetSimplexDomainView: View {
|
||||
@State private var saving = false
|
||||
@State private var original = ""
|
||||
@State private var didSave = false
|
||||
@State private var editing = false
|
||||
|
||||
init(title: LocalizedStringKey, footer: LocalizedStringKey, prompt: String, simplexName: String, save: @escaping (String?) async -> Bool) {
|
||||
self.title = title
|
||||
self.footer = footer
|
||||
self.prompt = prompt
|
||||
self._simplexName = State(initialValue: simplexName)
|
||||
self.save = save
|
||||
self._original = State(initialValue: simplexName)
|
||||
self._editing = State(initialValue: simplexName.isEmpty)
|
||||
}
|
||||
|
||||
private var changed: Bool {
|
||||
normalized(simplexName) != normalized(original)
|
||||
@@ -770,14 +781,28 @@ struct SetSimplexDomainView: View {
|
||||
var body: some View {
|
||||
List {
|
||||
Section {
|
||||
ZStack(alignment: .trailing) {
|
||||
TextField(prompt, text: $simplexName)
|
||||
.autocorrectionDisabled(true)
|
||||
.textInputAutocapitalization(.never)
|
||||
.padding(.trailing, isValid ? 0 : 20)
|
||||
if !isValid {
|
||||
Image(systemName: "exclamationmark.circle")
|
||||
.foregroundColor(.red)
|
||||
if editing {
|
||||
ZStack(alignment: .trailing) {
|
||||
TextField(prompt, text: $simplexName)
|
||||
.autocorrectionDisabled(true)
|
||||
.textInputAutocapitalization(.never)
|
||||
.padding(.trailing, isValid ? 0 : 20)
|
||||
if !isValid {
|
||||
Image(systemName: "exclamationmark.circle")
|
||||
.foregroundColor(.red)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Button {
|
||||
UIPasteboard.general.string = simplexName
|
||||
} label: {
|
||||
HStack {
|
||||
Text(simplexName)
|
||||
.foregroundColor(theme.colors.onBackground)
|
||||
Spacer()
|
||||
Image(systemName: "doc.on.doc")
|
||||
.foregroundColor(theme.colors.secondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
} header: {
|
||||
@@ -786,37 +811,40 @@ struct SetSimplexDomainView: View {
|
||||
Text(footer).foregroundColor(theme.colors.secondary)
|
||||
}
|
||||
Section {
|
||||
Button {
|
||||
openBrowserAlert(uri: "https://github.com/simplex-chat/simplex-chat/blob/master/docs/guide/register-simplex-name.md")
|
||||
} label: {
|
||||
Text("Register a test name")
|
||||
}
|
||||
if !original.isEmpty {
|
||||
Button("Remove") {
|
||||
simplexName = ""
|
||||
}
|
||||
}
|
||||
Button {
|
||||
saving = true
|
||||
Task {
|
||||
let ok = await save(normalized(simplexName))
|
||||
await MainActor.run {
|
||||
saving = false
|
||||
if ok {
|
||||
didSave = true
|
||||
dismiss()
|
||||
}
|
||||
if editing {
|
||||
if simplexName.isEmpty {
|
||||
Button {
|
||||
openBrowserAlert(uri: "https://github.com/simplex-chat/simplex-chat/blob/master/docs/guide/register-simplex-name.md")
|
||||
} label: {
|
||||
Text("Register a test name")
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Text("Save")
|
||||
Button {
|
||||
saving = true
|
||||
Task {
|
||||
let ok = await save(normalized(simplexName))
|
||||
await MainActor.run {
|
||||
saving = false
|
||||
if ok {
|
||||
didSave = true
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Text("Save")
|
||||
}
|
||||
.disabled(saving || !isValid || !changed)
|
||||
} else {
|
||||
Button("Remove name") {
|
||||
simplexName = ""
|
||||
editing = true
|
||||
}
|
||||
}
|
||||
.disabled(saving || !isValid || !changed)
|
||||
}
|
||||
}
|
||||
.navigationTitle(title)
|
||||
.navigationBarTitleDisplayMode(.large)
|
||||
.onAppear { original = simplexName }
|
||||
.onDisappear {
|
||||
if !didSave, changed, isValid {
|
||||
let domain = normalized(simplexName)
|
||||
|
||||
+38
-19
@@ -3,6 +3,7 @@ package chat.simplex.common.views.usersettings
|
||||
import SectionBottomSpacer
|
||||
import SectionDividerSpaced
|
||||
import SectionItemView
|
||||
import SectionItemViewSpaceBetween
|
||||
import SectionTextFooter
|
||||
import SectionView
|
||||
import androidx.compose.foundation.layout.*
|
||||
@@ -10,13 +11,16 @@ import androidx.compose.material.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalClipboardManager
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import chat.simplex.common.platform.*
|
||||
import chat.simplex.common.ui.theme.*
|
||||
import chat.simplex.common.views.*
|
||||
import chat.simplex.common.views.chat.item.openBrowserAlert
|
||||
import chat.simplex.common.views.helpers.*
|
||||
import chat.simplex.res.MR
|
||||
import dev.icerock.moko.resources.compose.painterResource
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
@@ -40,7 +44,9 @@ fun SetSimplexDomainView(
|
||||
) {
|
||||
val name = rememberSaveable { mutableStateOf(simplexName) }
|
||||
val saving = remember { mutableStateOf(false) }
|
||||
val editing = rememberSaveable { mutableStateOf(simplexName.isBlank()) }
|
||||
val uriHandler = LocalUriHandler.current
|
||||
val clipboard = LocalClipboardManager.current
|
||||
|
||||
fun addSimplexTLD(s: String): String {
|
||||
return if (s.contains(".")) s else "$s.simplex"
|
||||
@@ -123,31 +129,44 @@ fun SetSimplexDomainView(
|
||||
ColumnWithScrollBar {
|
||||
AppBarTitle(title)
|
||||
SectionView {
|
||||
Box(Modifier.padding(horizontal = DEFAULT_PADDING)) {
|
||||
ProfileNameField(
|
||||
name,
|
||||
placeholder,
|
||||
isValid = { isValidName(it) },
|
||||
onInvalidTap = { AlertManager.shared.showAlertMsg(title = generalGetString(MR.strings.invalid_name)) }
|
||||
)
|
||||
if (editing.value) {
|
||||
Box(Modifier.padding(horizontal = DEFAULT_PADDING)) {
|
||||
ProfileNameField(
|
||||
name,
|
||||
placeholder,
|
||||
isValid = { isValidName(it) },
|
||||
onInvalidTap = { AlertManager.shared.showAlertMsg(title = generalGetString(MR.strings.invalid_name)) }
|
||||
)
|
||||
}
|
||||
} else {
|
||||
SectionItemViewSpaceBetween(click = {
|
||||
clipboard.setText(AnnotatedString(name.value))
|
||||
showToast(generalGetString(MR.strings.copied))
|
||||
}) {
|
||||
Text(name.value)
|
||||
Icon(painterResource(MR.images.ic_content_copy), stringResource(MR.strings.copy_verb), tint = MaterialTheme.colors.secondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
SectionTextFooter(footer)
|
||||
SectionDividerSpaced()
|
||||
SectionView {
|
||||
SectionItemView({ openBrowserAlert("https://github.com/simplex-chat/simplex-chat/blob/master/docs/guide/register-simplex-name.md", uriHandler) }) {
|
||||
Text(stringResource(MR.strings.register_test_name), color = MaterialTheme.colors.primary)
|
||||
}
|
||||
if (simplexName.isNotBlank()) {
|
||||
SectionItemView({ name.value = "" }) {
|
||||
Text(stringResource(MR.strings.remove_verb), color = MaterialTheme.colors.primary)
|
||||
if (editing.value) {
|
||||
if (name.value.isBlank()) {
|
||||
SectionItemView({ openBrowserAlert("https://github.com/simplex-chat/simplex-chat/blob/master/docs/guide/register-simplex-name.md", uriHandler) }) {
|
||||
Text(stringResource(MR.strings.register_test_name), color = MaterialTheme.colors.primary)
|
||||
}
|
||||
}
|
||||
SectionItemView({ doSave(close) }, disabled = unchanged || saving.value || !isValid) {
|
||||
Text(
|
||||
stringResource(MR.strings.save_verb),
|
||||
color = if (unchanged || saving.value || !isValid) MaterialTheme.colors.secondary else MaterialTheme.colors.primary
|
||||
)
|
||||
}
|
||||
} else {
|
||||
SectionItemView({ name.value = ""; editing.value = true }) {
|
||||
Text(stringResource(MR.strings.remove_name), color = MaterialTheme.colors.primary)
|
||||
}
|
||||
}
|
||||
SectionItemView({ doSave(close) }, disabled = unchanged || saving.value || !isValid) {
|
||||
Text(
|
||||
stringResource(MR.strings.save_verb),
|
||||
color = if (unchanged || saving.value || !isValid) MaterialTheme.colors.secondary else MaterialTheme.colors.primary
|
||||
)
|
||||
}
|
||||
}
|
||||
SectionBottomSpacer()
|
||||
|
||||
@@ -398,6 +398,7 @@
|
||||
<string name="get_simplex_name_beta">Get SimpleX name (BETA)</string>
|
||||
<string name="channel_simplex_name">Channel SimpleX name</string>
|
||||
<string name="register_test_name">Register a test name</string>
|
||||
<string name="remove_name">Remove name</string>
|
||||
<string name="save_verb">Save</string>
|
||||
<string name="edit_verb">Edit</string>
|
||||
<string name="info_menu">Info</string>
|
||||
|
||||
Reference in New Issue
Block a user