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

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

Recorder: Simplify DialogActivity

Change-Id: I4723cf0d72b239e655ee739810765a4bc6735006
parent f4ad2daf
Loading
Loading
Loading
Loading
+52 −32
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package org.lineageos.recorder;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -40,11 +38,24 @@ public class DialogActivity extends AppCompatActivity {

        setFinishOnTouchOutside(true);

        new AlertDialog.Builder(this)
        final AlertDialog dialog = new AlertDialog.Builder(this)
                .setTitle(R.string.settings_title)
                .setView(setupAsSettingsScreen())
                .setView(R.layout.dialog_content_settings)
                .setOnDismissListener(dialogInterface -> finish())
                .show();

        final boolean isRecording = Utils.isRecording(this);

        mLocationSwitch = dialog.findViewById(
                R.id.dialog_content_settings_location_switch);
        if (mLocationSwitch != null) {
            setupLocationSwitch(mLocationSwitch, isRecording);
        }
        final SwitchCompat highQualitySwitch = dialog.findViewById(
                R.id.dialog_content_settings_high_quality_switch);
        if (highQualitySwitch != null) {
            setupHighQualitySwitch(highQualitySwitch, isRecording);
        }
    }

    @Override
@@ -84,19 +95,27 @@ public class DialogActivity extends AppCompatActivity {
        finish();
    }

    @NonNull
    private View setupAsSettingsScreen() {
        LayoutInflater inflater = getLayoutInflater();
        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 = Utils.getTagWithLocation(this);
        if (tagWithLocation && !hasLocationPerm) {
    private void setupLocationSwitch(@NonNull SwitchCompat locationSwitch,
                                     boolean isRecording) {
        final boolean tagWithLocation;
        if (Utils.getTagWithLocation(this)) {
            if (hasLocationPermission()) {
                tagWithLocation = true;
            } else {
                // Permission revoked -> disabled feature
                Utils.setTagWithLocation(this, false);
                tagWithLocation = false;
            }
        mLocationSwitch.setChecked(tagWithLocation);
        mLocationSwitch.setOnCheckedChangeListener((button, isChecked) -> {
        } else {
            tagWithLocation = false;
        }

        locationSwitch.setChecked(tagWithLocation);

        if (isRecording) {
            locationSwitch.setEnabled(false);
        } else {
            locationSwitch.setOnCheckedChangeListener((button, isChecked) -> {
                if (isChecked) {
                    if (hasLocationPermission()) {
                        Utils.setTagWithLocation(this, true);
@@ -107,19 +126,20 @@ public class DialogActivity extends AppCompatActivity {
                    Utils.setTagWithLocation(this, false);
                }
            });
        }
    }

        SwitchCompat highQualitySwitch =
                view.findViewById(R.id.dialog_content_settings_high_quality_switch);
        boolean highQuality = Utils.getRecordInHighQuality(this);
    private void setupHighQualitySwitch(@NonNull SwitchCompat highQualitySwitch,
                                        boolean isRecording) {
        final boolean highQuality = Utils.getRecordInHighQuality(this);
        highQualitySwitch.setChecked(highQuality);
        highQualitySwitch.setOnCheckedChangeListener(((buttonView, isChecked) ->
                Utils.setRecordingHighQuality(this, isChecked)));
        if (Utils.isRecording(this)) {
            mLocationSwitch.setEnabled(false);

        if (isRecording) {
            highQualitySwitch.setEnabled(false);
        } else {
            highQualitySwitch.setOnCheckedChangeListener((button, isChecked) ->
                    Utils.setRecordingHighQuality(this, isChecked));
        }

        return view;
    }

    private boolean hasLocationPermission() {