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

Commit d3f81b13 authored by Rohit Sekhar's avatar Rohit Sekhar
Browse files
Conflicts:
	app/src/main/java/org/lineageos/recorder/RecorderActivity.java
	app/src/main/res/layout/activity_main.xml
parents d4e77946 9f6f47c4
Loading
Loading
Loading
Loading

.gitattributes

0 → 100644
+9 −0
Original line number Diff line number Diff line
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto eol=lf

# Declare files that will always have CRLF line endings on checkout.
*.cmd text eol=crlf
*.bat text eol=crlf

# Denote all files that are truly binary and should not be modified.
*.png binary
+3 −3
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ android {
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.0-beta02'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
}
+7 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@

        <activity
            android:name=".RecorderActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.Main">
            <intent-filter>
@@ -53,6 +54,12 @@
                android:resource="@xml/shortcuts" />
        </activity>

        <activity
            android:name=".DeleteLastActivity"
            android:excludeFromRecents="true"
            android:label="@string/delete_title"
            android:theme="@style/AppTheme.DialogActivity" />

        <activity
            android:name=".ListActivity"
            android:label="@string/list_title"
+60 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017-2021 The LineageOS Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.lineageos.recorder;

import android.net.Uri;
import android.os.Bundle;

import androidx.activity.ComponentActivity;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;

import org.lineageos.recorder.task.DeleteRecordingTask;
import org.lineageos.recorder.task.TaskExecutor;
import org.lineageos.recorder.utils.LastRecordHelper;
import org.lineageos.recorder.utils.Utils;

public class DeleteLastActivity extends ComponentActivity {
    private TaskExecutor mTaskExecutor;

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

        setFinishOnTouchOutside(true);

        mTaskExecutor = new TaskExecutor();
        getLifecycle().addObserver(mTaskExecutor);

        final Uri uri = LastRecordHelper.getLastItemUri(this);
        if (uri == null) {
            finish();
        } else {
            new AlertDialog.Builder(this)
                    .setTitle(R.string.delete_title)
                    .setMessage(getString(R.string.delete_recording_message))
                    .setPositiveButton(R.string.delete, (d, which) -> mTaskExecutor.runTask(
                            new DeleteRecordingTask(getContentResolver(), uri), () -> {
                                d.dismiss();
                                Utils.cancelShareNotification(this);
                                LastRecordHelper.setLastItem(this, null);
                            }))
                    .setNegativeButton(R.string.cancel, null)
                    .setOnDismissListener(d -> finish())
                    .show();
        }
    }
}
+57 −75
Original line number Diff line number Diff line
@@ -16,13 +16,8 @@
package org.lineageos.recorder;

import android.Manifest;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -30,50 +25,37 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;

import org.lineageos.recorder.utils.LastRecordHelper;
import org.lineageos.recorder.utils.Utils;

public class DialogActivity extends AppCompatActivity {
    public static final String EXTRA_TITLE = "dialogTitle";
    public static final String EXTRA_DELETE_LAST_RECORDING = "deleteLastItem";
    private static final int REQUEST_LOCATION_PERMS = 214;

    private SwitchCompat mLocationSwitch;

    private SharedPreferences mPrefs;

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

        setFinishOnTouchOutside(true);

        mPrefs = getSharedPreferences(Utils.PREFS, 0);

        Intent intent = getIntent();
        boolean deleteLastRecording = intent.getBooleanExtra(EXTRA_DELETE_LAST_RECORDING, false);

        if (deleteLastRecording) {
            deleteLastItem();
            return;
        }

        int dialogTitle = intent.getIntExtra(EXTRA_TITLE, 0);

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

        if (dialogTitle != 0) {
            dialog.setTitle(dialogTitle);
        final boolean isRecording = Utils.isRecording(this);

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

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
@@ -113,49 +95,57 @@ public class DialogActivity extends AppCompatActivity {
        finish();
    }

    private void deleteLastItem() {
        Uri uri = LastRecordHelper.getLastItemUri(this);
        AlertDialog dialog = LastRecordHelper.deleteFile(this, uri);
        dialog.setOnDismissListener(d -> finish());
        dialog.show();
    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(0, android.R.anim.fade_out);
    }

    @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 = getTagWithLocation();
        if (tagWithLocation && !hasLocationPerm) {
            setTagWithLocation(false);
    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()) {
                    setTagWithLocation(true);
                        Utils.setTagWithLocation(this, true);
                    } else {
                        askLocationPermission();
                    }
                } else {
                setTagWithLocation(false);
                    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() {
@@ -168,18 +158,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);
        }
    }
}
Loading