From 11a988908ea7bec658fdb0e0ba2327dc8399b71a Mon Sep 17 00:00:00 2001 From: Bock Date: Tue, 4 Sep 2018 21:24:23 -0700 Subject: [PATCH 1/2] Add Youtube video App/Web compatibility Will Open Youtube app if enabled, will open Web UI otherwise --- Diveboard.xcodeproj/project.pbxproj | 6 ++- .../DiveDetailPhotosViewController.h | 4 +- .../DiveDetailPhotosViewController.m | 13 ++++-- .../DiveDetailPhotosViewController.xib | 26 ++++++------ .../DiveEditPhotosVC/DiveEditPhotoCell.h | 5 +++ .../DiveEditPhotosVC/DiveEditPhotoCell.m | 24 ++++++++++++ .../DiveEditPhotosVC/DiveEditPhotoCell.xib | 32 +++++++++------ Diveboard/Classes/Global/DiveInformation.h | 2 + Diveboard/Classes/Global/DiveInformation.m | 16 ++++++++ Diveboard/Classes/Global/Global.h | 2 +- Diveboard/Classes/Global/Global.m | 12 ++++++ .../Home/DivePicturesViewController-ipad.xib | 31 ++++++++++----- .../Classes/Home/DivePicturesViewController.h | 2 +- .../Classes/Home/DivePicturesViewController.m | 20 ++++++++++ .../Home/DivePicturesViewController.xib | 37 +++++++++++------- Diveboard/Resource/.DS_Store | Bin 6148 -> 10244 bytes 16 files changed, 175 insertions(+), 57 deletions(-) diff --git a/Diveboard.xcodeproj/project.pbxproj b/Diveboard.xcodeproj/project.pbxproj index 9ae10c9..d11f971 100644 --- a/Diveboard.xcodeproj/project.pbxproj +++ b/Diveboard.xcodeproj/project.pbxproj @@ -123,6 +123,7 @@ 3CF3378318BD48FE001D2DF0 /* DiveCountlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CF3378218BD48FE001D2DF0 /* DiveCountlineView.m */; }; 3CF3378518BD591F001D2DF0 /* DiveCountlineView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3CF3378418BD591F001D2DF0 /* DiveCountlineView.xib */; }; 3CF3780718DD22CD00D832B3 /* DiveEditViewController-ipad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3CF3780618DD22CD00D832B3 /* DiveEditViewController-ipad.xib */; }; + 6AB050AD213F672F00DC40BB /* btn_youtube.png in Resources */ = {isa = PBXBuildFile; fileRef = 6AB050AC213F672E00DC40BB /* btn_youtube.png */; }; C313798519DEDC2600F4B3DD /* libsqlite3.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = C313798419DEDC2600F4B3DD /* libsqlite3.0.dylib */; }; C31B7AA019DE465700BE6239 /* GZIP.m in Sources */ = {isa = PBXBuildFile; fileRef = C31B7A9F19DE465700BE6239 /* GZIP.m */; }; C31CC26B19E5903B001CA1F7 /* progress_mask.png in Resources */ = {isa = PBXBuildFile; fileRef = C31CC26A19E5903B001CA1F7 /* progress_mask.png */; }; @@ -432,6 +433,7 @@ 3CF3378218BD48FE001D2DF0 /* DiveCountlineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DiveCountlineView.m; sourceTree = ""; }; 3CF3378418BD591F001D2DF0 /* DiveCountlineView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DiveCountlineView.xib; sourceTree = ""; }; 3CF3780618DD22CD00D832B3 /* DiveEditViewController-ipad.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = "DiveEditViewController-ipad.xib"; sourceTree = ""; }; + 6AB050AC213F672E00DC40BB /* btn_youtube.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = btn_youtube.png; sourceTree = ""; }; C313798419DEDC2600F4B3DD /* libsqlite3.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.0.dylib; path = usr/lib/libsqlite3.0.dylib; sourceTree = SDKROOT; }; C31B7A9B19DE42FB00BE6239 /* libz.1.2.5.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.1.2.5.dylib; path = usr/lib/libz.1.2.5.dylib; sourceTree = SDKROOT; }; C31B7A9E19DE465700BE6239 /* GZIP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GZIP.h; sourceTree = ""; }; @@ -1042,10 +1044,10 @@ 3C13084618F3E1DC00D51AC7 /* DataRequestManager.m */, 3CE7FA4E1933731700D72A34 /* DiveBoardNavigationController.h */, 3CE7FA4F1933731700D72A34 /* DiveBoardNavigationController.m */, + E0B1D5AC19C9BE150007C481 /* DiveDatePicker.m */, 3C66AB0118F538C7000AB0D6 /* DiveOfflineModeManager.h */, 3C66AB0218F538C7000AB0D6 /* DiveOfflineModeManager.m */, E0B1D5AB19C9BE150007C481 /* DiveDatePicker.h */, - E0B1D5AC19C9BE150007C481 /* DiveDatePicker.m */, E0B1D5B219C9EE740007C481 /* DiveDatePicker.xib */, E035C3C819D0D17700FE5266 /* MKMapView+ZoomLevel.h */, E035C3C919D0D17700FE5266 /* MKMapView+ZoomLevel.m */, @@ -1128,6 +1130,7 @@ 3CE047BA18BCBB4C00FA47FF /* button */ = { isa = PBXGroup; children = ( + 6AB050AC213F672E00DC40BB /* btn_youtube.png */, C36D415119DB04B8003CBFE5 /* no_picture.png */, C3A1675719D9BEB300D29509 /* btn_checked.png */, C3A1675819D9BEB300D29509 /* btn_unchecked.png */, @@ -1919,6 +1922,7 @@ C3A92DBE19E098C9003C9B58 /* WalletViewController.xib in Resources */, 3C539E2018EA46C200470897 /* icon58.png in Resources */, 3C539E2218EA46C200470897 /* icon76.png in Resources */, + 6AB050AD213F672F00DC40BB /* btn_youtube.png in Resources */, C5B7350619F6C1F7005FA191 /* uv_idea.png in Resources */, E0A25C9119C62C300043A849 /* full_diveboard_grey.png in Resources */, E0A25C9819C716FE0043A849 /* btn_back_black.png in Resources */, diff --git a/Diveboard/Classes/DiveDetail/DiveDetailPhotosViewController.h b/Diveboard/Classes/DiveDetail/DiveDetailPhotosViewController.h index 8c5af53..c68fd38 100644 --- a/Diveboard/Classes/DiveDetail/DiveDetailPhotosViewController.h +++ b/Diveboard/Classes/DiveDetail/DiveDetailPhotosViewController.h @@ -25,7 +25,7 @@ @property (nonatomic, strong) id delegate; - (id)initWithDiveInformation:(DiveInformation *) diveInfo; -- (void)setDiveInformation:(DiveInformation *)diveInfo; - +- (void)setDiveInformation:(DiveInformation *) diveInfo; +- (void)didClickedYoutubeButton:(NSIndexPath *) indexPath :(NSString*)youtubeVideoId; @end diff --git a/Diveboard/Classes/DiveDetail/DiveDetailPhotosViewController.m b/Diveboard/Classes/DiveDetail/DiveDetailPhotosViewController.m index 31915c2..7764f62 100644 --- a/Diveboard/Classes/DiveDetail/DiveDetailPhotosViewController.m +++ b/Diveboard/Classes/DiveDetail/DiveDetailPhotosViewController.m @@ -9,7 +9,7 @@ #import "DiveDetailPhotosViewController.h" #import "DiveEditPhotoCell.h" #import "Global.h" -@interface DiveDetailPhotosViewController () +@interface DiveDetailPhotosViewController () { DiveInformation* m_DiveInformation; } @@ -127,10 +127,12 @@ -(DiveEditPhotoCell *)collectionView:(UICollectionView *)collectionView cellForI { DiveEditPhotoCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"PhotoCell" forIndexPath:indexPath]; - DivePicture* divePicture = [m_DiveInformation.divePictures objectAtIndex:indexPath.row]; [cell setDivePicture:indexPath:divePicture]; - + if (divePicture.isYoutube) { + [cell setYoutubeButton:indexPath:divePicture.youtubeVideoId]; + cell.delegate = self; + } return cell; @@ -163,4 +165,9 @@ - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollection return size; } +-(void)didClickedYoutubeButton:(NSIndexPath *)indexPath :(NSString*)youtubeVideoId +{ + [GlobalMethods launchYoutubeVideo:youtubeVideoId]; +} + @end diff --git a/Diveboard/Classes/DiveDetail/DiveDetailPhotosViewController.xib b/Diveboard/Classes/DiveDetail/DiveDetailPhotosViewController.xib index d3500ae..a801f85 100644 --- a/Diveboard/Classes/DiveDetail/DiveDetailPhotosViewController.xib +++ b/Diveboard/Classes/DiveDetail/DiveDetailPhotosViewController.xib @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -14,20 +18,20 @@ - + - + - + @@ -41,13 +45,7 @@ - - - - - - diff --git a/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.h b/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.h index 0cdb38c..98190b3 100644 --- a/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.h +++ b/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.h @@ -14,6 +14,7 @@ @optional - (void)didLongPressedPhoto:(UIGestureRecognizer*) gestureRecognizer :(NSIndexPath*)indexPath :(UIImage*)image; - (void)didClickedAddPhotoButton:(NSIndexPath*)indexPath; +- (void)didClickedYoutubeButton:(NSIndexPath*)indexPath :(NSString *)youtubeVideoId; @end @@ -22,11 +23,15 @@ IBOutlet UIImageView* m_imgDivePicture; IBOutlet UIButton* m_btnAdd; + IBOutlet UIButton* m_btnYoutube; } @property (nonatomic, strong) id delegate; +@property (nonatomic, copy) NSString* youtubeVideoId; - (void)setAddButton:(NSIndexPath*)indexPath; +- (void)setYoutubeButton:(NSIndexPath*)indexPath :(NSString *)youtubeVideoId; - (void)setDivePicture:(NSIndexPath*)indexPath :(DivePicture*)divePicture; - (IBAction)onAddButton:(id)sender; +- (IBAction)onYoutubeButton:(id)sender; @end diff --git a/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.m b/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.m index 1950555..884fdcc 100644 --- a/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.m +++ b/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.m @@ -43,6 +43,7 @@ - (void)setDivePicture:(NSIndexPath*)indexPath :(DivePicture*)divePicture{ m_indexPath = indexPath; [m_btnAdd setHidden:YES]; + [m_btnYoutube setHidden:YES]; _longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressDetected:)]; [self addGestureRecognizer:_longPressRecognizer]; @@ -65,6 +66,21 @@ -(void)setAddButton:(NSIndexPath *)indexPath [self removeGestureRecognizer:_longPressRecognizer]; +} + +-(void)setYoutubeButton:(NSIndexPath *)indexPath :(NSString *)youtubeVideoId +{ + + m_indexPath = indexPath; + self.youtubeVideoId = youtubeVideoId; + + [m_btnYoutube setBackgroundImage:[UIImage imageNamed:@"btn_youtube.png"] forState:UIControlStateNormal]; + + [m_btnYoutube setHidden:NO]; + + [self removeGestureRecognizer:_longPressRecognizer]; + + } -(void) longPressDetected:(UIGestureRecognizer*) gestureRecognizer{ @@ -83,4 +99,12 @@ - (void)onAddButton:(id)sender{ [self.delegate didClickedAddPhotoButton:m_indexPath]; } } +- (void)onYoutubeButton:(id)sender { + + if (self.delegate && [self.delegate respondsToSelector:@selector(didClickedYoutubeButton::)]) { + + [self.delegate didClickedYoutubeButton:m_indexPath :self.youtubeVideoId]; + } +} + @end diff --git a/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.xib b/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.xib index 680fb54..c226433 100644 --- a/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.xib +++ b/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.xib @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -17,32 +21,38 @@ - + + - + - - - - - diff --git a/Diveboard/Classes/Global/DiveInformation.h b/Diveboard/Classes/Global/DiveInformation.h index 5ce5c12..dba9d2c 100644 --- a/Diveboard/Classes/Global/DiveInformation.h +++ b/Diveboard/Classes/Global/DiveInformation.h @@ -67,6 +67,8 @@ @property (nonatomic, strong) NSString *permaLink; @property (nonatomic, strong) NSString *player; @property (nonatomic, strong) NSString *thumbnail; +@property (nonatomic) BOOL isYoutube; +@property (nonatomic, strong) NSString *youtubeVideoId; @property (nonatomic, strong) NSString *urlString; @property (nonatomic) BOOL isLocal; diff --git a/Diveboard/Classes/Global/DiveInformation.m b/Diveboard/Classes/Global/DiveInformation.m index a97bc64..b866e89 100644 --- a/Diveboard/Classes/Global/DiveInformation.m +++ b/Diveboard/Classes/Global/DiveInformation.m @@ -238,6 +238,22 @@ - (id)initWithDictionary:(NSDictionary *)data } } + //Check if Youtube Video + if ([self.media rangeOfString:@"video"].location != NSNotFound && [self.player rangeOfString:@"youtube.com"].location != NSNotFound) { + NSError *error = NULL; + NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"src\\=\\'http\\:\\/\\/www\\.youtube\\.com\\/embed\\/([a-zA-Z0-9]+)\\?wmode\\=opaque\\&autoplay\\=0\\'" + options:NSRegularExpressionCaseInsensitive + error:&error]; + NSArray *matches = [regex matchesInString:self.player options:0 range:NSMakeRange(0, [self.player length])]; + NSString *youtubeVideoId = NULL; + if (matches.count>0) { + //NSRange matchRange = [match range]; + NSRange matchRange = [matches[0] rangeAtIndex:1]; + self.youtubeVideoId = [self.player substringWithRange:matchRange]; + self.isYoutube = true; + } + } + return self; } diff --git a/Diveboard/Classes/Global/Global.h b/Diveboard/Classes/Global/Global.h index da6fa38..35aa108 100644 --- a/Diveboard/Classes/Global/Global.h +++ b/Diveboard/Classes/Global/Global.h @@ -127,7 +127,7 @@ typedef NSUInteger UserSettingDownloadType; + (NSString *) encodeValueToFloat:(NSString *)value; + (void)setBorderView:(UIView*)view borderColor:(UIColor *)color borderWidth:(float)borderWidth position:(NSString*)position; - ++ (void)launchYoutubeVideo:(NSString*)youtubeVideoId; @end diff --git a/Diveboard/Classes/Global/Global.m b/Diveboard/Classes/Global/Global.m index a7465a3..0f6df80 100644 --- a/Diveboard/Classes/Global/Global.m +++ b/Diveboard/Classes/Global/Global.m @@ -290,6 +290,18 @@ + (void)setBorderView:(UIView*)view borderColor:(UIColor *)color borderWidth:(fl } ++(void)launchYoutubeVideo:(NSString*)youtubeVideoId { + NSURL *linkToApp = [NSURL URLWithString:[NSString stringWithFormat:@"youtube://watch?v=%@",youtubeVideoId]]; + NSURL *linkToWeb = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.youtube.com/watch?v=%@",youtubeVideoId]]; + + if ([[UIApplication sharedApplication] canOpenURL:linkToApp]) { + [[UIApplication sharedApplication] openURL:linkToApp]; + } + else{ + [[UIApplication sharedApplication] openURL:linkToWeb]; + } + return; +} @end diff --git a/Diveboard/Classes/Home/DivePicturesViewController-ipad.xib b/Diveboard/Classes/Home/DivePicturesViewController-ipad.xib index e39b7da..b8b5aed 100644 --- a/Diveboard/Classes/Home/DivePicturesViewController-ipad.xib +++ b/Diveboard/Classes/Home/DivePicturesViewController-ipad.xib @@ -1,14 +1,18 @@ - - + + + + + - - - + + + + @@ -21,26 +25,33 @@ - + + + + + + + + - - + + - \ No newline at end of file + diff --git a/Diveboard/Classes/Home/DivePicturesViewController.h b/Diveboard/Classes/Home/DivePicturesViewController.h index 297c8d7..508fe29 100644 --- a/Diveboard/Classes/Home/DivePicturesViewController.h +++ b/Diveboard/Classes/Home/DivePicturesViewController.h @@ -15,7 +15,7 @@ { IBOutlet UIView *viewMain; IBOutlet UIButton *btnClose; - + IBOutlet UIImageView *btnYoutube; } //@property (nonatomic) int startIndex; diff --git a/Diveboard/Classes/Home/DivePicturesViewController.m b/Diveboard/Classes/Home/DivePicturesViewController.m index 0edd40f..9c0f3be 100644 --- a/Diveboard/Classes/Home/DivePicturesViewController.m +++ b/Diveboard/Classes/Home/DivePicturesViewController.m @@ -48,6 +48,11 @@ - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. + [btnYoutube setHidden:YES]; + UITapGestureRecognizer *singleFingerTap = + [[UITapGestureRecognizer alloc] initWithTarget:self + action:@selector(handleSingleTap:)]; + [self.view addGestureRecognizer:singleFingerTap]; } - (void)didReceiveMemoryWarning @@ -397,6 +402,12 @@ - (void) swapViewWithIncrease:(int)inc prevImageView = nil; } } + DivePicture *picture = [divePictures objectAtIndex:(int)divePictures.count - 1 - currentPictureIndex]; + if (picture.isYoutube) { + [btnYoutube setHidden:NO]; + } else { + [btnYoutube setHidden:YES]; + } } - (IBAction)closeAction:(id)sender { @@ -405,4 +416,13 @@ - (IBAction)closeAction:(id)sender { }]; } +- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer +{ + //CGPoint location = [recognizer locationInView:[recognizer.view superview]]; + DivePicture *picture = [divePictures objectAtIndex:(int)divePictures.count - 1 - currentPictureIndex]; + if (picture.isYoutube) { + [GlobalMethods launchYoutubeVideo:picture.youtubeVideoId]; + } +} + @end diff --git a/Diveboard/Classes/Home/DivePicturesViewController.xib b/Diveboard/Classes/Home/DivePicturesViewController.xib index 140bbca..4890b1f 100644 --- a/Diveboard/Classes/Home/DivePicturesViewController.xib +++ b/Diveboard/Classes/Home/DivePicturesViewController.xib @@ -1,49 +1,58 @@ - - + + + + + - + + + - + - + - + + + + + + + + - + + + - - - - - diff --git a/Diveboard/Resource/.DS_Store b/Diveboard/Resource/.DS_Store index 11d5f1f719da17c0822692f6a5afa2a35b3b6d07..828835a76a1e617409af3c3facc5db853a96563a 100644 GIT binary patch literal 10244 zcmeHMZEO@p7@qei?QU--D}Zu zT8Tyk@gx3__=SoeC@PxxP5gx#WAu+!0%+n#@Rvr7#zg)Q-d0w{-CFdUVy<(Jz;_C$u3nZC6aKTetO?Zs^Xff=Hi!xol*lHe6dBT2vEBRfk6E z>cZ8brIET+N`6=nW-nM)-`Y2r+W*XvXPBFhnhC6Vyo2-JoVfhRX?QjY({IsPBJl>b8=3DdC5?Wm{Njsrb{z= zhUmsIw60;gr}`8-u9>QCZr_AE&2;ozbS)vuC&W%u8PLW`%F1WWzA6yN?VKK@HyP7+ zC2cI`am_cG?Ct6Ib;yPCu)xyd+Q&XcmM%s;yU5TvcV%4l`C%M(1;ORHjM7 zFsY1kH4*Xel>k{nn#cyS4UdNra*!M%Pm?#uTjXtWl6*?W$XRlZ{6c;uzmea`p8!w* z#ZV4&U@pvqt6?#$g4M7FqR!sjpsU&1N)2EK*w;79lg{(uX<0-xk75A2j88YN>Ae)SgeVks5c4=C% zPd<*%V|+_U!7gN{w);{$LoT2^6vk$k&ngSf3Ct-GSG3Ln^C7v#3 q=im@z2C4u80d64S3R1kW@H_KleicuURt6@BF(8u}HplbKVFmz-DiDSM From d57c9c788a52493a188a2b3d9966de4bdb9837b4 Mon Sep 17 00:00:00 2001 From: Bock Date: Tue, 4 Sep 2018 21:27:37 -0700 Subject: [PATCH 2/2] Add missing icon Center button in view --- .../DiveEditPhotosVC/DiveEditPhotoCell.xib | 2 +- Diveboard/Resource/button/btn_youtube.png | Bin 0 -> 10820 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100755 Diveboard/Resource/button/btn_youtube.png diff --git a/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.xib b/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.xib index c226433..33c49da 100644 --- a/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.xib +++ b/Diveboard/Classes/DiveEdit/DiveEditPhotosVC/DiveEditPhotoCell.xib @@ -36,7 +36,7 @@