From 4daee3c3d8b804a08a4ef1f9976aab309a534ce2 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 13 Feb 2019 14:29:51 +0100 Subject: [PATCH] improving some settings related code --- .../pro/activities/SettingsActivity.kt | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt index 9515379d7..d3ed5cbc2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/SettingsActivity.kt @@ -553,47 +553,43 @@ class SettingsActivity : SimpleActivity() { } private fun setupDefaultStartTime() { - settings_set_default_start_time.text = getHoursString(config.defaultStartTime) - if (config.defaultStartTime == -1) { - settings_set_default_start_time.text = "/" - } + updateDefaultStartTimeText() settings_set_default_start_time_holder.setOnClickListener { val items = ArrayList() - items.add(RadioItem(-1, "/")) + items.add(RadioItem(-1, getString(R.string.next_full_hour))) (0..24).mapTo(items) { RadioItem(it, getHoursString(it)) } RadioGroupDialog(this@SettingsActivity, items, config.defaultStartTime) { - config.defaultStartTime = it as Int - settings_set_default_start_time.text = getHoursString(it) - if (it == -1) { - settings_set_default_start_time.text = "/" - } + config.defaultStartTime = it as Int + updateDefaultStartTimeText() } } } + private fun updateDefaultStartTimeText() { + settings_set_default_start_time.text = getHoursString(config.defaultStartTime) + if (config.defaultStartTime == -1) { + settings_set_default_start_time.text = getString(R.string.next_full_hour) + } + } + private fun setupDefaultDuration() { - var defaultDuration = config.defaultDuration - updateDefaultDurationText(defaultDuration) + updateDefaultDurationText() settings_set_default_duration_time_holder.setOnClickListener { - CustomIntervalPickerDialog(this, defaultDuration * 60) { + CustomIntervalPickerDialog(this, config.defaultDuration * 60) { val result = it / 60 - defaultDuration = result config.defaultDuration = result - updateDefaultDurationText(result) + updateDefaultDurationText() } } } - private fun updateDefaultDurationText(defaultDuration: Int) { - settings_set_default_duration_time.text = getDefaultDurationText(defaultDuration) - } - - private fun getDefaultDurationText(defaultDuration: Int): String { - return if (defaultDuration == 0) { - "0 " + getString(R.string.minutes_raw) + private fun updateDefaultDurationText() { + val duration = config.defaultDuration + settings_set_default_duration_time.text = if (duration == 0) { + "0 ${getString(R.string.minutes_raw)}" } else { - getFormattedMinutes(defaultDuration, false) + getFormattedMinutes(duration, false) } } }