Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…icker into pascualin-master

# Conflicts:
#	THCalendarDatePicker/THDatePickerViewController.h
#	THCalendarDatePicker/THDatePickerViewController.m
hons82 committed Mar 17, 2016
1 parent a9baf7f commit 915b2fd
Showing 11 changed files with 258 additions and 55 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -26,14 +26,14 @@ Install with [CocoaPods](http://cocoapods.org) by adding the following to your P

``` ruby
platform :ios, '6.1'
pod 'THCalendarDatePicker', '~> 1.2.5'
pod 'THCalendarDatePicker', '~> 1.2.6'
```
####Swift

``` ruby
platform :ios, '8.0'
use_frameworks!
pod 'THCalendarDatePicker', '~> 1.2.5'
pod 'THCalendarDatePicker', '~> 1.2.6'
```

**Note**: We follow http://semver.org for versioning the public API.
@@ -116,9 +116,11 @@ or how you could do it in Swift

- Fixed issue [#28](https://github.com/hons82/THCalendarDatePicker/issues/28)
- Fixed issue [#30](https://github.com/hons82/THCalendarDatePicker/issues/30)
- Fixed issue [#69](https://github.com/hons82/THCalendarDatePicker/issues/69)
- Pull request [#40](https://github.com/hons82/THCalendarDatePicker/pull/40)
- Pull request [#41](https://github.com/hons82/THCalendarDatePicker/pull/41)
- Pull request [#53](https://github.com/hons82/THCalendarDatePicker/pull/53)
- Pull request [#70](https://github.com/hons82/THCalendarDatePicker/pull/70)

### V1.1.X

@@ -157,6 +159,7 @@ or how you could do it in Swift
- [jeremiescheer](https://github.com/jeremiescheer)
- [powfulhong](https://github.com/powfulhong)
- [sparkdreamstudio](https://github.com/sparkdreamstudio)
- [Ignacio pascualin](https://github.com/pascualin)

# License

4 changes: 2 additions & 2 deletions THCalendarDatePicker.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "THCalendarDatePicker"
s.version = "1.2.5"
s.version = "1.2.6"
s.summary = "A DatePicker based on a custom calendar view"
s.homepage = "https://github.com/hons82/THCalendarDatePicker"
s.license = { :type => 'MIT', :file => 'LICENSE.md' }
@@ -12,7 +12,7 @@ Pod::Spec.new do |s|
s.source_files = 'THCalendarDatePicker/*.{h,m}'
s.resources = ["THCalendarDatePicker/*.xib", "THCalendarDatePicker/Images.xcassets"]
s.frameworks = 'QuartzCore'
s.dependency 'KNSemiModalViewController_hons82', '~> 0.4.3'
s.dependency 'KNSemiModalViewController_hons82', '~> 0.4.4'
s.prefix_header_contents = <<-EOS
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
3 changes: 1 addition & 2 deletions THCalendarDatePicker/THDateDay.m
Original file line number Diff line number Diff line change
@@ -51,8 +51,7 @@ -(void)setLightText:(BOOL)light {
UIColor * color = [UIColor colorWithWhite:.84 alpha:1];
[self.dateButton setTitleColor:color forState:UIControlStateNormal];
self.hasItemsIndicator.image = (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0") ? [UIImage imageNamed:@"calendar_littledot-disabled" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] : [UIImage imageNamed:@"calendar_littledot-disabled"]);
}
else {
} else {
UIColor * color = [UIColor colorWithWhite:.3 alpha:1];
[self.dateButton setTitleColor:color forState:UIControlStateNormal];
self.hasItemsIndicator.image = (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0") ? [UIImage imageNamed:@"calendar_littledot" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil] : [UIImage imageNamed:@"calendar_littledot"]);
7 changes: 7 additions & 0 deletions THCalendarDatePicker/THDatePickerViewController.h
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
@optional

-(void)datePicker:(THDatePickerViewController *)datePicker selectedDate:(NSDate *)selectedDate;
-(void)datePicker:(THDatePickerViewController *)datePicker deselectedDate:(NSDate *)deselectedDate;
-(void)datePickerDidHide:(THDatePickerViewController *)datePicker;

@end
@@ -43,6 +44,7 @@
@property (weak, nonatomic) IBOutlet UIView *toolbarBackgroundView;
@property (nonatomic) float slideAnimationDuration;
@property (strong, nonatomic) NSString* dateTitle;
@property (strong, nonatomic) NSArray * selectedDates;

- (void)setDateHasItemsCallback:(BOOL (^)(NSDate * date))callback;

@@ -51,6 +53,11 @@
*/
- (void)setAllowClearDate:(BOOL)allow;

/*! Enable Multi Day Selection
* \param allow selection of multiple days
*/
- (void)setAllowMultiDaySelection:(BOOL)allow;

/*! Enable Ok Button when selected Date has already been selected
* \param allow should show ok button
*/
139 changes: 108 additions & 31 deletions THCalendarDatePicker/THDatePickerViewController.m
Original file line number Diff line number Diff line change
@@ -29,6 +29,9 @@ @interface THDatePickerViewController () {
BOOL _disableYearSwitch;
BOOL (^_dateHasItemsCallback)(NSDate *);
float _slideAnimationDuration;
NSMutableArray * _selectedDates;
NSMutableArray * _selectedDateViews;
BOOL _allowMultiDaySelection;
}
@property (nonatomic, strong) NSDate * firstOfCurrentMonth;
@property (nonatomic, strong) THDateDay * currentDay;
@@ -67,6 +70,7 @@ @implementation THDatePickerViewController
@synthesize rounded = _rounded;
@synthesize historyFutureBasedOnInternal = _historyFutureBasedOnInternal;
@synthesize slideAnimationDuration = _slideAnimationDuration;
@synthesize selectedDates = _selectedDates;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
@@ -82,6 +86,9 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
_autoCloseCancelDelay = 1.0;
_dateTimeZone = [NSTimeZone defaultTimeZone];
_slideAnimationDuration = .5;
_selectedDates = [[NSMutableArray alloc] init];
_selectedDateViews = [[NSMutableArray alloc] init];
_allowMultiDaySelection = NO;
}
return self;
}
@@ -90,6 +97,11 @@ +(THDatePickerViewController *)datePicker {
return [[THDatePickerViewController alloc] initWithNibName:@"THDatePickerViewController" bundle:[NSBundle bundleForClass:self.class]];
}

-(void)setAllowMultiDaySelection:(BOOL)allow {
[self setAutoCloseOnSelectDate:!allow]; // Caution possible endless loop
_allowMultiDaySelection = allow;
}

- (void)setAllowClearDate:(BOOL)allow {
_allowClearDate = allow;
}
@@ -108,6 +120,7 @@ - (void)setClearAsToday:(BOOL)beTodayButton {
- (void)setAutoCloseOnSelectDate:(BOOL)autoClose {
if (!_allowClearDate)
[self setAllowClearDate:!autoClose];
_allowMultiDaySelection = !autoClose;
_autoCloseOnSelectDate = autoClose;
}

@@ -305,6 +318,22 @@ - (void)redrawDays {
if (self.selectedBackgroundColor)
[day setSelectedBackgroundColor:self.selectedBackgroundColor];

if(!_allowMultiDaySelection) {
if (_internalDate && ![[self dateWithOutTime:date] timeIntervalSinceDate:_internalDate]) {
self.currentDay = day;
[day setSelected:YES];
}
} else {
if ([_selectedDates containsObject:date]) {
if ([_selectedDates lastObject] == date) {
_internalDate = date;
}
[day setSelected:YES];
} else {
[day setSelected:NO];
}
}

[day setLightText:![self dateInCurrentMonth:date]];
[day setEnabled:![self dateInFutureAndShouldBeDisabled:date]];
[day indicateDayHasItems:(_dateHasItemsCallback && _dateHasItemsCallback(date))];
@@ -313,10 +342,6 @@ - (void)redrawDays {
[day.dateButton setTitle:[NSString stringWithFormat:@"%ld",(long)[comps day]]
forState:UIControlStateNormal];
[self.calendarDaysView addSubview:day];
if (_internalDate && ![[date dateWithOutTime] timeIntervalSinceDate:_internalDate]) {
self.currentDay = day;
[day setSelected:YES];
}
// @end
date = [_calendar dateByAddingComponents:offsetComponents toDate:date options:0];
curX += cellWidth;
@@ -352,20 +377,38 @@ - (void)redrawWeekdays:(int)dayWidth {

#pragma mark - Date Set, etc.

- (NSArray *)selectedDates {
return [[NSArray alloc] initWithArray:_selectedDates];
}

- (void)setSelectedDates:(NSArray *)selectedDates {

_selectedDates = [[NSMutableArray alloc] init];
for (NSDate* selectedDate in selectedDates) {
[_selectedDates addObject:[self dateWithOutTime:selectedDate]];
}
if ([_selectedDates count] > 0) {
_date = (NSDate*)[_selectedDates objectAtIndex:0];
_dateNoTime = !_date ? nil : [self dateWithOutTime:_date];
self.internalDate = [_dateNoTime dateByAddingTimeInterval:0];
}
[self redrawDays];
}

- (void)setDate:(NSDate *)date {
_date = date;
_dateNoTime = !date ? nil : [date dateWithOutTime];
self.internalDate = [_dateNoTime dateByAddingTimeInterval:0];
[self setSelectedDates:@[date]];
}

- (NSDate *)date {
if(!self.internalDate) return nil;
else if(!_date) return self.internalDate;
if(!self.internalDate)
return nil;
else if(!_date)
return self.internalDate;
else {
int ymd = NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay;
NSDateComponents* internalComps = [_calendar components:ymd fromDate:self.internalDate];
int time = NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond|NSCalendarUnitTimeZone;
NSDateComponents* origComps = [_calendar components:time fromDate:_date];
NSDateComponents* origComps = [_calendar components:time fromDate:(_allowMultiDaySelection && [_selectedDates count] > 0 ? [_selectedDates lastObject] : _date)];
[origComps setDay:[internalComps day]];
[origComps setMonth:[internalComps month]];
[origComps setYear:[internalComps year]];
@@ -374,16 +417,21 @@ - (NSDate *)date {
}

- (BOOL)shouldOkBeEnabled {
if (_autoCloseOnSelectDate)
return YES;
return (self.internalDate && _dateNoTime && (_allowSelectionOfSelectedDate || [self.internalDate timeIntervalSinceDate:_dateNoTime]))
|| (self.internalDate && !_dateNoTime)
|| (!self.internalDate && _dateNoTime);
if (!_allowMultiDaySelection) {
if (_autoCloseOnSelectDate)
return YES;
NSLog(@"interval %f",[self.internalDate timeIntervalSinceDate:_dateNoTime]);
return (self.internalDate && _dateNoTime && (_allowSelectionOfSelectedDate || [self.internalDate timeIntervalSinceDate:_dateNoTime]))
|| (self.internalDate && !_dateNoTime)
|| (!self.internalDate && _dateNoTime);
} else {
return ([_selectedDates count] > 0);
}
}

- (void)setInternalDate:(NSDate *)internalDate{
_internalDate = internalDate;
self.clearBtn.enabled = !!internalDate;
self.clearBtn.enabled = internalDate;
self.okBtn.enabled = [self shouldOkBeEnabled];
if(internalDate){
[self setDisplayedMonthFromDate:internalDate];
@@ -450,23 +498,44 @@ - (BOOL)setDateTimeZoneWithName:(NSString *)name {
#pragma mark - User Events

- (void)dateDayTapped:(THDateDay *)dateDay {
if (!_internalDate || [_internalDate timeIntervalSinceDate:dateDay.date] || _allowSelectionOfSelectedDate) { // new date selected
[self.currentDay setSelected:NO];
[self.currentDay setLightText:![self dateInCurrentMonth:self.currentDay.date]];
[dateDay setSelected:YES];
BOOL dateInDifferentMonth = ![self dateInCurrentMonth:dateDay.date];
NSDate *firstOfCurrentMonth = self.firstOfCurrentMonth;
[self setInternalDate:dateDay.date];
[self setCurrentDay:dateDay];
if (dateInDifferentMonth) {
[self slideTransitionViewInDirection:[dateDay.date timeIntervalSinceDate:firstOfCurrentMonth]<0 ? UISwipeGestureRecognizerDirectionRight : UISwipeGestureRecognizerDirectionLeft];
}
if ([self.delegate respondsToSelector:@selector(datePicker:selectedDate:)]) {
[self.delegate datePicker:self selectedDate:dateDay.date];
BOOL dateInDifferentMonth = ![self dateInCurrentMonth:dateDay.date];
NSDate *firstOfCurrentMonth = self.firstOfCurrentMonth;
if (!_allowMultiDaySelection) {
if (!_internalDate || [_internalDate timeIntervalSinceDate:dateDay.date] || _allowSelectionOfSelectedDate) { // new date selected
[self.currentDay setSelected:NO];
[self.currentDay setLightText:![self dateInCurrentMonth:self.currentDay.date]];
[dateDay setSelected:YES];
[self setInternalDate:dateDay.date];
[self setCurrentDay:dateDay];
[_selectedDates removeAllObjects];
[_selectedDates addObject:[self dateWithOutTime:dateDay.date]];
if ([self.delegate respondsToSelector:@selector(datePicker:selectedDate:)]) {
[self.delegate datePicker:self selectedDate:dateDay.date];
}
}
if (_autoCloseOnSelectDate) {
[self.delegate datePickerDonePressed:self];
} else {
[self setInternalDate:dateDay.date];
if (![_selectedDates containsObject:[self dateWithOutTime:dateDay.date]]){
[_selectedDates addObject:[self dateWithOutTime:dateDay.date]];
[dateDay setSelected:YES];
if ([self.delegate respondsToSelector:@selector(datePicker:selectedDate:)]) {
[self.delegate datePicker:self selectedDate:dateDay.date];
}
} else {
if ([self.delegate respondsToSelector:@selector(datePicker:deselectedDate:)]) {
[self.delegate datePicker:self deselectedDate:dateDay.date];
}
[dateDay setLightText:dateInDifferentMonth];
[dateDay setSelected:NO];
[_selectedDates removeObject:dateDay.date];
}
self.okBtn.enabled = [self shouldOkBeEnabled];
}
if (_autoCloseOnSelectDate) {
[self.delegate datePickerDonePressed:self];
}
if (dateInDifferentMonth) {
[self slideTransitionViewInDirection:[dateDay.date timeIntervalSinceDate:firstOfCurrentMonth]<0 ? UISwipeGestureRecognizerDirectionRight : UISwipeGestureRecognizerDirectionLeft];
}
}

@@ -613,6 +682,14 @@ - (BOOL)dateInCurrentMonth:(NSDate *)date{
return [comp1 year] == [comp2 year] && [comp1 month] == [comp2 month];
}

- (NSDate *)dateWithOutTime:(NSDate *)datDate {
if(!datDate) {
datDate = [NSDate date];
}
NSDateComponents* comps = [[NSCalendar currentCalendar] components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:datDate];
return [[NSCalendar currentCalendar] dateFromComponents:comps];
}

#pragma mark - Cleanup

- (void)didReceiveMemoryWarning {
10 changes: 5 additions & 5 deletions THCalendarDatePickerExample/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PODS:
- KNSemiModalViewController_hons82 (0.4.3)
- THCalendarDatePicker (1.2.5):
- KNSemiModalViewController_hons82 (~> 0.4.3)
- KNSemiModalViewController_hons82 (0.4.4)
- THCalendarDatePicker (1.2.6):
- KNSemiModalViewController_hons82 (~> 0.4.4)

DEPENDENCIES:
- THCalendarDatePicker (from `./../../THCalendarDatePicker`)
@@ -11,7 +11,7 @@ EXTERNAL SOURCES:
:path: "./../../THCalendarDatePicker"

SPEC CHECKSUMS:
KNSemiModalViewController_hons82: 08916c03c9320759006246aa5073b290a5fd5891
THCalendarDatePicker: 65c63c1814d1a27defc89f4b72ec7a1d01d5503d
KNSemiModalViewController_hons82: 22aead5ef5d8ca749bc1babb43fa7d6f14b030a3
THCalendarDatePicker: 809e0c11affecb7087eee08ca55a9a7ab083829b

COCOAPODS: 0.39.0
Loading

0 comments on commit 915b2fd

Please sign in to comment.