More work on multiple calls

This commit is contained in:
Juha Heinanen
2026-01-12 22:22:28 +02:00
parent 04656b4449
commit b07f0afbcf
6 changed files with 675 additions and 639 deletions

View File

@ -830,7 +830,7 @@ class BaresipService: Service() {
return
}
"call outgoing" -> {
if (call!!.status == "transferring")
if (call!!.status.value == "transferring")
break
stopMediaPlayer()
setCallVolume()
@ -989,8 +989,8 @@ class BaresipService: Service() {
}
"call answered" -> {
stopMediaPlayer()
if (call!!.status == "incoming")
call.status = "answered"
if (call!!.status.value == "incoming")
call.status.value = "answered"
else
return
}
@ -1002,7 +1002,7 @@ class BaresipService: Service() {
Log.d(TAG, "AoR $aor call $callp established in mode ${am.mode}")
if (am.mode != MODE_IN_COMMUNICATION)
am.mode = MODE_IN_COMMUNICATION
call!!.status = "connected"
call!!.status.value = "connected"
call.onhold = false
if (ua.account.callHistory)
call.startTime = GregorianCalendar()
@ -1020,7 +1020,7 @@ class BaresipService: Service() {
else
playRingBack()
}
if (!isMainVisible || call.status != "connected")
if (!isMainVisible || call.status.value != "connected")
return
}
"call verified", "call secure" -> {

View File

@ -5,7 +5,9 @@ import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import java.util.*
class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir: String, var status: String) {
class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir: String, initialStatus: String) {
var status: MutableState<String> = mutableStateOf(initialStatus)
var onhold = false
var held = false
@ -132,7 +134,7 @@ class Call(val callp: Long, val ua: UserAgent, val peerUri: String, val dir: Str
fun call(status: String): Call? {
for (c in BaresipService.calls.reversed())
if (c.status == status) return c
if (c.status.value == status) return c
return null
}

View File

@ -1,20 +1,20 @@
package com.tutpro.baresip
import java.util.*
import java.util.GregorianCalendar
class CallRow(
val aor: String, val peerUri: String, val direction: Int, startTime: GregorianCalendar?,
val stopTime: GregorianCalendar, val recording: Array<String>
data class CallRow(
val aor: String,
val peerUri: String,
var direction: Int,
var startTime: GregorianCalendar?,
var stopTime: GregorianCalendar,
var recording: Array<String>
) {
class Details(
val direction: Int, val startTime: GregorianCalendar?,
val stopTime: GregorianCalendar, val recording: Array<String>
data class Details(
var direction: Int,
var startTime: GregorianCalendar?,
var stopTime: GregorianCalendar,
var recording: Array<String>
)
val details = ArrayList<Details>()
init {
details.add(Details(direction, startTime, stopTime, recording))
}
val details = mutableListOf(Details(direction, startTime, stopTime, recording))
}

View File

@ -252,29 +252,20 @@ class MainActivity : ComponentActivity() {
navController = rememberNavController()
LaunchedEffect(key1 = viewModel, key2 = navController) {
LaunchedEffect(key1 = viewModel) {
viewModel.navigationCommand.collect { command ->
Log.d(TAG, "MainActivity: Received NavigationCommand: $command")
when (command) {
is NavigationCommand.NavigateToChat -> {
val route = "chat/${command.aor}/${command.peer}"
navController.navigate(route) {
launchSingleTop = true
popUpTo("main")
}
val route = "chat/${command.aor}/${command.peerUri}"
navController.navigate(route)
}
is NavigationCommand.NavigateToCalls -> {
val route = "calls/${command.aor}"
navController.navigate(route) {
launchSingleTop = true
popUpTo("main")
}
navController.navigate(route)
}
is NavigationCommand.NavigateToHome -> {
navController.navigate("main") {
launchSingleTop = true
popUpTo("main")
}
navController.navigate("main")
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -4,13 +4,40 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Mic
import kotlinx.coroutines.launch
// Sealed class for type-safe navigation events
sealed class NavigationCommand {
object NavigateToHome : NavigationCommand()
data class NavigateToCalls(val aor: String) : NavigationCommand()
data class NavigateToChat(val aor: String, val peerUri: String) : NavigationCommand()
}
class ViewModel: ViewModel() {
// A map to store message drafts. Key is "aor:peerUri"
private val messageDrafts = mutableMapOf<String, String>()
fun getAorPeerMessage(aor: String, peerUri: String): String {
return messageDrafts["$aor:$peerUri"] ?: ""
}
fun updateAorPeerMessage(aor: String, peerUri: String, message: String) {
val key = "$aor:$peerUri"
if (message.isEmpty()) {
messageDrafts.remove(key)
} else {
messageDrafts[key] = message
}
}
data class DialerState(
val callUri: MutableState<String> = mutableStateOf(""),
val callUriEnabled: MutableState<Boolean> = mutableStateOf(true),
@ -43,11 +70,24 @@ class ViewModel: ViewModel() {
private val _hideKeyboard = MutableStateFlow(0)
val hideKeyboard = _hideKeyboard.asStateFlow()
private val _navigationCommand = MutableSharedFlow<NavigationCommand>()
val navigationCommand = _navigationCommand.asSharedFlow()
private var _selectedCallRow: CallRow? = null
fun selectCallRow(callRow: CallRow) {
_selectedCallRow = callRow
}
fun consumeSelectedCallRow(): CallRow? {
val callRow = _selectedCallRow
_selectedCallRow = null
return callRow
}
fun onNewMessageReceived(aor: String, peerUri: String) {
val acc = Account.ofAor(aor)
if (acc != null) {
acc.unreadMessages = true
triggerAccountUpdate()
viewModelScope.launch {
_navigationCommand.emit(NavigationCommand.NavigateToChat(aor, peerUri))
}
}
@ -60,7 +100,7 @@ class ViewModel: ViewModel() {
}
fun triggerAccountUpdate() {
_accountUpdate.value = _accountUpdate.value + 1
_accountUpdate.value += 1
}
fun updateMicIcon(icon: ImageVector) {
@ -72,19 +112,23 @@ class ViewModel: ViewModel() {
}
fun requestShowKeyboard() {
_showKeyboard.value = _showKeyboard.value + 1
_showKeyboard.value += 1
}
fun requestHideKeyboard() {
_hideKeyboard.value = _hideKeyboard.value + 1
_hideKeyboard.value += 1
}
fun navigateToHome() {
// This function can be used to navigate to the main screen
viewModelScope.launch {
_navigationCommand.emit(NavigationCommand.NavigateToHome)
}
}
fun navigateToCalls(aor: String) {
// This function can be used to navigate to the calls screen
viewModelScope.launch {
_navigationCommand.emit(NavigationCommand.NavigateToCalls(aor))
}
}
}
}