mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-06-28 20:29:53 +00:00
android: mute/unmute in a chat menu (#1026)
* Mute/unmute in a chat menu * Better naming
This commit is contained in:
parent
65f3fe8afc
commit
aa79a3058c
4 changed files with 55 additions and 96 deletions
|
@ -64,42 +64,10 @@ fun ChatInfoView(
|
||||||
},
|
},
|
||||||
deleteContact = { deleteContactDialog(chat.chatInfo, chatModel, close) },
|
deleteContact = { deleteContactDialog(chat.chatInfo, chatModel, close) },
|
||||||
clearChat = { clearChatDialog(chat.chatInfo, chatModel, close) },
|
clearChat = { clearChatDialog(chat.chatInfo, chatModel, close) },
|
||||||
changeNtfsState = { enabled ->
|
|
||||||
changeNtfsState(enabled, chat, chatModel)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun changeNtfsState(enabled: Boolean, chat: Chat, chatModel: ChatModel) {
|
|
||||||
val newChatInfo = when(chat.chatInfo) {
|
|
||||||
is ChatInfo.Direct -> with (chat.chatInfo) {
|
|
||||||
ChatInfo.Direct(contact.copy(chatSettings = contact.chatSettings.copy(enableNtfs = enabled)))
|
|
||||||
}
|
|
||||||
is ChatInfo.Group -> with(chat.chatInfo) {
|
|
||||||
ChatInfo.Group(groupInfo.copy(chatSettings = groupInfo.chatSettings.copy(enableNtfs = enabled)))
|
|
||||||
}
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
withApi {
|
|
||||||
val res = when (newChatInfo) {
|
|
||||||
is ChatInfo.Direct -> with(newChatInfo) {
|
|
||||||
chatModel.controller.apiSetSettings(chatType, apiId, contact.chatSettings)
|
|
||||||
}
|
|
||||||
is ChatInfo.Group -> with(newChatInfo) {
|
|
||||||
chatModel.controller.apiSetSettings(chatType, apiId, groupInfo.chatSettings)
|
|
||||||
}
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
if (res && newChatInfo != null) {
|
|
||||||
chatModel.updateChatInfo(newChatInfo)
|
|
||||||
if (!enabled) {
|
|
||||||
chatModel.controller.ntfManager.cancelNotificationsForChat(chat.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deleteContactDialog(chatInfo: ChatInfo, chatModel: ChatModel, close: (() -> Unit)? = null) {
|
fun deleteContactDialog(chatInfo: ChatInfo, chatModel: ChatModel, close: (() -> Unit)? = null) {
|
||||||
AlertManager.shared.showAlertMsg(
|
AlertManager.shared.showAlertMsg(
|
||||||
title = generalGetString(R.string.delete_contact_question),
|
title = generalGetString(R.string.delete_contact_question),
|
||||||
|
@ -148,7 +116,6 @@ fun ChatInfoLayout(
|
||||||
onLocalAliasChanged: (String) -> Unit,
|
onLocalAliasChanged: (String) -> Unit,
|
||||||
deleteContact: () -> Unit,
|
deleteContact: () -> Unit,
|
||||||
clearChat: () -> Unit,
|
clearChat: () -> Unit,
|
||||||
changeNtfsState: (Boolean) -> Unit,
|
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
Modifier
|
Modifier
|
||||||
|
@ -192,18 +159,6 @@ fun ChatInfoLayout(
|
||||||
}
|
}
|
||||||
SectionSpacer()
|
SectionSpacer()
|
||||||
}
|
}
|
||||||
|
|
||||||
var ntfsEnabled by remember { mutableStateOf(chat.chatInfo.ntfsEnabled) }
|
|
||||||
SectionView(title = stringResource(R.string.settings_section_title_settings)) {
|
|
||||||
SectionItemView {
|
|
||||||
NtfsSwitch(ntfsEnabled) {
|
|
||||||
ntfsEnabled = !ntfsEnabled
|
|
||||||
changeNtfsState(ntfsEnabled)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SectionSpacer()
|
|
||||||
|
|
||||||
SectionView {
|
SectionView {
|
||||||
SectionItemView {
|
SectionItemView {
|
||||||
ClearChatButton(clearChat)
|
ClearChatButton(clearChat)
|
||||||
|
@ -350,38 +305,6 @@ fun SimplexServers(text: String, servers: List<String>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun NtfsSwitch(
|
|
||||||
ntfsEnabled: Boolean,
|
|
||||||
toggleNtfs: (Boolean) -> Unit
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
Modifier.fillMaxWidth(),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Outlined.Notifications,
|
|
||||||
stringResource(R.string.notifications),
|
|
||||||
tint = HighOrLowlight
|
|
||||||
)
|
|
||||||
Text(stringResource(R.string.notifications))
|
|
||||||
}
|
|
||||||
Switch(
|
|
||||||
checked = ntfsEnabled,
|
|
||||||
onCheckedChange = toggleNtfs,
|
|
||||||
colors = SwitchDefaults.colors(
|
|
||||||
checkedThumbColor = MaterialTheme.colors.primary,
|
|
||||||
uncheckedThumbColor = HighOrLowlight
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ClearChatButton(clearChat: () -> Unit) {
|
fun ClearChatButton(clearChat: () -> Unit) {
|
||||||
Row(
|
Row(
|
||||||
|
@ -437,7 +360,6 @@ fun PreviewChatInfoLayout() {
|
||||||
),
|
),
|
||||||
Contact.sampleData,
|
Contact.sampleData,
|
||||||
localAlias = "",
|
localAlias = "",
|
||||||
changeNtfsState = {},
|
|
||||||
developerTools = false,
|
developerTools = false,
|
||||||
connStats = null,
|
connStats = null,
|
||||||
onLocalAliasChanged = {},
|
onLocalAliasChanged = {},
|
||||||
|
|
|
@ -216,6 +216,7 @@ fun ChatView(chatModel: ChatModel) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
changeNtfsState = { enabled, currentValue -> changeNtfsStatePerChat(enabled, currentValue, chat, chatModel) },
|
||||||
onSearchValueChanged = { value ->
|
onSearchValueChanged = { value ->
|
||||||
if (searchText.value == value) return@ChatLayout
|
if (searchText.value == value) return@ChatLayout
|
||||||
val c = chatModel.getChat(chat.chatInfo.id) ?: return@ChatLayout
|
val c = chatModel.getChat(chat.chatInfo.id) ?: return@ChatLayout
|
||||||
|
@ -253,6 +254,7 @@ fun ChatLayout(
|
||||||
acceptCall: (Contact) -> Unit,
|
acceptCall: (Contact) -> Unit,
|
||||||
addMembers: (GroupInfo) -> Unit,
|
addMembers: (GroupInfo) -> Unit,
|
||||||
markRead: (CC.ItemRange, unreadCountAfter: Int?) -> Unit,
|
markRead: (CC.ItemRange, unreadCountAfter: Int?) -> Unit,
|
||||||
|
changeNtfsState: (Boolean, currentValue: MutableState<Boolean>) -> Unit,
|
||||||
onSearchValueChanged: (String) -> Unit,
|
onSearchValueChanged: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
Surface(
|
Surface(
|
||||||
|
@ -279,7 +281,7 @@ fun ChatLayout(
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = { ChatInfoToolbar(chat, back, info, startCall, addMembers, onSearchValueChanged) },
|
topBar = { ChatInfoToolbar(chat, back, info, startCall, addMembers, changeNtfsState, onSearchValueChanged) },
|
||||||
bottomBar = composeView,
|
bottomBar = composeView,
|
||||||
modifier = Modifier.navigationBarsWithImePadding(),
|
modifier = Modifier.navigationBarsWithImePadding(),
|
||||||
floatingActionButton = { floatingButton.value() },
|
floatingActionButton = { floatingButton.value() },
|
||||||
|
@ -304,8 +306,10 @@ fun ChatInfoToolbar(
|
||||||
info: () -> Unit,
|
info: () -> Unit,
|
||||||
startCall: (CallMediaType) -> Unit,
|
startCall: (CallMediaType) -> Unit,
|
||||||
addMembers: (GroupInfo) -> Unit,
|
addMembers: (GroupInfo) -> Unit,
|
||||||
|
changeNtfsState: (Boolean, currentValue: MutableState<Boolean>) -> Unit,
|
||||||
onSearchValueChanged: (String) -> Unit,
|
onSearchValueChanged: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
var showMenu by rememberSaveable { mutableStateOf(false) }
|
var showMenu by rememberSaveable { mutableStateOf(false) }
|
||||||
var showSearch by rememberSaveable { mutableStateOf(false) }
|
var showSearch by rememberSaveable { mutableStateOf(false) }
|
||||||
val onBackClicked = {
|
val onBackClicked = {
|
||||||
|
@ -351,6 +355,23 @@ fun ChatInfoToolbar(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val ntfsEnabled = remember { mutableStateOf(chat.chatInfo.ntfsEnabled) }
|
||||||
|
menuItems.add {
|
||||||
|
ItemAction(
|
||||||
|
if (ntfsEnabled.value) stringResource(R.string.mute_chat) else stringResource(R.string.unmute_chat),
|
||||||
|
if (ntfsEnabled.value) Icons.Outlined.NotificationsOff else Icons.Outlined.Notifications,
|
||||||
|
onClick = {
|
||||||
|
showMenu = false
|
||||||
|
// Just to make a delay before changing state of ntfsEnabled, otherwise it will redraw menu item with new value before closing the menu
|
||||||
|
scope.launch {
|
||||||
|
delay(200)
|
||||||
|
changeNtfsState(!ntfsEnabled.value, ntfsEnabled)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
barButtons.add {
|
barButtons.add {
|
||||||
IconButton({ showMenu = true }) {
|
IconButton({ showMenu = true }) {
|
||||||
Icon(Icons.Default.MoreVert, stringResource(R.string.icon_descr_more_button), tint = MaterialTheme.colors.primary)
|
Icon(Icons.Default.MoreVert, stringResource(R.string.icon_descr_more_button), tint = MaterialTheme.colors.primary)
|
||||||
|
@ -839,6 +860,7 @@ fun PreviewChatLayout() {
|
||||||
acceptCall = { _ -> },
|
acceptCall = { _ -> },
|
||||||
addMembers = { _ -> },
|
addMembers = { _ -> },
|
||||||
markRead = { _, _ -> },
|
markRead = { _, _ -> },
|
||||||
|
changeNtfsState = { _, _ -> },
|
||||||
onSearchValueChanged = {},
|
onSearchValueChanged = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -896,6 +918,7 @@ fun PreviewGroupChatLayout() {
|
||||||
acceptCall = { _ -> },
|
acceptCall = { _ -> },
|
||||||
addMembers = { _ -> },
|
addMembers = { _ -> },
|
||||||
markRead = { _, _ -> },
|
markRead = { _, _ -> },
|
||||||
|
changeNtfsState = { _, _ -> },
|
||||||
onSearchValueChanged = {},
|
onSearchValueChanged = {},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,9 +75,6 @@ fun GroupChatInfoView(chatModel: ChatModel, close: () -> Unit) {
|
||||||
deleteGroup = { deleteGroupDialog(chat.chatInfo, chatModel, close) },
|
deleteGroup = { deleteGroupDialog(chat.chatInfo, chatModel, close) },
|
||||||
clearChat = { clearChatDialog(chat.chatInfo, chatModel, close) },
|
clearChat = { clearChatDialog(chat.chatInfo, chatModel, close) },
|
||||||
leaveGroup = { leaveGroupDialog(groupInfo, chatModel, close) },
|
leaveGroup = { leaveGroupDialog(groupInfo, chatModel, close) },
|
||||||
changeNtfsState = { enabled ->
|
|
||||||
changeNtfsState(enabled, chat, chatModel)
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +124,6 @@ fun GroupChatInfoLayout(
|
||||||
deleteGroup: () -> Unit,
|
deleteGroup: () -> Unit,
|
||||||
clearChat: () -> Unit,
|
clearChat: () -> Unit,
|
||||||
leaveGroup: () -> Unit,
|
leaveGroup: () -> Unit,
|
||||||
changeNtfsState: (Boolean) -> Unit,
|
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
Modifier
|
Modifier
|
||||||
|
@ -162,17 +158,6 @@ fun GroupChatInfoLayout(
|
||||||
}
|
}
|
||||||
SectionSpacer()
|
SectionSpacer()
|
||||||
|
|
||||||
var ntfsEnabled by remember { mutableStateOf(chat.chatInfo.ntfsEnabled) }
|
|
||||||
SectionView(title = stringResource(R.string.settings_section_title_settings)) {
|
|
||||||
SectionItemView {
|
|
||||||
NtfsSwitch(ntfsEnabled) {
|
|
||||||
ntfsEnabled = !ntfsEnabled
|
|
||||||
changeNtfsState(ntfsEnabled)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SectionSpacer()
|
|
||||||
|
|
||||||
SectionView {
|
SectionView {
|
||||||
if (groupInfo.canEdit) {
|
if (groupInfo.canEdit) {
|
||||||
SectionItemView {
|
SectionItemView {
|
||||||
|
@ -367,7 +352,6 @@ fun PreviewGroupChatInfoLayout() {
|
||||||
members = listOf(GroupMember.sampleData, GroupMember.sampleData, GroupMember.sampleData),
|
members = listOf(GroupMember.sampleData, GroupMember.sampleData, GroupMember.sampleData),
|
||||||
developerTools = false,
|
developerTools = false,
|
||||||
addMembers = {}, showMemberInfo = {}, editGroupProfile = {}, deleteGroup = {}, clearChat = {}, leaveGroup = {},
|
addMembers = {}, showMemberInfo = {}, editGroupProfile = {}, deleteGroup = {}, clearChat = {}, leaveGroup = {},
|
||||||
changeNtfsState = {},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ fun ToggleNotificationsChatAction(chat: Chat, chatModel: ChatModel, ntfsEnabled:
|
||||||
if (ntfsEnabled) stringResource(R.string.mute_chat) else stringResource(R.string.unmute_chat),
|
if (ntfsEnabled) stringResource(R.string.mute_chat) else stringResource(R.string.unmute_chat),
|
||||||
if (ntfsEnabled) Icons.Outlined.NotificationsOff else Icons.Outlined.Notifications,
|
if (ntfsEnabled) Icons.Outlined.NotificationsOff else Icons.Outlined.Notifications,
|
||||||
onClick = {
|
onClick = {
|
||||||
changeNtfsState(!ntfsEnabled, chat, chatModel)
|
changeNtfsStatePerChat(!ntfsEnabled, mutableStateOf(ntfsEnabled), chat, chatModel)
|
||||||
showMenu.value = false
|
showMenu.value = false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -424,6 +424,36 @@ fun groupInvitationAcceptedAlert() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun changeNtfsStatePerChat(enabled: Boolean, currentState: MutableState<Boolean>, chat: Chat, chatModel: ChatModel) {
|
||||||
|
val newChatInfo = when(chat.chatInfo) {
|
||||||
|
is ChatInfo.Direct -> with (chat.chatInfo) {
|
||||||
|
ChatInfo.Direct(contact.copy(chatSettings = contact.chatSettings.copy(enableNtfs = enabled)))
|
||||||
|
}
|
||||||
|
is ChatInfo.Group -> with(chat.chatInfo) {
|
||||||
|
ChatInfo.Group(groupInfo.copy(chatSettings = groupInfo.chatSettings.copy(enableNtfs = enabled)))
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
withApi {
|
||||||
|
val res = when (newChatInfo) {
|
||||||
|
is ChatInfo.Direct -> with(newChatInfo) {
|
||||||
|
chatModel.controller.apiSetSettings(chatType, apiId, contact.chatSettings)
|
||||||
|
}
|
||||||
|
is ChatInfo.Group -> with(newChatInfo) {
|
||||||
|
chatModel.controller.apiSetSettings(chatType, apiId, groupInfo.chatSettings)
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
if (res && newChatInfo != null) {
|
||||||
|
chatModel.updateChatInfo(newChatInfo)
|
||||||
|
if (!enabled) {
|
||||||
|
chatModel.controller.ntfManager.cancelNotificationsForChat(chat.id)
|
||||||
|
}
|
||||||
|
currentState.value = enabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChatListNavLinkLayout(
|
fun ChatListNavLinkLayout(
|
||||||
chatLinkPreview: @Composable () -> Unit,
|
chatLinkPreview: @Composable () -> Unit,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue