Added checkbox to accept general terms and privacy policy

This commit is contained in:
Sylvain Berfini 2021-02-08 17:51:23 +01:00
parent a8ddc9a494
commit a332334250
5 changed files with 157 additions and 0 deletions

View file

@ -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);
}
}
});
}
}
}

View file

@ -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;

View file

@ -49,6 +49,27 @@
android:layout_height="match_parent"
android:columnCount="2">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_columnSpan="2"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_margin="10dp">
<CheckBox
android:id="@+id/terms_and_privacy_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/terms_and_privacy"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/account_creation"
style="@style/button_font"

View file

@ -49,6 +49,27 @@
android:layout_height="match_parent"
android:columnCount="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill"
android:layout_columnSpan="1"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layout_margin="10dp">
<CheckBox
android:id="@+id/terms_and_privacy_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/terms_and_privacy"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/account_creation"
style="@style/button_font"

View file

@ -135,6 +135,11 @@
<string name="phone_number_link_info_content_already_account">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.</string>
<string name="phone_number_overuse">Too much SMS have been sent to this number in a short period of time, try again in 24 hours.</string>
<string name="account_doesnt_exist">Account doesn\'t exist</string>
<string name="assistant_general_terms_link" translatable="false">https://www.linphone.org/general-terms</string>
<string name="assistant_privacy_policy_link" translatable="false">https://www.linphone.org/privacy-policy</string>
<string name="assistant_general_terms">terms of use</string>
<string name="assistant_privacy_policy">privacy policy</string>
<string name="assistant_read_and_agree_terms">I accept Belledonne Communications\' %1$s and %2$s</string>
<!-- Status -->
<string name="invalid_email">Invalid email</string>