11package com.bnyro.clock.presentation.screens.alarmpicker.components
22
3+ import android.content.ContentResolver
4+ import android.provider.Settings
35import androidx.compose.animation.AnimatedVisibility
46import androidx.compose.foundation.background
57import androidx.compose.foundation.border
@@ -8,8 +10,10 @@ import androidx.compose.foundation.layout.Arrangement
810import androidx.compose.foundation.layout.Box
911import androidx.compose.foundation.layout.Column
1012import androidx.compose.foundation.layout.Row
13+ import androidx.compose.foundation.layout.Spacer
1114import androidx.compose.foundation.layout.fillMaxSize
1215import androidx.compose.foundation.layout.fillMaxWidth
16+ import androidx.compose.foundation.layout.height
1317import androidx.compose.foundation.layout.padding
1418import androidx.compose.foundation.layout.size
1519import androidx.compose.foundation.rememberScrollState
@@ -26,7 +30,6 @@ import androidx.compose.material3.Icon
2630import androidx.compose.material3.MaterialTheme
2731import androidx.compose.material3.OutlinedButton
2832import androidx.compose.material3.OutlinedTextField
29- import androidx.compose.material3.Surface
3033import androidx.compose.material3.Text
3134import androidx.compose.runtime.Composable
3235import androidx.compose.runtime.getValue
@@ -84,11 +87,15 @@ fun AlarmPicker(currentAlarm: Alarm, onSave: (Alarm) -> Unit, onCancel: () -> Un
8487 var minutes by remember { mutableIntStateOf(initialTime.minutes) }
8588
8689 val scrollState = rememberScrollState()
87- Surface {
90+ Column (
91+ modifier = Modifier
92+ .fillMaxSize()
93+ .padding(horizontal = 8 .dp, vertical = 16 .dp)
94+ ) {
8895 Column (
8996 Modifier
90- .fillMaxSize( )
91- .padding(horizontal = 8 .dp, vertical = 16 .dp )
97+ .weight( 1f )
98+ .fillMaxWidth( )
9299 .verticalScroll(scrollState),
93100 horizontalAlignment = Alignment .CenterHorizontally ,
94101 verticalArrangement = Arrangement .SpaceEvenly
@@ -218,35 +225,41 @@ fun AlarmPicker(currentAlarm: Alarm, onSave: (Alarm) -> Unit, onCancel: () -> Un
218225 }
219226 )
220227 }
221- Row (
222- Modifier .align(Alignment .End ),
223- horizontalArrangement = Arrangement .spacedBy(16 .dp)
224- ) {
225- OutlinedButton (onClick = { onCancel.invoke() }) {
226- Text (text = stringResource(id = android.R .string.cancel))
227- }
228- Button (onClick = {
229- val alarm =
230- currentAlarm.copy(
231- time = (hours * 60 + minutes) * 60 * 1000L ,
232- label = label.takeIf { l -> l.isNotBlank() },
233- days = chosenDays.sorted(),
234- vibrate = vibrationEnabled,
235- soundName = soundName,
236- soundUri = soundUri,
237- repeat = repeat,
238- snoozeEnabled = snoozeEnabled,
239- snoozeMinutes = snoozeMinutes,
240- soundEnabled = soundEnabled,
241- vibrationPattern = vibrationPattern,
242- vibrationPatternName = vibrationPatternName
243- )
244- onSave(alarm)
245- }) {
246- Text (text = stringResource(id = android.R .string.ok))
247- }
228+ }
229+
230+ Row (
231+ Modifier .align(Alignment .End ),
232+ horizontalArrangement = Arrangement .spacedBy(16 .dp)
233+ ) {
234+ OutlinedButton (onClick = { onCancel.invoke() }) {
235+ Text (text = stringResource(id = android.R .string.cancel))
236+ }
237+ Button (onClick = {
238+ val alarm =
239+ currentAlarm.copy(
240+ time = (hours * 60 + minutes) * 60 * 1000L ,
241+ label = label.takeIf { l -> l.isNotBlank() },
242+ days = chosenDays.sorted(),
243+ vibrate = vibrationEnabled,
244+ soundName = soundName,
245+ soundUri = soundUri,
246+ repeat = repeat,
247+ snoozeEnabled = snoozeEnabled,
248+ snoozeMinutes = snoozeMinutes,
249+ soundEnabled = soundEnabled,
250+ vibrationPattern = vibrationPattern,
251+ vibrationPatternName = vibrationPatternName
252+ )
253+ onSave(alarm)
254+ }) {
255+ Text (text = stringResource(id = android.R .string.ok))
248256 }
249257 }
258+
259+ // extra spacing to fix that the buttons are overlapped by the navigation bar
260+ if (! isGestureNavigationMode(context.contentResolver)) {
261+ Spacer (modifier = Modifier .height(40 .dp))
262+ }
250263 }
251264 if (showRingtoneDialog) {
252265 RingtonePickerDialog (onDismissRequest = {
@@ -278,3 +291,7 @@ fun AlarmPicker(currentAlarm: Alarm, onSave: (Alarm) -> Unit, onCancel: () -> Un
278291 )
279292 }
280293}
294+
295+ fun isGestureNavigationMode (content : ContentResolver ? ): Boolean {
296+ return Settings .Secure .getInt(content, " navigation_mode" , 0 ) == 2
297+ }
0 commit comments