diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt index f2630cfeb..2f417be12 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/EventActivity.kt @@ -328,7 +328,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { fun setupStartTime() { hideKeyboard() - TimePickerDialog(this, mDialogTheme, startTimeSetListener, mEventStartDateTime.hourOfDay, mEventStartDateTime.minuteOfHour, true).show() + TimePickerDialog(this, mDialogTheme, startTimeSetListener, mEventStartDateTime.hourOfDay, mEventStartDateTime.minuteOfHour, config.use24hourFormat).show() } fun setupEndDate() { @@ -339,7 +339,7 @@ class EventActivity : SimpleActivity(), DBHelper.EventUpdateListener { fun setupEndTime() { hideKeyboard() - TimePickerDialog(this, mDialogTheme, endTimeSetListener, mEventEndDateTime.hourOfDay, mEventEndDateTime.minuteOfHour, true).show() + TimePickerDialog(this, mDialogTheme, endTimeSetListener, mEventEndDateTime.hourOfDay, mEventEndDateTime.minuteOfHour, config.use24hourFormat).show() } private val startDateSetListener = DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth -> diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt index a9701f008..510923dc7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/SettingsActivity.kt @@ -41,6 +41,7 @@ class SettingsActivity : SimpleActivity() { setupCustomizeColors() setupManageEventTypes() + setupHourFormat() setupSundayFirst() setupGoogleSync() setupWeeklyStart() @@ -64,6 +65,14 @@ class SettingsActivity : SimpleActivity() { } } + private fun setupHourFormat() { + settings_hour_format.isChecked = config.use24hourFormat + settings_hour_format_holder.setOnClickListener { + settings_hour_format.toggle() + config.use24hourFormat = settings_hour_format.isChecked + } + } + private fun setupGoogleSync() { settings_google_sync.isChecked = config.googleSync settings_google_sync_holder.setOnClickListener { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt index ac871697b..cb4fdeef5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Config.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.calendar.helpers import android.content.Context import android.media.RingtoneManager +import android.text.format.DateFormat import com.simplemobiletools.commons.helpers.BaseConfig import java.util.* @@ -17,6 +18,13 @@ class Config(context: Context) : BaseConfig(context) { } set(sundayFirst) = prefs.edit().putBoolean(SUNDAY_FIRST, sundayFirst).apply() + var use24hourFormat: Boolean + get() { + val use24hourFormat = DateFormat.is24HourFormat(context) + return prefs.getBoolean(USE_24_HOUR_FORMAT, use24hourFormat) + } + set(use24hourFormat) = prefs.edit().putBoolean(USE_24_HOUR_FORMAT, use24hourFormat).apply() + var displayWeekNumbers: Boolean get() = prefs.getBoolean(WEEK_NUMBERS, false) set(displayWeekNumbers) = prefs.edit().putBoolean(WEEK_NUMBERS, displayWeekNumbers).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt index 07138f8f7..d6e60df4c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -29,6 +29,7 @@ val DAY_SECONDS = 24 * 60 * 60 val WEEK_SECONDS = 7 * DAY_SECONDS // Shared Preferences +val USE_24_HOUR_FORMAT = "use_24_hour_format" val SUNDAY_FIRST = "sunday_first" val WEEK_NUMBERS = "week_numbers" val START_WEEKLY_AT = "start_weekly_at" diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Formatter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Formatter.kt index 2e2a876a8..da43b1e57 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Formatter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Formatter.kt @@ -1,8 +1,8 @@ package com.simplemobiletools.calendar.helpers import android.content.Context -import android.text.format.DateFormat import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.extensions.config import com.simplemobiletools.calendar.extensions.seconds import org.joda.time.DateTime import org.joda.time.DateTimeZone @@ -63,5 +63,5 @@ object Formatter { // use manually translated month names, as DateFormat and Joda have issues with a lot of languages fun getMonthName(context: Context, id: Int) = context.resources.getStringArray(R.array.months)[id - 1] - fun getTimePattern(context: Context) = if (DateFormat.is24HourFormat(context)) PATTERN_TIME_24 else PATTERN_TIME_12 + fun getTimePattern(context: Context) = if (context.config.use24hourFormat) PATTERN_TIME_24 else PATTERN_TIME_12 } diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 1d37daba0..fb7a700bb 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -49,6 +49,26 @@ + + + + + +