feat: Add custom value to TimeSelector

Signed-off-by: Myzel394 <50424412+Myzel394@users.noreply.github.com>
This commit is contained in:
Myzel394 2024-03-22 19:05:13 +01:00
parent dac133e6b3
commit aaee0c5cb6
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
2 changed files with 102 additions and 0 deletions

View File

@ -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),
)
}
}
}
}
}

View File

@ -212,4 +212,8 @@
<string name="ui_welcome_saveFolder_externalRequired">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.</string>
<string name="ui_welcome_saveFolder_customFolder_title">Select a Custom Folder</string>
<string name="ui_welcome_saveFolder_customFolder_message">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.</string>
<string name="ui_welcome_timeSettings_values_custom">Custom Duration</string>
<string name="ui_welcome_timeSettings_values_customFormat_mm">%s minutes</string>
<string name="ui_welcome_timeSettings_values_customFormat_hh_mm">%s hour, %s minutes</string>
<string name="ui_welcome_timeSettings_values_customFormat_h_mm">1 hour, %s minutes</string>
</resources>