|
|
|
@ -1,6 +1,7 @@
|
|
|
|
package org.tasks.compose.pickers
|
|
|
|
package org.tasks.compose.pickers
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.res.Configuration
|
|
|
|
import android.content.res.Configuration
|
|
|
|
|
|
|
|
import android.os.LocaleList
|
|
|
|
import androidx.compose.material3.DatePicker
|
|
|
|
import androidx.compose.material3.DatePicker
|
|
|
|
import androidx.compose.material3.DisplayMode
|
|
|
|
import androidx.compose.material3.DisplayMode
|
|
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
|
|
@ -8,22 +9,26 @@ import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.material3.TextButton
|
|
|
|
import androidx.compose.material3.TextButton
|
|
|
|
import androidx.compose.material3.rememberDatePickerState
|
|
|
|
import androidx.compose.material3.rememberDatePickerState
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
|
|
|
|
import androidx.compose.runtime.CompositionLocalProvider
|
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
|
import androidx.compose.runtime.derivedStateOf
|
|
|
|
import androidx.compose.runtime.derivedStateOf
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
|
|
|
|
import androidx.compose.ui.platform.LocalConfiguration
|
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
import org.tasks.R
|
|
|
|
import org.tasks.R
|
|
|
|
import org.tasks.themes.TasksTheme
|
|
|
|
import org.tasks.themes.TasksTheme
|
|
|
|
import org.tasks.time.DateTime
|
|
|
|
import org.tasks.time.DateTime
|
|
|
|
import timber.log.Timber
|
|
|
|
import timber.log.Timber
|
|
|
|
|
|
|
|
import java.util.Locale
|
|
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
|
|
@Composable
|
|
|
|
@Composable
|
|
|
|
fun DatePickerDialog(
|
|
|
|
fun DatePickerDialog(
|
|
|
|
initialDate: Long,
|
|
|
|
initialDate: Long,
|
|
|
|
displayMode: DisplayMode,
|
|
|
|
displayMode: DisplayMode,
|
|
|
|
|
|
|
|
firstDayOfWeek: Int,
|
|
|
|
setDisplayMode: (DisplayMode) -> Unit,
|
|
|
|
setDisplayMode: (DisplayMode) -> Unit,
|
|
|
|
selected: (Long) -> Unit,
|
|
|
|
selected: (Long) -> Unit,
|
|
|
|
dismiss: () -> Unit,
|
|
|
|
dismiss: () -> Unit,
|
|
|
|
@ -48,23 +53,51 @@ fun DatePickerDialog(
|
|
|
|
androidx.compose.material3.DatePickerDialog(
|
|
|
|
androidx.compose.material3.DatePickerDialog(
|
|
|
|
onDismissRequest = { dismiss() },
|
|
|
|
onDismissRequest = { dismiss() },
|
|
|
|
dismissButton = {
|
|
|
|
dismissButton = {
|
|
|
|
TextButton(onClick = dismiss) {
|
|
|
|
TextButton(onClick = dismiss) {
|
|
|
|
Text(text = stringResource(id = R.string.cancel))
|
|
|
|
Text(text = stringResource(id = R.string.cancel))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
confirmButton = {
|
|
|
|
confirmButton = {
|
|
|
|
TextButton(
|
|
|
|
TextButton(
|
|
|
|
onClick = {
|
|
|
|
onClick = {
|
|
|
|
datePickerState
|
|
|
|
datePickerState
|
|
|
|
.selectedDateMillis
|
|
|
|
.selectedDateMillis
|
|
|
|
?.let { selected(it - DateTime(it).offset) }
|
|
|
|
?.let { selected(it - DateTime(it).offset) }
|
|
|
|
}
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text(text = stringResource(id = R.string.ok))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
Text(text = stringResource(id = R.string.ok))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
DatePicker(state = datePickerState)
|
|
|
|
val currentLocale = LocalConfiguration.current.locales[0]
|
|
|
|
|
|
|
|
val customLocale = remember(currentLocale) {
|
|
|
|
|
|
|
|
if (firstDayOfWeek == 0) {
|
|
|
|
|
|
|
|
currentLocale
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Locale.Builder()
|
|
|
|
|
|
|
|
.setLocale(currentLocale)
|
|
|
|
|
|
|
|
.setUnicodeLocaleKeyword(
|
|
|
|
|
|
|
|
"fw",
|
|
|
|
|
|
|
|
when (firstDayOfWeek) {
|
|
|
|
|
|
|
|
2 -> "mon"
|
|
|
|
|
|
|
|
3 -> "tue"
|
|
|
|
|
|
|
|
4 -> "wed"
|
|
|
|
|
|
|
|
5 -> "thu"
|
|
|
|
|
|
|
|
6 -> "fri"
|
|
|
|
|
|
|
|
7 -> "sat"
|
|
|
|
|
|
|
|
else -> "sun"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CompositionLocalProvider(
|
|
|
|
|
|
|
|
LocalConfiguration provides Configuration(LocalConfiguration.current).apply {
|
|
|
|
|
|
|
|
setLocales(LocaleList(customLocale))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
DatePicker(state = datePickerState)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -77,6 +110,7 @@ fun DatePickerPreview() {
|
|
|
|
DatePickerDialog(
|
|
|
|
DatePickerDialog(
|
|
|
|
initialDate = DateTime().plusDays(1).millis,
|
|
|
|
initialDate = DateTime().plusDays(1).millis,
|
|
|
|
displayMode = DisplayMode.Picker,
|
|
|
|
displayMode = DisplayMode.Picker,
|
|
|
|
|
|
|
|
firstDayOfWeek = 0,
|
|
|
|
setDisplayMode = {},
|
|
|
|
setDisplayMode = {},
|
|
|
|
selected = {},
|
|
|
|
selected = {},
|
|
|
|
dismiss = {}
|
|
|
|
dismiss = {}
|
|
|
|
@ -93,6 +127,23 @@ fun DatePickerPreviewInput() {
|
|
|
|
DatePickerDialog(
|
|
|
|
DatePickerDialog(
|
|
|
|
initialDate = DateTime().plusDays(1).millis,
|
|
|
|
initialDate = DateTime().plusDays(1).millis,
|
|
|
|
displayMode = DisplayMode.Input,
|
|
|
|
displayMode = DisplayMode.Input,
|
|
|
|
|
|
|
|
firstDayOfWeek = 0,
|
|
|
|
|
|
|
|
setDisplayMode = {},
|
|
|
|
|
|
|
|
selected = {},
|
|
|
|
|
|
|
|
dismiss = {}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
|
|
|
|
|
|
@Preview(showBackground = true)
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
|
|
|
|
fun DatePickerPreviewOverrideFirstDay() {
|
|
|
|
|
|
|
|
TasksTheme {
|
|
|
|
|
|
|
|
DatePickerDialog(
|
|
|
|
|
|
|
|
initialDate = DateTime().plusDays(1).millis,
|
|
|
|
|
|
|
|
displayMode = DisplayMode.Picker,
|
|
|
|
|
|
|
|
firstDayOfWeek = 2,
|
|
|
|
setDisplayMode = {},
|
|
|
|
setDisplayMode = {},
|
|
|
|
selected = {},
|
|
|
|
selected = {},
|
|
|
|
dismiss = {}
|
|
|
|
dismiss = {}
|
|
|
|
|