mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 19:38:08 +00:00
Added QR code remote provisioning
This commit is contained in:
parent
4336266b7f
commit
e4f4396a6b
6 changed files with 37 additions and 7 deletions
|
|
@ -74,6 +74,10 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
|
|||
MutableLiveData<Event<Pair<String, Int>>>()
|
||||
}
|
||||
|
||||
val redToastToShowEvent: MutableLiveData<Event<Pair<String, Int>>> by lazy {
|
||||
MutableLiveData<Event<Pair<String, Int>>>()
|
||||
}
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
private lateinit var coreThread: Handler
|
||||
|
||||
|
|
@ -90,6 +94,19 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
|
|||
message: String?
|
||||
) {
|
||||
Log.i("$TAG Configuring state changed [$status]")
|
||||
if (status == Config.ConfiguringState.Successful) {
|
||||
val text = context.getString(
|
||||
org.linphone.R.string.assistant_qr_code_provisioning_done
|
||||
)
|
||||
greenToastToShowEvent.postValue(Event(Pair(text, org.linphone.R.drawable.smiley)))
|
||||
} else if (status == Config.ConfiguringState.Failed) {
|
||||
val text = context.getString(
|
||||
org.linphone.R.string.assistant_qr_code_provisioning_done
|
||||
)
|
||||
redToastToShowEvent.postValue(
|
||||
Event(Pair(text, org.linphone.R.drawable.warning_circle))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
|
|||
|
|
@ -83,16 +83,13 @@ class QrCodeScannerFragment : Fragment() {
|
|||
|
||||
viewModel.qrCodeFoundEvent.observe(viewLifecycleOwner) {
|
||||
it.consume { isValid ->
|
||||
if (isValid) {
|
||||
(requireActivity() as AssistantActivity).showGreenToast(
|
||||
getString(R.string.toast_assistant_qr_code_valid),
|
||||
R.drawable.check_fat_fill
|
||||
)
|
||||
} else {
|
||||
if (!isValid) {
|
||||
(requireActivity() as AssistantActivity).showRedToast(
|
||||
getString(R.string.toast_assistant_qr_code_invalid),
|
||||
R.drawable.warning_circle
|
||||
)
|
||||
} else {
|
||||
requireActivity().finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,11 @@ class QrCodeViewModel @UiThread constructor() : ViewModel() {
|
|||
val isValidUrl = Patterns.WEB_URL.matcher(result).matches()
|
||||
if (!isValidUrl) {
|
||||
Log.e("$TAG The content of the QR Code doesn't seem to be a valid web URL")
|
||||
} else {
|
||||
Log.i("$TAG QR code URL set, restarting the Core")
|
||||
core.provisioningUri = result
|
||||
coreContext.core.stop()
|
||||
coreContext.core.start()
|
||||
}
|
||||
qrCodeFoundEvent.postValue(Event(isValidUrl))
|
||||
}
|
||||
|
|
|
|||
9
app/src/main/res/drawable/smiley.xml
Normal file
9
app/src/main/res/drawable/smiley.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="256"
|
||||
android:viewportHeight="256">
|
||||
<path
|
||||
android:pathData="M128,24A104,104 0,1 0,232 128,104.11 104.11,0 0,0 128,24ZM128,216a88,88 0,1 1,88 -88A88.1,88.1 0,0 1,128 216ZM80,108a12,12 0,1 1,12 12A12,12 0,0 1,80 108ZM176,108a12,12 0,1 1,-12 -12A12,12 0,0 1,176 108ZM174.93,156c-10.29,17.79 -27.4,28 -46.93,28s-36.63,-10.2 -46.92,-28a8,8 0,1 1,13.84 -8c7.47,12.91 19.21,20 33.08,20s25.61,-7.1 33.07,-20a8,8 0,0 1,13.86 8Z"
|
||||
android:fillColor="#4e6074"/>
|
||||
</vector>
|
||||
|
|
@ -90,7 +90,7 @@
|
|||
android:id="@+id/no_contacts_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""
|
||||
android:text="@string/contacts_list_empty"
|
||||
app:layout_constraintBottom_toTopOf="@id/background"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
|
|
|||
|
|
@ -101,6 +101,8 @@
|
|||
<string name="assistant_country_picker_hint">Country name</string>
|
||||
<string name="assistant_account_login">Login</string>
|
||||
<string name="assistant_scan_qr_code">Scan QR code</string>
|
||||
<string name="assistant_qr_code_provisioning_done">Configuration successfully applied</string>
|
||||
<string name="assistant_qr_code_provisioning_error">Remote configuration failed!</string>
|
||||
<string name="assistant_login_third_party_sip_account">Use a third party SIP account</string>
|
||||
<string name="assistant_no_account_yet">No account yet?</string>
|
||||
<string name="assistant_account_register">Register</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue