mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Hidden separators, added red top bar for non-default accout registration failure notification
This commit is contained in:
parent
b105c436ba
commit
95baa55472
9 changed files with 112 additions and 25 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Boolean>()
|
||||
val showTopBar = MutableLiveData<Boolean>()
|
||||
|
||||
val callsLabel = MutableLiveData<String>()
|
||||
val atLeastOneCall = MutableLiveData<Boolean>()
|
||||
|
||||
val callLabel = MutableLiveData<String>()
|
||||
|
||||
val callsStatus = MutableLiveData<String>()
|
||||
|
||||
|
|
@ -50,8 +56,8 @@ class MainViewModel @UiThread constructor() : ViewModel() {
|
|||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
val changeSystemTopBarColorToInCallEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
val changeSystemTopBarColorEvent: MutableLiveData<Event<Int>> by lazy {
|
||||
MutableLiveData<Event<Int>>()
|
||||
}
|
||||
|
||||
val goBackToCallEvent: MutableLiveData<Event<Boolean>> 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))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,10 +85,12 @@
|
|||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/separator"
|
||||
android:layout_width="0dp"
|
||||
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"/>
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -107,10 +107,12 @@
|
|||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/separator"
|
||||
android:layout_width="0dp"
|
||||
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"/>
|
||||
|
|
|
|||
|
|
@ -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"/>
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -13,8 +13,32 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/green_success_500"
|
||||
android:onClick="@{() -> viewModel.goBackToCall()}">
|
||||
android:background="@{viewModel.atLeastOneCall ? @color/green_success_500 : @color/red_danger_500, default=@color/red_danger_500}"
|
||||
android:onClick="@{() -> viewModel.onTopBarClicked()}">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style_300"
|
||||
android:id="@+id/error_label"
|
||||
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="@string/connection_error_for_non_default_account"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:drawableStart="@drawable/bell_simple"
|
||||
android:drawablePadding="10dp"
|
||||
android:drawableTint="@color/white"
|
||||
android:visibility="@{viewModel.atLeastOneCall ? View.GONE : View.VISIBLE}"
|
||||
app:layout_constraintEnd_toStartOf="@id/close_notif"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style_800"
|
||||
|
|
@ -26,12 +50,15 @@
|
|||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@{viewModel.callsLabel, default=`John Doe`}"
|
||||
android:text="@{viewModel.callLabel, default=`John Doe`}"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="16sp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:drawableStart="@drawable/phone"
|
||||
android:drawablePadding="10dp"
|
||||
android:drawableTint="@color/white"
|
||||
android:visibility="@{viewModel.atLeastOneCall ? View.VISIBLE : View.GONE, default=gone}"
|
||||
app:layout_constraintEnd_toStartOf="@id/call_time"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
|
@ -47,11 +74,25 @@
|
|||
android:text="@{viewModel.callsStatus, default=`Paused`}"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="14sp"
|
||||
android:visibility="@{viewModel.atLeastOneCall ? View.VISIBLE : View.GONE, default=gone}"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/call_display_name"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/close_notif"
|
||||
android:onClick="@{() -> viewModel.closeTopBar()}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:src="@drawable/x"
|
||||
app:tint="@color/white"
|
||||
android:visibility="@{viewModel.atLeastOneCall ? View.GONE : View.VISIBLE}"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</layout>
|
||||
|
|
@ -355,6 +355,8 @@
|
|||
<string name="calls_count_label">%s calls</string>
|
||||
<string name="calls_paused_count_label">%s paused calls</string>
|
||||
|
||||
<string name="connection_error_for_non_default_account">Account connection error</string>
|
||||
|
||||
<!-- Keep <u></u> in following strings translations! -->
|
||||
<string name="welcome_carousel_skip"><u>Skip</u></string>
|
||||
<string name="assistant_forgotten_password"><u>Forgotten password?</u></string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue