Check credentials in assistant before exiting
This commit is contained in:
parent
20c0b611d0
commit
2979ca0934
7 changed files with 132 additions and 17 deletions
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
package org.linphone.activities.assistant.fragments
|
package org.linphone.activities.assistant.fragments
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -31,7 +32,9 @@ import org.linphone.R
|
||||||
import org.linphone.activities.assistant.viewmodels.AccountLoginViewModel
|
import org.linphone.activities.assistant.viewmodels.AccountLoginViewModel
|
||||||
import org.linphone.activities.assistant.viewmodels.AccountLoginViewModelFactory
|
import org.linphone.activities.assistant.viewmodels.AccountLoginViewModelFactory
|
||||||
import org.linphone.activities.assistant.viewmodels.SharedAssistantViewModel
|
import org.linphone.activities.assistant.viewmodels.SharedAssistantViewModel
|
||||||
|
import org.linphone.activities.main.viewmodels.DialogViewModel
|
||||||
import org.linphone.databinding.AssistantAccountLoginFragmentBinding
|
import org.linphone.databinding.AssistantAccountLoginFragmentBinding
|
||||||
|
import org.linphone.utils.DialogUtils
|
||||||
|
|
||||||
class AccountLoginFragment : AbstractPhoneFragment() {
|
class AccountLoginFragment : AbstractPhoneFragment() {
|
||||||
private lateinit var binding: AssistantAccountLoginFragmentBinding
|
private lateinit var binding: AssistantAccountLoginFragmentBinding
|
||||||
|
@ -94,6 +97,19 @@ class AccountLoginFragment : AbstractPhoneFragment() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
viewModel.invalidCredentialsEvent.observe(viewLifecycleOwner, Observer {
|
||||||
|
it.consume {
|
||||||
|
val dialogViewModel = DialogViewModel(getString(R.string.assistant_error_invalid_credentials))
|
||||||
|
val dialog: Dialog = DialogUtils.getDialog(requireContext(), dialogViewModel)
|
||||||
|
|
||||||
|
dialogViewModel.showDeleteButton({
|
||||||
|
dialog.dismiss()
|
||||||
|
}, getString(R.string.dialog_ok))
|
||||||
|
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
checkPermission()
|
checkPermission()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
package org.linphone.activities.assistant.fragments
|
package org.linphone.activities.assistant.fragments
|
||||||
|
|
||||||
|
import android.app.Dialog
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
@ -32,7 +33,9 @@ import org.linphone.R
|
||||||
import org.linphone.activities.assistant.viewmodels.GenericLoginViewModel
|
import org.linphone.activities.assistant.viewmodels.GenericLoginViewModel
|
||||||
import org.linphone.activities.assistant.viewmodels.GenericLoginViewModelFactory
|
import org.linphone.activities.assistant.viewmodels.GenericLoginViewModelFactory
|
||||||
import org.linphone.activities.assistant.viewmodels.SharedAssistantViewModel
|
import org.linphone.activities.assistant.viewmodels.SharedAssistantViewModel
|
||||||
|
import org.linphone.activities.main.viewmodels.DialogViewModel
|
||||||
import org.linphone.databinding.AssistantGenericAccountLoginFragmentBinding
|
import org.linphone.databinding.AssistantGenericAccountLoginFragmentBinding
|
||||||
|
import org.linphone.utils.DialogUtils
|
||||||
|
|
||||||
class GenericAccountLoginFragment : Fragment() {
|
class GenericAccountLoginFragment : Fragment() {
|
||||||
private lateinit var binding: AssistantGenericAccountLoginFragmentBinding
|
private lateinit var binding: AssistantGenericAccountLoginFragmentBinding
|
||||||
|
@ -71,5 +74,18 @@ class GenericAccountLoginFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
viewModel.invalidCredentialsEvent.observe(viewLifecycleOwner, Observer {
|
||||||
|
it.consume {
|
||||||
|
val dialogViewModel = DialogViewModel(getString(R.string.assistant_error_invalid_credentials))
|
||||||
|
val dialog: Dialog = DialogUtils.getDialog(requireContext(), dialogViewModel)
|
||||||
|
|
||||||
|
dialogViewModel.showDeleteButton({
|
||||||
|
dialog.dismiss()
|
||||||
|
}, getString(R.string.dialog_ok))
|
||||||
|
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,8 @@
|
||||||
package org.linphone.activities.assistant.viewmodels
|
package org.linphone.activities.assistant.viewmodels
|
||||||
|
|
||||||
import androidx.lifecycle.*
|
import androidx.lifecycle.*
|
||||||
import org.linphone.core.AccountCreator
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.core.AccountCreatorListenerStub
|
import org.linphone.core.*
|
||||||
import org.linphone.core.ProxyConfig
|
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
|
|
||||||
|
@ -50,6 +49,10 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM
|
||||||
MutableLiveData<Event<Boolean>>()
|
MutableLiveData<Event<Boolean>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val invalidCredentialsEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||||
|
MutableLiveData<Event<Boolean>>()
|
||||||
|
}
|
||||||
|
|
||||||
val goToSmsValidationEvent: MutableLiveData<Event<Boolean>> by lazy {
|
val goToSmsValidationEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||||
MutableLiveData<Event<Boolean>>()
|
MutableLiveData<Event<Boolean>>()
|
||||||
}
|
}
|
||||||
|
@ -71,6 +74,33 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var proxyConfigToCheck: ProxyConfig? = null
|
||||||
|
|
||||||
|
private val coreListener = object : CoreListenerStub() {
|
||||||
|
override fun onRegistrationStateChanged(
|
||||||
|
core: Core,
|
||||||
|
cfg: ProxyConfig,
|
||||||
|
state: RegistrationState,
|
||||||
|
message: String?
|
||||||
|
) {
|
||||||
|
if (cfg == proxyConfigToCheck) {
|
||||||
|
Log.i("[Assistant] [Account Login] Registration state is $state: $message")
|
||||||
|
waitForServerAnswer.value = false
|
||||||
|
if (state == RegistrationState.Ok) {
|
||||||
|
leaveAssistantEvent.value = Event(true)
|
||||||
|
core.removeListener(this)
|
||||||
|
} else if (state == RegistrationState.Failed) {
|
||||||
|
invalidCredentialsEvent.value = Event(true)
|
||||||
|
val authInfo = cfg.findAuthInfo()
|
||||||
|
if (authInfo != null) core.removeAuthInfo(authInfo)
|
||||||
|
core.removeProxyConfig(cfg)
|
||||||
|
proxyConfigToCheck = null
|
||||||
|
core.removeListener(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
accountCreator.addListener(listener)
|
accountCreator.addListener(listener)
|
||||||
|
|
||||||
|
@ -109,10 +139,10 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM
|
||||||
Log.i("[Assistant] [Account Login] Username is ${accountCreator.username}")
|
Log.i("[Assistant] [Account Login] Username is ${accountCreator.username}")
|
||||||
|
|
||||||
waitForServerAnswer.value = true
|
waitForServerAnswer.value = true
|
||||||
if (createProxyConfig()) {
|
coreContext.core.addListener(coreListener)
|
||||||
leaveAssistantEvent.value = Event(true)
|
if (!createProxyConfig()) {
|
||||||
} else {
|
|
||||||
waitForServerAnswer.value = false
|
waitForServerAnswer.value = false
|
||||||
|
coreContext.core.removeListener(coreListener)
|
||||||
// TODO: show error
|
// TODO: show error
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -140,6 +170,7 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM
|
||||||
|
|
||||||
private fun createProxyConfig(): Boolean {
|
private fun createProxyConfig(): Boolean {
|
||||||
val proxyConfig: ProxyConfig? = accountCreator.createProxyConfig()
|
val proxyConfig: ProxyConfig? = accountCreator.createProxyConfig()
|
||||||
|
proxyConfigToCheck = proxyConfig
|
||||||
|
|
||||||
if (proxyConfig == null) {
|
if (proxyConfig == null) {
|
||||||
Log.e("[Assistant] [Account Login] Account creator couldn't create proxy config")
|
Log.e("[Assistant] [Account Login] Account creator couldn't create proxy config")
|
||||||
|
|
|
@ -23,9 +23,8 @@ import androidx.lifecycle.MediatorLiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import org.linphone.core.AccountCreator
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.core.ProxyConfig
|
import org.linphone.core.*
|
||||||
import org.linphone.core.TransportType
|
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.utils.Event
|
import org.linphone.utils.Event
|
||||||
|
|
||||||
|
@ -51,8 +50,41 @@ class GenericLoginViewModel(private val accountCreator: AccountCreator) : ViewMo
|
||||||
|
|
||||||
val loginEnabled: MediatorLiveData<Boolean> = MediatorLiveData()
|
val loginEnabled: MediatorLiveData<Boolean> = MediatorLiveData()
|
||||||
|
|
||||||
|
val waitForServerAnswer = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
val leaveAssistantEvent = MutableLiveData<Event<Boolean>>()
|
val leaveAssistantEvent = MutableLiveData<Event<Boolean>>()
|
||||||
|
|
||||||
|
val invalidCredentialsEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||||
|
MutableLiveData<Event<Boolean>>()
|
||||||
|
}
|
||||||
|
|
||||||
|
private var proxyConfigToCheck: ProxyConfig? = null
|
||||||
|
|
||||||
|
private val coreListener = object : CoreListenerStub() {
|
||||||
|
override fun onRegistrationStateChanged(
|
||||||
|
core: Core,
|
||||||
|
cfg: ProxyConfig,
|
||||||
|
state: RegistrationState,
|
||||||
|
message: String?
|
||||||
|
) {
|
||||||
|
if (cfg == proxyConfigToCheck) {
|
||||||
|
Log.i("[Assistant] [Generic Login] Registration state is $state: $message")
|
||||||
|
waitForServerAnswer.value = false
|
||||||
|
if (state == RegistrationState.Ok) {
|
||||||
|
leaveAssistantEvent.value = Event(true)
|
||||||
|
core.removeListener(this)
|
||||||
|
} else if (state == RegistrationState.Failed) {
|
||||||
|
invalidCredentialsEvent.value = Event(true)
|
||||||
|
val authInfo = cfg.findAuthInfo()
|
||||||
|
if (authInfo != null) core.removeAuthInfo(authInfo)
|
||||||
|
core.removeProxyConfig(cfg)
|
||||||
|
proxyConfigToCheck = null
|
||||||
|
core.removeListener(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
transport.value = TransportType.Tls
|
transport.value = TransportType.Tls
|
||||||
|
|
||||||
|
@ -73,6 +105,9 @@ class GenericLoginViewModel(private val accountCreator: AccountCreator) : ViewMo
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createProxyConfig() {
|
fun createProxyConfig() {
|
||||||
|
waitForServerAnswer.value = true
|
||||||
|
coreContext.core.addListener(coreListener)
|
||||||
|
|
||||||
accountCreator.username = username.value
|
accountCreator.username = username.value
|
||||||
accountCreator.password = password.value
|
accountCreator.password = password.value
|
||||||
accountCreator.domain = domain.value
|
accountCreator.domain = domain.value
|
||||||
|
@ -80,15 +115,16 @@ class GenericLoginViewModel(private val accountCreator: AccountCreator) : ViewMo
|
||||||
accountCreator.transport = transport.value
|
accountCreator.transport = transport.value
|
||||||
|
|
||||||
val proxyConfig: ProxyConfig? = accountCreator.createProxyConfig()
|
val proxyConfig: ProxyConfig? = accountCreator.createProxyConfig()
|
||||||
|
proxyConfigToCheck = proxyConfig
|
||||||
|
|
||||||
if (proxyConfig == null) {
|
if (proxyConfig == null) {
|
||||||
Log.e("[Assistant] [Generic Login] Account creator couldn't create proxy config")
|
Log.e("[Assistant] [Generic Login] Account creator couldn't create proxy config")
|
||||||
|
coreContext.core.removeListener(coreListener)
|
||||||
// TODO: show error
|
// TODO: show error
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i("[Assistant] [Generic Login] Proxy config created")
|
Log.i("[Assistant] [Generic Login] Proxy config created")
|
||||||
leaveAssistantEvent.value = Event(true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isLoginButtonEnabled(): Boolean {
|
private fun isLoginButtonEnabled(): Boolean {
|
||||||
|
|
|
@ -75,12 +75,8 @@ class AccountSettingsViewModel(val proxyConfig: ProxyConfig) : GenericSettingsVi
|
||||||
) {
|
) {
|
||||||
if (state == RegistrationState.Cleared && cfg == proxyConfigToDelete) {
|
if (state == RegistrationState.Cleared && cfg == proxyConfigToDelete) {
|
||||||
Log.i("[Account Settings] Proxy config to remove registration is now cleared")
|
Log.i("[Account Settings] Proxy config to remove registration is now cleared")
|
||||||
val authInfo = cfg.findAuthInfo()
|
|
||||||
core.removeProxyConfig(cfg)
|
|
||||||
core.removeAuthInfo(authInfo)
|
|
||||||
|
|
||||||
waitForUnregister.value = false
|
waitForUnregister.value = false
|
||||||
proxyConfigRemovedEvent.value = Event(true)
|
deleteProxyConfig(cfg)
|
||||||
} else {
|
} else {
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
@ -140,10 +136,19 @@ class AccountSettingsViewModel(val proxyConfig: ProxyConfig) : GenericSettingsVi
|
||||||
}
|
}
|
||||||
// isDefault mutable is above
|
// isDefault mutable is above
|
||||||
|
|
||||||
|
private fun deleteProxyConfig(cfg: ProxyConfig) {
|
||||||
|
val authInfo = cfg.findAuthInfo()
|
||||||
|
core.removeProxyConfig(cfg)
|
||||||
|
core.removeAuthInfo(authInfo)
|
||||||
|
proxyConfigRemovedEvent.value = Event(true)
|
||||||
|
}
|
||||||
|
|
||||||
val deleteListener = object : SettingListenerStub() {
|
val deleteListener = object : SettingListenerStub() {
|
||||||
override fun onClicked() {
|
override fun onClicked() {
|
||||||
proxyConfigToDelete = proxyConfig
|
proxyConfigToDelete = proxyConfig
|
||||||
waitForUnregister.value = true
|
|
||||||
|
val registered = proxyConfig.state == RegistrationState.Ok
|
||||||
|
waitForUnregister.value = registered
|
||||||
|
|
||||||
if (core.defaultProxyConfig == proxyConfig) {
|
if (core.defaultProxyConfig == proxyConfig) {
|
||||||
Log.i("[Account Settings] Proxy config was default, let's look for a replacement")
|
Log.i("[Account Settings] Proxy config was default, let's look for a replacement")
|
||||||
|
@ -159,6 +164,11 @@ class AccountSettingsViewModel(val proxyConfig: ProxyConfig) : GenericSettingsVi
|
||||||
proxyConfig.edit()
|
proxyConfig.edit()
|
||||||
proxyConfig.enableRegister(false)
|
proxyConfig.enableRegister(false)
|
||||||
proxyConfig.done()
|
proxyConfig.done()
|
||||||
|
|
||||||
|
if (!registered) {
|
||||||
|
Log.w("[Account Settings] Proxy config isn't registered, don't unregister before removing it")
|
||||||
|
deleteProxyConfig(proxyConfig)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
xmlns:bind="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<data>
|
<data>
|
||||||
<import type="android.view.View"/>
|
<import type="android.view.View"/>
|
||||||
|
@ -235,6 +236,10 @@
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/wait_layout"
|
||||||
|
bind:visibility="@{viewModel.waitForServerAnswer}"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</layout>
|
</layout>
|
||||||
|
|
|
@ -234,6 +234,7 @@
|
||||||
<string name="assistant_error_invalid_email_address">Email address isn\t valid</string>
|
<string name="assistant_error_invalid_email_address">Email address isn\t valid</string>
|
||||||
<string name="assistant_error_username_too_long">Username has too many characters</string>
|
<string name="assistant_error_username_too_long">Username has too many characters</string>
|
||||||
<string name="assistant_error_account_not_activated">Your account has not been validated yet</string>
|
<string name="assistant_error_account_not_activated">Your account has not been validated yet</string>
|
||||||
|
<string name="assistant_error_invalid_credentials">Account does not exist or password does not match</string>
|
||||||
|
|
||||||
<!-- Assistant login -->
|
<!-- Assistant login -->
|
||||||
<string name="assistant_linphone_account">Use your &appName; account</string>
|
<string name="assistant_linphone_account">Use your &appName; account</string>
|
||||||
|
|
Loading…
Reference in a new issue