From 2fafcf6ea4d2759ef530b8b515df80dc8709ee3c Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 19 Oct 2016 19:27:31 +0200 Subject: [PATCH] setup the first day of the month --- .../calendar/fragments/YearFragment.kt | 16 +++++++++++++++- .../calendar/views/SmallMonthView.kt | 11 ++++++++--- 2 files changed, 23 insertions(+), 4 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 f08c471da..45821bcf1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/YearFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/YearFragment.kt @@ -5,9 +5,11 @@ import android.support.v4.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import com.simplemobiletools.calendar.Config import com.simplemobiletools.calendar.Constants import com.simplemobiletools.calendar.NavigationListener import com.simplemobiletools.calendar.R +import com.simplemobiletools.calendar.views.SmallMonthView import kotlinx.android.synthetic.main.year_fragment.view.* import org.joda.time.DateTime @@ -20,9 +22,21 @@ class YearFragment : Fragment() { mYear = arguments.getInt(Constants.YEAR_LABEL) - val days = DateTime().withYear(mYear).withDayOfMonth(1).withMonthOfYear(2).dayOfMonth().maximumValue + val dateTime = DateTime().withYear(mYear).withDayOfMonth(1).withMonthOfYear(2).withHourOfDay(12) + val days = dateTime.dayOfMonth().maximumValue view.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 + var dayOfWeek = dateTime.withMonthOfYear(i).dayOfWeek().get() + if (!sundayFirst) + dayOfWeek-- + + monthView.setFirstDay(dayOfWeek) + } + return view } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/views/SmallMonthView.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/views/SmallMonthView.kt index c5a7f0ca5..1f8197c19 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/views/SmallMonthView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/views/SmallMonthView.kt @@ -16,6 +16,7 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie var mDayWidth = 0f var mTextColor = 0 var mDays = 31 + var mFirstDay = 0 constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0) { } @@ -25,6 +26,10 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie invalidate() } + fun setFirstDay(firstDay: Int) { + mFirstDay = firstDay + } + init { val a = context.theme.obtainStyledAttributes( attrs, @@ -52,13 +57,13 @@ class SmallMonthView(context: Context, attrs: AttributeSet, defStyle: Int) : Vie mDayWidth = (canvas.width / 7).toFloat() } - var curId = 1 + var curId = 1 - mFirstDay for (y in 1..6) { for (x in 1..7) { - if (curId <= mDays) { + if (curId > 0 && curId <= mDays) { canvas.drawText(curId.toString(), x * mDayWidth, y * mDayWidth, mPaint) - curId++ } + curId++ } } }