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

Unverified Commit 1a569148 authored by Sebastiano Barezzi's avatar Sebastiano Barezzi
Browse files

Recorder: Add some null checks

:P

Change-Id: I9f933009a3b3ad1ca630a9ec0c422be4d987404a
parent b5635038
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
//
// Copyright (C) 2017-2021 The LineageOS Project
// Copyright (C) 2017-2024 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.
@@ -21,8 +21,8 @@ android_app {
    resource_dirs: ["src/main/res"],

    srcs: [
        "src/main/java/**/*.java",
        "src/main/gen/**/*.java"
        "src/main/java/**/*.kt",
        "src_aosp/main/java/**/*.kt",
    ],

    product_specific: true,
@@ -30,6 +30,7 @@ android_app {
    static_libs: [
        // DO NOT EDIT THIS SECTION MANUALLY
        "androidx.appcompat_appcompat",
        "androidx.core_core-ktx",
        "Recorder_com.google.android.material_material",
        "androidx-constraintlayout_constraintlayout",
    ],
+11 −2
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import org.lineageos.generatebp.models.Module

plugins {
    id("com.android.application")
    id("kotlin-android")
}

apply {
@@ -52,13 +53,21 @@ android {
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    // Align versions of all Kotlin components
    implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))

    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("androidx.core:core-ktx:1.10.1")
    implementation("com.google.android.material:material:1.9.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
}

app/src/main/gen/BuildConfig.java

deleted100644 → 0
+0 −20
Original line number Diff line number Diff line
/*
 * Copyright (C) 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;

public final class BuildConfig {
    public static final String APPLICATION_ID = "org.lineageos.recorder";
}
+0 −63
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 com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.lineageos.recorder.task.DeleteRecordingTask;
import org.lineageos.recorder.task.TaskExecutor;
import org.lineageos.recorder.utils.PreferencesManager;
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);

        PreferencesManager preferences = new PreferencesManager(this);

        final Uri uri = preferences.getLastItemUri();
        if (uri == null) {
            finish();
        } else {
            new MaterialAlertDialogBuilder(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);
                                preferences.setLastItemUri(null);
                            }))
                    .setNegativeButton(R.string.cancel, null)
                    .setOnDismissListener(d -> finish())
                    .show();
        }
    }
}
+49 −0
Original line number Diff line number Diff line
/*
 * SPDX-FileCopyrightText: 2017-2024 The LineageOS Project
 * SPDX-License-Identifier: Apache-2.0
 */

package org.lineageos.recorder

import android.content.DialogInterface
import android.os.Bundle
import androidx.activity.ComponentActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.lineageos.recorder.task.DeleteRecordingTask
import org.lineageos.recorder.task.TaskExecutor
import org.lineageos.recorder.utils.PreferencesManager
import org.lineageos.recorder.utils.Utils

class DeleteLastActivity : ComponentActivity() {
    private val taskExecutor = TaskExecutor()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setFinishOnTouchOutside(true)

        lifecycle.addObserver(taskExecutor)

        val preferences = PreferencesManager(this)
        val uri = preferences.lastItemUri ?: run {
            finish()
            return
        }

        MaterialAlertDialogBuilder(this)
            .setTitle(R.string.delete_title)
            .setMessage(getString(R.string.delete_recording_message))
            .setPositiveButton(R.string.delete) { d: DialogInterface, _: Int ->
                taskExecutor.runTask(
                    DeleteRecordingTask(contentResolver, uri)
                ) {
                    d.dismiss()
                    Utils.cancelShareNotification(this)
                    preferences.lastItemUri = null
                }
            }
            .setNegativeButton(R.string.cancel, null)
            .setOnDismissListener { finish() }
            .show()
    }
}
Loading