Skip to content

Commit

Permalink
Merge pull request #455 from Applandeo/MCVOS-39
Browse files Browse the repository at this point in the history
Mcvos 39
  • Loading branch information
pavlomelnyk authored Oct 31, 2023
2 parents 196c492 + b1fd6ce commit 2d0eb03
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 114 deletions.
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ apply plugin: 'kotlin-android-extensions'
ext {
PUBLISH_GROUP_ID = 'com.applandeo'
PUBLISH_ARTIFACT_ID = 'material-calendar-view'
PUBLISH_VERSION = '1.9.0-rc06'
PUBLISH_VERSION = '1.9.0'
}

android {
compileSdkVersion 33
defaultConfig {
minSdkVersion 15
targetSdkVersion 33
versionCode 2
versionCode 3
versionName PUBLISH_VERSION

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
2 changes: 1 addition & 1 deletion library/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ RELEASE_SIGNING_ENABLED=true

GROUP=com.applandeo
POM_ARTIFACT_ID=material-calendar-view
VERSION_NAME=1.9.0-rc06
VERSION_NAME=1.9.0

POM_NAME=Material-Calendar-View
POM_DESCRIPTION=Material-Calendar-View is a simple and customizable calendar widget for Android based on Material Design
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@ package com.applandeo.materialcalendarview
import android.graphics.drawable.Drawable
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import java.util.*
import java.util.Calendar

/*
In one of feature versions, the idea is to merge and replace EventDay and SelectedDay with this object
*/
class CalendarDay(val calendar: Calendar) {
data class CalendarDay(
val calendar: Calendar
) {
@ColorRes
var labelColor: Int? = null

@DrawableRes
var backgroundResource: Int? = null

var backgroundDrawable: Drawable? = null

@ColorRes
var selectedLabelColor: Int? = null

@DrawableRes
var selectedBackgroundResource: Int? = null

var selectedBackgroundDrawable: Drawable? = null

@DrawableRes
var imageResource: Int? = null
var imageDrawable: Drawable? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import androidx.annotation.LayoutRes
import com.applandeo.materialcalendarview.adapters.CalendarPageAdapter
import com.applandeo.materialcalendarview.exceptions.ErrorsMessages
import com.applandeo.materialcalendarview.exceptions.OutOfDateRangeException
import com.applandeo.materialcalendarview.listeners.OnCalendarDayClickListener
import com.applandeo.materialcalendarview.listeners.OnCalendarDayLongClickListener
import com.applandeo.materialcalendarview.listeners.OnCalendarPageChangeListener
import com.applandeo.materialcalendarview.listeners.OnDayClickListener
import com.applandeo.materialcalendarview.listeners.OnDayLongClickListener
Expand Down Expand Up @@ -94,28 +96,37 @@ class CalendarView @JvmOverloads constructor(
private fun initCalendarProperties(typedArray: TypedArray) = with(calendarProperties) {
headerColor = typedArray.getColor(R.styleable.CalendarView_headerColor, 0)
headerLabelColor = typedArray.getColor(R.styleable.CalendarView_headerLabelColor, 0)
abbreviationsBarColor = typedArray.getColor(R.styleable.CalendarView_abbreviationsBarColor, 0)
abbreviationsLabelsColor = typedArray.getColor(R.styleable.CalendarView_abbreviationsLabelsColor, 0)
abbreviationsLabelsSize = typedArray.getDimension(R.styleable.CalendarView_abbreviationsLabelsSize, 0F)
abbreviationsBarColor =
typedArray.getColor(R.styleable.CalendarView_abbreviationsBarColor, 0)
abbreviationsLabelsColor =
typedArray.getColor(R.styleable.CalendarView_abbreviationsLabelsColor, 0)
abbreviationsLabelsSize =
typedArray.getDimension(R.styleable.CalendarView_abbreviationsLabelsSize, 0F)
pagesColor = typedArray.getColor(R.styleable.CalendarView_pagesColor, 0)
daysLabelsColor = typedArray.getColor(R.styleable.CalendarView_daysLabelsColor, 0)
anotherMonthsDaysLabelsColor = typedArray.getColor(R.styleable.CalendarView_anotherMonthsDaysLabelsColor, 0)
anotherMonthsDaysLabelsColor =
typedArray.getColor(R.styleable.CalendarView_anotherMonthsDaysLabelsColor, 0)
todayLabelColor = typedArray.getColor(R.styleable.CalendarView_todayLabelColor, 0)
selectionColor = typedArray.getColor(R.styleable.CalendarView_selectionColor, 0)
selectionLabelColor = typedArray.getColor(R.styleable.CalendarView_selectionLabelColor, 0)
disabledDaysLabelsColor = typedArray.getColor(R.styleable.CalendarView_disabledDaysLabelsColor, 0)
highlightedDaysLabelsColor = typedArray.getColor(R.styleable.CalendarView_highlightedDaysLabelsColor, 0)
disabledDaysLabelsColor =
typedArray.getColor(R.styleable.CalendarView_disabledDaysLabelsColor, 0)
highlightedDaysLabelsColor =
typedArray.getColor(R.styleable.CalendarView_highlightedDaysLabelsColor, 0)
calendarType = typedArray.getInt(R.styleable.CalendarView_type, CLASSIC)
maximumDaysRange = typedArray.getInt(R.styleable.CalendarView_maximumDaysRange, 0)

if (typedArray.hasValue(R.styleable.CalendarView_firstDayOfWeek)) {
firstDayOfWeek = typedArray.getInt(R.styleable.CalendarView_firstDayOfWeek, Calendar.MONDAY)
firstDayOfWeek =
typedArray.getInt(R.styleable.CalendarView_firstDayOfWeek, Calendar.MONDAY)
}

eventsEnabled = typedArray.getBoolean(R.styleable.CalendarView_eventsEnabled, calendarType == CLASSIC)
eventsEnabled =
typedArray.getBoolean(R.styleable.CalendarView_eventsEnabled, calendarType == CLASSIC)
swipeEnabled = typedArray.getBoolean(R.styleable.CalendarView_swipeEnabled, true)
selectionDisabled = typedArray.getBoolean(R.styleable.CalendarView_selectionDisabled, false)
selectionBetweenMonthsEnabled = typedArray.getBoolean(R.styleable.CalendarView_selectionBetweenMonthsEnabled, false)
selectionBetweenMonthsEnabled =
typedArray.getBoolean(R.styleable.CalendarView_selectionBetweenMonthsEnabled, false)
previousButtonSrc = typedArray.getDrawable(R.styleable.CalendarView_previousButtonSrc)
forwardButtonSrc = typedArray.getDrawable(R.styleable.CalendarView_forwardButtonSrc)

Expand Down Expand Up @@ -291,18 +302,36 @@ class CalendarView @JvmOverloads constructor(
* @param onDayClickListener OnDayClickListener interface responsible for handle clicks on calendar cells
* @see OnDayClickListener
*/
@Deprecated("Use setOnCalendarDayClickListener instead")
fun setOnDayClickListener(onDayClickListener: OnDayClickListener) {
calendarProperties.onDayClickListener = onDayClickListener
}

/**
* @param onDayClickListener OnDayClickListener interface responsible for handle clicks on calendar cells
* @see OnCalendarDayClickListener
*/
fun setOnCalendarDayClickListener(onDayClickListener: OnCalendarDayClickListener) {
calendarProperties.onCalendarDayClickListener = onDayClickListener
}

/**
* @param onDayLongClickListener OnDayClickListener interface responsible for handle long clicks on calendar cells
* @see OnDayLongClickListener
*/
@Deprecated("Use setOnCalendarDayLongClickListener instead")
fun setOnDayLongClickListener(onDayLongClickListener: OnDayLongClickListener) {
calendarProperties.onDayLongClickListener = onDayLongClickListener
}

/**
* @param onDayLongClickListener OnDayClickListener interface responsible for handle long clicks on calendar cells
* @see OnCalendarDayLongClickListener
*/
fun setOnCalendarDayLongClickListener(onDayLongClickListener: OnCalendarDayLongClickListener) {
calendarProperties.onCalendarDayLongClickListener = onDayLongClickListener
}

/**
* This method set a current date of the calendar using Calendar object.
*
Expand Down Expand Up @@ -340,6 +369,7 @@ class CalendarView @JvmOverloads constructor(
* @param eventDays List of EventDay objects
* @see EventDay
*/
@Deprecated("Use setCalendarDays() instead")
fun setEvents(eventDays: List<EventDay>) {
if (calendarProperties.eventsEnabled) {
calendarProperties.eventDays = eventDays
Expand All @@ -348,7 +378,7 @@ class CalendarView @JvmOverloads constructor(
}

fun setCalendarDays(calendarDayProperties: List<CalendarDay>) {
calendarProperties.calendarDayProperties = calendarDayProperties.toMutableList()
calendarProperties.calendarDays = calendarDayProperties.toMutableList()
calendarPageAdapter.notifyDataSetChanged()
}

Expand Down Expand Up @@ -423,6 +453,7 @@ class CalendarView @JvmOverloads constructor(
calendarPageAdapter.notifyDataSetChanged()
}

@Deprecated("Use setCalendarDays(List<CalendarDay>) with isEnabled = false")
fun setDisabledDays(disabledDays: List<Calendar>) {
calendarProperties.disabledDays = disabledDays
calendarPageAdapter.notifyDataSetChanged()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.util.*

/**
* This class represents an event of a day. An instance of this class is returned when user click
* a day cell. This class can be overridden to make calendar more functional. A list of instances of
* a day cell. A list of instances of
* this class can be passed to CalendarView object using setEvents() method.
*
*
Expand All @@ -22,6 +22,7 @@ import java.util.*
* Created by Applandeo Team.
*/

@Deprecated("Use CalendarDay instead")
data class EventDay(val calendar: Calendar) {
//An object which contains image to display in the day row
internal var imageDrawable: EventImage = EventImage.EmptyEventImage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ private const val INVISIBLE_IMAGE_ALPHA = 0.12f
* Created by Applandeo team
*/
class CalendarDayAdapter(
context: Context,
private val calendarPageAdapter: CalendarPageAdapter,
private val calendarProperties: CalendarProperties,
dates: MutableList<Date>,
pageMonth: Int
context: Context,
private val calendarPageAdapter: CalendarPageAdapter,
private val calendarProperties: CalendarProperties,
dates: MutableList<Date>,
pageMonth: Int
) : ArrayAdapter<Date>(context, calendarProperties.itemLayoutResource, dates) {

private val pageMonth = if (pageMonth < 0) 11 else pageMonth

@SuppressLint("ViewHolder")
override fun getView(position: Int, view: View?, parent: ViewGroup): View {
val dayView = view
?: LayoutInflater.from(context).inflate(calendarProperties.itemLayoutResource, parent, false)
?: LayoutInflater.from(context)
.inflate(calendarProperties.itemLayoutResource, parent, false)

val day = GregorianCalendar().apply { time = getItem(position) }

Expand All @@ -59,8 +60,8 @@ class CalendarDayAdapter(
// Setting view for all SelectedDays
day.isSelectedDay() -> {
calendarPageAdapter.selectedDays
.firstOrNull { selectedDay -> selectedDay.calendar == day }
?.let { selectedDay -> selectedDay.view = dayLabel }
.firstOrNull { selectedDay -> selectedDay.calendar == day }
?.let { selectedDay -> selectedDay.view = dayLabel }
setSelectedDayColors(dayLabel, day, calendarProperties)
}

Expand All @@ -75,7 +76,11 @@ class CalendarDayAdapter(
!day.isActiveDay() -> dayLabel.setDayColors(calendarProperties.disabledDaysLabelsColor)

// Setting custom label color for event day
day.isEventDayWithLabelColor() -> setCurrentMonthDayColors(day, dayLabel, calendarProperties)
day.isEventDayWithLabelColor() -> setCurrentMonthDayColors(
day,
dayLabel,
calendarProperties
)

// Setting current month day color
else -> setCurrentMonthDayColors(day, dayLabel, calendarProperties)
Expand All @@ -86,7 +91,8 @@ class CalendarDayAdapter(
&& SelectedDay(this) in calendarPageAdapter.selectedDays
&& if (!calendarProperties.selectionBetweenMonthsEnabled) this[Calendar.MONTH] == pageMonth else true

private fun Calendar.isEventDayWithLabelColor() = this.isEventDayWithLabelColor(calendarProperties)
private fun Calendar.isEventDayWithLabelColor() =
this.isEventDayWithLabelColor(calendarProperties)

private fun Calendar.isCurrentMonthDay() = this[Calendar.MONTH] == pageMonth
&& !(calendarProperties.minimumDate != null
Expand All @@ -102,6 +108,23 @@ class CalendarDayAdapter(
return
}

calendarProperties.calendarDays.firstOrNull { it.calendar == day }
?.let { calendarDay ->
val imageResource = calendarDay.imageResource
if (imageResource != null) {
setImageResource(imageResource)
} else {
val imageDrawable = calendarDay.imageDrawable
if (imageDrawable != null) {
setImageDrawable(imageDrawable)
}
}
// If a day doesn't belong to current month then image is transparent
if (!day.isCurrentMonthDay() || !day.isActiveDay()) {
alpha = INVISIBLE_IMAGE_ALPHA
}
}

calendarProperties.eventDays.firstOrNull { it.calendar == day }?.let { eventDay ->
loadImage(eventDay.imageDrawable)
// If a day doesn't belong to current month then image is transparent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class CalendarPageAdapter(
private fun getPageDaysProperties(calendar: Calendar) {
val pageCalendarDays = calendarProperties.onPagePrepareListener?.invoke(calendar)
if (pageCalendarDays != null) {
val diff = pageCalendarDays.minus(calendarProperties.calendarDayProperties).distinct()
calendarProperties.calendarDayProperties.addAll(diff)
val diff = pageCalendarDays.minus(calendarProperties.calendarDays).distinct()
calendarProperties.calendarDays.addAll(diff)
}
}

Expand Down
Loading

0 comments on commit 2d0eb03

Please sign in to comment.