From 9510378c89ac17e21c1777bf1cab656df1348bdf Mon Sep 17 00:00:00 2001
From: aringot <alexis.ringot@fhstp.ac.at>
Date: Thu, 30 Aug 2018 13:25:55 +0200
Subject: [PATCH] Small refactoring to avoid creating an alert if we do not
 display it

---
 .../at/ac/fhstp/sonicontrol/MainActivity.java | 60 +++++++++----------
 1 file changed, 30 insertions(+), 30 deletions(-)

diff --git a/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/MainActivity.java b/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/MainActivity.java
index cd0b74b1..46d1d6ba 100644
--- a/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/MainActivity.java
+++ b/SoniControl/app/src/main/java/at/ac/fhstp/sonicontrol/MainActivity.java
@@ -1292,39 +1292,39 @@ public class MainActivity extends BaseActivity implements Scan.DetectionListener
     }
 
     public void activateAlertNoLocationEnabled() {
-        final AlertDialog.Builder activateLocationDialog = new AlertDialog.Builder(this);
-        LayoutInflater locationAlertInflater = LayoutInflater.from(this);
-        View cbLocationAlertLayout = locationAlertInflater.inflate(R.layout.alert_checkbox, null);
-        final CheckBox dontShowAgain = (CheckBox)cbLocationAlertLayout.findViewById(R.id.cbDontAskAgain);
-        activateLocationDialog.setView(cbLocationAlertLayout);
-        activateLocationDialog.setTitle(R.string.alert_location_is_off_title)
-                .setMessage(R.string.alert_location_is_off_message)
-                .setCancelable(true)
-                .setPositiveButton(R.string.alert_location_is_off_positive, new DialogInterface.OnClickListener() {
-                    public void onClick(DialogInterface dialog, int which) {
-                        if (dontShowAgain.isChecked()) {
-                            SharedPreferences.Editor editor = sharedPref.edit();
-                            editor.putBoolean(ConfigConstants.SETTINGS_ALERT_LOCATION_IS_OFF_DONT_ASK_AGAIN, true);
-                            editor.apply();
+        boolean skipMessage = sharedPref.getBoolean(ConfigConstants.SETTINGS_ALERT_LOCATION_IS_OFF_DONT_ASK_AGAIN, ConfigConstants.SETTINGS_ALERT_LOCATION_IS_OFF_DONT_ASK_AGAIN_DEFAULT);
+        if (!skipMessage) {
+            final AlertDialog.Builder activateLocationDialog = new AlertDialog.Builder(this);
+            LayoutInflater locationAlertInflater = LayoutInflater.from(this);
+            View cbLocationAlertLayout = locationAlertInflater.inflate(R.layout.alert_checkbox, null);
+            final CheckBox dontShowAgain = (CheckBox)cbLocationAlertLayout.findViewById(R.id.cbDontAskAgain);
+            activateLocationDialog.setView(cbLocationAlertLayout);
+            activateLocationDialog.setTitle(R.string.alert_location_is_off_title)
+                    .setMessage(R.string.alert_location_is_off_message)
+                    .setCancelable(true)
+                    .setPositiveButton(R.string.alert_location_is_off_positive, new DialogInterface.OnClickListener() {
+                        public void onClick(DialogInterface dialog, int which) {
+                            if (dontShowAgain.isChecked()) {
+                                SharedPreferences.Editor editor = sharedPref.edit();
+                                editor.putBoolean(ConfigConstants.SETTINGS_ALERT_LOCATION_IS_OFF_DONT_ASK_AGAIN, true);
+                                editor.apply();
+                            }
+                            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
+                            startActivity(intent);
                         }
-                        Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
-                        startActivity(intent);
-                    }
-                })
-                .setNegativeButton(R.string.alert_location_is_off_negative, new DialogInterface.OnClickListener() {
-                    public void onClick(DialogInterface dialog, int which) {
-                        if (dontShowAgain.isChecked()) {
-                            SharedPreferences.Editor editor = sharedPref.edit();
-                            editor.putBoolean(ConfigConstants.SETTINGS_ALERT_LOCATION_IS_OFF_DONT_ASK_AGAIN, true);
-                            editor.apply();
+                    })
+                    .setNegativeButton(R.string.alert_location_is_off_negative, new DialogInterface.OnClickListener() {
+                        public void onClick(DialogInterface dialog, int which) {
+                            if (dontShowAgain.isChecked()) {
+                                SharedPreferences.Editor editor = sharedPref.edit();
+                                editor.putBoolean(ConfigConstants.SETTINGS_ALERT_LOCATION_IS_OFF_DONT_ASK_AGAIN, true);
+                                editor.apply();
+                            }
+                            alertLocation.cancel();
                         }
-                        alertLocation.cancel();
-                    }
-                })
-                .setIcon(android.R.drawable.ic_dialog_info);
+                    })
+                    .setIcon(android.R.drawable.ic_dialog_info);
 
-        boolean skipMessage = sharedPref.getBoolean(ConfigConstants.SETTINGS_ALERT_LOCATION_IS_OFF_DONT_ASK_AGAIN, ConfigConstants.SETTINGS_ALERT_LOCATION_IS_OFF_DONT_ASK_AGAIN_DEFAULT);
-        if (!skipMessage) {
             alertLocation = activateLocationDialog.show();
         }
     }
-- 
GitLab