Giter Site home page Giter Site logo

kizitonwose / calendar Goto Github PK

View Code? Open in Web Editor NEW
4.4K 29.0 486.0 4.2 MB

A highly customizable calendar view and compose library for Android.

License: MIT License

Kotlin 100.00%
calendar calendarview date datepicker compose compose-calendar android heatmap-calendar month-calendar week-calendar

calendar's Introduction

Calendar

A highly customizable calendar library for Android, backed by RecyclerView for the view system, and LazyRow/LazyColumn for compose.

Tests Maven Central License Twitter

With this library, your calendar will look however you want it to.

Preview

Features

  • Single, multiple or range selection - Total flexibility to implement the date selection whichever way you like.
  • Week or month mode - Show a week-based calendar, or the typical month calendar.
  • Disable desired dates - Prevent selection of some dates by disabling them.
  • Boundary dates - Limit the calendar date range.
  • Custom date view/composable - Make your day cells look however you want, with any functionality you want.
  • Custom calendar view/composable - Make your calendar look however you want, with whatever functionality you want.
  • Custom first day of the week - Use any day as the first day of the week.
  • Horizontal or vertical scrolling calendar.
  • HeatMap calendar - Suitable for showing how data changes over time, like GitHub's contribution chart.
  • Month/Week headers and footers - Add headers/footers of any kind on each month/week.
  • Easily scroll to any date/week/month on the calendar via swipe actions or programmatically.
  • Use all RecyclerView/LazyRow/LazyColumn customizations since the calendar extends from RecyclerView for the view system and uses LazyRow/LazyColumn for compose.
  • Design your calendar however you want. The library provides the logic, you provide the views/composables.

Sample project

It's important to check out the sample app. There are lots of examples provided for both view and compose implementations. Most techniques that you would want to implement are already done in the examples.

Download the sample app here

View the sample app's source code here

Setup

The library uses java.time classes via Java 8+ API desugaring for backward compatibility since these classes were added in Java 8.

Step 1

This step is required ONLY if your app's minSdkVersion is below 26. Jump to step 2 if this does not apply to you.

To set up your project for desugaring, you need to first ensure that you are using Android Gradle plugin 4.0.0 or higher.

Then include the following in your app's build.gradle file:

android {
  defaultConfig {
    // Required ONLY if your minSdkVersion is below 21
    multiDexEnabled true
  }

  compileOptions {
    // Enable support for the new language APIs
    coreLibraryDesugaringEnabled true
    // Set Java compatibility (version can be higher if desired)
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  kotlinOptions {
    // Also add this for Kotlin projects (version can be higher if desired)
    jvmTarget = "1.8"
  }
}

dependencies {
  coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:<latest-version>'
}

You can find the latest version of desugar_jdk_libs here.

Step 2

Add the desired calendar library (view or compose) to your app build.gradle:

dependencies {
  // The view calendar library
  implementation 'com.kizitonwose.calendar:view:<latest-version>'

  // The compose calendar library
  implementation 'com.kizitonwose.calendar:compose:<latest-version>'
}

You can find the latest version of the library on the maven central badge above.

Snapshots of the development version are available in Sonatype’s snapshots repository.

If you're upgrading from version 1.x.x to 2.x.x, see the migration guide.

For the compose calendar library, ensure that you are using the library version that matches the Compose UI version in your project. If you use a version of the library that has a higher version of Compose UI than the one in your project, gradle will upgrade the Compose UI version in your project via transitive dependency.

Compose UI Calendar Library
1.2.x 2.0.x
1.3.x 2.1.x - 2.2.x
1.4.x 2.3.x
1.5.x 2.4.x
1.6.x 2.5.x

Usage

You can find the relevant documentation for the library in the links below.

View-based documentation Compose documentation

Share your creations

Made a cool calendar with this library? Share an image here.

Contributing

Found a bug? feel free to fix it and send a pull request or open an issue.

License

Calendar library is distributed under the MIT license. See LICENSE for details.

calendar's People

Contributors

0xflotus avatar alex-petrakov avatar angelalanis avatar cccc-22 avatar evjava avatar germinator avatar janbina avatar jeevuz avatar kizitonwose avatar luis-cortes avatar msimonides avatar paolorotolo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

calendar's Issues

First Day Of Week not working

Hi,

firstDayOfWeek paramater doesn't work. I try few things:
cvCalendarView.setup(currentMonth, lastMonth, DayOfWeek.MONDAY);
cvCalendarView.setup(currentMonth, lastMonth, DayOfWeek.of(1));

DayOfWeek firstDayOfWeek = WeekFields.of(DayOfWeek.MONDAY, 7).getFirstDayOfWeek();
cvCalendarView.setup(currentMonth, lastMonth, firstDayOfWeek);

Thank you for this great library! :)

Performance issue

Hi,

I'm using the latest version (0.2.0) of the library and facing some performance issues when loading the view for the first time.
In my application, the view sits inside a tab in BottomNavigationView, so the first time I visit the tab it takes up to one second to load the fragment with the view.
I tried to add another tab with Example5Fragment from your sample app and faced the same slowness issue.
Can you try to figure out the problem?

Thanks in advance.

Bug with monthHeaderBinder

Reproduce:

 <com.kizitonwose.calendarview.CalendarView
                android:id="@+id/calendarView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:cv_dayViewResource="@layout/item_calendar_day_layout"
                app:cv_orientation="horizontal"
                app:cv_scrollMode="paged"
                app:cv_hasBoundaries="false"
                app:cv_monthHeaderResource="@layout/item_month_header"
                app:cv_maxRowCount="6"/>
inner class MonthHeader : MonthHeaderFooterBinder<MonthViewContainer> {

        override fun bind(container: MonthViewContainer, month: CalendarMonth) {
            container.setName(month)
        }

        override fun create(view: View): MonthViewContainer = MonthViewContainer(view)
    }

CalendarMonth always the same.

Intermittent IndexOutOfBoundsException

I see the following error intermiitently as I start an activity which creates and renders a calendar. I have seen Index:7 as well as 14, but no other numbers. I am using v0.2.0

I create and render a calendar, then request data from a database and when it arrives I call the calendar's setup() again (different months to display), and paint the day cells again depending on the data. If I add a short delay c. 200ms before making the database call then the fault does not occur, so I am guessing the second setup() is messing with the first.

So I guess the questions are:
(1) What is causing the crash and can it be stopped?
(2) Is it OK to call setup() twice, or is there a better way to change the first and last month values dynamically?
(3) Is there a "onCalendarReady()" callback, or similar, which I can wait for before making my second setup() call? use to make changes?

Error log:

java.lang.IndexOutOfBoundsException: Index: 14, Size: 4
    at java.util.ArrayList.get(ArrayList.java:411)
    at com.kizitonwose.calendarview.ui.CalendarAdapter.notifyMonthScrollListenerIfNeeded(CalendarAdapter.kt:171)
    at com.kizitonwose.calendarview.ui.CalendarAdapter$notifyMonthScrollListenerIfNeeded$1.onAnimationsFinished(CalendarAdapter.kt:165)
    at androidx.recyclerview.widget.RecyclerView$ItemAnimator.dispatchAnimationsFinished(RecyclerView.java:13257)
    at androidx.recyclerview.widget.DefaultItemAnimator.dispatchFinishedWhenDone(DefaultItemAnimator.java:551)
    at androidx.recyclerview.widget.DefaultItemAnimator$5.onAnimationEnd(DefaultItemAnimator.java:249)
    at android.view.ViewPropertyAnimator$AnimatorEventListener.onAnimationEnd(ViewPropertyAnimator.java:1142)
    at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1149)
    at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1309)
    at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)
    at android.animation.AnimationHandler.-wrap2(AnimationHandler.java)
    at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:905)
    at android.view.Choreographer.doCallbacks(Choreographer.java:709)
    at android.view.Choreographer.doFrame(Choreographer.java:641)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:893)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:208)
    at android.app.ActivityThread.main(ActivityThread.java:6304)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)

Month paging

I'm currently displaying 6 monhts in a vertical calendar similar to example 2. In my project the bottom month is the most recent one and the top month is 6 months ago. Everything is fine. But I need more than 6 months and I should get the data from a web service.

So I set up this listener:
calendarView.addOnScrollListener(object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { calendarView.findFirstVisibleMonth()?.let { if (startMonth == it.yearMonth) { lastMonthReachedListener?.invoke(it.yearMonth) } } } })
which should detect when the top month is reached, trigger the listener and download the data for the next 6 months, then display them.

The problem is every time I setup the CalendarView to change the startMonth, the view gets scrolled to the new months at the start, instead of remaing at the current position, so the listener gets called again and loops like that.

when calling the setup method as reccomended ("You can call this any time") is it possible to mantain position? Or maybe you have some other ideas...

Min and max range for range calender

how can i set values for minimum and maximum values.
there is a method "setup" in which i can set minimum date but what about maximum date ?
Please help.

Sample app crashes since v0.2.6

Steps to reproduce the issue:

  1. Run the sample app and open Example 1.
  2. Click the Week mode checkbox to collapse the calendar.
  3. Click the Week mode checkbox one more time to expand the calendar.

After that the app should crash with the following stacktrace:

08-22 21:08:42.318 32144-32144/com.kizitonwose.calendarviewsample E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.kizitonwose.calendarviewsample, PID: 32144
    java.lang.IndexOutOfBoundsException: Invalid index 42, size is 16
        at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
        at java.util.ArrayList.get(ArrayList.java:308)
        at com.kizitonwose.calendarview.CalendarView.updateAdapterMonthConfig(CalendarView.kt:412)
        at com.kizitonwose.calendarview.CalendarView.updateAdapterMonthConfig$default(CalendarView.kt:406)
        at com.kizitonwose.calendarview.CalendarView.setHasBoundaries(CalendarView.kt:197)
        at com.kizitonwose.calendarviewsample.Example1Fragment$onViewCreated$4$$special$$inlined$doOnStart$1.onAnimationStart(Animator.kt:122)
        at android.animation.ValueAnimator.notifyStartListeners(ValueAnimator.java:1048)
        at android.animation.ValueAnimator.start(ValueAnimator.java:1110)
        at android.animation.ValueAnimator.start(ValueAnimator.java:1117)
        at com.kizitonwose.calendarviewsample.Example1Fragment$onViewCreated$4.onCheckedChanged(Example1Fragment.kt:192)
        at android.widget.CompoundButton.setChecked(CompoundButton.java:161)
        at android.widget.CompoundButton.toggle(CompoundButton.java:120)
        at android.widget.CompoundButton.performClick(CompoundButton.java:125)
        at android.view.View$PerformClick.run(View.java:21297)
        at android.os.Handler.handleCallback(Handler.java:743)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:150)
        at android.app.ActivityThread.main(ActivityThread.java:5621)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)

It seems that the issue was introduced by this commit. Looks like changes made to the adapter data are not always immediately reflected by calendarLayoutManager.findFirstVisibleItemPosition().

Type mismatch: inferred type is FragmentContainerActivity but LifecycleOwner was expected

After following the guidelines, it's throwing an error:

> Task :app:compileDebugKotlin
e: /Users/admin/Documents/bakbak/android/sootra/app/src/main/java/co/barfi/ui/fragmentcontainer/FragmentContainerActivity.kt: (62, 49): Type mismatch: inferred type is FragmentContainerActivity but LifecycleOwner was expected
e: /Users/admin/Documents/bakbak/android/sootra/app/src/main/java/co/barfi/ui/loginscreen/LoginActivity.kt: (98, 44): Type mismatch: inferred type is LoginActivity but LifecycleOwner was expected
e: /Users/admin/Documents/bakbak/android/sootra/app/src/main/java/co/barfi/ui/loginscreen/LoginActivity.kt: (122, 45): Type mismatch: inferred type is LoginActivity but LifecycleOwner was expected
e: /Users/admin/Documents/bakbak/android/sootra/app/src/main/java/co/barfi/ui/splash/SplashActivity.kt: (85, 55): Type mismatch: inferred type is SplashActivity but LifecycleOwner was expected
e: /Users/admin/Documents/bakbak/android/sootra/app/src/main/java/co/barfi/ui/splash/SplashActivity.kt: (117, 57): Type mismatch: inferred type is SplashActivity but LifecycleOwner was expected

> Task :app:compileDebugKotlin FAILED

More than one file was found with OS independent path 'META-INF/library_release.kotlin_module'

I've recently added the Chucker library to my app and got this build error:

Execution failed for task ':app:mergeDebugJavaResource'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > More than one file was found with OS independent path 'META-INF/library_release.kotlin_module'

It turns out that both CalendarView and Chucker are creating the same META-INF/library_release.kotlin_module file:

Captura de Pantalla 2019-10-10 a les 12 58 32

I've opened an issue on Chucker with more details about the error and some solutions: ChuckerTeam/chucker#134

While there is a way to fix this, it would be nice that to fix the issue on the library itself, which would avoid having every user apply the same fix :)

kotlin.TypeCastException: null cannot be cast to non-null type com.kizitonwose.calendarview.ui.MonthViewHolder

Hi Kizito!

First of all awesome lib! Kudos for it!

At the moment I'm consuming the CalendarView from an Android Java project.
For testing how stable the lib behave under certain scenarios I enabled Don't keep activities in Developer Options. After playing around, bringing the calendar view back and forth between foreground and background this exception arises:
kotlin.TypeCastException: null cannot be cast to non-null type com.kizitonwose.calendarview.ui.MonthViewHolder at com.kizitonwose.calendarview.ui.CalendarAdapter.notifyMonthScrollListenerIfNeeded(CalendarAdapter.kt:196) at com.kizitonwose.calendarview.ui.CalendarAdapter$onAttachedToRecyclerView$1.run(CalendarAdapter.kt:52) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Any idea how to fix this?

Thanks in advance!

Federico

Make CalendarDay Open

I'm running into a problem regarding selecting indates/outdates.

Using CalendarView.notifyDayChanged() I can show an indate/outdate as selected. Combining this with notifyDateChanged() when an indate/outdate is selected and you scroll to it's month, it is selected there as well.

The problem lies when you select a day in this month (ie. not an indate/outdate), if that date exists as an indate/outdate in another month, when you scroll to it, it won't be selected and there doesn't seem to be a way to do it.

I can think of getting this to work if when selecting any date, I call notifyDayChanged() with all 3 owners, but that would require the ability to instantiate new CalendarDay objects with the same LocalDate but different owners.

Is there an alternative way of doing this?,
thanks.

Different languages support

Hello,
First of all thanks for such a useful library. Could you tell me how to provide months' names in other languages to the calendar view?

Require complete minimal project so configuration can be understood

I have played with the sample app from Github and want to try to use the library in my own app. However, attempts at creating a minimal app fail. I suspect instructions are missing from the instructions on Github.

Please provide a complete worked example.

I did this:

1 In Android Studio, File > New > New Project and selected "Empty Activity"
2 Built and ran this successfully.
3 Added the two entries to the two build.gradle files described in readme.MD (version 0.1.2)
4 Sync fails with this:
ERROR: Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.1.0-beta01] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:5:5-19:19 to override.
5 I added the suggestion to AndroidManifest.xml - now get "ERROR: Manifest merger failed with multiple errors, see logs"

I note the sample app mainfest file includes: tools:ignore="GoogleAppIndexingWarning"

But this does not fix the problem.

Some (relevant?) discussion here? material-components/material-components-android#193

Week mode calendar crashes when orientation changes

Steps to reproduce in the sample app:

  1. Allow orientation changes by removing the forced screenOrientation attribute from the app's Manifest for the main Activity.
  2. Run the app and open "Example 7".
  3. Scroll to the right by about a month or more.
  4. Change the device's orientation.

The app should crash with this error:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.kizitonwose.calendarviewsample, PID: 10788
    kotlin.TypeCastException: null cannot be cast to non-null type com.kizitonwose.calendarview.ui.MonthViewHolder
        at com.kizitonwose.calendarview.ui.CalendarLayoutManager$scrollToDay$1.run(CalendarLayoutManager.kt:51)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Apparently, this

We already scrolled to this position so findViewHolder should not return null.

is not really true 😕. I assume it has something to do with restarting the activity, though I don't see why or how. Probably something to do with the fact that WeekMode doesn't really have MonthViewClass (or whatever it's called) and there isn't a proper check there.

I've found out that it happens inconsistently - you have to scroll by quite a bit, but some times (I think) less than other times. Oh and it happens when scrolling to the left, too.

Allow updating of in/out dates

Hi,

I'm working on a calendar that will require inDates and outDates to be selectable.

I've noticed that when notifyDateChanged is called it will only rebind the day view container of the date in it's own month. This means that if I click on an inDate or outDate it's container won't update.

Could something be added to allow inDates and outDates to also be rebound?

Continuos selection mode single day?

Was trying the Example 3 of the demo app and realized that the continuos selection mode doesn't allow for the same day selection for start and end. If the same day is selected only the start date is set. If I click it again, nothing happens.

This does come handy in some use cases, like booking roundtrips transport tickets for the same day.

Sticky headers

In my vertical scrolling calendar (similar to example2) I would like to have sticky headers. I've tried using this solution making a custom RecyclerView.ItemDecoration but, with "CalendarAdapter" being internal and not using the "viewType" parameter, I find it really difficult to make it work . Do you have any suggestions in how to implement such a thing? Internal or external to the library I could implement it myself, I'm just seeking some advice.

[Request] Strict date range

Is it possible to have a strict date range selection i.e. from 8th October 2019 until 8th October 2020 (one year sharp) Meaning that the dates after 8th October 2020 are not selectable. The same goes with the dates before 8th October 2019

What is the best way to achieve the above with the current setup. (I am looking at Example4 from the sample app.)

Do you think this could be a potential feature implemented by the library?

infinite months

Do you plan on support infinite scrolling? Since I see setup method does take in first month last month param, will you provide a method to setup the views without first month and last month? Thanks!

Duplicate 27 October

Hi,
did anyone encounter duplicate dates 27 October on iOS12.4?
Thanks for any insights;
j.

Centre date on calendar view

Hi @kizitonwose, awesome library!

Do you know if I can easily centre a date into the calendar view.
Using scrollTo date method the selected date is on top so this isn't working for my case.

Thanks

Duplicate class error

I am looking for help resolving a duplicate class error.

Having got the library working in a trivial app I tried to add it to a larger project. I get this error:

Duplicate class androidx.concurrent.futures.DirectExecutor found in modules
concurrent-futures-1.0.0-beta01.jar (androidx.concurrent:concurrent-futures:1.0.0-beta01) and
futures-1.0.0-alpha01.jar (androidx.concurrent:futures:1.0.0-alpha01)

I am a newbie here, but looks like CalendarView uses the -beta01 library and the -alpha01 library is used by WorkManager:
https://developer.android.com/jetpack/androidx/releases/work

I had been using 'android.arch.work:work-runtime:1.0.0-alpha09' and it looks like if I change to 'android.arch.work:work-runtime:1.0.1' the duplicate class problem goes away, but the API seems significantly different and I would have to make big changes. Can I stay with 1.0.0-alpha09?

I see this: https://medium.com/mindorks/avoiding-conflicts-in-android-gradle-dependencies-28e4200ca235

but it is a bit over my head. Suggestions for working around this?

Make CalendarView class open?

Hi,

Would you consider making the CalendarView class open to allow developers to extend from it?

A use case would be to override onMeasureLayout to do something further.

Regards.

Feature request: Add ability to update a group of days in the calendar

Love this library and I'm making a lot of cool progress with it.

At the moment there are few methods to notify changes:

notifyDayChanged(), notifyMonthChanged() , notifyCalendarChanged() ...

It would be nice to have a method which does this for a range of days or a group of days within a month or group of days in the calendar.

KotlinNullPointerException

Hi, thank's for great lib. However, I faced the issue: crash when first open a fragment with calendar view. It happened once, and I think the problem is in using unsafe (!!) call.

kotlin.KotlinNullPointerException
        at com.kizitonwose.calendarview.ui.MonthViewHolder.bindMonth(MonthViewHolder.kt:39)
        at com.kizitonwose.calendarview.ui.CalendarAdapter.onBindViewHolder(CalendarAdapter.kt:144)
        at com.kizitonwose.calendarview.ui.CalendarAdapter.onBindViewHolder(CalendarAdapter.kt:27)
        at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:7033)
        at com.kizitonwose.calendarview.ui.CalendarAdapter.onBindViewHolder(CalendarAdapter.kt:135)
        at com.kizitonwose.calendarview.ui.CalendarAdapter.onBindViewHolder(CalendarAdapter.kt:27)
        at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7075)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5991)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6258)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6097)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6093)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2303)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1627)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1587)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:665)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4115)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:3832)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4385)
        at android.view.View.layout(View.java:20715)
        at android.view.ViewGroup.layout(ViewGroup.java:6202)
        at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1915)
        at android.view.View.layout(View.java:20715)
        at android.view.ViewGroup.layout(ViewGroup.java:6202)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:20715)
        at android.view.ViewGroup.layout(ViewGroup.java:6202)
        at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:444)


How to disable scroll?

Is there possible to disable scrolling? and can scroll only programmatically (smoothScrollToMonth() or scrollToMonth())

What is wrong with your calendar ?

2019-09-02 18 19 44
2019-09-02 18 19 40

Whay is not dispay 31

val firstMonth = currentMonth.minusMonths(10) val lastMonth = currentMonth.plusMonths(10) val firstDayOfWeek = DayOfWeek.MONDAY calendarView.setup(firstMonth, lastMonth, firstDayOfWeek) calendarView.inDateStyle = InDateStyle.ALL_MONTHS calendarView.maxRowCount = 5 calendarView.hasBoundaries = true

Feature request: 31x1 calendar view

Thank you very much for this library. It is very useful.This is a request for a further development, and/or suggestions for how I might try to make the development myself.

My application monitors medication adherence. I issue reminders to take medication and I record when the user takes their medication. I display information about when medication is taken, or missed. So your calendar is useful for this. But a different view would be good.

Adherence is best displayed graphically, so stakeholders can see at a glance when and whether the user took their medication, over (say) a month. Figure 5 at this paper shows the idea: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3403197/pdf/bcp0073-0691.pdf - a version of my own app looks like this: https://www.dropbox.com/s/dyvdxjozmh3jwdb/Screenshot_20190625-220402_Medication%20Monitor.jpg?dl=0

So the ideal would be a CalendarView that has days of the month (1...31) on the X axis and time of the day (00:00- 23:59) on the Y axis. The actual time that medication was taken would be displayed as a dot at the correct X/Y position. Colour-coding can show status (e.g. taken on time, taken at the wrong time, not taken etc).

I would think that the existing library could be adapted reasonably well:

  • days would be displayed as cells arranged in a 31x1 array instead of a 7x6 array.

  • the calendar views (one per month) can scroll left and right as happens at present.

  • The day of week legend (MON, TUE, WED...) might need to be replaced by days (1...31) or perhaps week numbers (across 7 days).

  • each day cell (narrow and long) needs to be painted with data: background colour to indicate status and small shapes (circles, squares) rendered to indicate the actual data point. One approach might be to divide each day cell into 24, 48 or 96 divisions that correspond to 60, 30 or 15 minute time slots. Each sub-cell could have different background colours and different drawable shapes painted to indicate data points. Or perhaps horizontal bands of colour and drawable items could be placed programmatically: looking at the sample app Example 5, I see the "@+id/exFiveDayFlightTop" and "@+id/exFiveDayFlightBottom" views might be positioned differently by changing the layout_marginBottom parameter.

  • There might need to be a provision to add vertical (1 pixel) dividers to divide each week (7 days).

  • Perhaps the horizontal scale could be for 1 week rather than one month.

What do you think? What might need to be changed? Does the "week view" facility already provide this facility, if we can display 31 days instead of 7?

Disabling days

Hi,

Thanks for the great library.

I'm looking for a feature of settings specific days as disabled and not selectable on the CalendarView. These disabled days should also stop range selection if they are inside this range.

Is this something possible for the library? I noticed the library is mostly focused on the UI customisation but just wanted to check with you.

Thanks.

CalendarView entity in layout file not being processed properly

I have this Java code (in an AppCompatActivity class) and a layout file which works fine in a simple example, but fails when I try to add the CalendarView to a larger existing app:

    CalendarView cv;
    cv = findViewById(R.id.calendarView);
    // then initialise the CalendarView 

and a layout file with this:

<com.kizitonwose.calendarview.CalendarView
    android:id="@+id/calendarView"
    ... />

I have an error in the java file "Type parameter T has incompatible upper bounds : View and CalendarView"

Explicitly casting: CalendarView calendarView = (CalendarView) findViewById(R.id.calendarView);
the error becomes "Inconvertable types: cannot cast 'android.view.View' to 'com.kizitonwose.calendarview.CalendarView'

It seems that somehow the CalendarView entity in the layout file is being treated as something else.

Interestingly, I cannot refactor/rename "@+id/calendarView" as the Refactor operation is greyed out. (I can refactor it if I change the XML to <CalendarView...) - is this a clue? Does it imply that the layout file is not being properly processed?

If I right-click on R.id.calendarView and click "Go to Declaration" I am correctly taken to the layout file. I appear to have added the library dependency correctly to build.gradle. No amount of cleaning or invalidating of caches have effects. I deleted the .gradle, build and app/build directories - no change.

What is happening and how do I fix it?

Is it usable in JAVA ?

Hi,
your lib seems to fit my needs , but it's all in kotlin. My app is still full java and there is no plan to migrate to kotlin any time soon.

Can i still use it ?

I'm stuck at the initialisation , i don't know how (and if i can/should) convert this parts to java :

class DayViewContainer(view: View) : ViewContainer(view) {
    val textView = view.calendarDayText
    
    // Without the kotlin android extensions plugin
    // val textView = view.findViewById<TextView>(R.id.calendarDayText)
}

This seems to be ok :

class DayViewContainer extends ViewContainer {
        DayViewContainer(View view) {
            super(view);
           TextView textView = view.findViewById(R.id.calendarDayText)
        }
    }

But i'm kind of lost here

calendarView.dayBinder = object : DayBinder<DayViewContainer> {
    // Called only when a new container is needed.
    override fun create(view: View) = DayViewContainer(view)
    
    // Called every time we need to reuse a container.
    override fun bind(container: DayViewContainer, day: CalendarDay) {
        container.textView.text = day.date.dayOfMonth.toString()
    }
}

Thanks

Weird issues?

Hi, I started by including your Example 5 into my project, but as part of another vertical RecyclerView. Anyways, the calendar shows up fine, but I have 2 weird issues:

  1. Month scroll listener gets invoked with one month earlier than shown on the calendar (e.g. calendar shows June days, but it says May on top). I'm using paged calendar, and this is invoked when I page it with finger.

  2. When I use buttons (next & previous) to move the calendar, it starts skipping months, but it's mostly skipping into past 1 or 2 months. So for e.g., If I go back from June to May, it ends up showing April.. But if I go forward from June to July, it ends up showing June again (because it skips one month back again).

Do you have any idea what this might be? Otherwise, library is great and very customizable. Thanks!

Performance issue with unbounded months on long date ranges

Steps to reproduce the issue in the sample app:

  1. Open Example7Fragment.kt and increase the date range between startMonth and endMonth in the setup(..) method to 10 years (for old and low-end devices even 3-5 years is enough).
  2. Run the app and open Example 7.

Expected behavior: the app should become unresponsive for several seconds. The greater the date range, the longer the freeze. The lag is more noticeable on old and low end devices.

Here is an example of how it looks: https://drive.google.com/open?id=10ge9IzonM8EYDdw4Y4oDSc761WrC308l

It seems that the problem only takes place when CalendarView.hasBoundaries is set to false. So after some dumb tests with measuring execution time inside MonthConfig.generateUnboundedMonths(..) I've discovered that the freezes are caused by removeAll() calls on each iteration of this loop at line 109.

It looks like that the problem is that remove operations for this type of collection take O(n) time and allDay list may contain significant amount of items when the date range is long enough.

Here is a small fix that uses Iterable.chunked(..) to split the allDays list and seems to solve the issue.
I can make a pull request if you want to.

Disable scroll but allow tap on item

@kizitonwose I'm stuck with the following situacion...
On one hand I need to disable the horizontal scrolling on the calendar as shown on here: #13 and do it programatically.
But at the same time I need to be able to tap/click on days of the calendar (by setting a click listener on the DayViewContainer view):
view.setOnClickListener(new View.OnClickListener()...
The problem is that by disabling the scroll I'm intercepting the Action.MOVE used by the taps as well, therefore onInterceptTouchEvent is swallowing the event, hence not allowing it to reach the defined view click listener.

So to sum up I need to disable the swiping of the calendar but allowing taps of each of days of the calendar...

Any suggestion?

Thanks in advance,

Federico

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.