Skip to content

Commit

Permalink
Merge branch 'percy-g2-bug-fix-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Apr 5, 2018
2 parents ea404d9 + 4398598 commit 38defb2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ dependencies {
implementation 'com.takisoft.fix:preference-v7:27.1.0.0'
implementation 'com.wdullaer:materialdatetimepicker:3.5.2'

compile 'com.googlecode.libphonenumber:libphonenumber:8.7.0'
implementation('com.mikepenz:aboutlibraries:6.0.2@aar') {
transitive = true
}

}
}
28 changes: 24 additions & 4 deletions src/main/java/org/havenapp/main/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.view.MenuItem;
import android.widget.Toast;

import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat;
import com.wdullaer.materialdatetimepicker.time.TimePickerDialog;

Expand All @@ -38,6 +39,7 @@
import org.havenapp.main.ui.MicrophoneConfigureActivity;

import java.io.File;
import java.util.Locale;

import info.guardianproject.netcipher.proxy.OrbotHelper;

Expand Down Expand Up @@ -83,6 +85,19 @@ public void onCreatePreferencesFix(Bundle bundle, String s) {
((SwitchPreferenceCompat) findPreference(PreferenceManager.SMS_ACTIVE)).setChecked(true);
}

findPreference(PreferenceManager.SMS_NUMBER).setOnPreferenceClickListener(preference -> {
if (preferences.getSmsNumber().isEmpty()) {
((EditTextPreference) findPreference(PreferenceManager.SMS_NUMBER)).setText(getCountryCode());
}
return false;
});
findPreference(PreferenceManager.REGISTER_SIGNAL).setOnPreferenceClickListener(preference -> {
if (preferences.getSignalUsername() == null) {
((EditTextPreference) findPreference(PreferenceManager.REGISTER_SIGNAL)).setText(getCountryCode());
}
return false;
});

if (checkValidString(preferences.getSmsNumber())) {
((EditTextPreference) findPreference(PreferenceManager.SMS_NUMBER)).setText(preferences.getSmsNumber().trim());
findPreference(PreferenceManager.SMS_NUMBER).setSummary(preferences.getSmsNumber().trim());
Expand Down Expand Up @@ -307,15 +322,15 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
case PreferenceManager.REGISTER_SIGNAL:
String signalNum = ((EditTextPreference) findPreference(PreferenceManager.REGISTER_SIGNAL)).getText();

if (checkValidString(signalNum)) {
if (checkValidString(signalNum) && !getCountryCode().equalsIgnoreCase(signalNum)) {
signalNum = "+" + signalNum.trim().replaceAll("[^0-9]", "");

preferences.setSignalUsername(signalNum);
findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(signalNum);

resetSignal(preferences.getSignalUsername());
activateSignal(preferences.getSignalUsername(), null);
} else {
} else if (!getCountryCode().equalsIgnoreCase(signalNum)) {
preferences.setSignalUsername("");
findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(R.string.register_signal_desc);
}
Expand Down Expand Up @@ -414,6 +429,11 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}
}

String getCountryCode() {
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
return "+" + String.valueOf(phoneUtil.getCountryCodeForRegion(Locale.getDefault().getCountry()));
}

private void setPhoneNumber() {
boolean smsActive = ((SwitchPreferenceCompat) findPreference(PreferenceManager.SMS_ACTIVE)).isChecked();
String phoneNumber = ((EditTextPreference) findPreference(PreferenceManager.SMS_NUMBER)).getText();
Expand All @@ -423,10 +443,10 @@ private void setPhoneNumber() {
preferences.activateSms(false);
}

if (checkValidString(phoneNumber)) {
if (checkValidString(phoneNumber) && !getCountryCode().equalsIgnoreCase(phoneNumber)) {
preferences.setSmsNumber(phoneNumber.trim());
findPreference(PreferenceManager.SMS_NUMBER).setSummary(phoneNumber.trim());
} else {
} else if (!getCountryCode().equalsIgnoreCase(phoneNumber)){
preferences.setSmsNumber("");
findPreference(PreferenceManager.SMS_NUMBER).setSummary(R.string.sms_dialog_message);
}
Expand Down

0 comments on commit 38defb2

Please sign in to comment.