diff --git a/app/src/main/java/org/linphone/ui/call/CallActivity.kt b/app/src/main/java/org/linphone/ui/call/CallActivity.kt index 6c7cd38c8..c6ce254f6 100644 --- a/app/src/main/java/org/linphone/ui/call/CallActivity.kt +++ b/app/src/main/java/org/linphone/ui/call/CallActivity.kt @@ -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) diff --git a/app/src/main/java/org/linphone/ui/call/viewmodel/CallsViewModel.kt b/app/src/main/java/org/linphone/ui/call/viewmodel/CallsViewModel.kt index d5c41ee92..6e68153d0 100644 --- a/app/src/main/java/org/linphone/ui/call/viewmodel/CallsViewModel.kt +++ b/app/src/main/java/org/linphone/ui/call/viewmodel/CallsViewModel.kt @@ -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>() + val otherCallsLabel = MutableLiveData() + + val otherCallsStatus = MutableLiveData() + + val goToCallsListEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + + val changeSystemTopBarColorToMultipleCallsEvent: MutableLiveData> by lazy { + MutableLiveData>() + } + 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)) + } + } } diff --git a/app/src/main/java/org/linphone/ui/main/viewmodel/MainViewModel.kt b/app/src/main/java/org/linphone/ui/main/viewmodel/MainViewModel.kt index 44b60adfb..69ce2bb24 100644 --- a/app/src/main/java/org/linphone/ui/main/viewmodel/MainViewModel.kt +++ b/app/src/main/java/org/linphone/ui/main/viewmodel/MainViewModel.kt @@ -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() - val callDisplayName = MutableLiveData() + val callsLabel = MutableLiveData() - val callStatus = MutableLiveData() + val callsStatus = MutableLiveData() val changeSystemTopBarColorToInCallEvent: MutableLiveData> by lazy { MutableLiveData>() @@ -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)) diff --git a/app/src/main/res/layout/call_activity.xml b/app/src/main/res/layout/call_activity.xml index d4cce75c9..71c5843e8 100644 --- a/app/src/main/res/layout/call_activity.xml +++ b/app/src/main/res/layout/call_activity.xml @@ -8,6 +8,9 @@ + + + + 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"/> + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/main_activity_in_call_top_bar.xml b/app/src/main/res/layout/main_activity_in_call_top_bar.xml index d6362e5ec..33f063046 100644 --- a/app/src/main/res/layout/main_activity_in_call_top_bar.xml +++ b/app/src/main/res/layout/main_activity_in_call_top_bar.xml @@ -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" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e0cdb1310..dafda000e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -319,6 +319,8 @@ Call is being transferred to %s Call has been transferred to %s Call transfer to %s failed! + %i calls + %i paused calls Skip