perf: dialog onDismissRequest auto close

This commit is contained in:
lisonge 2024-08-05 17:11:47 +08:00
parent 3025a96957
commit 602879da5f
8 changed files with 124 additions and 67 deletions

View File

@ -46,7 +46,6 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
@ -365,7 +364,6 @@ fun AdvancedPage() {
} }
if (showPortDlg) { if (showPortDlg) {
Dialog(onDismissRequest = { showPortDlg = false }) {
var value by remember { var value by remember {
mutableStateOf(store.httpServerPort.toString()) mutableStateOf(store.httpServerPort.toString())
} }
@ -389,7 +387,11 @@ fun AdvancedPage() {
) )
}, },
) )
}, onDismissRequest = { showPortDlg = false }, confirmButton = { }, onDismissRequest = {
if (value.isEmpty()) {
showPortDlg = false
}
}, confirmButton = {
TextButton( TextButton(
enabled = value.isNotEmpty(), enabled = value.isNotEmpty(),
onClick = { onClick = {
@ -417,7 +419,6 @@ fun AdvancedPage() {
}) })
} }
} }
}
@Composable @Composable
private fun ShizukuFragment(enabled: Boolean = true) { private fun ShizukuFragment(enabled: Boolean = true) {

View File

@ -396,7 +396,11 @@ fun AppItemPage(
focusRequester.requestFocus() focusRequester.requestFocus()
} }
}, },
onDismissRequest = { setEditGroupRaw(null) }, onDismissRequest = {
if (source.isEmpty()) {
setEditGroupRaw(null)
}
},
dismissButton = { dismissButton = {
TextButton(onClick = { setEditGroupRaw(null) }) { TextButton(onClick = { setEditGroupRaw(null) }) {
Text(text = "取消") Text(text = "取消")
@ -488,7 +492,11 @@ fun AppItemPage(
focusRequester.requestFocus() focusRequester.requestFocus()
} }
}, },
onDismissRequest = { setExcludeGroupRaw(null) }, onDismissRequest = {
if (source.isEmpty()) {
setExcludeGroupRaw(null)
}
},
dismissButton = { dismissButton = {
TextButton(onClick = { setExcludeGroupRaw(null) }) { TextButton(onClick = { setExcludeGroupRaw(null) }) {
Text(text = "取消") Text(text = "取消")
@ -532,7 +540,11 @@ fun AppItemPage(
placeholder = { Text(text = "请输入规则组\n可以是APP规则\n也可以是单个规则组") }, placeholder = { Text(text = "请输入规则组\n可以是APP规则\n也可以是单个规则组") },
maxLines = 10, maxLines = 10,
) )
}, onDismissRequest = { showAddDlg = false }, confirmButton = { }, onDismissRequest = {
if (source.isEmpty()) {
showAddDlg = false
}
}, confirmButton = {
TextButton(onClick = { TextButton(onClick = {
val newAppRaw = try { val newAppRaw = try {
RawSubscription.parseRawApp(source) RawSubscription.parseRawApp(source)

View File

@ -257,7 +257,11 @@ fun CategoryPage(subsItemId: Long) {
placeholder = { Text(text = "请输入类别名称") }, placeholder = { Text(text = "请输入类别名称") },
singleLine = true singleLine = true
) )
}, onDismissRequest = { setEditNameCategory(null) }, dismissButton = { }, onDismissRequest = {
if (source.isEmpty()) {
setEditNameCategory(null)
}
}, dismissButton = {
TextButton(onClick = { setEditNameCategory(null) }) { TextButton(onClick = { setEditNameCategory(null) }) {
Text(text = "取消") Text(text = "取消")
} }
@ -300,7 +304,11 @@ fun CategoryPage(subsItemId: Long) {
placeholder = { Text(text = "请输入类别名称") }, placeholder = { Text(text = "请输入类别名称") },
singleLine = true singleLine = true
) )
}, onDismissRequest = { showAddDlg = false }, dismissButton = { }, onDismissRequest = {
if (source.isEmpty()) {
showAddDlg = false
}
}, dismissButton = {
TextButton(onClick = { showAddDlg = false }) { TextButton(onClick = { showAddDlg = false }) {
Text(text = "取消") Text(text = "取消")
} }

View File

@ -388,7 +388,11 @@ fun GlobalRuleExcludePage(subsItemId: Long, groupKey: Int) {
focusRequester.requestFocus() focusRequester.requestFocus()
} }
}, },
onDismissRequest = { showEditDlg = false }, onDismissRequest = {
if (source.isEmpty()) {
showEditDlg = false
}
},
dismissButton = { dismissButton = {
TextButton(onClick = { showEditDlg = false }) { TextButton(onClick = { showEditDlg = false }) {
Text(text = "取消") Text(text = "取消")

View File

@ -7,7 +7,6 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
@ -322,7 +321,11 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) {
placeholder = { Text(text = "请输入规则组") }, placeholder = { Text(text = "请输入规则组") },
maxLines = 10, maxLines = 10,
) )
}, onDismissRequest = { showAddDlg = false }, confirmButton = { }, onDismissRequest = {
if (source.isEmpty()) {
showAddDlg = false
}
}, confirmButton = {
TextButton(onClick = { TextButton(onClick = {
val newGroup = try { val newGroup = try {
RawSubscription.parseRawGlobalGroup(source) RawSubscription.parseRawGlobalGroup(source)
@ -403,7 +406,11 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) {
focusRequester.requestFocus() focusRequester.requestFocus()
} }
}, },
onDismissRequest = { setEditGroupRaw(null) }, onDismissRequest = {
if (source.isEmpty()) {
setEditGroupRaw(null)
}
},
dismissButton = { dismissButton = {
TextButton(onClick = { setEditGroupRaw(null) }) { TextButton(onClick = { setEditGroupRaw(null) }) {
Text(text = "取消") Text(text = "取消")
@ -452,7 +459,6 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) {
if (showGroupItem != null) { if (showGroupItem != null) {
AlertDialog( AlertDialog(
modifier = Modifier.defaultMinSize(300.dp),
onDismissRequest = { setShowGroupItem(null) }, onDismissRequest = { setShowGroupItem(null) },
title = { title = {
Text(text = "规则组详情") Text(text = "规则组详情")

View File

@ -307,7 +307,11 @@ fun SubsPage(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
placeholder = { Text(text = "请输入规则\n若应用规则已经存在则追加") }, placeholder = { Text(text = "请输入规则\n若应用规则已经存在则追加") },
) )
}, onDismissRequest = { showAddDlg = false }, confirmButton = { }, onDismissRequest = {
if (source.isEmpty()) {
showAddDlg = false
}
}, confirmButton = {
TextButton(onClick = { TextButton(onClick = {
val newAppRaw = try { val newAppRaw = try {
RawSubscription.parseRawApp(source) RawSubscription.parseRawApp(source)
@ -401,7 +405,11 @@ fun SubsPage(
focusRequester.requestFocus() focusRequester.requestFocus()
} }
}, },
onDismissRequest = { editRawApp = null }, confirmButton = { onDismissRequest = {
if (source.isEmpty()) {
editRawApp = null
}
}, confirmButton = {
TextButton(onClick = { TextButton(onClick = {
try { try {
val newAppRaw = RawSubscription.parseRawApp(source) val newAppRaw = RawSubscription.parseRawApp(source)

View File

@ -125,7 +125,11 @@ fun useSettingsPage(): ScaffoldExt {
) )
}, },
) )
}, onDismissRequest = { showToastInputDlg = false }, confirmButton = { }, onDismissRequest = {
if (value.isEmpty()) {
showToastInputDlg = false
}
}, confirmButton = {
TextButton(enabled = value.isNotEmpty(), onClick = { TextButton(enabled = value.isNotEmpty(), onClick = {
storeFlow.update { it.copy(clickToast = value) } storeFlow.update { it.copy(clickToast = value) }
showToastInputDlg = false showToastInputDlg = false
@ -186,7 +190,11 @@ fun useSettingsPage(): ScaffoldExt {
) )
}, },
) )
}, onDismissRequest = { showNotifTextInputDlg = false }, confirmButton = { }, onDismissRequest = {
if (value.isEmpty()) {
showNotifTextInputDlg = false
}
}, confirmButton = {
TextButton(enabled = value.isNotEmpty(), onClick = { TextButton(enabled = value.isNotEmpty(), onClick = {
storeFlow.update { it.copy(customNotifText = value) } storeFlow.update { it.copy(customNotifText = value) }
showNotifTextInputDlg = false showNotifTextInputDlg = false

View File

@ -145,7 +145,17 @@ fun useSubsManagePage(): ScaffoldExt {
}, },
isError = link.isNotEmpty() && !URLUtil.isNetworkUrl(link), isError = link.isNotEmpty() && !URLUtil.isNetworkUrl(link),
) )
}, onDismissRequest = { showAddLinkDialog = false }, confirmButton = { }, onDismissRequest = {
if (link.isEmpty()) {
showAddLinkDialog = false
}
}, dismissButton = {
TextButton(onClick = {
showAddLinkDialog = false
}) {
Text(text = "取消")
}
}, confirmButton = {
TextButton(enabled = link.isNotBlank(), onClick = { TextButton(enabled = link.isNotBlank(), onClick = {
if (!URLUtil.isNetworkUrl(link)) { if (!URLUtil.isNetworkUrl(link)) {
toast("非法链接") toast("非法链接")
@ -166,7 +176,7 @@ fun useSubsManagePage(): ScaffoldExt {
vm.addSubsFromUrl(url = link) vm.addSubsFromUrl(url = link)
} }
}) { }) {
Text(text = "添加") Text(text = "确认")
} }
}) })
} }