Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Add disabled days to calendar date picker #223

Merged
merged 6 commits into from
Feb 1, 2016

Conversation

TylerMcCraw
Copy link
Contributor

Why?

I'd like to add support for disabling days so that users cannot select specific days defined by the application. The user should be able to visually see the days that are disabled and they should not be able to select the days that are defined as "disabled".

What Changed?

  • Updated the CalendarDatePickerFragment so that it can be passed a hashmap of specific calendar days that would be disabled.
  • Added one minor style attribute so that users can define the color of disabled days.
  • Added a sample fragment so that developers who want to to use this feature can play around with the feature.

@ct-bot
Copy link
Collaborator

ct-bot commented Dec 21, 2015

Can one of the admins verify this patch?

@fchauveau
Copy link
Member

Hello @TylerMcCraw Thank you for the PR
I'll look at this next week.

@fchauveau
Copy link
Member

Hi @TylerMcCraw
Why are you using a HashMap for disabled days and not a simple ArrayList ?

@TylerMcCraw
Copy link
Contributor Author

I'm using a HashMap for efficiency purposes in checking if the day that is currently being drawn is a disabled day.
The mDisabledDays.containsKey(disabledDayKey) call in drawMonthDay of the SimpleMonthView class should have a quicker lookup time than having to loop over an array list or something similar every time a day is drawn.

@TylerMcCraw
Copy link
Contributor Author

I've pushed two more commits to fix one minor issue with the dialog as it is destroyed and to add one minor feature to allow users to also change text color of disabled days if they would prefer to change the text color rather than changing the background color of disabled days.

@CedricGatay
Copy link
Contributor

Hi @TylerMcCraw, thank you for the great quality of your contribution.
Wouldn't it be possible to use a SparseArray with indices mapped to yyyymmdd as an int (taking care of zeroes of course) ? This way we've almost get the best of both solutions, performance wise it should be slower than an HashMap but it is far more efficient regarding memory (and we all know this is critical).

What do you think of this ?

@TylerMcCraw
Copy link
Contributor Author

@CedricGatay I agree and that's definitely doable.
I have most of it switched over to a SparseArray type already now.
However, this will require me to change CalendarDay to a Parcelable type, since it's necessary to marshall/save the disabled days in the instance state of CalendarDatePickerDialogFragment using outState.putSparseParcelableArray().

What are your thoughts on this? I can continue making CalendarDay implement Parcelable or is there another way for us to ensure the disabled days aren't lost when the fragment is destroyed and recreated?

Thanks!

@fchauveau
Copy link
Member

@TylerMcCraw Make CalendarDay Parcelable is a good solution. So keep on this way

@TylerMcCraw
Copy link
Contributor Author

Finished!
Please don't forget to look over the previous commit that I added in with 5fe010b
Thanks for your help, guys!

@fchauveau
Copy link
Member

@TylerMcCraw nice job I'll test it in the next days

@CedricGatay
Copy link
Contributor

@TylerMcCraw can you please rebase your work as it now contains conflict. Sorry for the delay reviewing it, we have a lot of things to do....

@TylerMcCraw
Copy link
Contributor Author

@CedricGatay Sorry for the late response. I'm going to try to rebase it today to fix any conflicts.
I also found a couple small bugs that could use your review 😄
I'll try to commit those later today as well.
Thanks!

# Conflicts:
#	library/src/main/java/com/codetroopers/betterpickers/calendardatepicker/CalendarDatePickerDialogFragment.java
#	sample/src/main/res/values/colors.xml
@TylerMcCraw
Copy link
Contributor Author

@CedricGatay I've now made my fixes, merged with the main master branch, and resolved conflicts.
Please have a look and let me know if there's anything else I need to do.

Thanks again.

@CedricGatay
Copy link
Contributor

Thank you @TylerMcCraw I will look at it soon. Thank you for rebasing your work.

@team it seems that our Cloudbees build is somehow broken when it comes to installing build tools, we need to figure this out.

@fchauveau
Copy link
Member

@CedricGatay
It's all right for merging to me.
Just some refactor to do on sample and style, but i'll do it after merge

@CedricGatay
Copy link
Contributor

Ok for me too, merging

CedricGatay added a commit that referenced this pull request Feb 1, 2016
Add disabled days to calendar date picker
@CedricGatay CedricGatay merged commit d9ffc20 into code-troopers:master Feb 1, 2016
@fchauveau
Copy link
Member

Hi @TylerMcCraw
Disabled days are available in version 2.5.0 just released.
Thx

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants