Android library for horizontal single row calendar. With this library, you aren't attached to library built-in UI. You can create really beautiful and customizable UI and use selection features without hands getting dirty with RecyclerView and SelectionTracker.
With this library, you aren't attached to library built-in UI. You can create really beautiful and customizable UI and use selection features without hands getting dirty with RecyclerView and SelectionTracker.
dependencies { implementation 'com.michalsvec:single-row-calednar:1.0.0' }
com.michalsvec single-row-calednar 1.0.0 pom
val myCalendarViewManager = object : CalendarViewManager { override fun setCalendarViewResourceId( position: Int, date: Date, isSelected: Boolean ): Int { // return item layout files, which you have created }override fun bindDataToCalendarView( holder: SingleRowCalendarAdapter.CalendarViewHolder, date: Date, position: Int, isSelected: Boolean ) { // bind data to calendar item views }
}
val mySelectionManager = object : CalendarSelectionManager { override fun canBeItemSelected(position: Int, date: Date): Boolean { // return true if item can be selected } }
val myCalendarChangesObserver = object : CalendarChangesObserver { override fun whenWeekMonthYearChanged(weekNumber: String,monthNumber: String,monthName: String,year: String,date: Date) { super.whenWeekMonthYearChanged(weekNumber, monthNumber, monthName, year, date) }override fun whenSelectionChanged(isSelected: Boolean, position: Int, date: Date) { super.whenSelectionChanged(isSelected, position, date) } override fun whenCalendarScrolled(dx: Int, dy: Int) { super.whenCalendarScrolled(dx, dy) } override fun whenSelectionRestored() { super.whenSelectionRestored() } override fun whenSelectionRefreshed() { super.whenSelectionRefreshed() }
}
You can choose between two ways of doing it. If you want simple provide few past of future days, you should specify these attributes
pastDaysCount,
futureDaysCountand
includeCurrentDatein an XML or directly in code. If you are not satisfied with the previous solution you can specify your own list of dates using
setDatesfunction. When you provide dates to the calendar you can also set you initial position using this property
initialPositionIndex.
val singleRowCalendar = main_single_row_calendar.apply { calendarViewManager = myCalendarViewManager calendarChangesObserver = myCalendarChangesObserver calendarSelectionManager = mySelectionManager futureDaysCount = 30 includeCurrentDate = true init() }
pastDaysCount
futureDaysCount
includeCurrentDate
initialPositionIndex
multiSelection
deselection
longPress
calendarChangesObserver
calendarViewManager
calendarSelectionManager
setDates(newDateList: List)
pastDaysCountand
futureDaysCountyou can specify your list of dates
getDates()
getSelectedIndexes()
getSelectedDates()
onSaveInstanceState(state: Bundle)
onRestoreInstanceState(state: Bundle)
hasSelection()
isSelected(position: Int)
deselect(position: Int)
select(position: Int)
setItemsSelected(positionList: List, selected: Boolean)* you can select or deselect multiple items at once
clearSelection()
You can use DateUtils class when you want get some values from date. *
getDayName(date: Date)* returns day name, for example Friday, Thursday, Monday, etc... *
getDay3LettersName(date: Date)* returns day abbreviation, for example Fri, Thu, Mon, etc... *
getDay1LetterName(date: Date)* returns day abbreviation, for example F, T, M, S, etc... *
getMonthNumber(date: Date)* returns month number, for example 1, 3, 12, 9, etc... *
getMonthName(date: Date)* returns month name, for example December, September, January, etc... *
getMonth3LettersName(date: Date)* returns month abbreviation, for example Jan, Feb, Dec, etc... *
getYear(date: Date)* returns year, for example 2010, 2019, 2020, 2034... *
getDayNumber(date: Date)* returns number of day in a month, for example 15, 16, 17, etc... *
getNumberOfWeek(date: Date)* returns number of week in a year, for example 1, 5, 22, 50 etc... *
getFutureDates(count: Int)* returns a list of future dates with specified length *
getPastDates(count: Int)* returns a list of past dates with specified length *
getDates(pastDays: Int, futureDays: Int, includeCurrentDate: Boolean)
The library is licensed under Apache License.