diff --git a/src/main/java/org/havenapp/main/PreferenceManager.java b/src/main/java/org/havenapp/main/PreferenceManager.java
index 7dc3c990..24711e77 100644
--- a/src/main/java/org/havenapp/main/PreferenceManager.java
+++ b/src/main/java/org/havenapp/main/PreferenceManager.java
@@ -86,6 +86,7 @@ public class PreferenceManager {
public static final String REMOTE_ACCESS_CRED = "remote_access_credential";
private static final String SIGNAL_USERNAME = "signal_username";
+ private static final String SIGNAL_VERIFIED_USERNAME = "signal_verified_username";
private static final String FIRST_LAUNCH = "first_launch";
@@ -119,6 +120,16 @@ public void setFirstLaunch(boolean firstLaunch) {
prefsEditor.commit();
}
+ /**
+ * Returns the Signal username registered. This may not be a good way to check for
+ * Signal set up since this may not be verified.
+ *
+ * Usages should be checked with {@link #isSignalVerified()}
+ *
+ * @see #isSignalVerified()
+ *
+ * @return the Signal username; null when nothing is set up
+ */
public String getSignalUsername ()
{
return appSharedPrefs.getString(SIGNAL_USERNAME,null);
@@ -130,6 +141,37 @@ public void setSignalUsername (String signalUsername)
prefsEditor.commit();
}
+ /**
+ * Returns the Signal username verified. This may not be a good way to check for
+ * Signal set up since this may invalidated by a call to register with a different username.
+ *
+ * Usages should be checked with {@link #isSignalVerified()}
+ *
+ * @see #isSignalVerified()
+ *
+ * @return the verified Signal username; null when no Signal username is verified even though registered.
+ */
+ @Nullable
+ public String getVerifiedSignalUsername() {
+ return appSharedPrefs.getString(SIGNAL_VERIFIED_USERNAME, null);
+ }
+
+ public void setVerifiedSignalUsername(String verifiedSignalUsername) {
+ prefsEditor.putString(SIGNAL_VERIFIED_USERNAME, verifiedSignalUsername);
+ prefsEditor.commit();
+ }
+
+ /**
+ * Checks if Signal is registered and verified for the Signal username returned by
+ * {@link #getSignalUsername()}
+ *
+ * @return true iff registered Signal username is same as that of the verified one.
+ */
+ public boolean isSignalVerified() {
+ return !TextUtils.isEmpty(getSignalUsername()) &&
+ getSignalUsername().equals(getVerifiedSignalUsername());
+ }
+
public void activateRemoteAccess (boolean active) {
prefsEditor.putBoolean(REMOTE_ACCESS_ACTIVE,active);
prefsEditor.commit();
diff --git a/src/main/java/org/havenapp/main/SettingsFragment.java b/src/main/java/org/havenapp/main/SettingsFragment.java
index b53a7457..5134ed9a 100644
--- a/src/main/java/org/havenapp/main/SettingsFragment.java
+++ b/src/main/java/org/havenapp/main/SettingsFragment.java
@@ -217,6 +217,7 @@ public void onCreatePreferences(Bundle bundle, String s) {
});
checkSignalUsername();
+ checkSignalUsernameVerification();
((EditTextPreference) findPreference(PreferenceManager.VERIFY_SIGNAL)).setText("");
askForPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, 1);
@@ -410,6 +411,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
findPreference(PreferenceManager.REGISTER_SIGNAL).setSummary(R.string.register_signal_desc);
}
onRemoteNotificationParameterChange();
+ checkSignalUsernameVerification();
break;
case PreferenceManager.VERIFY_SIGNAL: {
String text = ((EditTextPreference) findPreference(PreferenceManager.VERIFY_SIGNAL)).getText();
@@ -418,6 +420,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}
activateSignal(preferences.getSignalUsername(), text);
onRemoteNotificationParameterChange();
+ checkSignalUsernameVerification();
break;
}
case PreferenceManager.REMOTE_PHONE_NUMBER:
@@ -585,12 +588,26 @@ private void checkSignalUsername() {
}
}
+ private void checkSignalUsernameVerification() {
+ String signalUsername = preferences.getSignalUsername();
+
+ // this will fail for all users currently has signal verified
+ if (checkValidString(signalUsername) &&
+ signalUsername.equals(preferences.getVerifiedSignalUsername())) {
+ findPreference(PreferenceManager.VERIFY_SIGNAL)
+ .setSummary(R.string.verification_dialog_summary_verified);
+ } else {
+ findPreference(PreferenceManager.VERIFY_SIGNAL)
+ .setSummary(R.string.verification_dialog_summary);
+ }
+ }
+
private void activateSignal(String username, String verifyCode) {
SignalSender sender = SignalSender.getInstance(mActivity, username);
if (TextUtils.isEmpty(verifyCode)) {
- ProgressDialog progressDialog = ProgressDialog.show(getContext(), "Registering to Signal",
- "Please wait while we register you to Signal services");
+ ProgressDialog progressDialog = ProgressDialog.show(getContext(), getString(R.string.registering_to_signal),
+ getString(R.string.signal_registration_desc));
sender.register(preferences.getVoiceVerificationEnabled(),
new SignalExecutorTask.TaskResult() {
@Override
@@ -610,14 +627,16 @@ public void onFailure(@NonNull String msg) {
}
});
} else {
- ProgressDialog progressDialog = ProgressDialog.show(getContext(), "Verifying",
- "Please wait while we verify your registration to Signal services");
+ ProgressDialog progressDialog = ProgressDialog.show(getContext(), getString(R.string.verifying_signal),
+ getString(R.string.verifying_signal_desc));
sender.verify(verifyCode, new SignalExecutorTask.TaskResult() {
@Override
public void onSuccess(@NonNull String msg) {
if (isAdded() && getActivity() != null) {
progressDialog.dismiss();
}
+ // mark that the current registered signal username is verified
+ preferences.setVerifiedSignalUsername(preferences.getSignalUsername());
Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
}
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 6bc6acf3..35ef029e 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -117,6 +117,7 @@
Enter a remote phone number to send alert notifications to
A phone number to send from using Signal
Tap to verify your Signal number
+ Signal number is verified
Enter a phone number to send a test alert notification message to
Test notifications…
Service Address
@@ -177,5 +178,9 @@
Recording…
LIGHT DETECTED
Clean deleted logs from disk
+ Registering to Signal
+ Please wait while we register you to Signal services
+ Verifying
+ Please wait while we verify your registration to Signal services