Open automatically chat or call history screen when baresip icon with notification dot is touuched
This commit is contained in:
@ -102,7 +102,8 @@ class MainActivity : ComponentActivity() {
|
||||
else
|
||||
exitProcess(0)
|
||||
}
|
||||
} else
|
||||
}
|
||||
else
|
||||
handleServiceEvent(this, viewModel, first.event, first.params)
|
||||
}
|
||||
}
|
||||
@ -254,6 +255,9 @@ class MainActivity : ComponentActivity() {
|
||||
val route = "calls/${command.aor}"
|
||||
navController.navigate(route)
|
||||
}
|
||||
is NavigationCommand.NavigateToChats -> {
|
||||
navController.navigate("chats")
|
||||
}
|
||||
is NavigationCommand.NavigateToHome ->
|
||||
navController.navigate("main") {
|
||||
popUpTo("main") { inclusive = true }
|
||||
@ -302,6 +306,21 @@ class MainActivity : ComponentActivity() {
|
||||
intent.removeExtra("action")
|
||||
handleIntent(applicationContext, viewModel, intent, action)
|
||||
}
|
||||
else if (intent.action == Intent.ACTION_MAIN && !atStartup) {
|
||||
val activeNotifications = nm.activeNotifications
|
||||
if (activeNotifications.any { it.id == CALL_MISSED_NOTIFICATION_ID }) {
|
||||
val ua = BaresipService.uas.value.find { it.account.missedCalls }
|
||||
if (ua != null)
|
||||
viewModel.navigateToCalls(ua.account.aor)
|
||||
}
|
||||
else if (activeNotifications.any { it.id == MESSAGE_NOTIFICATION_ID }) {
|
||||
val lastUnread = BaresipService.messages.lastOrNull { it.new }
|
||||
if (lastUnread != null)
|
||||
viewModel.onNewMessageReceived(lastUnread.aor, lastUnread.peerUri)
|
||||
else
|
||||
viewModel.navigateToChats()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
||||
@ -16,6 +16,7 @@ import kotlinx.coroutines.launch
|
||||
// Sealed class for type-safe navigation events
|
||||
sealed class NavigationCommand {
|
||||
object NavigateToHome : NavigationCommand()
|
||||
object NavigateToChats : NavigationCommand()
|
||||
data class NavigateToCalls(val aor: String) : NavigationCommand()
|
||||
data class NavigateToChat(val aor: String, val peerUri: String) : NavigationCommand()
|
||||
}
|
||||
@ -31,11 +32,10 @@ class ViewModel: ViewModel() {
|
||||
|
||||
fun updateAorPeerMessage(aor: String, peerUri: String, message: String) {
|
||||
val key = "$aor:$peerUri"
|
||||
if (message.isEmpty()) {
|
||||
if (message.isEmpty())
|
||||
messageDrafts.remove(key)
|
||||
} else {
|
||||
else
|
||||
messageDrafts[key] = message
|
||||
}
|
||||
}
|
||||
|
||||
data class DialerState(
|
||||
@ -162,4 +162,10 @@ class ViewModel: ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun navigateToChats() {
|
||||
viewModelScope.launch {
|
||||
_navigationCommand.emit(NavigationCommand.NavigateToChats)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user