Skip to content

Commit

Permalink
refactor: Move settings out of SettingsScreen's atoms
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Oct 26, 2023
1 parent ca33e57 commit 68438a6
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 184 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun BitrateTile() {
fun BitrateTile(
settings: AppSettings,
) {
val scope = rememberCoroutineScope()
val showDialog = rememberUseCaseState()
val dataStore = LocalContext.current.dataStore
val settings = dataStore
.data
.collectAsState(initial = AppSettings.getDefaultInstance())
.value

fun updateValue(bitRate: Int) {
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,9 @@ import app.myzel394.alibi.ui.enums.Screen
@Composable
fun CustomNotificationTile(
navController: NavController,
settings: AppSettings,
) {
val dataStore = LocalContext.current.dataStore
val settings = dataStore
.data
.collectAsState(initial = AppSettings.getDefaultInstance())
.value

val label = if (settings.notificationSettings == null)
stringResource(R.string.ui_settings_option_customNotification_description_setup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ import app.myzel394.alibi.ui.components.atoms.SettingsTile
import kotlinx.coroutines.launch

@Composable
fun DeleteRecordingsImmediatelyTile() {
fun DeleteRecordingsImmediatelyTile(
settings: AppSettings,
) {
val scope = rememberCoroutineScope()

val dataStore = LocalContext.current.dataStore
val settings = dataStore
.data
.collectAsState(initial = AppSettings.getDefaultInstance())
.value

SettingsTile(
title = stringResource(R.string.ui_settings_option_deleteRecordingsImmediately_title),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app.myzel394.alibi.ui.components.SettingsScreen.atoms

import android.media.MediaRecorder
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AudioFile
import androidx.compose.material.icons.filled.Memory
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
Expand Down Expand Up @@ -35,17 +34,15 @@ import kotlinx.coroutines.launch
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun EncoderTile(
snackbarHostState: SnackbarHostState
snackbarHostState: SnackbarHostState,
settings: AppSettings,
) {
val scope = rememberCoroutineScope()
val showDialog = rememberUseCaseState()
val dataStore = LocalContext.current.dataStore
val settings = dataStore
.data
.collectAsState(initial = AppSettings.getDefaultInstance())
.value

val updatedOutputFormatLabel = stringResource(R.string.ui_settings_option_encoder_extra_outputFormatChanged)
val updatedOutputFormatLabel =
stringResource(R.string.ui_settings_option_encoder_extra_outputFormatChanged)

fun updateValue(encoder: Int?) {
scope.launch {
Expand Down Expand Up @@ -92,7 +89,7 @@ fun EncoderTile(
selected = settings.audioRecorderSettings.encoder == index,
)
}.toList()
) {index, option ->
) { index, _ ->
updateValue(index)
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ import kotlinx.coroutines.launch


@Composable
fun ForceExactMaxDurationTile() {
fun ForceExactMaxDurationTile(
settings: AppSettings,
) {
val scope = rememberCoroutineScope()
val showDialog = rememberUseCaseState()
val dataStore = LocalContext.current.dataStore
val settings = dataStore
.data
.collectAsState(initial = AppSettings.getDefaultInstance())
.value

fun updateValue(forceExactMaxDuration: Boolean) {
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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.db.AudioRecorderSettings
import app.myzel394.alibi.ui.components.atoms.SettingsTile
import app.myzel394.alibi.ui.utils.IconResource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun IntervalDurationTile() {
fun IntervalDurationTile(
settings: AppSettings,
) {
val scope = rememberCoroutineScope()
val showDialog = rememberUseCaseState()
val dataStore = LocalContext.current.dataStore
val settings = dataStore
.data
.collectAsState(initial = AppSettings.getDefaultInstance())
.value

fun updateValue(intervalDuration: Long) {
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MaxDurationTile() {
fun MaxDurationTile(
settings: AppSettings,
) {
val scope = rememberCoroutineScope()
val showDialog = rememberUseCaseState()
val dataStore = LocalContext.current.dataStore
val settings = dataStore
.data
.collectAsState(initial = AppSettings.getDefaultInstance())
.value

fun updateValue(maxDuration: Long) {
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
package app.myzel394.alibi.ui.components.SettingsScreen.atoms

import android.media.MediaRecorder
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AudioFile
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarVisuals
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
Expand All @@ -35,14 +29,12 @@ import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun OutputFormatTile() {
fun OutputFormatTile(
settings: AppSettings,
) {
val scope = rememberCoroutineScope()
val showDialog = rememberUseCaseState()
val dataStore = LocalContext.current.dataStore
val settings = dataStore
.data
.collectAsState(initial = AppSettings.getDefaultInstance())
.value
val availableOptions = if (settings.audioRecorderSettings.encoder == null)
AudioRecorderSettings.OUTPUT_FORMAT_INDEX_TEXT_MAP.keys.toTypedArray()
else AudioRecorderSettings.ENCODER_SUPPORTED_OUTPUT_FORMATS_MAP[settings.audioRecorderSettings.encoder]!!
Expand Down Expand Up @@ -74,7 +66,7 @@ fun OutputFormatTile() {
selected = settings.audioRecorderSettings.outputFormat == option,
)
}.toList()
) {index, option ->
) { index, _ ->
updateValue(availableOptions[index])
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,12 @@ import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SamplingRateTile() {
fun SamplingRateTile(
settings: AppSettings,
) {
val scope = rememberCoroutineScope()
val showDialog = rememberUseCaseState()
val dataStore = LocalContext.current.dataStore
val settings = dataStore
.data
.collectAsState(initial = AppSettings.getDefaultInstance())
.value

fun updateValue(samplingRate: Int?) {
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ import kotlinx.coroutines.launch


@Composable
fun ShowAllMicrophonesTile() {
fun ShowAllMicrophonesTile(
settings: AppSettings,
) {
val scope = rememberCoroutineScope()
val dataStore = LocalContext.current.dataStore
val settings = dataStore
.data
.collectAsState(initial = AppSettings.getDefaultInstance())
.value

fun updateValue(showAllMicrophones: Boolean) {
scope.launch {
Expand Down
Loading

0 comments on commit 68438a6

Please sign in to comment.