mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-06-06 17:42:31 +00:00
ui: reset hints in dev tools (#4613)
* ui: reset hints in dev tools * fix disabled, icon, remove damage * icon
This commit is contained in:
@@ -13,6 +13,8 @@ struct DeveloperView: View {
|
||||
@EnvironmentObject var theme: AppTheme
|
||||
@AppStorage(DEFAULT_DEVELOPER_TOOLS) private var developerTools = false
|
||||
@AppStorage(GROUP_DEFAULT_CONFIRM_DB_UPGRADES, store: groupDefaults) private var confirmDatabaseUpgrades = false
|
||||
@State private var hintsUnchanged = hintDefaultsUnchanged()
|
||||
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
|
||||
var body: some View {
|
||||
@@ -33,6 +35,10 @@ struct DeveloperView: View {
|
||||
} label: {
|
||||
settingsRow("terminal", color: theme.colors.secondary) { Text("Chat console") }
|
||||
}
|
||||
settingsRow("lightbulb.max", color: theme.colors.secondary) {
|
||||
Button("Reset all hints", action: resetHintDefaults)
|
||||
.disabled(hintsUnchanged)
|
||||
}
|
||||
settingsRow("chevron.left.forwardslash.chevron.right", color: theme.colors.secondary) {
|
||||
Toggle("Show developer options", isOn: $developerTools)
|
||||
}
|
||||
@@ -55,6 +61,21 @@ struct DeveloperView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func resetHintDefaults() {
|
||||
for def in hintDefaults {
|
||||
if let val = appDefaults[def] as? Bool {
|
||||
UserDefaults.standard.set(val, forKey: def)
|
||||
}
|
||||
}
|
||||
hintsUnchanged = true
|
||||
}
|
||||
}
|
||||
|
||||
private func hintDefaultsUnchanged() -> Bool {
|
||||
hintDefaults.allSatisfy { def in
|
||||
appDefaults[def] as? Bool == UserDefaults.standard.bool(forKey: def)
|
||||
}
|
||||
}
|
||||
|
||||
struct DeveloperView_Previews: PreviewProvider {
|
||||
|
||||
@@ -120,6 +120,18 @@ let appDefaults: [String: Any] = [
|
||||
DEFAULT_CURRENT_THEME_IDS: "{}"
|
||||
]
|
||||
|
||||
// only Bool defaults can be used here,
|
||||
// or hintDefaultsUnchanged and resetHintDefaults need to be changed
|
||||
let hintDefaults = [
|
||||
DEFAULT_LA_NOTICE_SHOWN,
|
||||
DEFAULT_ONE_HAND_UI_CARD_SHOWN,
|
||||
DEFAULT_LIVE_MESSAGE_ALERT_SHOWN,
|
||||
DEFAULT_SHOW_HIDDEN_PROFILES_NOTICE,
|
||||
DEFAULT_SHOW_MUTE_PROFILE_ALERT,
|
||||
DEFAULT_SHOW_DELETE_CONVERSATION_NOTICE,
|
||||
DEFAULT_SHOW_DELETE_CONTACT_NOTICE
|
||||
]
|
||||
|
||||
// not used anymore
|
||||
enum ConnectViaLinkTab: String {
|
||||
case scan
|
||||
|
||||
+10
@@ -227,6 +227,16 @@ class AppPreferences {
|
||||
|
||||
val oneHandUI = mkBoolPreference(SHARED_PREFS_ONE_HAND_UI, appPlatform.isAndroid)
|
||||
|
||||
val hintPreferences: List<Pair<SharedPreference<Boolean>, Boolean>> = listOf(
|
||||
laNoticeShown to false,
|
||||
// SHARED_PREFS_ONE_HAND_UI_CARD_SHOWN to false,
|
||||
liveMessageAlertShown to false,
|
||||
showHiddenProfilesNotice to true,
|
||||
showMuteProfileAlert to true,
|
||||
showDeleteConversationNotice to true,
|
||||
showDeleteContactNotice to true,
|
||||
)
|
||||
|
||||
private fun mkIntPreference(prefName: String, default: Int) =
|
||||
SharedPreference(
|
||||
get = fun() = settings.getInt(prefName, default),
|
||||
|
||||
+3
@@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import chat.simplex.common.model.*
|
||||
@@ -30,9 +31,11 @@ fun DeveloperView(
|
||||
AppBarTitle(stringResource(MR.strings.settings_developer_tools))
|
||||
val developerTools = m.controller.appPrefs.developerTools
|
||||
val devTools = remember { developerTools.state }
|
||||
val unchangedHints = mutableStateOf(unchangedHintPreferences())
|
||||
SectionView {
|
||||
InstallTerminalAppItem(uriHandler)
|
||||
ChatConsoleItem { withAuth(generalGetString(MR.strings.auth_open_chat_console), generalGetString(MR.strings.auth_log_in_using_credential), showCustomModal { it, close -> TerminalView(it, close) }) }
|
||||
ResetHintsItem(unchangedHints)
|
||||
SettingsPreferenceItem(painterResource(MR.images.ic_code), stringResource(MR.strings.show_developer_options), developerTools)
|
||||
SectionTextFooter(
|
||||
generalGetString(if (devTools.value) MR.strings.show_dev_options else MR.strings.hide_dev_options) + " " +
|
||||
|
||||
+25
@@ -330,6 +330,31 @@ fun ChatLockItem(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable fun ResetHintsItem(unchangedHints: MutableState<Boolean>) {
|
||||
SectionItemView({
|
||||
resetHintPreferences()
|
||||
unchangedHints.value = true
|
||||
}, disabled = unchangedHints.value) {
|
||||
Icon(
|
||||
painter = painterResource(MR.images.ic_lightbulb),
|
||||
contentDescription = "Lightbulb",
|
||||
tint = MaterialTheme.colors.secondary,
|
||||
)
|
||||
TextIconSpaced()
|
||||
Text(generalGetString(MR.strings.reset_all_hints), color = if (unchangedHints.value) MaterialTheme.colors.secondary else MaterialTheme.colors.primary)
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetHintPreferences() {
|
||||
for ((pref, def) in appPreferences.hintPreferences) {
|
||||
pref.set(def)
|
||||
}
|
||||
}
|
||||
|
||||
fun unchangedHintPreferences(): Boolean = appPreferences.hintPreferences.all { (pref, def) ->
|
||||
pref.state.value == def
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AppVersionItem(showVersion: () -> Unit) {
|
||||
SectionItemViewWithIcon(showVersion) { AppVersionText() }
|
||||
|
||||
@@ -739,6 +739,7 @@
|
||||
<string name="xftp_servers_other">Other XFTP servers</string>
|
||||
<string name="subscription_percentage">Show percentage</string>
|
||||
<string name="install_simplex_chat_for_terminal">Install SimpleX Chat for terminal</string>
|
||||
<string name="reset_all_hints">Reset all hints</string>
|
||||
<string name="star_on_github">Star on GitHub</string>
|
||||
<string name="contribute">Contribute</string>
|
||||
<string name="rate_the_app">Rate the app</string>
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#5f6368">
|
||||
<path
|
||||
d="M480-84.5q-33.5 0-56.75-23.25T400-164.5h160q0 33.5-23.25 56.75T480-84.5Zm-160-143V-285h320v57.5H320Zm4.5-119.5q-65-42.5-102.75-106T184-595.87q0-120.39 87.76-208.26 87.77-87.87 208-87.87Q600-892 688-804.13q88 87.87 88 208.26 0 79.37-37.25 142.87T635.5-347h-311Zm21.32-57.5h269.3q47.88-32 75.63-82.51 27.75-50.51 27.75-108.95 0-98.04-70.04-168.29-70.04-70.25-168.37-70.25-98.34 0-168.46 70.12-70.13 70.12-70.13 168.57 0 58.49 28 108.9 28 50.41 76.32 82.41Zm134.18 0Z" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 604 B |
Reference in New Issue
Block a user