From fe16aa91c0589e6777b42e189df9cf6bd5d661c4 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 8 Feb 2021 17:10:07 +0100 Subject: [PATCH] Added read & agreed to general terms and privacy policy mandatory checkbox in assistant --- .../assistant/fragments/WelcomeFragment.kt | 58 +++++++++++++++++++ .../assistant/viewmodels/WelcomeViewModel.kt | 7 +++ .../java/org/linphone/core/CorePreferences.kt | 6 ++ .../assistant_welcome_fragment.xml | 21 +++++++ .../res/layout/assistant_welcome_fragment.xml | 30 ++++++++-- app/src/main/res/values/strings.xml | 5 ++ 6 files changed, 123 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/linphone/activities/assistant/fragments/WelcomeFragment.kt b/app/src/main/java/org/linphone/activities/assistant/fragments/WelcomeFragment.kt index 8fa87cb4e..3c1cc57c0 100644 --- a/app/src/main/java/org/linphone/activities/assistant/fragments/WelcomeFragment.kt +++ b/app/src/main/java/org/linphone/activities/assistant/fragments/WelcomeFragment.kt @@ -19,8 +19,17 @@ */ package org.linphone.activities.assistant.fragments +import android.content.Intent +import android.net.Uri import android.os.Bundle +import android.text.SpannableString +import android.text.Spanned +import android.text.method.LinkMovementMethod +import android.text.style.ClickableSpan +import android.view.View import androidx.lifecycle.ViewModelProvider +import java.util.regex.Pattern +import org.linphone.LinphoneApplication.Companion.corePreferences import org.linphone.R import org.linphone.activities.GenericFragment import org.linphone.activities.assistant.viewmodels.WelcomeViewModel @@ -63,5 +72,54 @@ class WelcomeFragment : GenericFragment() { binding.setRemoteProvisioningClickListener { navigateToRemoteProvisioning() } + + viewModel.termsAndPrivacyAccepted.observe(viewLifecycleOwner, { + if (it) corePreferences.readAndAgreeTermsAndPrivacy = true + }) + + setUpTermsAndPrivacyLinks() + } + + private fun setUpTermsAndPrivacyLinks() { + val terms = getString(R.string.assistant_general_terms) + val privacy = getString(R.string.assistant_privacy_policy) + + val label = getString( + R.string.assistant_read_and_agree_terms, + terms, + privacy + ) + val spannable = SpannableString(label) + + val termsMatcher = Pattern.compile(terms).matcher(label) + if (termsMatcher.find()) { + val clickableSpan: ClickableSpan = object : ClickableSpan() { + override fun onClick(widget: View) { + val browserIntent = Intent( + Intent.ACTION_VIEW, + Uri.parse(getString(R.string.assistant_general_terms_link)) + ) + startActivity(browserIntent) + } + } + 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) { + val browserIntent = Intent( + Intent.ACTION_VIEW, + Uri.parse(getString(R.string.assistant_privacy_policy_link)) + ) + startActivity(browserIntent) + } + } + spannable.setSpan(clickableSpan, policyMatcher.start(0), policyMatcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) + } + + binding.termsAndPrivacy.text = spannable + binding.termsAndPrivacy.movementMethod = LinkMovementMethod.getInstance() } } diff --git a/app/src/main/java/org/linphone/activities/assistant/viewmodels/WelcomeViewModel.kt b/app/src/main/java/org/linphone/activities/assistant/viewmodels/WelcomeViewModel.kt index 8dfd7fc7c..d31a2ba89 100644 --- a/app/src/main/java/org/linphone/activities/assistant/viewmodels/WelcomeViewModel.kt +++ b/app/src/main/java/org/linphone/activities/assistant/viewmodels/WelcomeViewModel.kt @@ -19,6 +19,7 @@ */ package org.linphone.activities.assistant.viewmodels +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import org.linphone.LinphoneApplication.Companion.corePreferences @@ -27,4 +28,10 @@ class WelcomeViewModel : ViewModel() { val showLinphoneLogin: Boolean = corePreferences.showLinphoneLogin val showGenericLogin: Boolean = corePreferences.showGenericLogin val showRemoteProvisioning: Boolean = corePreferences.showRemoteProvisioning + + val termsAndPrivacyAccepted = MutableLiveData() + + init { + termsAndPrivacyAccepted.value = corePreferences.readAndAgreeTermsAndPrivacy + } } diff --git a/app/src/main/java/org/linphone/core/CorePreferences.kt b/app/src/main/java/org/linphone/core/CorePreferences.kt index a5b457ba8..c570e0554 100644 --- a/app/src/main/java/org/linphone/core/CorePreferences.kt +++ b/app/src/main/java/org/linphone/core/CorePreferences.kt @@ -55,6 +55,12 @@ class CorePreferences constructor(private val context: Context) { config.setBool("app", "keep_service_alive", value) } + var readAndAgreeTermsAndPrivacy: Boolean + get() = config.getBool("app", "read_and_agree_terms_and_privacy", false) + set(value) { + config.setBool("app", "read_and_agree_terms_and_privacy", value) + } + /* UI */ var forcePortrait: Boolean diff --git a/app/src/main/res/layout-land/assistant_welcome_fragment.xml b/app/src/main/res/layout-land/assistant_welcome_fragment.xml index 25fd5a04e..8eb656873 100644 --- a/app/src/main/res/layout-land/assistant_welcome_fragment.xml +++ b/app/src/main/res/layout-land/assistant_welcome_fragment.xml @@ -66,6 +66,27 @@ android:layout_height="match_parent" android:columnCount="2"> + + + + + + + + + + + + + + + + \nThanks to your phone number, your friends will find you more easily.\n\n You will see in your address book who is using &appName; and your friends will know that they can reach you on &appName; as well.\n \nYour friends will find you more easily if you link your account to your phone number\n\nYou will see in your address book who is using &appName; and your friends will know that they can reach you on &appName; as well.\n You can only use your phone number with one &appName; account.\n\nIf you had already linked your number to an other account but you prefer to use this one, simply link it now and your number will automatically be moved to this account. + https://www.linphone.org/general-terms + https://www.linphone.org/privacy-policy + terms of use + privacy policy + I accept Belledonne Communications\' %1$s and %2$s Only digits are expected here