Browse Source

Show a confirmation dialog on registration and verification success

Signed-off-by: Arka Prava Basu <arkaprava94@gmail.com>
Arka Prava Basu 4 months ago
parent
commit
6f4e95f297

+ 33 - 3
src/main/java/org/havenapp/main/SettingsFragment.java

@@ -9,6 +9,7 @@ import android.annotation.SuppressLint;
9 9
 import android.app.Activity;
10 10
 import android.app.ProgressDialog;
11 11
 import android.content.Context;
12
+import android.content.DialogInterface;
12 13
 import android.content.Intent;
13 14
 import android.content.SharedPreferences;
14 15
 import android.content.pm.PackageManager;
@@ -38,6 +39,7 @@ import java.io.File;
38 39
 import java.util.Locale;
39 40
 
40 41
 import androidx.annotation.NonNull;
42
+import androidx.appcompat.app.AlertDialog;
41 43
 import androidx.appcompat.app.AppCompatActivity;
42 44
 import androidx.core.app.ActivityCompat;
43 45
 import androidx.core.content.ContextCompat;
@@ -420,7 +422,6 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
420 422
                 }
421 423
                 activateSignal(preferences.getSignalUsername(), text);
422 424
                 onRemoteNotificationParameterChange();
423
-                checkSignalUsernameVerification();
424 425
                 break;
425 426
             }
426 427
             case PreferenceManager.REMOTE_PHONE_NUMBER:
@@ -615,7 +616,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
615 616
                     if (isAdded() && getActivity() != null) {
616 617
                         progressDialog.dismiss();
617 618
                     }
618
-                    Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
619
+                    showRegistrationSuccessDialog();
619 620
                 }
620 621
 
621 622
                 @Override
@@ -637,7 +638,8 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
637 638
                     }
638 639
                     // mark that the current registered signal username is verified
639 640
                     preferences.setVerifiedSignalUsername(preferences.getSignalUsername());
640
-                    Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
641
+                    checkSignalUsernameVerification();
642
+                    showVerificationSuccessDialog();
641 643
                 }
642 644
 
643 645
                 @Override
@@ -651,6 +653,34 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
651 653
         }
652 654
     }
653 655
 
656
+    private void showRegistrationSuccessDialog() {
657
+        if (!isAdded() || getActivity() == null) {
658
+            return;
659
+        }
660
+
661
+        new AlertDialog.Builder(getActivity())
662
+                .setTitle(R.string.registration_successful)
663
+                .setMessage(getString(R.string.signal_reg_success_desc, preferences.getSignalUsername()))
664
+                .setPositiveButton(R.string.verify, (dialog, which) -> {
665
+                    dialog.dismiss();
666
+                    findPreference(PreferenceManager.VERIFY_SIGNAL).performClick();
667
+                })
668
+                .setNegativeButton(R.string.ok, (dialog, which) -> dialog.dismiss())
669
+                .show();
670
+    }
671
+
672
+    private void showVerificationSuccessDialog() {
673
+        if (!isAdded() || getActivity() == null) {
674
+            return;
675
+        }
676
+
677
+        new AlertDialog.Builder(getActivity())
678
+                .setTitle(R.string.verification_successful)
679
+                .setMessage(R.string.signal_verification_success_desc)
680
+                .setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss())
681
+                .show();
682
+    }
683
+
654 684
     private void resetSignal(String username) {
655 685
         if (checkValidString((username))) {
656 686
             SignalSender sender = SignalSender.getInstance(mActivity, username.trim());

+ 5 - 0
src/main/res/values/strings.xml

@@ -182,5 +182,10 @@
182 182
     <string name="signal_registration_desc">Please wait while we register you to Signal services</string>
183 183
     <string name="verifying_signal">Verifying</string>
184 184
     <string name="verifying_signal_desc">Please wait while we verify your registration to Signal services</string>
185
+    <string name="ok">Ok</string>
186
+    <string name="registration_successful">Registration Successful</string>
187
+    <string name="signal_reg_success_desc">You have successfully registered to Signal services. Next Step is to verify the registration for %s</string>
188
+    <string name="verification_successful">Verification Successful</string>
189
+    <string name="signal_verification_success_desc">All set to send Haven alerts from Signal!</string>
185 190
 
186 191
 </resources>