Skip to content

Commit

Permalink
Recorder: Move from tasks to coroutines and flows
Browse files Browse the repository at this point in the history
Query code stolen from Glimpse

Co-authored-by: Luca Stefani <[email protected]>
Change-Id: Ibed443b7e0b0860a1a4511987c9a8b5cde14096a
  • Loading branch information
SebaUbuntu and luca020400 committed Sep 9, 2024
1 parent 73e00e2 commit c587995
Show file tree
Hide file tree
Showing 36 changed files with 971 additions and 865 deletions.
6 changes: 6 additions & 0 deletions app/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@ android_app {

static_libs: [
// DO NOT EDIT THIS SECTION MANUALLY
"androidx.activity_activity-ktx",
"androidx.appcompat_appcompat",
"androidx.core_core-ktx",
"Recorder_com.google.android.material_material",
"androidx-constraintlayout_constraintlayout",
"androidx.lifecycle_lifecycle-livedata-ktx",
"androidx.lifecycle_lifecycle-service",
"androidx.lifecycle_lifecycle-viewmodel-ktx",
"androidx.recyclerview_recyclerview",
"androidx.recyclerview_recyclerview-selection",
],

sdk_version: "34",
Expand Down
12 changes: 11 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,20 @@ dependencies {
// Align versions of all Kotlin components
implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.8.0"))

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

// Lifecycle
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.7.0")
implementation("androidx.lifecycle:lifecycle-service:2.7.0")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0")

// Recyclerview
implementation("androidx.recyclerview:recyclerview:1.3.2")
implementation("androidx.recyclerview:recyclerview-selection:1.1.0")
}

configure<GenerateBpPluginExtension> {
Expand Down
20 changes: 9 additions & 11 deletions app/src/main/java/org/lineageos/recorder/DeleteLastActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ package org.lineageos.recorder
import android.content.DialogInterface
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import org.lineageos.recorder.task.DeleteRecordingTask
import org.lineageos.recorder.task.TaskExecutor
import kotlinx.coroutines.launch
import org.lineageos.recorder.utils.PreferencesManager
import org.lineageos.recorder.utils.Utils
import org.lineageos.recorder.viewmodels.RecordingsViewModel

class DeleteLastActivity : ComponentActivity() {
private val taskExecutor = TaskExecutor()
// View models
private val model: RecordingsViewModel by viewModels()

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

setFinishOnTouchOutside(true)

lifecycle.addObserver(taskExecutor)

val preferences = PreferencesManager(this)
val uri = preferences.lastItemUri ?: run {
finish()
Expand All @@ -34,12 +34,10 @@ class DeleteLastActivity : ComponentActivity() {
.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)
lifecycleScope.launch {
model.deleteRecordings(uri)
preferences.lastItemUri = null
d.dismiss()
}
}
.setNegativeButton(R.string.cancel, null)
Expand Down
Loading

0 comments on commit c587995

Please sign in to comment.