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() { private fun setupDefaultStartTime() {
updateDefaultStartTimeText() updateDefaultStartTimeText()
settings_default_start_time_holder.setOnClickListener { 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>() 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(DEFAULT_START_TIME_NEXT_FULL_HOUR, getString(R.string.next_full_hour)))
items.add(RadioItem(0, getString(R.string.other_time))) items.add(RadioItem(0, getString(R.string.other_time)))
RadioGroupDialog(this@SettingsActivity, items, currentDefaultTime) { 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 config.defaultStartTime = it
updateDefaultStartTimeText() updateDefaultStartTimeText()
} else { } else {
@ -595,12 +601,14 @@ class SettingsActivity : SimpleActivity() {
} }
private fun updateDefaultStartTimeText() { private fun updateDefaultStartTimeText() {
if (config.defaultStartTime == DEFAULT_START_TIME_NEXT_FULL_HOUR) { when (config.defaultStartTime) {
settings_default_start_time.text = getString(R.string.next_full_hour) DEFAULT_START_TIME_CURRENT_TIME -> settings_default_start_time.text = getString(R.string.current_time)
} else { DEFAULT_START_TIME_NEXT_FULL_HOUR -> settings_default_start_time.text = getString(R.string.next_full_hour)
val hours = config.defaultStartTime / 60 else -> {
val minutes = config.defaultStartTime % 60 val hours = config.defaultStartTime / 60
settings_default_start_time.text = String.format("%02d:%02d", hours, minutes) 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) newDateTime = newDateTime.minusDays(1)
} }
return if (defaultStartTime == -1) { return when (defaultStartTime) {
newDateTime.seconds() DEFAULT_START_TIME_CURRENT_TIME -> {
} else { val currMinutes = calendar.get(Calendar.MINUTE)
val hours = defaultStartTime / 60 dateTime.withMinuteOfHour(currMinutes).seconds()
val minutes = defaultStartTime % 60 }
dateTime = Formatter.getLocalDateTimeFromCode(dayCode).withHourOfDay(hours).withMinuteOfHour(minutes) DEFAULT_START_TIME_NEXT_FULL_HOUR -> newDateTime.seconds()
newDateTime = dateTime 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 // make sure the date doesn't change
newDateTime.withDate(dateTime.year, dateTime.monthOfYear, dateTime.dayOfMonth).seconds() 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 ITEM_HEADER = 2
const val DEFAULT_START_TIME_NEXT_FULL_HOUR = -1 const val DEFAULT_START_TIME_NEXT_FULL_HOUR = -1
const val DEFAULT_START_TIME_CURRENT_TIME = -2
const val DAY = 86400 const val DAY = 86400
const val WEEK = 604800 const val WEEK = 604800