diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt index 2e29600bb..8e0b38d52 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/EventActivity.kt @@ -46,7 +46,6 @@ import kotlinx.android.synthetic.main.activity_event.view.event_reminder_3 import kotlinx.android.synthetic.main.item_attendee.view.* import org.joda.time.DateTime import org.joda.time.DateTimeZone -import java.util.Calendar import java.util.TimeZone import java.util.regex.Pattern @@ -1449,13 +1448,13 @@ class EventActivity : SimpleActivity() { private fun setupStartDate() { hideKeyboard() - val datepicker = DatePickerDialog( + val datePicker = DatePickerDialog( this, getDatePickerDialogTheme(), startDateSetListener, mEventStartDateTime.year, mEventStartDateTime.monthOfYear - 1, mEventStartDateTime.dayOfMonth ) - datepicker.datePicker.firstDayOfWeek = if (config.isSundayFirst) Calendar.SUNDAY else Calendar.MONDAY - datepicker.show() + datePicker.datePicker.firstDayOfWeek = getJavaDayOfWeekFromJoda(config.firstDayOfWeek) + datePicker.show() } private fun setupStartTime() { @@ -1493,13 +1492,13 @@ class EventActivity : SimpleActivity() { private fun setupEndDate() { hideKeyboard() - val datepicker = DatePickerDialog( + val datePicker = DatePickerDialog( this, getDatePickerDialogTheme(), endDateSetListener, mEventEndDateTime.year, mEventEndDateTime.monthOfYear - 1, mEventEndDateTime.dayOfMonth ) - datepicker.datePicker.firstDayOfWeek = if (config.isSundayFirst) Calendar.SUNDAY else Calendar.MONDAY - datepicker.show() + datePicker.datePicker.firstDayOfWeek = getJavaDayOfWeekFromJoda(config.firstDayOfWeek) + datePicker.show() } private fun setupEndTime() { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt index 84df33745..08342f34d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/activities/TaskActivity.kt @@ -536,7 +536,7 @@ class TaskActivity : SimpleActivity() { this, getDatePickerDialogTheme(), dateSetListener, mTaskDateTime.year, mTaskDateTime.monthOfYear - 1, mTaskDateTime.dayOfMonth ) - datePicker.datePicker.firstDayOfWeek = if (config.isSundayFirst) Calendar.SUNDAY else Calendar.MONDAY + datePicker.datePicker.firstDayOfWeek = getJavaDayOfWeekFromJoda(config.firstDayOfWeek) datePicker.show() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/RepeatLimitTypePickerDialog.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/RepeatLimitTypePickerDialog.kt index c53251ff2..b702c3733 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/RepeatLimitTypePickerDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/dialogs/RepeatLimitTypePickerDialog.kt @@ -8,11 +8,11 @@ import com.simplemobiletools.calendar.pro.R import com.simplemobiletools.calendar.pro.extensions.config import com.simplemobiletools.calendar.pro.extensions.seconds import com.simplemobiletools.calendar.pro.helpers.Formatter +import com.simplemobiletools.calendar.pro.helpers.getJavaDayOfWeekFromJoda import com.simplemobiletools.calendar.pro.helpers.getNowSeconds import com.simplemobiletools.commons.extensions.* import kotlinx.android.synthetic.main.dialog_repeat_limit_type_picker.view.* import org.joda.time.DateTime -import java.util.* class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Long, val startTS: Long, val callback: (repeatLimit: Long) -> Unit) { private var dialog: AlertDialog? = null @@ -88,13 +88,13 @@ class RepeatLimitTypePickerDialog(val activity: Activity, var repeatLimit: Long, private fun showRepetitionLimitDialog() { val repeatLimitDateTime = Formatter.getDateTimeFromTS(if (repeatLimit != 0L) repeatLimit else getNowSeconds()) - val datepicker = DatePickerDialog( + val datePicker = DatePickerDialog( activity, activity.getDatePickerDialogTheme(), repetitionLimitDateSetListener, repeatLimitDateTime.year, repeatLimitDateTime.monthOfYear - 1, repeatLimitDateTime.dayOfMonth ) - datepicker.datePicker.firstDayOfWeek = if (activity.config.isSundayFirst) Calendar.SUNDAY else Calendar.MONDAY - datepicker.show() + datePicker.datePicker.firstDayOfWeek = getJavaDayOfWeekFromJoda(activity.config.firstDayOfWeek) + datePicker.show() } private val repetitionLimitDateSetListener = DatePickerDialog.OnDateSetListener { v, year, monthOfYear, dayOfMonth -> diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt index 8b5a77e47..a5e260ffd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Config.kt @@ -30,7 +30,10 @@ class Config(context: Context) : BaseConfig(context) { set(startWeekWithCurrentDay) = prefs.edit().putBoolean(START_WEEK_WITH_CURRENT_DAY, startWeekWithCurrentDay).apply() var firstDayOfWeek: Int - get() = prefs.getInt(FIRST_DAY_OF_WEEK, getDefaultFirstDayOfWeekJoda()) + get() { + val defaultFirstDayOfWeek = Calendar.getInstance(Locale.getDefault()).firstDayOfWeek + return prefs.getInt(FIRST_DAY_OF_WEEK, getJodaDayOfWeekFromJava(defaultFirstDayOfWeek)) + } set(firstDayOfWeek) = prefs.edit().putInt(FIRST_DAY_OF_WEEK, firstDayOfWeek).apply() var showMidnightSpanningEventsAtTop: Boolean diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt index 833469d0d..dd6653912 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/pro/helpers/Constants.kt @@ -315,3 +315,29 @@ fun getDefaultFirstDayOfWeekJoda(): Int { else -> DateTimeConstants.SUNDAY } } + +fun getJodaDayOfWeekFromJava(dayOfWeek: Int): Int { + return when (dayOfWeek) { + Calendar.SUNDAY -> DateTimeConstants.SUNDAY + Calendar.MONDAY -> DateTimeConstants.MONDAY + Calendar.TUESDAY -> DateTimeConstants.TUESDAY + Calendar.WEDNESDAY -> DateTimeConstants.WEDNESDAY + Calendar.THURSDAY -> DateTimeConstants.THURSDAY + Calendar.FRIDAY -> DateTimeConstants.FRIDAY + Calendar.SATURDAY -> DateTimeConstants.SATURDAY + else -> throw IllegalArgumentException("Invalid day: $dayOfWeek") + } +} + +fun getJavaDayOfWeekFromJoda(dayOfWeek: Int): Int { + return when (dayOfWeek) { + DateTimeConstants.SUNDAY -> Calendar.SUNDAY + DateTimeConstants.MONDAY -> Calendar.MONDAY + DateTimeConstants.TUESDAY -> Calendar.TUESDAY + DateTimeConstants.WEDNESDAY -> Calendar.WEDNESDAY + DateTimeConstants.THURSDAY -> Calendar.THURSDAY + DateTimeConstants.FRIDAY -> Calendar.FRIDAY + DateTimeConstants.SATURDAY -> Calendar.SATURDAY + else -> throw IllegalArgumentException("Invalid day: $dayOfWeek") + } +}