mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
refactor: Improve structure
This commit is contained in:
parent
3ff6638e95
commit
824fc4ef4f
@ -73,5 +73,7 @@ dependencies {
|
||||
|
||||
implementation 'com.arthenica:ffmpeg-kit-full:5.1'
|
||||
|
||||
implementation "androidx.datastore:datastore-preferences:1.0.0"
|
||||
|
||||
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
|
||||
}
|
@ -29,7 +29,7 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service android:name=".RecorderService" android:foregroundServiceType="microphone" />
|
||||
<service android:name=".services.RecorderService" android:foregroundServiceType="microphone" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -10,6 +10,7 @@ import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import app.myzel394.locationtest.ui.screens.AudioRecorder
|
||||
import app.myzel394.locationtest.ui.theme.LocationTestTheme
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package app.myzel394.locationtest
|
||||
package app.myzel394.locationtest.services
|
||||
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
@ -12,9 +12,9 @@ import android.os.Looper
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.core.app.NotificationCompat
|
||||
import app.myzel394.locationtest.R
|
||||
import com.arthenica.ffmpegkit.FFmpegKit
|
||||
import com.arthenica.ffmpegkit.ReturnCode
|
||||
import kotlinx.coroutines.NonCancellable.start
|
||||
import java.io.File
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
@ -30,7 +30,7 @@ class RecorderService: Service() {
|
||||
|
||||
private var mediaRecorder: MediaRecorder? = null
|
||||
private var onError: MediaRecorder.OnErrorListener? = null
|
||||
private var onStateChange: (RecorderService.RecorderState) -> Unit = {}
|
||||
private var onStateChange: (RecorderState) -> Unit = {}
|
||||
|
||||
private var counter = 0
|
||||
|
||||
@ -66,7 +66,7 @@ class RecorderService: Service() {
|
||||
this.onError = onError
|
||||
}
|
||||
|
||||
fun setOnStateChangeListener(onStateChange: (RecorderService.RecorderState) -> Unit) {
|
||||
fun setOnStateChangeListener(onStateChange: (RecorderState) -> Unit) {
|
||||
this.onStateChange = onStateChange
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package app.myzel394.locationtest
|
||||
package app.myzel394.locationtest.ui.screens
|
||||
|
||||
import android.Manifest
|
||||
import android.content.ComponentName
|
||||
@ -10,13 +10,13 @@ import android.os.IBinder
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.core.content.ContextCompat
|
||||
import app.myzel394.locationtest.services.RecorderService
|
||||
|
||||
@Composable
|
||||
fun AudioRecorder() {
|
||||
@ -30,7 +30,7 @@ fun AudioRecorder() {
|
||||
val connection = remember {
|
||||
object : ServiceConnection {
|
||||
override fun onServiceConnected(name: ComponentName?, binder: IBinder?) {
|
||||
service = (binder as RecorderService.LocalBinder).getService().also {service ->
|
||||
service = (binder as RecorderService.LocalBinder).getService().also { service ->
|
||||
service.setOnStateChangeListener {
|
||||
println("asd")
|
||||
}
|
||||
@ -45,7 +45,7 @@ fun AudioRecorder() {
|
||||
val isRecording = service?.isRecording ?: false
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
Intent(context, RecorderService::class.java).also {intent ->
|
||||
Intent(context, RecorderService::class.java).also { intent ->
|
||||
context.bindService(intent, connection, Context.BIND_AUTO_CREATE)
|
||||
}
|
||||
}
|
||||
@ -61,13 +61,13 @@ fun AudioRecorder() {
|
||||
}
|
||||
|
||||
if (isRecording) {
|
||||
Intent(context, RecorderService::class.java).also {intent ->
|
||||
Intent(context, RecorderService::class.java).also { intent ->
|
||||
intent.action = RecorderService.Actions.STOP.toString()
|
||||
|
||||
context.startService(intent)
|
||||
}
|
||||
} else {
|
||||
Intent(context, RecorderService::class.java).also {intent ->
|
||||
Intent(context, RecorderService::class.java).also { intent ->
|
||||
intent.action = RecorderService.Actions.START.toString()
|
||||
|
||||
ContextCompat.startForegroundService(context, intent)
|
Loading…
x
Reference in New Issue
Block a user