allow setting the current time as the default at new events

This commit is contained in:
tibbi 2021-04-14 22:51:25 +02:00
parent 42135f9b5b
commit dfb7061450
3 changed files with 31 additions and 17 deletions

View File

@ -572,13 +572,19 @@ class SettingsActivity : SimpleActivity() {
private fun setupDefaultStartTime() {
updateDefaultStartTimeText()
settings_default_start_time_holder.setOnClickListener {
val currentDefaultTime = if (config.defaultStartTime == DEFAULT_START_TIME_NEXT_FULL_HOUR) DEFAULT_START_TIME_NEXT_FULL_HOUR else 0
val currentDefaultTime = when (config.defaultStartTime) {
DEFAULT_START_TIME_NEXT_FULL_HOUR -> DEFAULT_START_TIME_NEXT_FULL_HOUR
DEFAULT_START_TIME_CURRENT_TIME -> DEFAULT_START_TIME_CURRENT_TIME
else -> 0
}
val items = ArrayList<RadioItem>()
items.add(RadioItem(DEFAULT_START_TIME_CURRENT_TIME, getString(R.string.current_time)))
items.add(RadioItem(DEFAULT_START_TIME_NEXT_FULL_HOUR, getString(R.string.next_full_hour)))
items.add(RadioItem(0, getString(R.string.other_time)))
RadioGroupDialog(this@SettingsActivity, items, currentDefaultTime) {
if (it as Int == DEFAULT_START_TIME_NEXT_FULL_HOUR) {
if (it as Int == DEFAULT_START_TIME_NEXT_FULL_HOUR || it == DEFAULT_START_TIME_CURRENT_TIME) {
config.defaultStartTime = it
updateDefaultStartTimeText()
} else {
@ -595,12 +601,14 @@ class SettingsActivity : SimpleActivity() {
}
private fun updateDefaultStartTimeText() {
if (config.defaultStartTime == DEFAULT_START_TIME_NEXT_FULL_HOUR) {
settings_default_start_time.text = getString(R.string.next_full_hour)
} else {
val hours = config.defaultStartTime / 60
val minutes = config.defaultStartTime % 60
settings_default_start_time.text = String.format("%02d:%02d", hours, minutes)
when (config.defaultStartTime) {
DEFAULT_START_TIME_CURRENT_TIME -> settings_default_start_time.text = getString(R.string.current_time)
DEFAULT_START_TIME_NEXT_FULL_HOUR -> settings_default_start_time.text = getString(R.string.next_full_hour)
else -> {
val hours = config.defaultStartTime / 60
val minutes = config.defaultStartTime % 60
settings_default_start_time.text = String.format("%02d:%02d", hours, minutes)
}
}
}

View File

@ -350,16 +350,21 @@ fun Context.getNewEventTimestampFromCode(dayCode: String, allowChangingDay: Bool
newDateTime = newDateTime.minusDays(1)
}
return if (defaultStartTime == -1) {
newDateTime.seconds()
} else {
val hours = defaultStartTime / 60
val minutes = defaultStartTime % 60
dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(hours).withMinuteOfHour(minutes)
newDateTime = dateTime
return when (defaultStartTime) {
DEFAULT_START_TIME_CURRENT_TIME -> {
val currMinutes = calendar.get(Calendar.MINUTE)
dateTime.withMinuteOfHour(currMinutes).seconds()
}
DEFAULT_START_TIME_NEXT_FULL_HOUR -> newDateTime.seconds()
else -> {
val hours = defaultStartTime / 60
val minutes = defaultStartTime % 60
dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(hours).withMinuteOfHour(minutes)
newDateTime = dateTime
// make sure the date doesn't change
newDateTime.withDate(dateTime.year, dateTime.monthOfYear, dateTime.dayOfMonth).seconds()
// make sure the date doesn't change
newDateTime.withDate(dateTime.year, dateTime.monthOfYear, dateTime.dayOfMonth).seconds()
}
}
}

View File

@ -35,6 +35,7 @@ const val ITEM_EVENT_SIMPLE = 1
const val ITEM_HEADER = 2
const val DEFAULT_START_TIME_NEXT_FULL_HOUR = -1
const val DEFAULT_START_TIME_CURRENT_TIME = -2
const val DAY = 86400
const val WEEK = 604800