From 5d78b612a533de134174ca2988b4ebd87f980cd8 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 28 Oct 2023 16:54:32 +0200 Subject: [PATCH] current stand --- app/src/main/AndroidManifest.xml | 4 + .../services/AudioRecorderTileService.kt | 75 ++++++++++++------- .../myzel394/alibi/services/TempActivity.kt | 24 ++++++ 3 files changed, 75 insertions(+), 28 deletions(-) create mode 100644 app/src/main/java/app/myzel394/alibi/services/TempActivity.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 515a6ad..fde0fe2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -35,6 +35,10 @@ + + diff --git a/app/src/main/java/app/myzel394/alibi/services/AudioRecorderTileService.kt b/app/src/main/java/app/myzel394/alibi/services/AudioRecorderTileService.kt index e2408d5..9df45ab 100644 --- a/app/src/main/java/app/myzel394/alibi/services/AudioRecorderTileService.kt +++ b/app/src/main/java/app/myzel394/alibi/services/AudioRecorderTileService.kt @@ -1,13 +1,17 @@ package app.myzel394.alibi.services +import android.app.Activity import android.app.ActivityManager import android.content.ComponentName import android.content.Context import android.content.Intent import android.content.ServiceConnection +import android.os.Bundle import android.os.IBinder +import android.os.PersistableBundle import android.service.quicksettings.Tile import android.service.quicksettings.TileService +import androidx.compose.animation.core.updateTransition import androidx.core.content.ContextCompat import app.myzel394.alibi.R import app.myzel394.alibi.dataStore @@ -29,17 +33,17 @@ class AudioRecorderTileService : TileService() { override fun onStartListening() { super.onStartListening() + println("started =================") - println("Before start") scope.launch { - println("Getting recorder...") val state = getRecorderState() - println("All right updating") updateTile(state) } } override fun onStopListening() { + println("stoppeeeeeeeeeeeed =================") + runCatching { connection?.let { unbindService(it) } connection = null @@ -48,32 +52,44 @@ class AudioRecorderTileService : TileService() { super.onStopListening() } - private fun startRecording() { - scope.launch { - dataStore.data.collectLatest { appSettings -> - val notificationDetails = appSettings.notificationSettings?.let { - RecorderNotificationHelper.NotificationDetails.fromNotificationSettings( - this@AudioRecorderTileService, - it, - ) - } - - val intent = - Intent(this@AudioRecorderTileService, AudioRecorderService::class.java).apply { - action = "init" - - if (notificationDetails != null) { - putExtra( - "notificationDetails", - Json.encodeToString( - RecorderNotificationHelper.NotificationDetails.serializer(), - notificationDetails, - ), - ) - } - } - ContextCompat.startForegroundService(this@AudioRecorderTileService, intent) + private suspend fun startRecording() { + dataStore.data.collectLatest { appSettings -> + val notificationDetails = appSettings.notificationSettings?.let { + RecorderNotificationHelper.NotificationDetails.fromNotificationSettings( + this@AudioRecorderTileService, + it, + ) } + + val intent = + Intent(this, AudioRecorderService::class.java).apply { + action = "init" + } + ContextCompat.startForegroundService(this, intent) + + /* + val intent = + Intent(this@AudioRecorderTileService, AudioRecorderService::class.java).apply { + action = "init" + + if (notificationDetails != null) { + putExtra( + "notificationDetails", + Json.encodeToString( + RecorderNotificationHelper.NotificationDetails.serializer(), + notificationDetails, + ), + ) + } + } + ContextCompat.startForegroundService(this@AudioRecorderTileService, intent) + + println("recorder") + val recorder = getRecorder() + println("recorder eta ${recorder}") + recorder?.startRecording() + + */ } } @@ -84,6 +100,9 @@ class AudioRecorderTileService : TileService() { when (state) { RecorderState.IDLE -> { + // Already update to provide a fast UI response + // Optimistically assume that the state will change + updateTile(RecorderState.RECORDING) AudioRecorderExporter.clearAllRecordings(this@AudioRecorderTileService) startRecording() } diff --git a/app/src/main/java/app/myzel394/alibi/services/TempActivity.kt b/app/src/main/java/app/myzel394/alibi/services/TempActivity.kt new file mode 100644 index 0000000..40d3d1d --- /dev/null +++ b/app/src/main/java/app/myzel394/alibi/services/TempActivity.kt @@ -0,0 +1,24 @@ +package app.myzel394.alibi.services + +import android.app.Activity +import android.content.Intent +import android.os.Bundle +import android.os.PersistableBundle +import androidx.core.content.ContextCompat + + +class TempActivity : Activity() { + override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) { + super.onCreate(savedInstanceState, persistentState) + } + + override fun onStart() { + super.onStart() + + val intent = + Intent(this, AudioRecorderService::class.java).apply { + action = "init" + } + ContextCompat.startForegroundService(this, intent) + } +}