From a7a098ca9d6b79cb240f313476e46456d018fa06 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 19 Oct 2016 19:31:59 +0200 Subject: [PATCH] update the yearly view if Sunday as the first day is toggled --- .../calendar/fragments/YearFragment.kt | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/YearFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/YearFragment.kt index 45821bcf1..ef71233fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/YearFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/YearFragment.kt @@ -16,28 +16,39 @@ import org.joda.time.DateTime class YearFragment : Fragment() { private var mListener: NavigationListener? = null private var mYear = 0 + private var mSundayFirst = false + lateinit var mView: View override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { - val view = inflater!!.inflate(R.layout.year_fragment, container, false) - + mView = inflater!!.inflate(R.layout.year_fragment, container, false) mYear = arguments.getInt(Constants.YEAR_LABEL) + setupMonths() + return mView + } + override fun onResume() { + super.onResume() + val sundayFirst = Config.newInstance(context).isSundayFirst + if (sundayFirst != mSundayFirst) { + mSundayFirst = sundayFirst + setupMonths() + } + } + + fun setupMonths() { val dateTime = DateTime().withYear(mYear).withDayOfMonth(1).withMonthOfYear(2).withHourOfDay(12) val days = dateTime.dayOfMonth().maximumValue - view.month_2.setDays(days) + mView.month_2.setDays(days) val res = resources - val sundayFirst = Config.newInstance(context).isSundayFirst for (i in 1..12) { - val monthView = view.findViewById(res.getIdentifier("month_" + i, "id", activity.packageName)) as SmallMonthView + val monthView = mView.findViewById(res.getIdentifier("month_" + i, "id", activity.packageName)) as SmallMonthView var dayOfWeek = dateTime.withMonthOfYear(i).dayOfWeek().get() - if (!sundayFirst) + if (!mSundayFirst) dayOfWeek-- monthView.setFirstDay(dayOfWeek) } - - return view } fun setListener(listener: NavigationListener) {