Added top bar while in call to display paused calls

This commit is contained in:
Sylvain Berfini 2023-10-02 16:24:10 +02:00
parent 1d0abc4cb9
commit 860371e698
7 changed files with 183 additions and 23 deletions

View file

@ -34,6 +34,7 @@ import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
import androidx.window.layout.FoldingFeature
import androidx.window.layout.WindowInfoTracker
import androidx.window.layout.WindowLayoutInfo
@ -207,6 +208,25 @@ class CallActivity : AppCompatActivity() {
}
}
callsViewModel.goToCallsListEvent.observe(this) {
it.consume {
val navController = findNavController(R.id.call_nav_container)
val action = ActiveCallFragmentDirections.actionActiveCallFragmentToCallsListFragment()
navController.navigate(action)
}
}
callsViewModel.changeSystemTopBarColorToMultipleCallsEvent.observe(this) {
it.consume { useInCallColor ->
val color = if (useInCallColor) {
AppUtils.getColor(R.color.green_success_500)
} else {
AppUtils.getColor(R.color.orange_main_500)
}
window.statusBarColor = color
}
}
sharedViewModel.toggleFullScreenEvent.observe(this) {
it.consume { hide ->
hideUI(hide)

View file

@ -24,11 +24,13 @@ import androidx.annotation.WorkerThread
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.core.Call
import org.linphone.core.Core
import org.linphone.core.CoreListenerStub
import org.linphone.core.tools.Log
import org.linphone.ui.call.model.CallModel
import org.linphone.utils.AppUtils
import org.linphone.utils.Event
import org.linphone.utils.LinphoneUtils
@ -49,6 +51,18 @@ class CallsViewModel @UiThread constructor() : ViewModel() {
val noCallFoundEvent = MutableLiveData<Event<Boolean>>()
val otherCallsLabel = MutableLiveData<String>()
val otherCallsStatus = MutableLiveData<String>()
val goToCallsListEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
val changeSystemTopBarColorToMultipleCallsEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
private val coreListener = object : CoreListenerStub() {
@WorkerThread
override fun onCallStateChanged(
@ -119,6 +133,8 @@ class CallsViewModel @UiThread constructor() : ViewModel() {
}
}
}
updateOtherCallsInfo()
}
}
@ -150,6 +166,8 @@ class CallsViewModel @UiThread constructor() : ViewModel() {
}
else -> {}
}
updateOtherCallsInfo()
} else {
Log.w("$TAG No call found, leaving Call activity")
noCallFoundEvent.postValue(Event(true))
@ -167,4 +185,40 @@ class CallsViewModel @UiThread constructor() : ViewModel() {
core.removeListener(coreListener)
}
}
@UiThread
fun goToCallsList() {
goToCallsListEvent.value = Event(true)
}
@WorkerThread
private fun updateOtherCallsInfo() {
val core = coreContext.core
if (core.callsNb > 1) {
if (core.callsNb == 2) {
val found = core.calls.find {
it.state == Call.State.Paused
}
if (found != null) {
val contact = coreContext.contactsManager.findContactByAddress(
found.remoteAddress
)
otherCallsLabel.postValue(
contact?.name ?: LinphoneUtils.getDisplayName(found.remoteAddress)
)
otherCallsStatus.postValue(LinphoneUtils.callStateToString(found.state))
} else {
Log.e("$TAG Failed to find a paused call")
}
} else {
otherCallsLabel.postValue(
AppUtils.getFormattedString(R.string.calls_paused_count_label, core.callsNb)
)
otherCallsStatus.postValue("") // TODO: improve ?
}
Log.i("$TAG At least one other call, asking fragment to change status bar color")
changeSystemTopBarColorToMultipleCallsEvent.postValue(Event(true))
}
}
}

View file

@ -24,10 +24,12 @@ import androidx.annotation.WorkerThread
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.core.Call
import org.linphone.core.Core
import org.linphone.core.CoreListenerStub
import org.linphone.core.tools.Log
import org.linphone.utils.AppUtils
import org.linphone.utils.Event
import org.linphone.utils.LinphoneUtils
@ -38,9 +40,9 @@ class MainViewModel @UiThread constructor() : ViewModel() {
val atLastOneCall = MutableLiveData<Boolean>()
val callDisplayName = MutableLiveData<String>()
val callsLabel = MutableLiveData<String>()
val callStatus = MutableLiveData<String>()
val callsStatus = MutableLiveData<String>()
val changeSystemTopBarColorToInCallEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
@ -99,26 +101,33 @@ class MainViewModel @UiThread constructor() : ViewModel() {
@WorkerThread
private fun updateCurrentCallInfo() {
val core = coreContext.core
val currentCall = core.currentCall
if (currentCall != null) {
val contact = coreContext.contactsManager.findContactByAddress(
currentCall.remoteAddress
)
callDisplayName.postValue(
contact?.name ?: LinphoneUtils.getDisplayName(currentCall.remoteAddress)
)
callStatus.postValue(LinphoneUtils.callStateToString(currentCall.state))
} else {
val firstCall = core.calls.firstOrNull()
if (firstCall != null) {
if (core.callsNb == 1) {
val currentCall = core.currentCall
if (currentCall != null) {
val contact = coreContext.contactsManager.findContactByAddress(
firstCall.remoteAddress
currentCall.remoteAddress
)
callDisplayName.postValue(
contact?.name ?: LinphoneUtils.getDisplayName(firstCall.remoteAddress)
callsLabel.postValue(
contact?.name ?: LinphoneUtils.getDisplayName(currentCall.remoteAddress)
)
callStatus.postValue(LinphoneUtils.callStateToString(firstCall.state))
callsStatus.postValue(LinphoneUtils.callStateToString(currentCall.state))
} else {
val firstCall = core.calls.firstOrNull()
if (firstCall != null) {
val contact = coreContext.contactsManager.findContactByAddress(
firstCall.remoteAddress
)
callsLabel.postValue(
contact?.name ?: LinphoneUtils.getDisplayName(firstCall.remoteAddress)
)
callsStatus.postValue(LinphoneUtils.callStateToString(firstCall.state))
}
}
} else {
callsLabel.postValue(
AppUtils.getFormattedString(R.string.calls_count_label, core.callsNb)
)
callsStatus.postValue("") // TODO: improve ?
}
Log.i("$TAG At least a call, asking fragment to change status bar color")
changeSystemTopBarColorToInCallEvent.postValue(Event(true))

View file

@ -8,6 +8,9 @@
<variable
name="callViewModel"
type="org.linphone.ui.call.viewmodel.CurrentCallViewModel" />
<variable
name="callsViewModel"
type="org.linphone.ui.call.viewmodel.CallsViewModel" />
</data>
<androidx.coordinatorlayout.widget.CoordinatorLayout
@ -20,13 +23,28 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/other_calls_top_bar"
layout="@layout/call_activity_other_calls_top_bar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="@{callsViewModel.callsCount >= 2 ? View.VISIBLE : View.GONE, default=gone}"
app:viewModel="@{callsViewModel}"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/call_nav_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:navGraph="@navigation/call_nav_graph"/>
app:navGraph="@navigation/call_nav_graph"
app:layout_constraintTop_toBottomOf="@id/other_calls_top_bar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<LinearLayout
android:id="@+id/toasts_area"

View file

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View" />
<variable
name="viewModel"
type="org.linphone.ui.call.viewmodel.CallsViewModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green_success_500"
android:onClick="@{() -> viewModel.goToCallsList()}">
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style_800"
android:id="@+id/call_display_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:gravity="center_vertical"
android:text="@{viewModel.otherCallsLabel, default=`John Doe`}"
android:textColor="@color/white"
android:textSize="16sp"
android:drawableStart="@drawable/pause_call"
android:drawablePadding="10dp"
android:drawableTint="@color/white"
app:layout_constraintEnd_toStartOf="@id/call_time"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<androidx.appcompat.widget.AppCompatTextView
style="@style/default_text_style"
android:id="@+id/call_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="@{viewModel.otherCallsStatus, default=`Paused`}"
android:textColor="@color/white"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/call_display_name"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View file

@ -26,7 +26,7 @@
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:gravity="center_vertical"
android:text="@{viewModel.callDisplayName, default=`John Doe`}"
android:text="@{viewModel.callsLabel, default=`John Doe`}"
android:textColor="@color/white"
android:textSize="16sp"
android:drawableStart="@drawable/phone"
@ -44,7 +44,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:text="@{viewModel.callStatus, default=`Paused`}"
android:text="@{viewModel.callsStatus, default=`Paused`}"
android:textColor="@color/white"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"

View file

@ -319,6 +319,8 @@
<string name="toast_call_transfer_in_progress">Call is being transferred to %s</string>
<string name="toast_call_transfer_successful">Call has been transferred to %s</string>
<string name="toast_call_transfer_failed">Call transfer to %s failed!</string>
<string name="calls_count_label">%i calls</string>
<string name="calls_paused_count_label">%i paused calls</string>
<!-- Keep <u></u> in following strings translations! -->
<string name="welcome_carousel_skip"><u>Skip</u></string>