diff --git a/app/src/main/java/app/myzel394/alibi/ui/components/WelcomeScreen/atoms/TimeSelector.kt b/app/src/main/java/app/myzel394/alibi/ui/components/WelcomeScreen/atoms/TimeSelector.kt index 182115d..560bae5 100644 --- a/app/src/main/java/app/myzel394/alibi/ui/components/WelcomeScreen/atoms/TimeSelector.kt +++ b/app/src/main/java/app/myzel394/alibi/ui/components/WelcomeScreen/atoms/TimeSelector.kt @@ -7,9 +7,16 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Edit +import androidx.compose.material.icons.filled.Timer +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.RadioButton import androidx.compose.material3.Text +import androidx.compose.material3.contentColorFor +import androidx.compose.material3.minimumInteractiveComponentSize import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -27,6 +34,14 @@ import androidx.compose.ui.semantics.semantics import androidx.compose.ui.unit.dp import app.myzel394.alibi.R import app.myzel394.alibi.dataStore +import app.myzel394.alibi.ui.utils.IconResource +import com.maxkeppeker.sheets.core.models.base.Header +import com.maxkeppeker.sheets.core.models.base.IconSource +import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState +import com.maxkeppeler.sheets.duration.DurationDialog +import com.maxkeppeler.sheets.duration.models.DurationConfig +import com.maxkeppeler.sheets.duration.models.DurationFormat +import com.maxkeppeler.sheets.duration.models.DurationSelection import kotlinx.coroutines.launch const val MINUTES_5 = 1000 * 60 * 5L @@ -34,6 +49,7 @@ const val MINUTES_15 = 1000 * 60 * 15L const val MINUTES_30 = 1000 * 60 * 30L const val HOURS_1 = 1000 * 60 * 60L +@OptIn(ExperimentalMaterial3Api::class) @Composable fun TimeSelector( modifier: Modifier = Modifier, @@ -94,5 +110,87 @@ fun TimeSelector( Text(label) } } + + let { + val showDialog = rememberUseCaseState() + val label = stringResource(R.string.ui_welcome_timeSettings_values_custom) + val selected = selectedDuration !in OPTIONS.keys + + DurationDialog( + state = showDialog, + header = Header.Default( + title = stringResource(R.string.ui_settings_option_maxDuration_title), + icon = IconSource( + painter = IconResource.fromImageVector(Icons.Default.Timer) + .asPainterResource(), + contentDescription = null, + ) + ), + selection = DurationSelection { newTimeInSeconds -> + selectedDuration = newTimeInSeconds * 1000L + }, + config = DurationConfig( + timeFormat = DurationFormat.HH_MM, + currentTime = selectedDuration / 1000, + minTime = 60, + maxTime = 23 * 60 * 60 + 60 * 59, + ) + ) + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp), + modifier = Modifier + .fillMaxWidth() + .semantics { + contentDescription = label + } + .clickable { + showDialog.show() + } + .clip(MaterialTheme.shapes.medium) + .padding(16.dp) + ) { + Icon( + Icons.Default.Edit, + contentDescription = null, + modifier = Modifier + .minimumInteractiveComponentSize() + .padding(2.dp), + tint = if (selected) MaterialTheme.colorScheme.primary else contentColorFor( + MaterialTheme.colorScheme.surfaceContainer + ) + ) + if (selected) { + val totalMinutes = selectedDuration / 1000 / 60 + val minutes = totalMinutes % 60 + val hours = (totalMinutes / 60).toInt() + + Text( + text = when (hours) { + 0 -> stringResource( + R.string.ui_welcome_timeSettings_values_customFormat_mm, + minutes + ) + + 1 -> stringResource( + R.string.ui_welcome_timeSettings_values_customFormat_h_mm, + minutes + ) + + else -> stringResource( + R.string.ui_welcome_timeSettings_values_customFormat_hh_mm, + hours, + minutes + ) + }, + color = MaterialTheme.colorScheme.primary, + ) + } else { + Text( + text = stringResource(R.string.ui_welcome_timeSettings_values_custom), + ) + } + } + } } } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 15abe38..30641a9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -212,4 +212,8 @@ Please select either the Media Folder or a Custom Folder. Alibi has not enough space to store the batches in the internal storage. Alternatively, go back one step and select a shorter duration. Select a Custom Folder You will now be asked to select a folder where Alibi should store the batches. Please select a folder where you have write access to. + Custom Duration + %s minutes + %s hour, %s minutes + 1 hour, %s minutes \ No newline at end of file