Always place received chat message at the bottom of the message list
This commit is contained in:
@ -145,7 +145,7 @@ private fun ChatScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val addMessage = { newMessage: Message ->
|
val addMessage = { newMessage: Message ->
|
||||||
chatMessages = chatMessages + newMessage
|
chatMessages = listOf(newMessage) + chatMessages
|
||||||
}
|
}
|
||||||
|
|
||||||
DisposableEffect(key1 = lifecycleOwner, key2 = account.aor, key3 = peerUri) {
|
DisposableEffect(key1 = lifecycleOwner, key2 = account.aor, key3 = peerUri) {
|
||||||
@ -213,7 +213,15 @@ private fun TopAppBar(
|
|||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = {
|
title = {
|
||||||
Text(
|
Text(
|
||||||
text = format(ctx.getString(R.string.chat_with), Utils.friendlyUri(ctx, peerUri, account)),
|
text = format(
|
||||||
|
stringResource(R.string.chat_with),
|
||||||
|
Utils.friendlyUri(
|
||||||
|
uri = peerUri,
|
||||||
|
account = account,
|
||||||
|
anonymous = stringResource(R.string.anonymous),
|
||||||
|
unknown = stringResource(R.string.unknown)
|
||||||
|
)
|
||||||
|
),
|
||||||
fontSize = 22.sp,
|
fontSize = 22.sp,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
@ -225,7 +233,6 @@ private fun TopAppBar(
|
|||||||
actionIconContentColor = MaterialTheme.colorScheme.onPrimary
|
actionIconContentColor = MaterialTheme.colorScheme.onPrimary
|
||||||
),
|
),
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
val ctx = LocalContext.current
|
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
val serviceIntent = Intent(ctx, BaresipService::class.java)
|
val serviceIntent = Intent(ctx, BaresipService::class.java)
|
||||||
@ -312,9 +319,8 @@ private fun ChatContent(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun Account(account: Account) {
|
private fun Account(account: Account) {
|
||||||
val ctx = LocalContext.current
|
|
||||||
Text(
|
Text(
|
||||||
text = ctx.getString(R.string.account) + " " + account.text(),
|
text = stringResource(R.string.account) + " " + account.text(),
|
||||||
modifier = Modifier.fillMaxWidth().padding(top = 8.dp, bottom = 8.dp),
|
modifier = Modifier.fillMaxWidth().padding(top = 8.dp, bottom = 8.dp),
|
||||||
fontSize = 18.sp,
|
fontSize = 18.sp,
|
||||||
fontWeight = FontWeight.SemiBold,
|
fontWeight = FontWeight.SemiBold,
|
||||||
@ -329,8 +335,15 @@ private fun Messages(
|
|||||||
messages: List<Message>,
|
messages: List<Message>,
|
||||||
onMessageDeleted: () -> Unit
|
onMessageDeleted: () -> Unit
|
||||||
) {
|
) {
|
||||||
val ctx = LocalContext.current
|
val peerName = Utils.friendlyUri(
|
||||||
val peerName = Utils.friendlyUri(ctx, peerUri, account)
|
uri = peerUri,
|
||||||
|
account = account,
|
||||||
|
anonymous = stringResource(R.string.anonymous),
|
||||||
|
unknown = stringResource(R.string.unknown)
|
||||||
|
)
|
||||||
|
|
||||||
|
val shortMessageQuestion = stringResource(R.string.short_message_question)
|
||||||
|
val deleteString = stringResource(R.string.delete)
|
||||||
|
|
||||||
val showDialog = remember { mutableStateOf(false) }
|
val showDialog = remember { mutableStateOf(false) }
|
||||||
val dialogMessage = remember { mutableStateOf("") }
|
val dialogMessage = remember { mutableStateOf("") }
|
||||||
@ -398,9 +411,9 @@ private fun Messages(
|
|||||||
) {
|
) {
|
||||||
CustomElements.Button(
|
CustomElements.Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
dialogMessage.value = ctx.getString(R.string.short_message_question)
|
dialogMessage.value = shortMessageQuestion
|
||||||
secondButtonText.value = ""
|
secondButtonText.value = ""
|
||||||
lastButtonText.value = ctx.getString(R.string.delete)
|
lastButtonText.value = deleteString
|
||||||
lastAction.value = {
|
lastAction.value = {
|
||||||
message.delete()
|
message.delete()
|
||||||
onMessageDeleted()
|
onMessageDeleted()
|
||||||
@ -475,6 +488,10 @@ private fun NewMessage(
|
|||||||
val showDialog = remember { mutableStateOf(false) }
|
val showDialog = remember { mutableStateOf(false) }
|
||||||
val dialogMessage = remember { mutableStateOf("") }
|
val dialogMessage = remember { mutableStateOf("") }
|
||||||
|
|
||||||
|
val airplaneMode = stringResource(R.string.airplane_mode)
|
||||||
|
val messageFailed = stringResource(R.string.message_failed)
|
||||||
|
val noTelephonyProvider = stringResource(R.string.no_telephony_provider)
|
||||||
|
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
showDialog = showDialog,
|
showDialog = showDialog,
|
||||||
title = stringResource(R.string.notice),
|
title = stringResource(R.string.notice),
|
||||||
@ -553,7 +570,7 @@ private fun NewMessage(
|
|||||||
addMessage(msg)
|
addMessage(msg)
|
||||||
if (ua.account.isMobile) {
|
if (ua.account.isMobile) {
|
||||||
if (ua.status != circleGreen.getValue(colorblind)) {
|
if (ua.status != circleGreen.getValue(colorblind)) {
|
||||||
dialogMessage.value = ctx.getString(R.string.airplane_mode)
|
dialogMessage.value = airplaneMode
|
||||||
showDialog.value = true
|
showDialog.value = true
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -566,11 +583,11 @@ private fun NewMessage(
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
ctx, "${ctx.getString(R.string.message_failed)}!",
|
ctx, "$messageFailed!",
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
msg.direction = MESSAGE_UP_FAIL
|
msg.direction = MESSAGE_UP_FAIL
|
||||||
msg.responseReason = ctx.getString(R.string.message_failed)
|
msg.responseReason = messageFailed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -578,7 +595,7 @@ private fun NewMessage(
|
|||||||
if (Utils.isTelUri(peerUri)) {
|
if (Utils.isTelUri(peerUri)) {
|
||||||
if (ua.account.telProvider == "") {
|
if (ua.account.telProvider == "") {
|
||||||
dialogMessage.value = String.format(
|
dialogMessage.value = String.format(
|
||||||
ctx.getString(R.string.no_telephony_provider),
|
noTelephonyProvider,
|
||||||
Utils.plainAor(aor)
|
Utils.plainAor(aor)
|
||||||
)
|
)
|
||||||
showDialog.value = true
|
showDialog.value = true
|
||||||
@ -591,11 +608,11 @@ private fun NewMessage(
|
|||||||
if (msgUri != "") {
|
if (msgUri != "") {
|
||||||
if (Api.message_send(ua.uap, msgUri, msgText, time.toString()) != 0) {
|
if (Api.message_send(ua.uap, msgUri, msgText, time.toString()) != 0) {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
ctx, "${ctx.getString(R.string.message_failed)}!",
|
ctx, "$messageFailed!",
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
).show()
|
).show()
|
||||||
msg.direction = MESSAGE_UP_FAIL
|
msg.direction = MESSAGE_UP_FAIL
|
||||||
msg.responseReason = ctx.getString(R.string.message_failed)
|
msg.responseReason = messageFailed
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
newMessage.value = TextFieldValue("")
|
newMessage.value = TextFieldValue("")
|
||||||
|
|||||||
Reference in New Issue
Block a user