android: preferences - fix reset & save buttons being enabled when displayed as disabled, fix info rows being interactive (#1414)

This commit is contained in:
JRoberts
2022-11-25 11:53:29 +04:00
committed by GitHub
parent e32b24ef70
commit a58a0fae29
3 changed files with 20 additions and 32 deletions

View File

@@ -1,8 +1,8 @@
package chat.simplex.app.views.chat
import InfoRow
import SectionDivider
import SectionItemView
import SectionItemWithValue
import SectionSpacer
import SectionTextFooter
import SectionView
@@ -74,13 +74,11 @@ private fun ContactPreferencesLayout(
FeatureSection(Feature.FullDelete, user.fullPreferences.fullDelete.allow, contact.mergedPreferences.fullDelete, allowFullDeletion) {
applyPrefs(featuresAllowed.copy(fullDelete = it))
}
SectionSpacer()
val allowVoice: MutableState<ContactFeatureAllowed> = remember(featuresAllowed) { mutableStateOf(featuresAllowed.voice) }
FeatureSection(Feature.Voice, user.fullPreferences.voice.allow, contact.mergedPreferences.voice, allowVoice) {
applyPrefs(featuresAllowed.copy(voice = it))
}
SectionSpacer()
ResetSaveButtons(
reset = reset,
@@ -119,13 +117,9 @@ private fun FeatureSection(
)
}
SectionDivider()
SectionItemWithValue(
InfoRow(
generalGetString(R.string.chat_preferences_contact_allows),
remember { mutableStateOf(pref.contactPreference.allow) },
listOf(ValueTitleDesc(pref.contactPreference.allow, pref.contactPreference.allow.text, "")),
icon = null,
enabled = remember { mutableStateOf(true) },
onSelected = {}
pref.contactPreference.allow.text
)
}
SectionTextFooter(feature.enabledDescription(enabled))
@@ -134,11 +128,11 @@ private fun FeatureSection(
@Composable
private fun ResetSaveButtons(reset: () -> Unit, save: () -> Unit, disabled: Boolean) {
SectionView {
SectionItemView(reset) {
SectionItemView(reset, disabled = disabled) {
Text(stringResource(R.string.reset_verb), color = if (disabled) HighOrLowlight else MaterialTheme.colors.primary)
}
SectionDivider()
SectionItemView(save) {
SectionItemView(save, disabled = disabled) {
Text(stringResource(R.string.save_and_notify_contact), color = if (disabled) HighOrLowlight else MaterialTheme.colors.primary)
}
}

View File

@@ -1,8 +1,8 @@
package chat.simplex.app.views.chat.group
import InfoRow
import SectionDivider
import SectionItemView
import SectionItemWithValue
import SectionSpacer
import SectionTextFooter
import SectionView
@@ -64,19 +64,19 @@ private fun GroupPreferencesLayout(
FeatureSection(Feature.FullDelete, allowFullDeletion, groupInfo) {
applyPrefs(preferences.copy(fullDelete = GroupPreference(enable = it)))
}
SectionSpacer()
val allowVoice = remember(preferences) { mutableStateOf(preferences.voice.enable) }
FeatureSection(Feature.Voice, allowVoice, groupInfo) {
applyPrefs(preferences.copy(voice = GroupPreference(enable = it)))
}
SectionSpacer()
ResetSaveButtons(
reset = reset,
save = savePrefs,
disabled = preferences == currentPreferences
)
if (groupInfo.canEdit) {
SectionSpacer()
ResetSaveButtons(
reset = reset,
save = savePrefs,
disabled = preferences == currentPreferences
)
}
}
}
@@ -94,13 +94,9 @@ private fun FeatureSection(feature: Feature, enableFeature: State<GroupFeatureEn
)
}
} else {
SectionItemWithValue(
InfoRow(
feature.text(),
remember { mutableStateOf(enableFeature.value) },
listOf(ValueTitleDesc(enableFeature.value, enableFeature.value.text, "")),
icon = null,
enabled = remember { mutableStateOf(true) },
onSelected = {}
enableFeature.value.text
)
}
}
@@ -110,11 +106,11 @@ private fun FeatureSection(feature: Feature, enableFeature: State<GroupFeatureEn
@Composable
private fun ResetSaveButtons(reset: () -> Unit, save: () -> Unit, disabled: Boolean) {
SectionView {
SectionItemView(reset) {
SectionItemView(reset, disabled = disabled) {
Text(stringResource(R.string.reset_verb), color = if (disabled) HighOrLowlight else MaterialTheme.colors.primary)
}
SectionDivider()
SectionItemView(save) {
SectionItemView(save, disabled = disabled) {
Text(stringResource(R.string.save_and_notify_group_members), color = if (disabled) HighOrLowlight else MaterialTheme.colors.primary)
}
}

View File

@@ -65,13 +65,11 @@ private fun PreferencesLayout(
FeatureSection(Feature.FullDelete, allowFullDeletion) {
applyPrefs(preferences.copy(fullDelete = ChatPreference(allow = it)))
}
SectionSpacer()
val allowVoice = remember(preferences) { mutableStateOf(preferences.voice.allow) }
FeatureSection(Feature.Voice, allowVoice) {
applyPrefs(preferences.copy(voice = ChatPreference(allow = it)))
}
SectionSpacer()
ResetSaveButtons(
reset = reset,
@@ -100,11 +98,11 @@ private fun FeatureSection(feature: Feature, allowFeature: State<FeatureAllowed>
@Composable
private fun ResetSaveButtons(reset: () -> Unit, save: () -> Unit, disabled: Boolean) {
SectionView {
SectionItemView(reset) {
SectionItemView(reset, disabled = disabled) {
Text(stringResource(R.string.reset_verb), color = if (disabled) HighOrLowlight else MaterialTheme.colors.primary)
}
SectionDivider()
SectionItemView(save) {
SectionItemView(save, disabled = disabled) {
Text(stringResource(R.string.save_and_notify_contacts), color = if (disabled) HighOrLowlight else MaterialTheme.colors.primary)
}
}