From b9e115205934548e7549cbc23dcb77387dab78e7 Mon Sep 17 00:00:00 2001 From: Mark Injerd Date: Thu, 18 Jan 2024 00:46:11 -0500 Subject: [PATCH] Fix detail and ignore dialogs closing when notification received --- .../com/pilot51/voicenotify/NotifyList.kt | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/pilot51/voicenotify/NotifyList.kt b/app/src/main/java/com/pilot51/voicenotify/NotifyList.kt index cec46fa..8e9b842 100644 --- a/app/src/main/java/com/pilot51/voicenotify/NotifyList.kt +++ b/app/src/main/java/com/pilot51/voicenotify/NotifyList.kt @@ -92,9 +92,15 @@ private fun LogDialog( @Composable private fun ItemList(list: List) { + var detailDialogInfo by remember { mutableStateOf(null) } + var ignoreDialogApp by remember { mutableStateOf(null) } LazyColumn(modifier = Modifier.fillMaxWidth()) { itemsIndexed(list) { index, item -> - Item(item) + Item( + item = item, + onShowDetail = { detailDialogInfo = item }, + onShowIgnore = { ignoreDialogApp = item.app } + ) if (index < list.lastIndex) { Divider( modifier = Modifier.padding(vertical = 16.dp), @@ -104,13 +110,21 @@ private fun ItemList(list: List) { } } } + detailDialogInfo?.let { + DetailDialog(it) { detailDialogInfo = null } + } + ignoreDialogApp?.let { + IgnoreDialog(it) { ignoreDialogApp = null } + } } @OptIn(ExperimentalFoundationApi::class) @Composable -private fun Item(item: NotificationInfo) { - var showDetailDialog by remember(item) { mutableStateOf(false) } - var showIgnoreDialog by remember(item) { mutableStateOf(false) } +private fun Item( + item: NotificationInfo, + onShowDetail: () -> Unit, + onShowIgnore: () -> Unit +) { val logMessage = remember(item) { StringBuilder().apply { arrayOf(item.contentTitle, item.contentText).forEach { @@ -124,8 +138,8 @@ private fun Item(item: NotificationInfo) { Column(modifier = Modifier .fillMaxWidth() .combinedClickable( - onClick = { showDetailDialog = true }, - onLongClick = { if (item.app != null) showIgnoreDialog = true } + onClick = onShowDetail, + onLongClick = item.app?.run { onShowIgnore } ) ) { Text( @@ -158,12 +172,6 @@ private fun Item(item: NotificationInfo) { ) } } - if (showDetailDialog) { - DetailDialog(item) { showDetailDialog = false } - } - if (showIgnoreDialog) { - item.app?.let { IgnoreDialog(it) { showIgnoreDialog = false } } - } } @Composable