Improved dialog handling
This commit is contained in:
@@ -90,10 +90,13 @@ class ChatsActivity: ComponentActivity() {
|
|||||||
internal lateinit var aor: String
|
internal lateinit var aor: String
|
||||||
internal lateinit var account: Account
|
internal lateinit var account: Account
|
||||||
private lateinit var chatRequest: ActivityResultLauncher<Intent>
|
private lateinit var chatRequest: ActivityResultLauncher<Intent>
|
||||||
|
|
||||||
private var _uaMessages = mutableStateOf<List<Message>>(emptyList())
|
private var _uaMessages = mutableStateOf<List<Message>>(emptyList())
|
||||||
private var uaMessages: List<Message> by _uaMessages
|
private var uaMessages: List<Message> by _uaMessages
|
||||||
private var showNotice by mutableStateOf(false)
|
|
||||||
private var noticeMessage = mutableStateOf("")
|
private val alertTitle = mutableStateOf("")
|
||||||
|
private val alertMessage = mutableStateOf("")
|
||||||
|
private val showAlert = mutableStateOf(false)
|
||||||
|
|
||||||
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
|
||||||
override fun handleOnBackPressed() {
|
override fun handleOnBackPressed() {
|
||||||
@@ -231,6 +234,16 @@ class ChatsActivity: ComponentActivity() {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChatsContent(ctx: Context, contentPadding: PaddingValues) {
|
fun ChatsContent(ctx: Context, contentPadding: PaddingValues) {
|
||||||
|
|
||||||
|
if (showAlert.value) {
|
||||||
|
AlertDialog(
|
||||||
|
showDialog = showAlert,
|
||||||
|
title = alertTitle.value,
|
||||||
|
message = alertMessage.value,
|
||||||
|
positiveButtonText = stringResource(R.string.ok),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
@@ -239,9 +252,6 @@ class ChatsActivity: ComponentActivity() {
|
|||||||
) {
|
) {
|
||||||
Account(account)
|
Account(account)
|
||||||
Chats(ctx, account)
|
Chats(ctx, account)
|
||||||
if (showNotice)
|
|
||||||
Notice()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,18 +283,20 @@ class ChatsActivity: ComponentActivity() {
|
|||||||
val neutralButtonText = remember { mutableStateOf("") }
|
val neutralButtonText = remember { mutableStateOf("") }
|
||||||
val neutralAction = remember { mutableStateOf({}) }
|
val neutralAction = remember { mutableStateOf({}) }
|
||||||
|
|
||||||
AlertDialog(
|
if (showDialog.value)
|
||||||
showDialog = showDialog,
|
AlertDialog(
|
||||||
title = getString(R.string.confirmation),
|
showDialog = showDialog,
|
||||||
message = dialogMessage.value,
|
title = getString(R.string.confirmation),
|
||||||
positiveButtonText = positiveButtonText.value,
|
message = dialogMessage.value,
|
||||||
onPositiveClicked = positiveAction.value,
|
positiveButtonText = positiveButtonText.value,
|
||||||
neutralButtonText = neutralButtonText.value,
|
onPositiveClicked = positiveAction.value,
|
||||||
onNeutralClicked = neutralAction.value,
|
neutralButtonText = neutralButtonText.value,
|
||||||
negativeButtonText = getString(R.string.cancel)
|
onNeutralClicked = neutralAction.value,
|
||||||
)
|
negativeButtonText = getString(R.string.cancel)
|
||||||
|
)
|
||||||
|
|
||||||
val lazyListState = rememberLazyListState()
|
val lazyListState = rememberLazyListState()
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.imePadding()
|
.imePadding()
|
||||||
@@ -612,18 +624,6 @@ class ChatsActivity: ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun Notice() {
|
|
||||||
AlertDialog(
|
|
||||||
showDialog = remember { mutableStateOf(true) },
|
|
||||||
title = getString(R.string.notice),
|
|
||||||
message = noticeMessage.value,
|
|
||||||
positiveButtonText = getString(R.string.ok),
|
|
||||||
onPositiveClicked = { showNotice = false },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun makeChat(chatPeer: String) {
|
private fun makeChat(chatPeer: String) {
|
||||||
val peerUri = if (Utils.isTelNumber(chatPeer))
|
val peerUri = if (Utils.isTelNumber(chatPeer))
|
||||||
"tel:$chatPeer"
|
"tel:$chatPeer"
|
||||||
@@ -631,18 +631,20 @@ class ChatsActivity: ComponentActivity() {
|
|||||||
chatPeer
|
chatPeer
|
||||||
val uri = if (Utils.isTelUri(peerUri)) {
|
val uri = if (Utils.isTelUri(peerUri)) {
|
||||||
if (account.telProvider == "") {
|
if (account.telProvider == "") {
|
||||||
noticeMessage.value =
|
alertTitle.value = getString(R.string.notice)
|
||||||
|
alertMessage.value =
|
||||||
String.format(getString(R.string.no_telephony_provider), account.aor)
|
String.format(getString(R.string.no_telephony_provider), account.aor)
|
||||||
showNotice = true
|
showAlert.value = true
|
||||||
""
|
""
|
||||||
} else
|
} else
|
||||||
Utils.telToSip(peerUri, account)
|
Utils.telToSip(peerUri, account)
|
||||||
} else
|
} else
|
||||||
Utils.uriComplete(peerUri, aor)
|
Utils.uriComplete(peerUri, aor)
|
||||||
if (noticeMessage.value.isEmpty()) {
|
if (alertMessage.value.isEmpty()) {
|
||||||
if (!Utils.checkUri(uri)) {
|
if (!Utils.checkUri(uri)) {
|
||||||
noticeMessage.value = String.format(getString(R.string.invalid_sip_or_tel_uri), uri)
|
alertTitle.value = getString(R.string.notice)
|
||||||
showNotice = true
|
alertMessage.value = String.format(getString(R.string.invalid_sip_or_tel_uri), uri)
|
||||||
|
showAlert.value = true
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val i = Intent(this@ChatsActivity, ChatActivity::class.java)
|
val i = Intent(this@ChatsActivity, ChatActivity::class.java)
|
||||||
|
|||||||
Reference in New Issue
Block a user