From fc9f4e54612f350f47b8118ee1fbc10af053b8dc Mon Sep 17 00:00:00 2001 From: Anatoliy Shulipov Date: Fri, 2 Apr 2021 15:22:16 +0300 Subject: [PATCH] Add ability to change new params through xml --- .../java/ru/cleverpumpkin/calendar/CalendarView.kt | 8 -------- .../calendar/style/CalendarStyleAttributes.kt | 11 +++++------ .../calendar/style/CalendarStyleAttributesReader.kt | 12 +++++++++++- crunchycalendar/src/main/res/values/attrs.xml | 2 ++ .../src/main/res/layout/fragment_demo_selection.xml | 1 + 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/crunchycalendar/src/main/java/ru/cleverpumpkin/calendar/CalendarView.kt b/crunchycalendar/src/main/java/ru/cleverpumpkin/calendar/CalendarView.kt index ae66b8b..e2ebcca 100644 --- a/crunchycalendar/src/main/java/ru/cleverpumpkin/calendar/CalendarView.kt +++ b/crunchycalendar/src/main/java/ru/cleverpumpkin/calendar/CalendarView.kt @@ -574,14 +574,6 @@ class CalendarView @JvmOverloads constructor( setDateCellTextColor(colorStateList) } - /** - * Sets - */ - fun useSeparateWeekendDaysBarTextColor(used: Boolean){ - calendarStyleAttributes.useSeparateColorForWeekendDays = used - daysBarView.applyStyle(calendarStyleAttributes) - } - /** * Add custom [RecyclerView.ItemDecoration] that will be used for the Calendar view decoration. */ diff --git a/crunchycalendar/src/main/java/ru/cleverpumpkin/calendar/style/CalendarStyleAttributes.kt b/crunchycalendar/src/main/java/ru/cleverpumpkin/calendar/style/CalendarStyleAttributes.kt index fbd877e..507fad7 100644 --- a/crunchycalendar/src/main/java/ru/cleverpumpkin/calendar/style/CalendarStyleAttributes.kt +++ b/crunchycalendar/src/main/java/ru/cleverpumpkin/calendar/style/CalendarStyleAttributes.kt @@ -43,16 +43,15 @@ internal class CalendarStyleAttributes( var monthTextStyle: Int = Typeface.NORMAL, + @DrawableRes + var dateCellBackgroundShapeForm: Int = R.drawable.calendar_date_shape_form, + @ColorRes var dateCellBackgroundColorRes: Int = R.color.calendar_date_bg_selector, var dateCellTextColorStateList: ColorStateList = requireNotNull( ContextCompat.getColorStateList(context, R.color.calendar_date_text_selector) - ), - - var dateCellBackgroundShapeForm: Int = R.drawable.calendar_date_shape_form, - - var useSeparateColorForWeekendDays: Boolean = false + ) ) { @@ -63,5 +62,5 @@ internal class CalendarStyleAttributes( } else { field } - + } \ No newline at end of file diff --git a/crunchycalendar/src/main/java/ru/cleverpumpkin/calendar/style/CalendarStyleAttributesReader.kt b/crunchycalendar/src/main/java/ru/cleverpumpkin/calendar/style/CalendarStyleAttributesReader.kt index 591e678..dd294c6 100644 --- a/crunchycalendar/src/main/java/ru/cleverpumpkin/calendar/style/CalendarStyleAttributesReader.kt +++ b/crunchycalendar/src/main/java/ru/cleverpumpkin/calendar/style/CalendarStyleAttributesReader.kt @@ -56,6 +56,11 @@ internal object CalendarStyleAttributesReader { daysBarTextColor ) + daysBarWeekendTextColor = typedArray.getColor( + R.styleable.CalendarView_calendar_day_bar_weekend_text_color, + daysBarWeekendTextColor + ) + monthTextColor = typedArray.getColor( R.styleable.CalendarView_calendar_month_text_color, monthTextColor @@ -71,8 +76,13 @@ internal object CalendarStyleAttributesReader { monthTextStyle ) - dateCellBackgroundColorRes = typedArray.getResourceId( + dateCellBackgroundShapeForm = typedArray.getResourceId( R.styleable.CalendarView_calendar_date_background, + dateCellBackgroundShapeForm + ) + + dateCellBackgroundColorRes = typedArray.getResourceId( + R.styleable.CalendarView_calendar_date_background_tint, dateCellBackgroundColorRes ) diff --git a/crunchycalendar/src/main/res/values/attrs.xml b/crunchycalendar/src/main/res/values/attrs.xml index 767b239..7bf63d3 100644 --- a/crunchycalendar/src/main/res/values/attrs.xml +++ b/crunchycalendar/src/main/res/values/attrs.xml @@ -11,6 +11,7 @@ + @@ -21,6 +22,7 @@ + diff --git a/sample/src/main/res/layout/fragment_demo_selection.xml b/sample/src/main/res/layout/fragment_demo_selection.xml index 81ec96f..c44c11e 100644 --- a/sample/src/main/res/layout/fragment_demo_selection.xml +++ b/sample/src/main/res/layout/fragment_demo_selection.xml @@ -3,6 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical">