current stand

This commit is contained in:
Myzel394 2023-10-28 16:54:32 +02:00
parent 7bdae55876
commit 5d78b612a5
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
3 changed files with 75 additions and 28 deletions

View File

@ -35,6 +35,10 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".services.TempActivity"
android:exported="false" />
<receiver <receiver
android:name=".receivers.LocalChangeReceiver" android:name=".receivers.LocalChangeReceiver"
android:exported="false"> android:exported="false">

View File

@ -1,13 +1,17 @@
package app.myzel394.alibi.services package app.myzel394.alibi.services
import android.app.Activity
import android.app.ActivityManager import android.app.ActivityManager
import android.content.ComponentName import android.content.ComponentName
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.ServiceConnection import android.content.ServiceConnection
import android.os.Bundle
import android.os.IBinder import android.os.IBinder
import android.os.PersistableBundle
import android.service.quicksettings.Tile import android.service.quicksettings.Tile
import android.service.quicksettings.TileService import android.service.quicksettings.TileService
import androidx.compose.animation.core.updateTransition
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import app.myzel394.alibi.R import app.myzel394.alibi.R
import app.myzel394.alibi.dataStore import app.myzel394.alibi.dataStore
@ -29,17 +33,17 @@ class AudioRecorderTileService : TileService() {
override fun onStartListening() { override fun onStartListening() {
super.onStartListening() super.onStartListening()
println("started =================")
println("Before start")
scope.launch { scope.launch {
println("Getting recorder...")
val state = getRecorderState() val state = getRecorderState()
println("All right updating")
updateTile(state) updateTile(state)
} }
} }
override fun onStopListening() { override fun onStopListening() {
println("stoppeeeeeeeeeeeed =================")
runCatching { runCatching {
connection?.let { unbindService(it) } connection?.let { unbindService(it) }
connection = null connection = null
@ -48,32 +52,44 @@ class AudioRecorderTileService : TileService() {
super.onStopListening() super.onStopListening()
} }
private fun startRecording() { private suspend fun startRecording() {
scope.launch { dataStore.data.collectLatest { appSettings ->
dataStore.data.collectLatest { appSettings -> val notificationDetails = appSettings.notificationSettings?.let {
val notificationDetails = appSettings.notificationSettings?.let { RecorderNotificationHelper.NotificationDetails.fromNotificationSettings(
RecorderNotificationHelper.NotificationDetails.fromNotificationSettings( this@AudioRecorderTileService,
this@AudioRecorderTileService, it,
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)
} }
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) { when (state) {
RecorderState.IDLE -> { RecorderState.IDLE -> {
// Already update to provide a fast UI response
// Optimistically assume that the state will change
updateTile(RecorderState.RECORDING)
AudioRecorderExporter.clearAllRecordings(this@AudioRecorderTileService) AudioRecorderExporter.clearAllRecordings(this@AudioRecorderTileService)
startRecording() startRecording()
} }

View File

@ -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)
}
}