mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 19:38:08 +00:00
Added clickable links to conditions & privacy policy dialog
This commit is contained in:
parent
a7a22f39d2
commit
b08aa2ae1f
11 changed files with 101 additions and 26 deletions
|
|
@ -194,6 +194,34 @@ class LoginFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
model.privacyPolicyClickedEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
val browserIntent = Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse("https://www.linphone.org/privacy-policy")
|
||||
)
|
||||
try {
|
||||
startActivity(browserIntent)
|
||||
} catch (e: Exception) {
|
||||
Log.e("$TAG Can't start activity: $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
model.generalTermsClickedEvent.observe(viewLifecycleOwner) {
|
||||
it.consume {
|
||||
val browserIntent = Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse("https://www.linphone.org/general-terms")
|
||||
)
|
||||
try {
|
||||
startActivity(browserIntent)
|
||||
} catch (e: Exception) {
|
||||
Log.e("$TAG Can't start activity: $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,15 +19,73 @@
|
|||
*/
|
||||
package org.linphone.ui.assistant.model
|
||||
|
||||
import android.text.SpannableString
|
||||
import android.text.Spanned
|
||||
import android.text.style.ClickableSpan
|
||||
import android.view.View
|
||||
import androidx.annotation.UiThread
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import java.util.regex.Pattern
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.utils.Event
|
||||
|
||||
class AcceptConditionsAndPolicyDialogModel @UiThread constructor() {
|
||||
companion object {
|
||||
private const val TAG = "[Accept Terms & Policy Dialog Model]"
|
||||
}
|
||||
|
||||
val message = MutableLiveData<SpannableString>()
|
||||
|
||||
val dismissEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
val conditionsAcceptedEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
val generalTermsClickedEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
val privacyPolicyClickedEvent = MutableLiveData<Event<Boolean>>()
|
||||
|
||||
init {
|
||||
val privacy = "politique de confidentialité"
|
||||
val terms = "conditions d'utilisation"
|
||||
|
||||
val label = "En continuant, vous notre $privacy et nos $terms."
|
||||
val spannable = SpannableString(label)
|
||||
|
||||
val termsMatcher = Pattern.compile(terms).matcher(label)
|
||||
if (termsMatcher.find()) {
|
||||
val clickableSpan: ClickableSpan = object : ClickableSpan() {
|
||||
override fun onClick(widget: View) {
|
||||
Log.i("$TAG Clicked on general terms link")
|
||||
generalTermsClickedEvent.value = Event(true)
|
||||
}
|
||||
}
|
||||
spannable.setSpan(
|
||||
clickableSpan,
|
||||
termsMatcher.start(0),
|
||||
termsMatcher.end(),
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
}
|
||||
|
||||
val policyMatcher = Pattern.compile(privacy).matcher(label)
|
||||
if (policyMatcher.find()) {
|
||||
val clickableSpan: ClickableSpan = object : ClickableSpan() {
|
||||
override fun onClick(widget: View) {
|
||||
Log.i("$TAG Clicked on privacy policy link")
|
||||
privacyPolicyClickedEvent.value = Event(true)
|
||||
}
|
||||
}
|
||||
spannable.setSpan(
|
||||
clickableSpan,
|
||||
policyMatcher.start(0),
|
||||
policyMatcher.end(),
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
}
|
||||
|
||||
message.value = spannable
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun dismiss() {
|
||||
dismissEvent.value = Event(true)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import android.app.Dialog
|
|||
import android.content.Context
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Window
|
||||
import android.view.WindowManager
|
||||
|
|
@ -60,6 +61,7 @@ class DialogUtils {
|
|||
false
|
||||
)
|
||||
binding.viewModel = viewModel
|
||||
binding.message.movementMethod = LinkMovementMethod.getInstance()
|
||||
|
||||
return getDialog(context, binding)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:onClick="@{() -> viewModel.dismiss()}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dialog_background_shadow"
|
||||
|
|
@ -38,7 +36,9 @@
|
|||
app:layout_constraintBottom_toBottomOf="@id/anchor"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/title" />
|
||||
app:layout_constraintTop_toTopOf="@id/title"
|
||||
android:clickable="true"
|
||||
android:focusable="true" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style_800"
|
||||
|
|
@ -63,8 +63,9 @@
|
|||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="En continuant, vous notre politique de confidentialité et nos conditions d'utilisation."
|
||||
android:text="@{viewModel.message, default=`En continuant, vous notre politique de confidentialité et nos conditions d'utilisation.`}"
|
||||
android:textSize="14sp"
|
||||
android:autoLink="web"
|
||||
app:layout_constraintBottom_toTopOf="@id/cancel"
|
||||
app:layout_constraintStart_toStartOf="@id/dialog_background"
|
||||
app:layout_constraintEnd_toEndOf="@id/dialog_background"
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:onClick="@{() -> viewModel.dismiss()}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dialog_background_shadow"
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:onClick="@{() -> viewModel.dismiss()}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dialog_background_shadow"
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:onClick="@{() -> viewModel.dismiss()}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dialog_background_shadow"
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:onClick="@{() -> viewModel.dismiss()}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dialog_background_shadow"
|
||||
|
|
|
|||
|
|
@ -13,9 +13,7 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:onClick="@{dismissClickListener}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dialog_background_shadow"
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:onClick="@{() -> viewModel.dismiss()}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dialog_background_shadow"
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@
|
|||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:onClick="@{() -> viewModel.dismiss()}"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dialog_background_shadow"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue