allow toggling 24 hour format in settings

This commit is contained in:
tibbi 2017-02-21 21:55:27 +01:00
parent c7c2f117de
commit e92d0f9bf6
6 changed files with 42 additions and 4 deletions

View File

@ -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 ->

View File

@ -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 {

View File

@ -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()

View File

@ -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"

View File

@ -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
}

View File

@ -49,6 +49,26 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_hour_format_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_hour_format"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/use_24_hour_format"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_google_sync_holder"
android:layout_width="match_parent"