Composed chats and chats activities
Removed unused code and menu resource files
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package com.tutpro.baresip
|
package com.tutpro.baresip
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.DialogInterface
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
@@ -74,7 +73,7 @@ import androidx.compose.ui.text.input.KeyboardCapitalization
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.tutpro.baresip.CustomElements.AlertDialog
|
||||||
import com.tutpro.baresip.CustomElements.Text
|
import com.tutpro.baresip.CustomElements.Text
|
||||||
import com.tutpro.baresip.CustomElements.verticalScrollbar
|
import com.tutpro.baresip.CustomElements.verticalScrollbar
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -257,6 +256,25 @@ class ChatActivity : ComponentActivity() {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Messages(ctx: Context) {
|
fun Messages(ctx: Context) {
|
||||||
|
|
||||||
|
val showDialog = remember { mutableStateOf(false) }
|
||||||
|
val dialogMessage = remember { mutableStateOf("") }
|
||||||
|
val positiveButtonText = remember { mutableStateOf("") }
|
||||||
|
val positiveAction = remember { mutableStateOf({}) }
|
||||||
|
val neutralButtonText = remember { mutableStateOf("") }
|
||||||
|
val neutralAction = remember { mutableStateOf({}) }
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
showDialog = showDialog,
|
||||||
|
title = getString(R.string.confirmation),
|
||||||
|
message = dialogMessage.value,
|
||||||
|
positiveButtonText = positiveButtonText.value,
|
||||||
|
onPositiveClicked = positiveAction.value,
|
||||||
|
neutralButtonText = neutralButtonText.value,
|
||||||
|
onNeutralClicked = neutralAction.value,
|
||||||
|
negativeButtonText = getString(R.string.cancel)
|
||||||
|
)
|
||||||
|
|
||||||
val lazyListState = rememberLazyListState()
|
val lazyListState = rememberLazyListState()
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
@@ -319,65 +337,34 @@ class ChatActivity : ComponentActivity() {
|
|||||||
) {
|
) {
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
val dialogClickListener =
|
if (chatPeer == peerUri) {
|
||||||
DialogInterface.OnClickListener { _, which ->
|
dialogMessage.value = String.format(ctx.getString(R.string.long_message_question),
|
||||||
when (which) {
|
peerUri
|
||||||
DialogInterface.BUTTON_POSITIVE -> {
|
)
|
||||||
val i = Intent(ctx, BaresipContactActivity::class.java)
|
positiveButtonText.value = ctx.getString(R.string.add_contact)
|
||||||
val b = Bundle()
|
positiveAction.value = {
|
||||||
b.putBoolean("new", true)
|
val i = Intent(ctx, BaresipContactActivity::class.java)
|
||||||
b.putString("uri", peerUri)
|
val b = Bundle()
|
||||||
i.putExtras(b)
|
b.putBoolean("new", true)
|
||||||
ctx.startActivity(i)
|
b.putString("uri", peerUri)
|
||||||
}
|
i.putExtras(b)
|
||||||
|
ctx.startActivity(i)
|
||||||
DialogInterface.BUTTON_NEGATIVE -> {
|
|
||||||
message.delete()
|
|
||||||
_chatMessages.value = uaPeerMessages(aor, peerUri)
|
|
||||||
}
|
|
||||||
|
|
||||||
DialogInterface.BUTTON_NEUTRAL -> {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val builder = MaterialAlertDialogBuilder(ctx, R.style.AlertDialogTheme)
|
neutralButtonText.value = ctx.getString(R.string.delete)
|
||||||
if (chatPeer == peerUri)
|
neutralAction.value = {
|
||||||
with(builder) {
|
message.delete()
|
||||||
setTitle(R.string.confirmation)
|
_chatMessages.value = uaPeerMessages(aor, peerUri)
|
||||||
setMessage(
|
|
||||||
String.format(
|
|
||||||
ctx.getString(R.string.long_message_question),
|
|
||||||
peerUri
|
|
||||||
)
|
|
||||||
)
|
|
||||||
setNeutralButton(
|
|
||||||
ctx.getString(R.string.cancel),
|
|
||||||
dialogClickListener
|
|
||||||
)
|
|
||||||
setNegativeButton(
|
|
||||||
ctx.getString(R.string.delete),
|
|
||||||
dialogClickListener
|
|
||||||
)
|
|
||||||
setPositiveButton(
|
|
||||||
ctx.getString(R.string.add_contact),
|
|
||||||
dialogClickListener
|
|
||||||
)
|
|
||||||
show()
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
with(builder) {
|
else {
|
||||||
setTitle(R.string.confirmation)
|
dialogMessage.value = ctx.getString(R.string.short_message_question)
|
||||||
setMessage(ctx.getText(R.string.short_message_question))
|
positiveButtonText.value = ctx.getString(R.string.delete)
|
||||||
setNeutralButton(
|
positiveAction.value = {
|
||||||
ctx.getString(R.string.cancel),
|
message.delete()
|
||||||
dialogClickListener
|
_chatMessages.value = uaPeerMessages(aor, peerUri)
|
||||||
)
|
|
||||||
setNegativeButton(
|
|
||||||
ctx.getString(R.string.delete),
|
|
||||||
dialogClickListener
|
|
||||||
)
|
|
||||||
show()
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
showDialog.value = true
|
||||||
},
|
},
|
||||||
shape = if (message.direction == MESSAGE_DOWN)
|
shape = if (message.direction == MESSAGE_DOWN)
|
||||||
RoundedCornerShape(50.dp, 20.dp, 20.dp, 10.dp)
|
RoundedCornerShape(50.dp, 20.dp, 20.dp, 10.dp)
|
||||||
@@ -441,8 +428,18 @@ class ChatActivity : ComponentActivity() {
|
|||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun NewMessage(ctx: Context, peerUri: String) {
|
fun NewMessage(ctx: Context, peerUri: String) {
|
||||||
|
|
||||||
|
val showDialog = remember { mutableStateOf(false) }
|
||||||
|
val dialogMessage = remember { mutableStateOf("") }
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
showDialog = showDialog,
|
||||||
|
title = getString(R.string.notice),
|
||||||
|
message = dialogMessage.value,
|
||||||
|
positiveButtonText = getString(R.string.ok),
|
||||||
|
)
|
||||||
|
|
||||||
var newMessage by remember { mutableStateOf("") }
|
var newMessage by remember { mutableStateOf("") }
|
||||||
// var textFieldState = rememberTextFieldState()
|
|
||||||
Row(modifier = Modifier
|
Row(modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.navigationBarsPadding()
|
.navigationBarsPadding()
|
||||||
@@ -479,13 +476,10 @@ class ChatActivity : ComponentActivity() {
|
|||||||
_chatMessages.value += msg
|
_chatMessages.value += msg
|
||||||
if (Utils.isTelUri(peerUri))
|
if (Utils.isTelUri(peerUri))
|
||||||
if (ua.account.telProvider == "") {
|
if (ua.account.telProvider == "") {
|
||||||
Utils.alertView(
|
dialogMessage.value = String.format(
|
||||||
ctx, getString(R.string.notice),
|
getString(R.string.no_telephony_provider),
|
||||||
String.format(
|
Utils.plainAor(aor))
|
||||||
getString(R.string.no_telephony_provider),
|
showDialog.value = true
|
||||||
Utils.plainAor(aor)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
msgUri = Utils.telToSip(peerUri, ua.account)
|
msgUri = Utils.telToSip(peerUri, ua.account)
|
||||||
}
|
}
|
||||||
@@ -569,13 +563,10 @@ class ChatActivity : ComponentActivity() {
|
|||||||
_chatMessages.value += msg
|
_chatMessages.value += msg
|
||||||
if (Utils.isTelUri(peerUri))
|
if (Utils.isTelUri(peerUri))
|
||||||
if (ua.account.telProvider == "") {
|
if (ua.account.telProvider == "") {
|
||||||
Utils.alertView(
|
dialogMessage.value = String.format(
|
||||||
ctx, getString(R.string.notice),
|
getString(R.string.no_telephony_provider),
|
||||||
String.format(
|
Utils.plainAor(aor))
|
||||||
getString(R.string.no_telephony_provider),
|
showDialog.value = true
|
||||||
Utils.plainAor(aor)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
msgUri = Utils.telToSip(peerUri, ua.account)
|
msgUri = Utils.telToSip(peerUri, ua.account)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import android.content.Intent
|
|||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.format.DateUtils.isToday
|
import android.text.format.DateUtils.isToday
|
||||||
import android.view.Menu
|
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
@@ -527,7 +526,6 @@ class ChatsActivity: ComponentActivity() {
|
|||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
}
|
}
|
||||||
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = newPeer,
|
value = newPeer,
|
||||||
placeholder = {
|
placeholder = {
|
||||||
@@ -584,18 +582,20 @@ class ChatsActivity: ComponentActivity() {
|
|||||||
modifier = Modifier.padding(end = 4.dp),
|
modifier = Modifier.padding(end = 4.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
showSuggestions = false
|
showSuggestions = false
|
||||||
var peerUri = newPeer.trim()
|
var peerText = newPeer.trim()
|
||||||
if (peerUri.isNotEmpty()) {
|
if (peerText.isNotEmpty()) {
|
||||||
val uris = Contact.contactUris(peerUri)
|
val uris = Contact.contactUris(peerText)
|
||||||
if (uris.size == 1) {
|
if (uris.isEmpty())
|
||||||
|
makeChat(peerText)
|
||||||
|
else if (uris.size == 1)
|
||||||
makeChat(uris[0])
|
makeChat(uris[0])
|
||||||
} else if (uris.size > 1) {
|
else {
|
||||||
items.value = uris
|
items.value = uris
|
||||||
itemAction.value = { index ->
|
itemAction.value = { index ->
|
||||||
makeChat(uris[index])
|
makeChat(uris[index])
|
||||||
}
|
}
|
||||||
|
showDialog.value = true
|
||||||
}
|
}
|
||||||
showDialog.value = true
|
|
||||||
}
|
}
|
||||||
newPeer = ""
|
newPeer = ""
|
||||||
focusManager.clearFocus()
|
focusManager.clearFocus()
|
||||||
|
|||||||
@@ -329,16 +329,6 @@ class CodecsActivity : ComponentActivity() {
|
|||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
||||||
|
|
||||||
super.onCreateOptionsMenu(menu)
|
|
||||||
val inflater = menuInflater
|
|
||||||
inflater.inflate(R.menu.check_icon, menu)
|
|
||||||
return true
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun goBack() {
|
private fun goBack() {
|
||||||
BaresipService.activities.remove("codecs,$aor,$media")
|
BaresipService.activities.remove("codecs,$aor,$media")
|
||||||
finish()
|
finish()
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<item android:id="@+id/help"
|
|
||||||
android:title="@string/help" />
|
|
||||||
|
|
||||||
</menu>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/callIcon"
|
|
||||||
android:title=""
|
|
||||||
app:showAsAction="always"
|
|
||||||
android:icon="@drawable/call_small"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</menu>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/checkIcon"
|
|
||||||
android:title=""
|
|
||||||
app:showAsAction="always"
|
|
||||||
android:icon="@drawable/ic_action_check"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</menu>
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<item android:id="@+id/about"
|
|
||||||
android:title="@string/about" />
|
|
||||||
|
|
||||||
<item android:id="@+id/config"
|
|
||||||
android:title="@string/configuration" />
|
|
||||||
|
|
||||||
<item android:id="@+id/accounts"
|
|
||||||
android:title="@string/accounts" />
|
|
||||||
|
|
||||||
<item android:id="@+id/backup"
|
|
||||||
android:title="@string/backup" />
|
|
||||||
|
|
||||||
<item android:id="@+id/restore"
|
|
||||||
android:title="@string/restore" />
|
|
||||||
|
|
||||||
<item android:id="@+id/logcat"
|
|
||||||
android:visible="false"
|
|
||||||
android:title="@string/logcat" />
|
|
||||||
|
|
||||||
<item android:id="@+id/restart"
|
|
||||||
android:title="@string/restart" />
|
|
||||||
|
|
||||||
<item android:id="@+id/quit"
|
|
||||||
android:title="@string/quit" />
|
|
||||||
|
|
||||||
</menu>
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/micIcon"
|
|
||||||
android:title=""
|
|
||||||
app:showAsAction="always"
|
|
||||||
android:icon="@drawable/mic_on"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</menu>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/recIcon"
|
|
||||||
android:title=""
|
|
||||||
app:showAsAction="always"
|
|
||||||
android:icon="@drawable/rec_off" />
|
|
||||||
|
|
||||||
</menu>
|
|
||||||
Reference in New Issue
Block a user