mirror of
https://github.com/nextcloud/talk-android
synced 2025-08-15 16:05:11 +01:00
Merge pull request #5153 from nextcloud/issue_5150/remindMeLater
Some UI changes to Remind me later
This commit is contained in:
commit
910da04247
@ -10,7 +10,7 @@ package com.nextcloud.talk.ui.dialog
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.compose.animation.animateContentSize
|
import android.text.format.DateFormat
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||||
@ -18,6 +18,7 @@ import androidx.compose.foundation.layout.Column
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.requiredSizeIn
|
import androidx.compose.foundation.layout.requiredSizeIn
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
@ -28,10 +29,12 @@ import androidx.compose.foundation.verticalScroll
|
|||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.DateRange
|
import androidx.compose.material.icons.filled.DateRange
|
||||||
import androidx.compose.material3.DatePicker
|
import androidx.compose.material3.DatePicker
|
||||||
|
import androidx.compose.material3.DatePickerDefaults
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.SelectableDates
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
@ -48,6 +51,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.draw.scale
|
import androidx.compose.ui.draw.scale
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
@ -114,7 +118,7 @@ class DateTimeCompose(val bundle: Bundle) {
|
|||||||
) {
|
) {
|
||||||
Surface(
|
Surface(
|
||||||
shape = RoundedCornerShape(INT_8.dp),
|
shape = RoundedCornerShape(INT_8.dp),
|
||||||
modifier = Modifier.fillMaxWidth().animateContentSize()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -183,27 +187,31 @@ class DateTimeCompose(val bundle: Bundle) {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun Body() {
|
private fun Body() {
|
||||||
|
val context = LocalContext.current
|
||||||
val currTime = LocalDateTime.now()
|
val currTime = LocalDateTime.now()
|
||||||
|
|
||||||
|
val timeFormatter = DateTimeFormatter.ofPattern(timePattern(context))
|
||||||
|
val dayTimeFormatter = DateTimeFormatter.ofPattern(dayTimePattern(context))
|
||||||
|
|
||||||
val laterToday = LocalDateTime.now()
|
val laterToday = LocalDateTime.now()
|
||||||
.withHour(INT_18)
|
.withHour(INT_18)
|
||||||
.withMinute(0)
|
.withMinute(0)
|
||||||
.withSecond(0)
|
.withSecond(0)
|
||||||
val laterTodayStr = laterToday.format(DateTimeFormatter.ofPattern(PATTERN))
|
val laterTodayStr = laterToday.format(timeFormatter)
|
||||||
|
|
||||||
val tomorrow = LocalDateTime.now()
|
val tomorrow = LocalDateTime.now()
|
||||||
.plusDays(1)
|
.plusDays(1)
|
||||||
.withHour(INT_8)
|
.withHour(INT_8)
|
||||||
.withMinute(0)
|
.withMinute(0)
|
||||||
.withSecond(0)
|
.withSecond(0)
|
||||||
val tomorrowStr = tomorrow.format(DateTimeFormatter.ofPattern(PATTERN))
|
val tomorrowStr = tomorrow.format(dayTimeFormatter)
|
||||||
|
|
||||||
val thisWeekend = LocalDateTime.now()
|
val thisWeekend = LocalDateTime.now()
|
||||||
.with(nextOrSame(DayOfWeek.SATURDAY))
|
.with(nextOrSame(DayOfWeek.SATURDAY))
|
||||||
.withHour(INT_8)
|
.withHour(INT_8)
|
||||||
.withMinute(0)
|
.withMinute(0)
|
||||||
.withSecond(0)
|
.withSecond(0)
|
||||||
val thisWeekendStr = thisWeekend.format(DateTimeFormatter.ofPattern(PATTERN))
|
val thisWeekendStr = thisWeekend.format(dayTimeFormatter)
|
||||||
|
|
||||||
val nextWeek = LocalDateTime.now()
|
val nextWeek = LocalDateTime.now()
|
||||||
.plusWeeks(1)
|
.plusWeeks(1)
|
||||||
@ -211,7 +219,7 @@ class DateTimeCompose(val bundle: Bundle) {
|
|||||||
.withHour(INT_8)
|
.withHour(INT_8)
|
||||||
.withMinute(0)
|
.withMinute(0)
|
||||||
.withSecond(0)
|
.withSecond(0)
|
||||||
val nextWeekStr = nextWeek.format(DateTimeFormatter.ofPattern(PATTERN))
|
val nextWeekStr = nextWeek.format(dayTimeFormatter)
|
||||||
|
|
||||||
if (currTime < laterToday) {
|
if (currTime < laterToday) {
|
||||||
TimeOption(
|
TimeOption(
|
||||||
@ -222,16 +230,14 @@ class DateTimeCompose(val bundle: Bundle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tomorrow.dayOfWeek < DayOfWeek.SATURDAY) {
|
TimeOption(
|
||||||
TimeOption(
|
label = stringResource(R.string.tomorrow),
|
||||||
label = stringResource(R.string.tomorrow),
|
timeString = tomorrowStr
|
||||||
timeString = tomorrowStr
|
) {
|
||||||
) {
|
setTime(tomorrow)
|
||||||
setTime(tomorrow)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currTime.dayOfWeek < DayOfWeek.SATURDAY) {
|
if (currTime.dayOfWeek < DayOfWeek.FRIDAY) {
|
||||||
TimeOption(
|
TimeOption(
|
||||||
label = stringResource(R.string.this_weekend),
|
label = stringResource(R.string.this_weekend),
|
||||||
timeString = thisWeekendStr
|
timeString = thisWeekendStr
|
||||||
@ -240,11 +246,13 @@ class DateTimeCompose(val bundle: Bundle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeOption(
|
if (currTime.dayOfWeek != DayOfWeek.SUNDAY) {
|
||||||
label = stringResource(R.string.next_week),
|
TimeOption(
|
||||||
timeString = nextWeekStr
|
label = stringResource(R.string.next_week),
|
||||||
) {
|
timeString = nextWeekStr
|
||||||
setTime(nextWeek)
|
) {
|
||||||
|
setTime(nextWeek)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HorizontalDivider()
|
HorizontalDivider()
|
||||||
@ -257,11 +265,13 @@ class DateTimeCompose(val bundle: Bundle) {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun Header() {
|
private fun Header() {
|
||||||
|
val context = LocalContext.current
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(INT_8.dp)
|
.padding(INT_8.dp)
|
||||||
|
.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Text(stringResource(R.string.nc_remind), modifier = Modifier.weight(1f))
|
Text(stringResource(R.string.nc_remind), modifier = Modifier.weight(HALF_WEIGHT))
|
||||||
|
|
||||||
val reminderState = chatViewModel.getReminderExistState
|
val reminderState = chatViewModel.getReminderExistState
|
||||||
.asFlow()
|
.asFlow()
|
||||||
@ -277,9 +287,16 @@ class DateTimeCompose(val bundle: Bundle) {
|
|||||||
else -> {}
|
else -> {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeState.value != LocalDateTime.ofEpochSecond(0, 0, ZoneOffset.MIN)) {
|
val timeText = if (timeState.value != LocalDateTime.ofEpochSecond(0, 0, ZoneOffset.MIN)) {
|
||||||
Text(timeState.value.format(DateTimeFormatter.ofPattern(PATTERN)))
|
timeState.value.format(DateTimeFormatter.ofPattern(fullPattern(context)))
|
||||||
|
} else {
|
||||||
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Text(
|
||||||
|
timeText,
|
||||||
|
modifier = Modifier.weight(HALF_WEIGHT)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
HorizontalDivider()
|
HorizontalDivider()
|
||||||
}
|
}
|
||||||
@ -295,8 +312,23 @@ class DateTimeCompose(val bundle: Bundle) {
|
|||||||
modifier = Modifier.verticalScroll(scrollState)
|
modifier = Modifier.verticalScroll(scrollState)
|
||||||
) {
|
) {
|
||||||
if (!isCollapsed.value) {
|
if (!isCollapsed.value) {
|
||||||
val datePickerState = rememberDatePickerState()
|
val todayMillis = LocalDate.now().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli()
|
||||||
val timePickerState = rememberTimePickerState()
|
val currentYear = LocalDate.now().year
|
||||||
|
val selectableDates = object : SelectableDates {
|
||||||
|
override fun isSelectableDate(utcTimeMillis: Long): Boolean = utcTimeMillis >= todayMillis
|
||||||
|
|
||||||
|
override fun isSelectableYear(year: Int): Boolean = year >= currentYear
|
||||||
|
}
|
||||||
|
|
||||||
|
val datePickerState = rememberDatePickerState(
|
||||||
|
selectableDates = selectableDates
|
||||||
|
)
|
||||||
|
val now = LocalDateTime.now()
|
||||||
|
val timePickerState = rememberTimePickerState(
|
||||||
|
initialHour = now.hour,
|
||||||
|
initialMinute = now.minute,
|
||||||
|
is24Hour = DateFormat.is24HourFormat(LocalContext.current)
|
||||||
|
)
|
||||||
|
|
||||||
BoxWithConstraints(
|
BoxWithConstraints(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -307,10 +339,15 @@ class DateTimeCompose(val bundle: Bundle) {
|
|||||||
DatePicker(
|
DatePicker(
|
||||||
state = datePickerState,
|
state = datePickerState,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.scale(scale)
|
.scale(scale),
|
||||||
|
colors = DatePickerDefaults.colors(
|
||||||
|
containerColor = Color.White
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
TimePicker(
|
TimePicker(
|
||||||
state = timePickerState
|
state = timePickerState
|
||||||
)
|
)
|
||||||
@ -356,6 +393,14 @@ class DateTimeCompose(val bundle: Bundle) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun timePattern(context: Context): String = if (DateFormat.is24HourFormat(context)) "HH:mm" else "hh:mm a"
|
||||||
|
|
||||||
|
private fun dayTimePattern(context: Context): String =
|
||||||
|
if (DateFormat.is24HourFormat(context)) "EEE, HH:mm" else "EEE, hh:mm a"
|
||||||
|
|
||||||
|
private fun fullPattern(context: Context): String =
|
||||||
|
if (DateFormat.is24HourFormat(context)) "dd MMM, HH:mm" else "dd MMM, hh:mm a"
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun TimeOption(label: String, timeString: String, onClick: () -> Unit) {
|
private fun TimeOption(label: String, timeString: String, onClick: () -> Unit) {
|
||||||
Row(
|
Row(
|
||||||
@ -370,7 +415,6 @@ class DateTimeCompose(val bundle: Bundle) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val PATTERN = "dd MMM, HH:mm a"
|
|
||||||
private const val HALF_WEIGHT = 0.5f
|
private const val HALF_WEIGHT = 0.5f
|
||||||
private const val INT_8 = 8
|
private const val INT_8 = 8
|
||||||
private const val INT_16 = 16
|
private const val INT_16 = 16
|
||||||
|
Loading…
Reference in New Issue
Block a user