mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-05-07 05:53:07 +00:00
Disable account creation if push notifications aren't available
This commit is contained in:
parent
e5617d53ee
commit
4336266b7f
7 changed files with 64 additions and 4 deletions
|
|
@ -126,6 +126,16 @@ class RegisterFragment : Fragment() {
|
|||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
|
||||
})
|
||||
|
||||
viewModel.pushNotificationsAvailable.observe(viewLifecycleOwner) { available ->
|
||||
if (!available) {
|
||||
val text = getString(R.string.assistant_account_register_unavailable_no_push_toast)
|
||||
(requireActivity() as AssistantActivity).showRedToast(
|
||||
text,
|
||||
R.drawable.warning_circle
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.normalizedPhoneNumberEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { number ->
|
||||
showPhoneNumberConfirmationDialog(number)
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ import org.linphone.core.Factory
|
|||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.AppUtils
|
||||
import org.linphone.utils.Event
|
||||
import org.linphone.utils.LinphoneUtils
|
||||
|
||||
class AccountCreationViewModel @UiThread constructor() : ViewModel() {
|
||||
companion object {
|
||||
|
|
@ -74,6 +75,8 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val createEnabled = MediatorLiveData<Boolean>()
|
||||
|
||||
val pushNotificationsAvailable = MutableLiveData<Boolean>()
|
||||
|
||||
val confirmationMessage = MutableLiveData<String>()
|
||||
|
||||
val smsCodeFirstDigit = MutableLiveData<String>()
|
||||
|
|
@ -274,6 +277,8 @@ class AccountCreationViewModel @UiThread constructor() : ViewModel() {
|
|||
operationInProgress.value = false
|
||||
|
||||
coreContext.postOnCoreThread { core ->
|
||||
pushNotificationsAvailable.postValue(LinphoneUtils.arePushNotificationsAvailable(core))
|
||||
|
||||
val dialPlans = Factory.instance().dialPlans.toList()
|
||||
for (dialPlan in dialPlans) {
|
||||
dialPlansList.add(dialPlan)
|
||||
|
|
|
|||
|
|
@ -42,6 +42,6 @@ class CallLogHistoryModel @WorkerThread constructor(val callLog: CallLog) {
|
|||
)
|
||||
|
||||
isSuccessful.postValue(callLog.status == Call.Status.Success)
|
||||
iconResId.postValue(LinphoneUtils.getIconResId(callLog.status, callLog.dir))
|
||||
iconResId.postValue(LinphoneUtils.getCallIconResId(callLog.status, callLog.dir))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ class CallLogModel @WorkerThread constructor(private val callLog: CallLog) {
|
|||
friendExists = false
|
||||
}
|
||||
|
||||
iconResId.postValue(LinphoneUtils.getIconResId(callLog.status, callLog.dir))
|
||||
iconResId.postValue(LinphoneUtils.getCallIconResId(callLog.status, callLog.dir))
|
||||
}
|
||||
|
||||
@UiThread
|
||||
|
|
|
|||
|
|
@ -160,9 +160,49 @@ class LinphoneUtils {
|
|||
return core.defaultAccount?.params?.audioVideoConferenceFactoryAddress != null
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
fun arePushNotificationsAvailable(core: Core): Boolean {
|
||||
if (!core.isPushNotificationAvailable) {
|
||||
Log.w(
|
||||
"$TAG Push notifications aren't available in the Core, disable account creation"
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
val pushConfig = core.pushNotificationConfig
|
||||
if (pushConfig == null) {
|
||||
Log.w(
|
||||
"$TAG Core's push notifications configuration is null, disable account creation"
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
if (pushConfig.provider.isNullOrEmpty()) {
|
||||
Log.w(
|
||||
"$TAG Core's push notifications configuration provider is null or empty, disable account creation"
|
||||
)
|
||||
return false
|
||||
}
|
||||
if (pushConfig.param.isNullOrEmpty()) {
|
||||
Log.w(
|
||||
"$TAG Core's push notifications configuration param is null or empty, disable account creation"
|
||||
)
|
||||
return false
|
||||
}
|
||||
if (pushConfig.prid.isNullOrEmpty()) {
|
||||
Log.w(
|
||||
"$TAG Core's push notifications configuration prid is null or empty, disable account creation"
|
||||
)
|
||||
return false
|
||||
}
|
||||
|
||||
Log.i("$TAG Push notifications seems to be available")
|
||||
return true
|
||||
}
|
||||
|
||||
@AnyThread
|
||||
@IntegerRes
|
||||
fun getIconResId(callStatus: Status, callDir: Dir): Int {
|
||||
fun getCallIconResId(callStatus: Status, callDir: Dir): Int {
|
||||
return when (callStatus) {
|
||||
Status.Missed -> {
|
||||
if (callDir == Dir.Outgoing) {
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@
|
|||
<androidx.appcompat.widget.AppCompatEditText
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/username"
|
||||
android:enabled="@{viewModel.pushNotificationsAvailable}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginStart="16dp"
|
||||
|
|
@ -131,6 +132,7 @@
|
|||
<androidx.appcompat.widget.AppCompatEditText
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/phone_number"
|
||||
android:enabled="@{viewModel.pushNotificationsAvailable}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="50dp"
|
||||
android:paddingStart="120dp"
|
||||
|
|
@ -151,6 +153,7 @@
|
|||
<androidx.appcompat.widget.AppCompatSpinner
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/prefix"
|
||||
android:enabled="@{viewModel.pushNotificationsAvailable}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:paddingStart="20dp"
|
||||
|
|
@ -192,6 +195,7 @@
|
|||
<androidx.appcompat.widget.AppCompatEditText
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/password"
|
||||
android:enabled="@{viewModel.pushNotificationsAvailable}"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_marginStart="16dp"
|
||||
|
|
@ -237,7 +241,7 @@
|
|||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:onClick="@{() -> viewModel.confirmPhoneNumber()}"
|
||||
android:enabled="@{viewModel.createEnabled && !viewModel.operationInProgress, default=false}"
|
||||
android:enabled="@{viewModel.createEnabled && viewModel.pushNotificationsAvailable && !viewModel.operationInProgress, default=false}"
|
||||
style="@style/primary_button_label_style"
|
||||
android:id="@+id/create"
|
||||
android:layout_width="0dp"
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@
|
|||
<string name="assistant_secure_mode_default_title">Default</string>
|
||||
<string name="assistant_secure_mode_interoperable_title">Interoperable</string>
|
||||
<string name="assistant_secure_mode_finish_account_login">Continue</string>
|
||||
<string name="assistant_account_register_unavailable_no_push_toast">Push notifications not available, account creation disabled</string>
|
||||
<string name="assistant_account_register_username_already_in_use_error">This account already exists</string>
|
||||
<string name="assistant_account_register_username_invalid_characters_error">Invalid characters: capital letters and special characters are not allowed</string>
|
||||
<string name="assistant_account_register_username_too_short_error">Username is too short</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue