Skip to content

Commit

Permalink
Fix detail and ignore dialogs closing when notification received
Browse files Browse the repository at this point in the history
  • Loading branch information
pilot51 committed Jan 18, 2024
1 parent 6ac3cb6 commit b9e1152
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions app/src/main/java/com/pilot51/voicenotify/NotifyList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,15 @@ private fun LogDialog(

@Composable
private fun ItemList(list: List<NotificationInfo>) {
var detailDialogInfo by remember { mutableStateOf<NotificationInfo?>(null) }
var ignoreDialogApp by remember { mutableStateOf<App?>(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),
Expand All @@ -104,13 +110,21 @@ private fun ItemList(list: List<NotificationInfo>) {
}
}
}
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 {
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b9e1152

Please sign in to comment.