feat: Improve CustomRecordingNotificationsScreen behavior; Add save support (wip)

This commit is contained in:
Myzel394 2023-10-24 10:22:05 +02:00
parent d0885ba877
commit 15bb9b4051
No known key found for this signature in database
GPG Key ID: 50098FCA22080F0F
5 changed files with 82 additions and 14 deletions

View File

@ -28,6 +28,10 @@ data class AppSettings(
return copy(audioRecorderSettings = audioRecorderSettings) return copy(audioRecorderSettings = audioRecorderSettings)
} }
fun setNotificationSettings(notificationSettings: NotificationSettings?): AppSettings {
return copy(notificationSettings = notificationSettings)
}
fun setHasSeenOnboarding(hasSeenOnboarding: Boolean): AppSettings { fun setHasSeenOnboarding(hasSeenOnboarding: Boolean): AppSettings {
return copy(hasSeenOnboarding = hasSeenOnboarding) return copy(hasSeenOnboarding = hasSeenOnboarding)
} }
@ -418,6 +422,7 @@ data class AudioRecorderSettings(
data class NotificationSettings( data class NotificationSettings(
val title: String, val title: String,
val message: String, val message: String,
val iconID: Int,
val showOngoing: Boolean, val showOngoing: Boolean,
val preset: Preset? = null, val preset: Preset? = null,
) { ) {
@ -428,6 +433,7 @@ data class NotificationSettings(
val showOngoing: Boolean, val showOngoing: Boolean,
val iconID: Int, val iconID: Int,
) { ) {
@Serializable
data object Default : Preset( data object Default : Preset(
R.string.ui_audioRecorder_state_recording_title, R.string.ui_audioRecorder_state_recording_title,
R.string.ui_audioRecorder_state_recording_description, R.string.ui_audioRecorder_state_recording_description,
@ -435,6 +441,7 @@ data class NotificationSettings(
R.drawable.launcher_monochrome_noopacity, R.drawable.launcher_monochrome_noopacity,
) )
@Serializable
data object Weather : Preset( data object Weather : Preset(
R.string.ui_audioRecorder_state_recording_fake_weather_title, R.string.ui_audioRecorder_state_recording_fake_weather_title,
R.string.ui_audioRecorder_state_recording_fake_weather_description, R.string.ui_audioRecorder_state_recording_fake_weather_description,
@ -442,6 +449,7 @@ data class NotificationSettings(
R.drawable.ic_cloud R.drawable.ic_cloud
) )
@Serializable
data object Player : Preset( data object Player : Preset(
R.string.ui_audioRecorder_state_recording_fake_player_title, R.string.ui_audioRecorder_state_recording_fake_player_title,
R.string.ui_audioRecorder_state_recording_fake_player_description, R.string.ui_audioRecorder_state_recording_fake_player_description,
@ -449,6 +457,7 @@ data class NotificationSettings(
R.drawable.ic_note, R.drawable.ic_note,
) )
@Serializable
data object Browser : Preset( data object Browser : Preset(
R.string.ui_audioRecorder_state_recording_fake_browser_title, R.string.ui_audioRecorder_state_recording_fake_browser_title,
R.string.ui_audioRecorder_state_recording_fake_browser_description, R.string.ui_audioRecorder_state_recording_fake_browser_description,
@ -456,6 +465,7 @@ data class NotificationSettings(
R.drawable.ic_download, R.drawable.ic_download,
) )
@Serializable
data object VPN : Preset( data object VPN : Preset(
R.string.ui_audioRecorder_state_recording_fake_vpn_title, R.string.ui_audioRecorder_state_recording_fake_vpn_title,
R.string.ui_audioRecorder_state_recording_fake_vpn_description, R.string.ui_audioRecorder_state_recording_fake_vpn_description,
@ -470,6 +480,7 @@ data class NotificationSettings(
title = "", title = "",
message = "", message = "",
showOngoing = preset.showOngoing, showOngoing = preset.showOngoing,
iconID = preset.iconID,
preset = preset, preset = preset,
) )
} }

View File

@ -36,6 +36,7 @@ import app.myzel394.alibi.ui.utils.openNotificationsSettings
@Composable @Composable
fun LandingElement( fun LandingElement(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
onOpenEditor: () -> Unit,
) { ) {
val context = LocalContext.current val context = LocalContext.current
@ -82,7 +83,7 @@ fun LandingElement(
style = MaterialTheme.typography.bodySmall, style = MaterialTheme.typography.bodySmall,
) )
Button( Button(
onClick = {}, onClick = onOpenEditor,
colors = ButtonDefaults.filledTonalButtonColors(), colors = ButtonDefaults.filledTonalButtonColors(),
) { ) {
Icon( Icon(

View File

@ -24,7 +24,7 @@ import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.atoms
@OptIn(ExperimentalFoundationApi::class) @OptIn(ExperimentalFoundationApi::class)
@Composable @Composable
fun NotificationPresetsRoulette( fun NotificationPresetsRoulette(
onClick: (String, String, Int, Boolean) -> Unit, onClick: (String, String, Int, Boolean, NotificationSettings.Preset) -> Unit,
) { ) {
val state = rememberLazyListState() val state = rememberLazyListState()
@ -62,6 +62,7 @@ fun NotificationPresetsRoulette(
presetDescription, presetDescription,
preset.iconID, preset.iconID,
preset.showOngoing, preset.showOngoing,
preset,
) )
}, },
preset = preset, preset = preset,

View File

@ -37,6 +37,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -56,6 +57,7 @@ import app.myzel394.alibi.ui.BIG_PRIMARY_BUTTON_SIZE
import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.atoms.NotificationPresetSelect import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.atoms.NotificationPresetSelect
import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.molecules.EditNotificationInput import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.molecules.EditNotificationInput
import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.molecules.NotificationPresetsRoulette import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.molecules.NotificationPresetsRoulette
import kotlinx.coroutines.newFixedThreadPoolContext
val HORIZONTAL_PADDING = 16.dp; val HORIZONTAL_PADDING = 16.dp;
@ -63,7 +65,7 @@ val HORIZONTAL_PADDING = 16.dp;
@Composable @Composable
fun NotificationEditor( fun NotificationEditor(
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
scrollState: ScrollState, onNotificationChange: (String, String, Int, Boolean, NotificationSettings.Preset?) -> Unit,
) { ) {
val defaultTitle = stringResource(R.string.ui_audioRecorder_state_recording_title) val defaultTitle = stringResource(R.string.ui_audioRecorder_state_recording_title)
val defaultDescription = stringResource(R.string.ui_audioRecorder_state_recording_description) val defaultDescription = stringResource(R.string.ui_audioRecorder_state_recording_description)
@ -80,8 +82,10 @@ fun NotificationEditor(
var icon: Int by rememberSaveable { var icon: Int by rememberSaveable {
mutableIntStateOf(R.drawable.launcher_monochrome_noopacity) mutableIntStateOf(R.drawable.launcher_monochrome_noopacity)
} }
var preset: NotificationSettings.Preset? by remember {
mutableStateOf(null)
}
// TODO: Add Preview functionality
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
@ -150,16 +154,25 @@ fun NotificationEditor(
verticalArrangement = Arrangement.spacedBy(32.dp), verticalArrangement = Arrangement.spacedBy(32.dp),
) { ) {
NotificationPresetsRoulette( NotificationPresetsRoulette(
onClick = { presetTitle, presetDescription, presetIcon, presetShowOngoing -> onClick = { presetTitle, presetDescription, presetIcon, presetShowOngoing, newPreset ->
title = presetTitle title = presetTitle
description = presetDescription description = presetDescription
icon = presetIcon icon = presetIcon
showOngoing = presetShowOngoing showOngoing = presetShowOngoing
preset = newPreset
} }
) )
Button( Button(
onClick = { /*TODO*/ }, onClick = {
onNotificationChange(
title,
description,
icon,
showOngoing,
preset,
)
},
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(horizontal = HORIZONTAL_PADDING) .padding(horizontal = HORIZONTAL_PADDING)

View File

@ -22,7 +22,13 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberTopAppBarState import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
@ -35,9 +41,11 @@ import app.myzel394.alibi.R
import app.myzel394.alibi.dataStore import app.myzel394.alibi.dataStore
import app.myzel394.alibi.db.AppSettings import app.myzel394.alibi.db.AppSettings
import app.myzel394.alibi.db.NotificationSettings import app.myzel394.alibi.db.NotificationSettings
import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.atoms.LandingElement
import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.atoms.NotificationPresetSelect import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.atoms.NotificationPresetSelect
import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.molecules.EditNotificationInput import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.molecules.EditNotificationInput
import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.organisms.NotificationEditor import app.myzel394.alibi.ui.components.CustomRecordingNotificationsScreen.organisms.NotificationEditor
import kotlinx.coroutines.launch
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
@ -47,7 +55,6 @@ fun CustomRecordingNotificationsScreen(
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior( val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
rememberTopAppBarState() rememberTopAppBarState()
) )
val scrollState = rememberScrollState()
val dataStore = LocalContext.current.dataStore val dataStore = LocalContext.current.dataStore
val settings = dataStore val settings = dataStore
@ -55,6 +62,16 @@ fun CustomRecordingNotificationsScreen(
.collectAsState(initial = AppSettings.getDefaultInstance()) .collectAsState(initial = AppSettings.getDefaultInstance())
.value .value
var showEditor: Boolean by rememberSaveable {
mutableStateOf(false)
}
LaunchedEffect(settings.notificationSettings) {
if (settings.notificationSettings != null) {
showEditor = true
}
}
Scaffold( Scaffold(
topBar = { topBar = {
TopAppBar( TopAppBar(
@ -75,13 +92,38 @@ fun CustomRecordingNotificationsScreen(
modifier = Modifier modifier = Modifier
.nestedScroll(scrollBehavior.nestedScrollConnection) .nestedScroll(scrollBehavior.nestedScrollConnection)
) { padding -> ) { padding ->
if (settings.notificationSettings == null) { if (showEditor) {
} val scope = rememberCoroutineScope()
NotificationEditor( NotificationEditor(
modifier = Modifier modifier = Modifier
.padding(padding) .padding(padding)
.padding(vertical = 16.dp), .padding(vertical = 16.dp),
scrollState = scrollState, onNotificationChange = { title, description, icon, showOngoing, preset ->
scope.launch {
dataStore.updateData { settings ->
settings.setNotificationSettings(
if (preset == null) {
NotificationSettings(
title = title,
message = description,
iconID = icon,
showOngoing = showOngoing,
)
} else {
NotificationSettings.fromPreset(preset)
}
) )
} }
} }
}
)
} else {
LandingElement(
onOpenEditor = {
showEditor = true
}
)
}
}
}