From 2c16b5911a4f01d91bfb905399632e78d719f3e5 Mon Sep 17 00:00:00 2001 From: Sam Pengilly Date: Fri, 21 Jun 2019 11:48:31 +1000 Subject: [PATCH] Fix exceptions causing render to fail in the layout editor. The main cause with calendarMode not being set was that an exception was occurring inside the state setup in the constructor, this exception was being swallowed by the try-catch block surrounding the setup logic. The exception that was occurring in the state setup was the ThreeTen missing zone data one. By calling `AndroidThreeTen.init(context)` for edit mode at the beginning of the constructor this exception can be prevented. Another exception that was occurring was due to a null `previousMonth` in the `TitleChanger`. While this PR results in the calendar displaying in the layout editor, the dates displayed aren't a complete representation of the month, and the calendar mode isn't properly honoured. --- .../materialcalendarview/MaterialCalendarView.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java b/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java index 623b4a69..f0de12a1 100644 --- a/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java +++ b/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java @@ -27,6 +27,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import com.jakewharton.threetenabp.AndroidThreeTen; import com.prolificinteractive.materialcalendarview.format.ArrayWeekDayFormatter; import com.prolificinteractive.materialcalendarview.format.DayFormatter; import com.prolificinteractive.materialcalendarview.format.MonthArrayTitleFormatter; @@ -249,6 +250,10 @@ public MaterialCalendarView(Context context) { public MaterialCalendarView(Context context, AttributeSet attrs) { super(context, attrs); + if (isInEditMode()) { + AndroidThreeTen.init(context); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { //If we're on good Android versions, turn off clipping for cool effects setClipToPadding(false); @@ -430,6 +435,10 @@ private void setupChildren() { } private void updateUi() { + if (isInEditMode()) { + titleChanger.setPreviousMonth(currentMonth); + } + titleChanger.change(currentMonth); enableView(buttonPast, canGoBack()); enableView(buttonFuture, canGoForward());