Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit f4ad2daf authored by 2bllw8's avatar 2bllw8 Committed by Michael Bestas
Browse files

Recorder: Don't get location if the preference is disabled

Change-Id: I5296ca0dd9d580f7c4702dd77880b8f1a4023877
parent 3fe6eb4f
Loading
Loading
Loading
Loading
+5 −18
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
package org.lineageos.recorder;

import android.Manifest;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -35,16 +34,12 @@ public class DialogActivity extends AppCompatActivity {

    private SwitchCompat mLocationSwitch;

    private SharedPreferences mPrefs;

    @Override
    protected void onCreate(@Nullable Bundle savedInstance) {
        super.onCreate(savedInstance);

        setFinishOnTouchOutside(true);

        mPrefs = getSharedPreferences(Utils.PREFS, 0);

        new AlertDialog.Builder(this)
                .setTitle(R.string.settings_title)
                .setView(setupAsSettingsScreen())
@@ -95,21 +90,21 @@ public class DialogActivity extends AppCompatActivity {
        final View view = inflater.inflate(R.layout.dialog_content_settings, null);
        mLocationSwitch = view.findViewById(R.id.dialog_content_settings_location_switch);
        boolean hasLocationPerm = hasLocationPermission();
        boolean tagWithLocation = getTagWithLocation();
        boolean tagWithLocation = Utils.getTagWithLocation(this);
        if (tagWithLocation && !hasLocationPerm) {
            setTagWithLocation(false);
            Utils.setTagWithLocation(this, false);
            tagWithLocation = false;
        }
        mLocationSwitch.setChecked(tagWithLocation);
        mLocationSwitch.setOnCheckedChangeListener((button, isChecked) -> {
            if (isChecked) {
                if (hasLocationPermission()) {
                    setTagWithLocation(true);
                    Utils.setTagWithLocation(this, true);
                } else {
                    askLocationPermission();
                }
            } else {
                setTagWithLocation(false);
                Utils.setTagWithLocation(this, false);
            }
        });

@@ -137,18 +132,10 @@ public class DialogActivity extends AppCompatActivity {
                REQUEST_LOCATION_PERMS);
    }

    private void setTagWithLocation(boolean enabled) {
        mPrefs.edit().putBoolean(Utils.PREF_TAG_WITH_LOCATION, enabled).apply();
    }

    private boolean getTagWithLocation() {
        return mPrefs.getBoolean(Utils.PREF_TAG_WITH_LOCATION, false);
    }

    private void toggleAfterPermissionRequest(int requestCode) {
        if (requestCode == REQUEST_LOCATION_PERMS) {
            mLocationSwitch.setChecked(true);
            setTagWithLocation(true);
            Utils.setTagWithLocation(this, true);
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ public final class LocationHelper {

    @Nullable
    private Location getLastGoodLocation() {
        if (locationManager == null) {
        if (locationManager == null || !Utils.getTagWithLocation(context)) {
            return null;
        }
        Location lastGoodLocation;
+13 −2
Original line number Diff line number Diff line
@@ -38,8 +38,8 @@ public final class Utils {
    public static final String PREF_RECORDING_NOTHING = "nothing";
    private static final String PREF_RECORDING_SOUND = "sound";
    private static final String PREF_RECORDING_PAUSED = "paused";
    public static final String PREF_TAG_WITH_LOCATION = "tag_with_location";
    public static final String PREF_RECORDING_QUALITY = "recording_quality";
    private static final String PREF_TAG_WITH_LOCATION = "tag_with_location";
    private static final String PREF_RECORDING_QUALITY = "recording_quality";

    private Utils() {
    }
@@ -153,6 +153,17 @@ public final class Utils {
        return prefs.getInt(PREF_RECORDING_QUALITY, 0) == 1;
    }

    public static void setTagWithLocation(@NonNull Context context, boolean tagWithLocation) {
        SharedPreferences prefs = context.getSharedPreferences(PREFS, 0);
        prefs.edit().putBoolean(PREF_TAG_WITH_LOCATION, tagWithLocation).apply();
    }

    public static boolean getTagWithLocation(@NonNull Context context) {
        SharedPreferences prefs = context.getSharedPreferences(PREFS, 0);
        return prefs.getBoolean(PREF_TAG_WITH_LOCATION, false);
    }


    public enum UiStatus {
        NOTHING,
        SOUND,