Skip to content

Commit

Permalink
Show a confirmation dialog on registration and verification success
Browse files Browse the repository at this point in the history
Signed-off-by: Arka Prava Basu <[email protected]>
  • Loading branch information
archie94 committed Mar 26, 2019
1 parent 35c968f commit 6f4e95f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/main/java/org/havenapp/main/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
Expand Down Expand Up @@ -38,6 +39,7 @@
import java.util.Locale;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
Expand Down Expand Up @@ -420,7 +422,6 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}
activateSignal(preferences.getSignalUsername(), text);
onRemoteNotificationParameterChange();
checkSignalUsernameVerification();
break;
}
case PreferenceManager.REMOTE_PHONE_NUMBER:
Expand Down Expand Up @@ -615,7 +616,7 @@ public void onSuccess(@NonNull String msg) {
if (isAdded() && getActivity() != null) {
progressDialog.dismiss();
}
Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
showRegistrationSuccessDialog();
}

@Override
Expand All @@ -637,7 +638,8 @@ public void onSuccess(@NonNull String msg) {
}
// mark that the current registered signal username is verified
preferences.setVerifiedSignalUsername(preferences.getSignalUsername());
Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
checkSignalUsernameVerification();
showVerificationSuccessDialog();
}

@Override
Expand All @@ -651,6 +653,34 @@ public void onFailure(@NonNull String msg) {
}
}

private void showRegistrationSuccessDialog() {
if (!isAdded() || getActivity() == null) {
return;
}

new AlertDialog.Builder(getActivity())
.setTitle(R.string.registration_successful)
.setMessage(getString(R.string.signal_reg_success_desc, preferences.getSignalUsername()))
.setPositiveButton(R.string.verify, (dialog, which) -> {
dialog.dismiss();
findPreference(PreferenceManager.VERIFY_SIGNAL).performClick();
})
.setNegativeButton(R.string.ok, (dialog, which) -> dialog.dismiss())
.show();
}

private void showVerificationSuccessDialog() {
if (!isAdded() || getActivity() == null) {
return;
}

new AlertDialog.Builder(getActivity())
.setTitle(R.string.verification_successful)
.setMessage(R.string.signal_verification_success_desc)
.setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
.show();
}

private void resetSignal(String username) {
if (checkValidString((username))) {
SignalSender sender = SignalSender.getInstance(mActivity, username.trim());
Expand Down
5 changes: 5 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,10 @@
<string name="signal_registration_desc">Please wait while we register you to Signal services</string>
<string name="verifying_signal">Verifying</string>
<string name="verifying_signal_desc">Please wait while we verify your registration to Signal services</string>
<string name="ok">Ok</string>
<string name="registration_successful">Registration Successful</string>
<string name="signal_reg_success_desc">You have successfully registered to Signal services. Next Step is to verify the registration for %s</string>
<string name="verification_successful">Verification Successful</string>
<string name="signal_verification_success_desc">All set to send Haven alerts from Signal!</string>

</resources>

0 comments on commit 6f4e95f

Please sign in to comment.