mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Show persistent red toast while default account is in failed registration state
This commit is contained in:
parent
a66d29ba2e
commit
7eaa5cfb22
3 changed files with 82 additions and 0 deletions
|
|
@ -29,6 +29,7 @@ import androidx.annotation.DrawableRes
|
|||
import androidx.annotation.UiThread
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.core.view.children
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
|
|
@ -43,6 +44,7 @@ import org.linphone.R
|
|||
import org.linphone.databinding.MainActivityBinding
|
||||
import org.linphone.ui.main.viewmodel.MainViewModel
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.slideInToastFromTop
|
||||
import org.linphone.utils.slideInToastFromTopForDuration
|
||||
|
||||
@UiThread
|
||||
|
|
@ -97,6 +99,21 @@ class MainActivity : AppCompatActivity() {
|
|||
coreContext.showCallActivity()
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.defaultAccountRegistrationErrorEvent.observe(this) {
|
||||
it.consume { error ->
|
||||
val tag = "DEFAULT_ACCOUNT_REGISTRATION_ERROR"
|
||||
if (error) {
|
||||
// First remove any already existing connection error toat
|
||||
removePersistentRedToast(tag)
|
||||
|
||||
val message = getString(R.string.toast_default_account_connection_state_error)
|
||||
showPersistentRedToast(message, R.drawable.warning_circle, tag)
|
||||
} else {
|
||||
removePersistentRedToast(tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
|
|
@ -151,6 +168,30 @@ class MainActivity : AppCompatActivity() {
|
|||
)
|
||||
}
|
||||
|
||||
private fun showPersistentRedToast(
|
||||
message: String,
|
||||
@DrawableRes icon: Int,
|
||||
tag: String,
|
||||
doNotTint: Boolean = false
|
||||
) {
|
||||
val redToast = AppUtils.getRedToast(this, binding.toastsArea, message, icon, doNotTint)
|
||||
redToast.root.tag = tag
|
||||
binding.toastsArea.addView(redToast.root)
|
||||
|
||||
redToast.root.slideInToastFromTop(
|
||||
binding.toastsArea as ViewGroup,
|
||||
true
|
||||
)
|
||||
}
|
||||
|
||||
fun removePersistentRedToast(tag: String) {
|
||||
for (child in binding.toastsArea.children) {
|
||||
if (child.tag == tag) {
|
||||
binding.toastsArea.removeView(child)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadContacts() {
|
||||
coreContext.contactsManager.loadContacts(this)
|
||||
|
||||
|
|
|
|||
|
|
@ -25,9 +25,11 @@ import androidx.lifecycle.MutableLiveData
|
|||
import androidx.lifecycle.ViewModel
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
import org.linphone.R
|
||||
import org.linphone.core.Account
|
||||
import org.linphone.core.Call
|
||||
import org.linphone.core.Core
|
||||
import org.linphone.core.CoreListenerStub
|
||||
import org.linphone.core.RegistrationState
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.Event
|
||||
|
|
@ -44,6 +46,10 @@ class MainViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val callsStatus = MutableLiveData<String>()
|
||||
|
||||
val defaultAccountRegistrationErrorEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
val changeSystemTopBarColorToInCallEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
|
@ -52,6 +58,8 @@ class MainViewModel @UiThread constructor() : ViewModel() {
|
|||
MutableLiveData<Event<Boolean>>()
|
||||
}
|
||||
|
||||
var defaultAccountRegistrationFailed = false
|
||||
|
||||
private val coreListener = object : CoreListenerStub() {
|
||||
@WorkerThread
|
||||
override fun onLastCallEnded(core: Core) {
|
||||
|
|
@ -71,9 +79,41 @@ class MainViewModel @UiThread constructor() : ViewModel() {
|
|||
}
|
||||
atLastOneCall.postValue(core.callsNb > 0)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
override fun onAccountRegistrationStateChanged(
|
||||
core: Core,
|
||||
account: Account,
|
||||
state: RegistrationState?,
|
||||
message: String
|
||||
) {
|
||||
when (state) {
|
||||
RegistrationState.Failed -> {
|
||||
if (account == core.defaultAccount) {
|
||||
Log.e("$TAG Default account registration failed!")
|
||||
defaultAccountRegistrationFailed = true
|
||||
defaultAccountRegistrationErrorEvent.postValue(Event(true))
|
||||
} else {
|
||||
// TODO: show red top bar for non-default account registration failure
|
||||
}
|
||||
}
|
||||
RegistrationState.Ok -> {
|
||||
if (account == core.defaultAccount && defaultAccountRegistrationFailed) {
|
||||
Log.i("$TAG Default account is now registered")
|
||||
defaultAccountRegistrationFailed = false
|
||||
defaultAccountRegistrationErrorEvent.postValue(Event(false))
|
||||
} else {
|
||||
// TODO: hide red top bar for non-default account registration failure
|
||||
}
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
defaultAccountRegistrationFailed = false
|
||||
|
||||
coreContext.postOnCoreThread { core ->
|
||||
core.addListener(coreListener)
|
||||
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@
|
|||
<string name="toast_alert_low_cellular_signal">Low cellular signal!</string>
|
||||
<string name="toast_alert_low_cellular_signal_cleared">Cellular signal is no longer low</string>
|
||||
<string name="toast_call_can_be_trusted">This call can be trusted</string>
|
||||
<string name="toast_default_account_connection_state_error">Connection error!</string>
|
||||
|
||||
<string name="assistant_account_login">Login</string>
|
||||
<string name="assistant_scan_qr_code">Scan QR code</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue