diff --git a/app/src/main/java/org/linphone/ui/main/MainActivity.kt b/app/src/main/java/org/linphone/ui/main/MainActivity.kt index 35d63aae0..069dd812d 100644 --- a/app/src/main/java/org/linphone/ui/main/MainActivity.kt +++ b/app/src/main/java/org/linphone/ui/main/MainActivity.kt @@ -76,16 +76,18 @@ class MainActivity : AppCompatActivity() { } binding.viewModel = viewModel - viewModel.changeSystemTopBarColorToInCallEvent.observe(this) { - it.consume { useInCallColor -> - val color = if (useInCallColor) { - AppUtils.getColor(R.color.green_success_500) - } else { - AppUtils.getColor(R.color.orange_main_500) + viewModel.changeSystemTopBarColorEvent.observe(this) { + it.consume { mode -> + val color = when (mode) { + MainViewModel.IN_CALL -> AppUtils.getColor(R.color.green_success_500) + MainViewModel.ACCOUNT_REGISTRATION_FAILURE -> AppUtils.getColor( + R.color.red_danger_500 + ) + else -> AppUtils.getColor(R.color.orange_main_500) } lifecycleScope.launch { withContext(Dispatchers.IO) { - delay(if (useInCallColor) 1000 else 0) + delay(if (mode == MainViewModel.IN_CALL) 1000 else 0) withContext(Dispatchers.Main) { window.statusBarColor = color } 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 b5784fe84..d12a40000 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 @@ -38,11 +38,17 @@ import org.linphone.utils.LinphoneUtils class MainViewModel @UiThread constructor() : ViewModel() { companion object { private const val TAG = "[Main ViewModel]" + + const val NONE = 0 + const val ACCOUNT_REGISTRATION_FAILURE = 1 + const val IN_CALL = 2 } - val atLastOneCall = MutableLiveData() + val showTopBar = MutableLiveData() - val callsLabel = MutableLiveData() + val atLeastOneCall = MutableLiveData() + + val callLabel = MutableLiveData() val callsStatus = MutableLiveData() @@ -50,8 +56,8 @@ class MainViewModel @UiThread constructor() : ViewModel() { MutableLiveData>() } - val changeSystemTopBarColorToInCallEvent: MutableLiveData> by lazy { - MutableLiveData>() + val changeSystemTopBarColorEvent: MutableLiveData> by lazy { + MutableLiveData>() } val goBackToCallEvent: MutableLiveData> by lazy { @@ -64,7 +70,7 @@ class MainViewModel @UiThread constructor() : ViewModel() { @WorkerThread override fun onLastCallEnded(core: Core) { Log.i("$TAG Last call ended, asking fragment to change back status bar color") - changeSystemTopBarColorToInCallEvent.postValue(Event(false)) + changeSystemTopBarColorEvent.postValue(Event(NONE)) } @WorkerThread @@ -77,7 +83,9 @@ class MainViewModel @UiThread constructor() : ViewModel() { if (core.callsNb > 0) { updateCurrentCallInfo() } - atLastOneCall.postValue(core.callsNb > 0) + val calls = core.callsNb > 0 + showTopBar.postValue(calls) + atLeastOneCall.postValue(calls) } @WorkerThread @@ -94,7 +102,16 @@ class MainViewModel @UiThread constructor() : ViewModel() { defaultAccountRegistrationFailed = true defaultAccountRegistrationErrorEvent.postValue(Event(true)) } else { - // TODO: show red top bar for non-default account registration failure + Log.e("$TAG Non-default account registration failed!") + // Do not show connection error top bar if there is a call + if (atLeastOneCall.value == false) { + changeSystemTopBarColorEvent.postValue( + Event( + ACCOUNT_REGISTRATION_FAILURE + ) + ) + showTopBar.postValue(true) + } } } RegistrationState.Ok -> { @@ -103,7 +120,17 @@ class MainViewModel @UiThread constructor() : ViewModel() { defaultAccountRegistrationFailed = false defaultAccountRegistrationErrorEvent.postValue(Event(false)) } else { - // TODO: hide red top bar for non-default account registration failure + // If no call and no account is in Failed state, hide top bar + val found = core.accountList.find { + it.state == RegistrationState.Failed + } + if (found == null) { + Log.i("$TAG No account in Failed state anymore") + if (atLeastOneCall.value == false) { + changeSystemTopBarColorEvent.postValue(Event(NONE)) + showTopBar.postValue(false) + } + } } } else -> {} @@ -113,6 +140,7 @@ class MainViewModel @UiThread constructor() : ViewModel() { init { defaultAccountRegistrationFailed = false + showTopBar.value = false coreContext.postOnCoreThread { core -> core.addListener(coreListener) @@ -120,7 +148,10 @@ class MainViewModel @UiThread constructor() : ViewModel() { if (core.callsNb > 0) { updateCurrentCallInfo() } - atLastOneCall.postValue(core.callsNb > 0) + + val calls = core.callsNb > 0 + showTopBar.postValue(calls) + atLeastOneCall.postValue(calls) } } @@ -134,7 +165,12 @@ class MainViewModel @UiThread constructor() : ViewModel() { } @UiThread - fun goBackToCall() { + fun closeTopBar() { + showTopBar.value = false + } + + @UiThread + fun onTopBarClicked() { goBackToCallEvent.value = Event(true) } @@ -147,7 +183,7 @@ class MainViewModel @UiThread constructor() : ViewModel() { val contact = coreContext.contactsManager.findContactByAddress( currentCall.remoteAddress ) - callsLabel.postValue( + callLabel.postValue( contact?.name ?: LinphoneUtils.getDisplayName(currentCall.remoteAddress) ) callsStatus.postValue(LinphoneUtils.callStateToString(currentCall.state)) @@ -157,19 +193,19 @@ class MainViewModel @UiThread constructor() : ViewModel() { val contact = coreContext.contactsManager.findContactByAddress( firstCall.remoteAddress ) - callsLabel.postValue( + callLabel.postValue( contact?.name ?: LinphoneUtils.getDisplayName(firstCall.remoteAddress) ) callsStatus.postValue(LinphoneUtils.callStateToString(firstCall.state)) } } } else { - callsLabel.postValue( + callLabel.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)) + changeSystemTopBarColorEvent.postValue(Event(IN_CALL)) } } diff --git a/app/src/main/res/layout/call_list_cell.xml b/app/src/main/res/layout/call_list_cell.xml index 59afaa7e7..11e00f12a 100644 --- a/app/src/main/res/layout/call_list_cell.xml +++ b/app/src/main/res/layout/call_list_cell.xml @@ -85,10 +85,12 @@ app:layout_constraintBottom_toBottomOf="parent"/> diff --git a/app/src/main/res/layout/chat_list_cell.xml b/app/src/main/res/layout/chat_list_cell.xml index d3cd23f7b..971cd8a1a 100644 --- a/app/src/main/res/layout/chat_list_cell.xml +++ b/app/src/main/res/layout/chat_list_cell.xml @@ -185,6 +185,7 @@ android:layout_width="0dp" android:layout_height="1dp" android:layout_marginEnd="10dp" + android:visibility="gone" android:background="@color/gray_main2_200" app:layout_constraintStart_toStartOf="@id/name" app:layout_constraintEnd_toEndOf="parent" diff --git a/app/src/main/res/layout/contact_list_cell.xml b/app/src/main/res/layout/contact_list_cell.xml index 566b70670..e53fad32a 100644 --- a/app/src/main/res/layout/contact_list_cell.xml +++ b/app/src/main/res/layout/contact_list_cell.xml @@ -107,10 +107,12 @@ app:layout_constraintBottom_toBottomOf="parent"/> diff --git a/app/src/main/res/layout/history_list_cell.xml b/app/src/main/res/layout/history_list_cell.xml index 99b5a10f0..90318ea80 100644 --- a/app/src/main/res/layout/history_list_cell.xml +++ b/app/src/main/res/layout/history_list_cell.xml @@ -127,6 +127,7 @@ android:layout_height="1dp" android:layout_marginEnd="10dp" android:background="@color/gray_main2_200" + android:visibility="gone" app:layout_constraintStart_toStartOf="@id/name" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintBottom_toBottomOf="parent"/> diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index 49b87b934..bffb3243e 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -27,7 +27,7 @@ layout="@layout/main_activity_in_call_top_bar" android:layout_width="0dp" android:layout_height="wrap_content" - android:visibility="@{viewModel.atLastOneCall ? View.VISIBLE : View.GONE, default=gone}" + android:visibility="@{viewModel.showTopBar ? View.VISIBLE : View.GONE, default=gone}" app:viewModel="@{viewModel}" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" 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 33f063046..175bc9637 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 @@ -13,8 +13,32 @@ + android:background="@{viewModel.atLeastOneCall ? @color/green_success_500 : @color/red_danger_500, default=@color/red_danger_500}" + android:onClick="@{() -> viewModel.onTopBarClicked()}"> + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d9a67caf0..a3cf026e9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -355,6 +355,8 @@ %s calls %s paused calls + Account connection error + Skip Forgotten password?