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
|
||||
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
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.sp
|
||||
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.verticalScrollbar
|
||||
import kotlinx.coroutines.launch
|
||||
@ -257,6 +256,25 @@ class ChatActivity : ComponentActivity() {
|
||||
|
||||
@Composable
|
||||
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 coroutineScope = rememberCoroutineScope()
|
||||
|
||||
@ -319,65 +337,34 @@ class ChatActivity : ComponentActivity() {
|
||||
) {
|
||||
Button(
|
||||
onClick = {
|
||||
val dialogClickListener =
|
||||
DialogInterface.OnClickListener { _, which ->
|
||||
when (which) {
|
||||
DialogInterface.BUTTON_POSITIVE -> {
|
||||
val i = Intent(ctx, BaresipContactActivity::class.java)
|
||||
val b = Bundle()
|
||||
b.putBoolean("new", true)
|
||||
b.putString("uri", peerUri)
|
||||
i.putExtras(b)
|
||||
ctx.startActivity(i)
|
||||
}
|
||||
|
||||
DialogInterface.BUTTON_NEGATIVE -> {
|
||||
message.delete()
|
||||
_chatMessages.value = uaPeerMessages(aor, peerUri)
|
||||
}
|
||||
|
||||
DialogInterface.BUTTON_NEUTRAL -> {
|
||||
}
|
||||
}
|
||||
if (chatPeer == peerUri) {
|
||||
dialogMessage.value = String.format(ctx.getString(R.string.long_message_question),
|
||||
peerUri
|
||||
)
|
||||
positiveButtonText.value = ctx.getString(R.string.add_contact)
|
||||
positiveAction.value = {
|
||||
val i = Intent(ctx, BaresipContactActivity::class.java)
|
||||
val b = Bundle()
|
||||
b.putBoolean("new", true)
|
||||
b.putString("uri", peerUri)
|
||||
i.putExtras(b)
|
||||
ctx.startActivity(i)
|
||||
}
|
||||
val builder = MaterialAlertDialogBuilder(ctx, R.style.AlertDialogTheme)
|
||||
if (chatPeer == peerUri)
|
||||
with(builder) {
|
||||
setTitle(R.string.confirmation)
|
||||
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()
|
||||
neutralButtonText.value = ctx.getString(R.string.delete)
|
||||
neutralAction.value = {
|
||||
message.delete()
|
||||
_chatMessages.value = uaPeerMessages(aor, peerUri)
|
||||
}
|
||||
else
|
||||
with(builder) {
|
||||
setTitle(R.string.confirmation)
|
||||
setMessage(ctx.getText(R.string.short_message_question))
|
||||
setNeutralButton(
|
||||
ctx.getString(R.string.cancel),
|
||||
dialogClickListener
|
||||
)
|
||||
setNegativeButton(
|
||||
ctx.getString(R.string.delete),
|
||||
dialogClickListener
|
||||
)
|
||||
show()
|
||||
}
|
||||
else {
|
||||
dialogMessage.value = ctx.getString(R.string.short_message_question)
|
||||
positiveButtonText.value = ctx.getString(R.string.delete)
|
||||
positiveAction.value = {
|
||||
message.delete()
|
||||
_chatMessages.value = uaPeerMessages(aor, peerUri)
|
||||
}
|
||||
}
|
||||
showDialog.value = true
|
||||
},
|
||||
shape = if (message.direction == MESSAGE_DOWN)
|
||||
RoundedCornerShape(50.dp, 20.dp, 20.dp, 10.dp)
|
||||
@ -441,8 +428,18 @@ class ChatActivity : ComponentActivity() {
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
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 textFieldState = rememberTextFieldState()
|
||||
Row(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.navigationBarsPadding()
|
||||
@ -479,13 +476,10 @@ class ChatActivity : ComponentActivity() {
|
||||
_chatMessages.value += msg
|
||||
if (Utils.isTelUri(peerUri))
|
||||
if (ua.account.telProvider == "") {
|
||||
Utils.alertView(
|
||||
ctx, getString(R.string.notice),
|
||||
String.format(
|
||||
getString(R.string.no_telephony_provider),
|
||||
Utils.plainAor(aor)
|
||||
)
|
||||
)
|
||||
dialogMessage.value = String.format(
|
||||
getString(R.string.no_telephony_provider),
|
||||
Utils.plainAor(aor))
|
||||
showDialog.value = true
|
||||
} else {
|
||||
msgUri = Utils.telToSip(peerUri, ua.account)
|
||||
}
|
||||
@ -569,13 +563,10 @@ class ChatActivity : ComponentActivity() {
|
||||
_chatMessages.value += msg
|
||||
if (Utils.isTelUri(peerUri))
|
||||
if (ua.account.telProvider == "") {
|
||||
Utils.alertView(
|
||||
ctx, getString(R.string.notice),
|
||||
String.format(
|
||||
getString(R.string.no_telephony_provider),
|
||||
Utils.plainAor(aor)
|
||||
)
|
||||
)
|
||||
dialogMessage.value = String.format(
|
||||
getString(R.string.no_telephony_provider),
|
||||
Utils.plainAor(aor))
|
||||
showDialog.value = true
|
||||
} else {
|
||||
msgUri = Utils.telToSip(peerUri, ua.account)
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@ import android.content.Intent
|
||||
import android.graphics.BitmapFactory
|
||||
import android.os.Bundle
|
||||
import android.text.format.DateUtils.isToday
|
||||
import android.view.Menu
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.compose.setContent
|
||||
@ -527,7 +526,6 @@ class ChatsActivity: ComponentActivity() {
|
||||
}
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
|
||||
OutlinedTextField(
|
||||
value = newPeer,
|
||||
placeholder = {
|
||||
@ -584,18 +582,20 @@ class ChatsActivity: ComponentActivity() {
|
||||
modifier = Modifier.padding(end = 4.dp),
|
||||
onClick = {
|
||||
showSuggestions = false
|
||||
var peerUri = newPeer.trim()
|
||||
if (peerUri.isNotEmpty()) {
|
||||
val uris = Contact.contactUris(peerUri)
|
||||
if (uris.size == 1) {
|
||||
var peerText = newPeer.trim()
|
||||
if (peerText.isNotEmpty()) {
|
||||
val uris = Contact.contactUris(peerText)
|
||||
if (uris.isEmpty())
|
||||
makeChat(peerText)
|
||||
else if (uris.size == 1)
|
||||
makeChat(uris[0])
|
||||
} else if (uris.size > 1) {
|
||||
else {
|
||||
items.value = uris
|
||||
itemAction.value = { index ->
|
||||
makeChat(uris[index])
|
||||
}
|
||||
showDialog.value = true
|
||||
}
|
||||
showDialog.value = true
|
||||
}
|
||||
newPeer = ""
|
||||
focusManager.clearFocus()
|
||||
|
||||
@ -329,16 +329,6 @@ class CodecsActivity : ComponentActivity() {
|
||||
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() {
|
||||
BaresipService.activities.remove("codecs,$aor,$media")
|
||||
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