diff --git a/LifeLog/LifeLog.xcodeproj/project.pbxproj b/LifeLog/LifeLog.xcodeproj/project.pbxproj index 3fb2046..49fa243 100644 --- a/LifeLog/LifeLog.xcodeproj/project.pbxproj +++ b/LifeLog/LifeLog.xcodeproj/project.pbxproj @@ -49,6 +49,7 @@ E9373E4D1F361A230059355A /* HistoryGraphObject.m in Sources */ = {isa = PBXBuildFile; fileRef = E9373E4C1F361A230059355A /* HistoryGraphObject.m */; }; E9682E2E1F39675A00FE05A2 /* RankingTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E9682E2C1F39675A00FE05A2 /* RankingTableViewCell.m */; }; E9682E2F1F39675A00FE05A2 /* RankingTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = E9682E2D1F39675A00FE05A2 /* RankingTableViewCell.xib */; }; + E997E0261F3AB66500709FB1 /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E997E0251F3AB66500709FB1 /* Social.framework */; }; E99E13AB1F336F3600C78787 /* CollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = E99E13AA1F336F3600C78787 /* CollectionView.m */; }; E99E13AD1F336F4500C78787 /* CollectionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = E99E13AC1F336F4500C78787 /* CollectionView.xib */; }; E99E13B11F33720600C78787 /* LabelCollectionViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E99E13AF1F33720600C78787 /* LabelCollectionViewCell.m */; }; @@ -151,6 +152,7 @@ E9682E2B1F39675A00FE05A2 /* RankingTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RankingTableViewCell.h; sourceTree = ""; }; E9682E2C1F39675A00FE05A2 /* RankingTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RankingTableViewCell.m; sourceTree = ""; }; E9682E2D1F39675A00FE05A2 /* RankingTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RankingTableViewCell.xib; sourceTree = ""; }; + E997E0251F3AB66500709FB1 /* Social.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Social.framework; path = System/Library/Frameworks/Social.framework; sourceTree = SDKROOT; }; E99E13A91F336F3600C78787 /* CollectionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CollectionView.h; sourceTree = ""; }; E99E13AA1F336F3600C78787 /* CollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CollectionView.m; sourceTree = ""; }; E99E13AC1F336F4500C78787 /* CollectionView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = CollectionView.xib; sourceTree = ""; }; @@ -167,6 +169,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + E997E0261F3AB66500709FB1 /* Social.framework in Frameworks */, 011799F0F2B47D80472673CE /* Pods_LifeLog.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -191,6 +194,7 @@ 020C1721B642EF36F31E1BB4 /* Frameworks */ = { isa = PBXGroup; children = ( + E997E0251F3AB66500709FB1 /* Social.framework */, 2D9F4ED6F06C8F252B9EAF48 /* Pods_LifeLog.framework */, ); name = Frameworks; diff --git a/LifeLog/LifeLog/CollectionView.h b/LifeLog/LifeLog/CollectionView.h index 5516b6c..da37054 100644 --- a/LifeLog/LifeLog/CollectionView.h +++ b/LifeLog/LifeLog/CollectionView.h @@ -12,6 +12,7 @@ NSInteger _number; int _selectedIndex; + BOOL _isEnableSelection; float _spacing; float _cornerRadius; @@ -27,6 +28,7 @@ @property (weak, nonatomic) IBOutlet UIView *view; @property (weak, nonatomic) IBOutlet UICollectionView *collectionView; +-(void) disableSelection; -(void) setButtonNumber: (NSInteger) number; -(void) setSpacing: (float) spacing; -(void) setCornerRadius: (float) radius; diff --git a/LifeLog/LifeLog/CollectionView.m b/LifeLog/LifeLog/CollectionView.m index 11a8621..6069091 100644 --- a/LifeLog/LifeLog/CollectionView.m +++ b/LifeLog/LifeLog/CollectionView.m @@ -24,6 +24,8 @@ _highlightColor = [Utilities convertHecToColor:0x999999]; _normalColor = [UIColor whiteColor]; _textColor = [UIColor blackColor]; + _isEnableSelection = true; + _selectedIndex = 0; } return self; } @@ -33,6 +35,13 @@ [self.collectionView registerNib:[UINib nibWithNibName:@"LabelCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"LabelCell"]; } + +-(void) disableSelection { + _isEnableSelection = false; + _selectedIndex = -1; + [self.collectionView reloadData]; +} + -(void) setButtonNumber: (NSInteger) number { _number = number; } @@ -91,8 +100,12 @@ } -(void) collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { - _selectedIndex = indexPath.row; - [collectionView reloadData]; - self.changeCurrentIndex(_selectedIndex); + if(_isEnableSelection) { + _selectedIndex = indexPath.row; + [collectionView reloadData]; + } + if(self.changeCurrentIndex != NULL) { + self.changeCurrentIndex(_selectedIndex); + } } @end diff --git a/LifeLog/LifeLog/HistoryViewController.m b/LifeLog/LifeLog/HistoryViewController.m index 86d0302..edd960f 100644 --- a/LifeLog/LifeLog/HistoryViewController.m +++ b/LifeLog/LifeLog/HistoryViewController.m @@ -72,8 +72,14 @@ NSArray *shareTitle = [NSArray arrayWithObjects:NSLocalizedString(@"lifelog.history.share.1", nil), NSLocalizedString(@"lifelog.history.share.2", nil), NSLocalizedString(@"lifelog.history.share.3", nil), NSLocalizedString(@"lifelog.history.share.4", nil), NSLocalizedString(@"lifelog.history.share.5", nil), nil]; [self.viewCollectionShare setButtonNumber:typeTitle.count]; [self.viewCollectionShare setSpacing:3]; - [self.viewCollectionShare setSelectedIndex:-1]; [self.viewCollectionShare setArrayTitle:shareTitle]; + [self.viewCollectionShare disableSelection]; + + //add tap gesture for enable tap on gesture on CollectionView in ScrollView + UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureAction:)]; + [recognizer setNumberOfTapsRequired:1]; + self.scrollView.userInteractionEnabled = YES; + [self.scrollView addGestureRecognizer:recognizer]; } - (void)setupChartView { @@ -204,11 +210,37 @@ [UIView animateWithDuration:0.5 animations:^{ self.tableListHistory.alpha = alphaValue; self.scrollView.alpha = 1.0 - alphaValue; - } completion:^(bool completed) { + } completion:^(BOOL completed) { [self callRequestToUpdateData]; }]; } +-(void)gestureAction:(UITapGestureRecognizer *) sender +{ + CGPoint touchLocation = [sender locationOfTouch:0 inView:self.viewCollectionShare]; + NSIndexPath *indexPath = [self.viewCollectionShare.collectionView indexPathForItemAtPoint:touchLocation]; + NSString * content = @"Finish 500 steps"; + HistoryViewController __weak *weakSelf = self; + if(indexPath != NULL) { + switch (indexPath.row) { + case 0: //share facebook + [Utilities shareFacebook:content withViewController:weakSelf]; + break; + case 1: //share twitter + [Utilities shareTwitter:content withViewController:weakSelf]; + break; + case 2 : //share line + [Utilities shareLine:content withViewController:weakSelf]; + break; + case 3: // share email + [Utilities shareEmail:content withViewController:weakSelf]; + break; + default: + break; + } + } +} + #pragma mark UITableView Delegate - (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { if(_curHisList == nil || _curHisList.count == 0) { diff --git a/LifeLog/LifeLog/HistoryViewController.xib b/LifeLog/LifeLog/HistoryViewController.xib index ff7b934..960f1b5 100644 --- a/LifeLog/LifeLog/HistoryViewController.xib +++ b/LifeLog/LifeLog/HistoryViewController.xib @@ -1,10 +1,10 @@ - + - + @@ -136,11 +136,11 @@ - - + + - - + + @@ -155,7 +155,7 @@ - + - + diff --git a/LifeLog/LifeLog/Utilities.h b/LifeLog/LifeLog/Utilities.h index c74517e..88f08f5 100644 --- a/LifeLog/LifeLog/Utilities.h +++ b/LifeLog/LifeLog/Utilities.h @@ -13,4 +13,10 @@ + (NSString *)addCommaFromNumber:(NSInteger)number; + (UIColor *)convertHecToColor:(int) hex; + (void)showErrorMessage:(NSString *)message withViewController:(UIViewController *)vc; + +//share function ++ (void) shareFacebook : (NSString *) content withViewController:(UIViewController *)vc; ++ (void) shareTwitter : (NSString *) content withViewController:(UIViewController *)vc; ++ (void) shareLine : (NSString *) content withViewController:(UIViewController *)vc; ++ (void) shareEmail : (NSString *) content withViewController:(UIViewController *)vc; @end diff --git a/LifeLog/LifeLog/Utilities.m b/LifeLog/LifeLog/Utilities.m index 8e6fdb7..fff0348 100644 --- a/LifeLog/LifeLog/Utilities.m +++ b/LifeLog/LifeLog/Utilities.m @@ -6,6 +6,8 @@ // Copyright © 2017 PhongNV. All rights reserved. // +#import + #import "Utilities.h" @implementation Utilities @@ -48,4 +50,61 @@ } } ++ (void) shareFacebook : (NSString *) content withViewController:(UIViewController *)vc { + if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) + { + SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; + + [composeViewController setInitialText:content]; + [composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) { + + switch (result) { + case SLComposeViewControllerResultCancelled: + NSLog(@"canceled"); + break; + case SLComposeViewControllerResultDone: + NSLog(@"done"); + break; + default: + break; + } + }]; + [vc presentViewController:composeViewController animated:YES completion:nil]; + } + else { + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=FACEBOOK"]]; + } +} + ++ (void) shareTwitter : (NSString *) content withViewController:(UIViewController *)vc { + if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) + { + SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]; + + [composeViewController setInitialText:content]; + [composeViewController setCompletionHandler:^(SLComposeViewControllerResult result) { + + switch (result) { + case SLComposeViewControllerResultCancelled: + NSLog(@"canceled"); + break; + case SLComposeViewControllerResultDone: + NSLog(@"done"); + break; + default: + break; + } + }]; + [vc presentViewController:composeViewController animated:YES completion:nil]; + } + else { + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=TWITTER"]]; + } +} + ++ (void) shareLine : (NSString *) content withViewController:(UIViewController *)vc { +} + ++ (void) shareEmail : (NSString *) content withViewController:(UIViewController *)vc { +} @end