current stand

This commit is contained in:
Myzel394 2023-10-27 16:44:53 +02:00
parent 76bfb97dad
commit 60fc16f2c4
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
5 changed files with 160 additions and 0 deletions

View File

@ -13,6 +13,8 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name=".UpdateSettingsApp"
android:allowBackup="true"
@ -56,6 +58,14 @@
android:name="autoStoreLocales"
android:value="true" />
</service>
<receiver
android:name=".receivers.BootReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>

View File

@ -0,0 +1,43 @@
package app.myzel394.alibi.receivers
import android.content.BroadcastReceiver
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.IBinder
import androidx.core.content.ContextCompat
import app.myzel394.alibi.services.AudioRecorderService
import app.myzel394.alibi.services.RecorderService
import app.myzel394.alibi.ui.enums.Screen
import app.myzel394.alibi.ui.models.AudioRecorderModel
class BootReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
println("Received new intent: ${intent?.action}")
if (intent?.action == Intent.ACTION_BOOT_COMPLETED) {
println("Starting service")
val connection = object : ServiceConnection {
override fun onServiceConnected(className: ComponentName, service: IBinder) {
((service as RecorderService.RecorderBinder).getService() as AudioRecorderService).also { recorder ->
recorder.startRecording()
}
}
override fun onServiceDisconnected(arg0: ComponentName) {
}
}
val intent = Intent(context, AudioRecorderService::class.java).apply {
action = "initStart"
}
println("Starting service checking context")
if (context != null) {
println("Starting service with context")
ContextCompat.startForegroundService(context, intent)
}
}
}
}

View File

@ -57,6 +57,10 @@ abstract class RecorderService : Service() {
}
}
"initStart" -> {
startRecording()
}
"changeState" -> {
val newState = intent.getStringExtra("newState")?.let {
RecorderState.valueOf(it)

View File

@ -0,0 +1,101 @@
package app.myzel394.alibi.ui.components.SettingsScreen.atoms
import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.Smartphone
import androidx.compose.material.icons.filled.Translate
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.core.os.LocaleListCompat
import app.myzel394.alibi.R
import app.myzel394.alibi.SUPPORTED_LOCALES
import app.myzel394.alibi.db.AppSettings
import app.myzel394.alibi.ui.components.atoms.SettingsTile
import app.myzel394.alibi.ui.utils.IconResource
import com.maxkeppeker.sheets.core.models.base.ButtonStyle
import com.maxkeppeker.sheets.core.models.base.Header
import com.maxkeppeker.sheets.core.models.base.IconSource
import com.maxkeppeker.sheets.core.models.base.SelectionButton
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
import com.maxkeppeler.sheets.list.ListDialog
import com.maxkeppeler.sheets.list.models.ListOption
import com.maxkeppeler.sheets.list.models.ListSelection
import java.util.Locale
/*
val BOOT_BEHAVIOR_TITLE_MAP = mapOf<AppSettings.BootBehavior, Int>(
AppSettings.BootBehavior.SHOW_NOTIFICATION to R.string.ui_settings_bootBehavior_values_SHOW_NOTIFICATION_title,
AppSettings.BootBehavior.START_RECORDING to R.string.ui_settings_bootBehavior_values_START_RECORDING_title
)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BootBehaviorTile() {
val showDialog = rememberUseCaseState()
ListDialog(
state = showDialog,
header = Header.Default(
title = stringResource(R.string.ui_settings_bootBehavior_title),
icon = IconSource(
painter = IconResource.fromImageVector(Icons.Default.Smartphone)
.asPainterResource(),
contentDescription = null,
)
),
selection = ListSelection.Single(
showRadioButtons = true,
options = AppSettings.BootBehavior.entries.map {
ListOption(
titleText = stringResource("ui_settings_bootBehavior_values_${it.name}_title"),
subtitleText = stringResource("ui_settings_bootBehavior_values_${it.name}_subtitle"),
)
}.toList(),
options = IntRange(0, AppSettings.BootBehavior.entries.size).map { index ->
val locale = locales[index]!!
ListOption(
titleText = locale.displayName,
subtitleText = locale.getDisplayName(Locale.ENGLISH),
)
}.toList(),
positiveButton = SelectionButton(
icon = IconSource(
painter = IconResource.fromImageVector(Icons.Default.CheckCircle)
.asPainterResource(),
contentDescription = null,
),
text = stringResource(android.R.string.ok),
type = ButtonStyle.TEXT,
)
) { index, _ ->
AppCompatDelegate.setApplicationLocales(
LocaleListCompat.forLanguageTags(
locales[index]!!.toLanguageTag(),
),
)
},
)
SettingsTile(
firstModifier = Modifier
.fillMaxHeight()
.clickable {
showDialog.show()
},
title = stringResource(R.string.ui_settings_bootBehavior_title),
leading = {
Icon(
Icons.Default.Smartphone,
contentDescription = null,
)
},
)
}
*/

View File

@ -109,4 +109,6 @@
<string name="ui_about_contribute_donation_githubSponsors">Become a GitHub Sponsor</string>
<string name="ui_settings_option_deleteRecordingsImmediately_title">Delete Recordings Immediately</string>
<string name="ui_settings_option_deleteRecordingsImmediately_description">If enabled, Alibi will immediately delete recordings after you have saved the file.</string>
<string name="ui_settings_bootBehavior_title">Boot Behavior</string>
<string name="ui_settings_bootBehavior_values_SHOW_NOTIFICATION_title">Show a notification</string>
</resources>