From a332334250a2f1808c33e0b13cde77db8ffbf9d2 Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Mon, 8 Feb 2021 17:51:23 +0100 Subject: [PATCH] Added checkbox to accept general terms and privacy policy --- .../assistant/MenuAssistantActivity.java | 101 ++++++++++++++++++ .../settings/LinphonePreferences.java | 9 ++ .../main/res/layout-land/assistant_menu.xml | 21 ++++ app/src/main/res/layout/assistant_menu.xml | 21 ++++ app/src/main/res/values/strings.xml | 5 + 5 files changed, 157 insertions(+) diff --git a/app/src/main/java/org/linphone/assistant/MenuAssistantActivity.java b/app/src/main/java/org/linphone/assistant/MenuAssistantActivity.java index 367955124..92b099a4e 100644 --- a/app/src/main/java/org/linphone/assistant/MenuAssistantActivity.java +++ b/app/src/main/java/org/linphone/assistant/MenuAssistantActivity.java @@ -20,11 +20,22 @@ package org.linphone.assistant; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.Spanned; +import android.text.method.LinkMovementMethod; +import android.text.style.ClickableSpan; import android.view.KeyEvent; import android.view.View; +import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.linphone.R; import org.linphone.settings.LinphonePreferences; @@ -122,6 +133,8 @@ public class MenuAssistantActivity extends AssistantActivity { PhoneAccountCreationAssistantActivity.class)); finish(); } + + setUpTermsAndPrivacyLinks(); } @Override @@ -158,4 +171,92 @@ public class MenuAssistantActivity extends AssistantActivity { } return super.onKeyDown(keyCode, event); } + + private void setUpTermsAndPrivacyLinks() { + String terms = getString(R.string.assistant_general_terms); + String privacy = getString(R.string.assistant_privacy_policy); + + String label = getString(R.string.assistant_read_and_agree_terms, terms, privacy); + Spannable spannable = new SpannableString(label); + + Matcher termsMatcher = Pattern.compile(terms).matcher(label); + if (termsMatcher.find()) { + ClickableSpan clickableSpan = + new ClickableSpan() { + @Override + public void onClick(@NonNull View widget) { + Intent browserIntent = + new 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); + } + + Matcher privacyMatcher = Pattern.compile(privacy).matcher(label); + if (privacyMatcher.find()) { + ClickableSpan clickableSpan = + new ClickableSpan() { + @Override + public void onClick(@NonNull View widget) { + Intent browserIntent = + new Intent( + Intent.ACTION_VIEW, + Uri.parse( + getString( + R.string + .assistant_privacy_policy_link))); + startActivity(browserIntent); + } + }; + spannable.setSpan( + clickableSpan, + privacyMatcher.start(0), + privacyMatcher.end(), + Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } + + TextView termsAndPrivacy = findViewById(R.id.terms_and_privacy); + final CheckBox termsAndPrivacyCheckBox = findViewById(R.id.terms_and_privacy_checkbox); + + termsAndPrivacy.setText(spannable); + termsAndPrivacy.setMovementMethod(new LinkMovementMethod()); + if (LinphonePreferences.instance().getReadAndAgreeTermsAndPrivacy()) { + termsAndPrivacyCheckBox.setEnabled(false); + termsAndPrivacyCheckBox.setChecked(true); + } else { + final TextView accountCreation = findViewById(R.id.account_creation); + final TextView accountConnection = findViewById(R.id.account_connection); + final TextView genericConnection = findViewById(R.id.generic_connection); + final TextView remoteConfiguration = findViewById(R.id.remote_configuration); + accountCreation.setEnabled(false); + accountConnection.setEnabled(false); + genericConnection.setEnabled(false); + remoteConfiguration.setEnabled(false); + + termsAndPrivacyCheckBox.setOnCheckedChangeListener( + new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (isChecked) { + LinphonePreferences.instance().setReadAndAgreeTermsAndPrivacy(true); + termsAndPrivacyCheckBox.setEnabled(false); + accountCreation.setEnabled(true); + accountConnection.setEnabled(true); + genericConnection.setEnabled(true); + remoteConfiguration.setEnabled(true); + } + } + }); + } + } } diff --git a/app/src/main/java/org/linphone/settings/LinphonePreferences.java b/app/src/main/java/org/linphone/settings/LinphonePreferences.java index 43e611e33..b946c3333 100644 --- a/app/src/main/java/org/linphone/settings/LinphonePreferences.java +++ b/app/src/main/java/org/linphone/settings/LinphonePreferences.java @@ -203,6 +203,15 @@ public class LinphonePreferences { return ringtone; } + public boolean getReadAndAgreeTermsAndPrivacy() { + if (getConfig() == null) return false; + return getConfig().getBool("app", "read_and_agree_terms_and_privacy", false); + } + + public void setReadAndAgreeTermsAndPrivacy(boolean value) { + getConfig().setBool("app", "read_and_agree_terms_and_privacy", value); + } + // Accounts settings private ProxyConfig getProxyConfig(int n) { if (getLc() == null) return null; diff --git a/app/src/main/res/layout-land/assistant_menu.xml b/app/src/main/res/layout-land/assistant_menu.xml index 1dd2ec3e7..92509cce2 100644 --- a/app/src/main/res/layout-land/assistant_menu.xml +++ b/app/src/main/res/layout-land/assistant_menu.xml @@ -49,6 +49,27 @@ android:layout_height="match_parent" android:columnCount="2"> + + + + + + + + + + + + + + + + You can only use your phone number with one Linphone 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. Too much SMS have been sent to this number in a short period of time, try again in 24 hours. Account doesn\'t exist + 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 Invalid email