From b96fa64ce1d5f707569681152ffafe322bd543d6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 22 Jan 2017 13:49:15 +0100 Subject: [PATCH] handle sunday as the first day in weekly view properly --- .../calendar/activities/MainActivity.kt | 9 ++++++++- .../simplemobiletools/calendar/fragments/WeekFragment.kt | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt index 7f01de5b9..0355fae4c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/MainActivity.kt @@ -41,6 +41,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { private var mSnackbar: Snackbar? = null private var mEventListFragment: EventListFragment? = null private var mStoredTextColor = 0 + private var mStoredIsSundayFirst = false companion object { var mWeekScrollY = 0 @@ -52,6 +53,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { calendar_fab.setOnClickListener { addNewEvent() } updateViewPager() mStoredTextColor = config.textColor + mStoredIsSundayFirst = config.isSundayFirst checkWhatsNewDialog() } @@ -60,6 +62,9 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { if (mStoredTextColor != config.textColor) updateViewPager() + if (mStoredIsSundayFirst != config.isSundayFirst && config.storedView == WEEKLY_VIEW) + fillWeeklyViewPager() + updateWidgets() updateTextColors(calendar_coordinator) } @@ -68,6 +73,7 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { super.onPause() checkDeleteEvents() mStoredTextColor = config.textColor + mStoredIsSundayFirst = config.isSundayFirst } override fun onDestroy() { @@ -174,7 +180,8 @@ class MainActivity : SimpleActivity(), EventListFragment.DeleteListener { } private fun fillWeeklyViewPager() { - val thisweek = DateTime().withDayOfWeek(1).withTime(0, 0, 0, 0).seconds() + val firstDayIndex = if (config.isSundayFirst) 7 else 1 + val thisweek = DateTime().withDayOfWeek(firstDayIndex).withTime(0, 0, 0, 0).seconds() val weekTSs = getWeekTimestamps(thisweek) val weeklyAdapter = MyWeekPagerAdapter(supportFragmentManager, weekTSs, object : WeekFragment.WeekScrollListener { override fun scrollTo(y: Int) { diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt index 99238d1b9..dd3ad6d36 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/WeekFragment.kt @@ -137,7 +137,7 @@ class WeekFragment : Fragment(), WeeklyCalendar { for (event in sorted) { val startDateTime = Formatter.getDateTimeFromTS(event.startTS) val endDateTime = Formatter.getDateTimeFromTS(event.endTS) - val dayOfWeek = startDateTime.dayOfWeek - if (context.config.isSundayFirst) 0 else 1 + val dayOfWeek = startDateTime.dayOfWeek - 1 val layout = getColumnWithId(dayOfWeek) val startMinutes = startDateTime.minuteOfDay