From 381a648a9b29d7327ec2c55e4fed630008324839 Mon Sep 17 00:00:00 2001 From: Benjamin Verdier Date: Fri, 27 Jul 2018 16:22:13 +0200 Subject: [PATCH] Add share button and share handling --- Classes/LinphoneUI/UIRecordingCell.h | 7 ++++-- Classes/LinphoneUI/UIRecordingCell.m | 28 +++++++++++++++++++++--- Classes/LinphoneUI/UIRecordingCell.xib | 25 ++++++++++++++------- Classes/PhoneMainView.h | 1 + Classes/RecordingsListTableView.h | 1 + Classes/RecordingsListTableView.m | 30 ++++++++++++++++++++------ Classes/RecordingsListView.m | 1 - 7 files changed, 72 insertions(+), 21 deletions(-) diff --git a/Classes/LinphoneUI/UIRecordingCell.h b/Classes/LinphoneUI/UIRecordingCell.h index 79abdda0f..d39999448 100644 --- a/Classes/LinphoneUI/UIRecordingCell.h +++ b/Classes/LinphoneUI/UIRecordingCell.h @@ -9,10 +9,13 @@ @interface UIRecordingCell : UITableViewCell -@property (weak, nonatomic) IBOutlet UILabel *nameLabel; @property (weak, nonatomic) IBOutlet UIView *playerView; +@property (weak, nonatomic) IBOutlet UILabel *nameLabel; +@property (strong, nonatomic) IBOutlet UIToolbar *toolbar; +@property (weak, nonatomic) IBOutlet UIBarButtonItem *shareButton; -@property(nonatomic, assign) NSString *recording; + +@property(nonatomic, assign) __block NSString *recording; - (id)initWithIdentifier:(NSString*)identifier; diff --git a/Classes/LinphoneUI/UIRecordingCell.m b/Classes/LinphoneUI/UIRecordingCell.m index 58475a8d2..79d59c977 100644 --- a/Classes/LinphoneUI/UIRecordingCell.m +++ b/Classes/LinphoneUI/UIRecordingCell.m @@ -16,7 +16,13 @@ static UILinphoneAudioPlayer *player; #pragma mark - Lifecycle Functions - +/* + * TODO: + * - When we scroll past a selected row, the player loads incorrectly (no buttons). Probably a problem in the player code. + * - mkv recording is probably buggy, wrong eof. wav playing works but does not display the length/timestamp. + * - When coming back from the action extension (to share a recording), we have to pop and reload the view for it to dislpay correctly. Find out why? + * - The share button is greyed out when not clicking it. idk why, it's really weird. +*/ - (id)initWithIdentifier:(NSString *)identifier { if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier])) { NSArray *arrayOfViews = @@ -28,6 +34,8 @@ static UILinphoneAudioPlayer *player; [self setFrame:CGRectMake(0, 0, sub.frame.size.width, 40)]; self = sub; self.recording = NULL; + _shareButton.target = self; + _shareButton.action = @selector(onShareButtonPressed); } return self; } @@ -42,7 +50,6 @@ static UILinphoneAudioPlayer *player; - (void)setRecording:(NSString *)arecording { _recording = arecording; if(_recording) { - //TODO: Parse file name to get name of contact and date NSArray *parsedRecording = [LinphoneUtils parseRecordingName:_recording]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"HH:mm:ss"]; @@ -86,8 +93,10 @@ static UILinphoneAudioPlayer *player; -(void)setSelected:(BOOL)selected animated:(BOOL)animated{ [super setSelected:selected animated:animated]; - if (!selected) + _toolbar.hidden = !selected; + if (!selected) { return; + } if (!player) player = [UILinphoneAudioPlayer audioPlayerWithFilePath:[self recording]]; else @@ -102,4 +111,17 @@ static UILinphoneAudioPlayer *player; [player open]; } +- (void)onShareButtonPressed { + UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[[NSURL fileURLWithPath:_recording]] applicationActivities:nil]; + [activityVC setCompletionWithItemsHandler:^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError) { + //This is used to select the same row when we get back to the recordings view. + NSString *file = player.file; + //This reloads the view, if don't it's empty for some reason. Idealy we'd want to do this before closing the view but it's functionnal. + [PhoneMainView.instance popCurrentView]; + [PhoneMainView.instance changeCurrentView:RecordingsListView.compositeViewDescription]; + [[(RecordingsListView *)VIEW(RecordingsListView) tableController] setSelected:file]; + }]; + [PhoneMainView.instance presentViewController:activityVC animated:YES completion:nil]; +} + @end diff --git a/Classes/LinphoneUI/UIRecordingCell.xib b/Classes/LinphoneUI/UIRecordingCell.xib index fe8ede5b3..f8fcd6aba 100644 --- a/Classes/LinphoneUI/UIRecordingCell.xib +++ b/Classes/LinphoneUI/UIRecordingCell.xib @@ -16,26 +16,35 @@ - + + + + + + + + - + + + diff --git a/Classes/PhoneMainView.h b/Classes/PhoneMainView.h index 710aaa97b..2680e1b3f 100644 --- a/Classes/PhoneMainView.h +++ b/Classes/PhoneMainView.h @@ -44,6 +44,7 @@ #import "HistoryDetailsView.h" #import "HistoryListView.h" #import "ImageView.h" +#import "RecordingsListView.h" #import "SettingsView.h" #import "SideMenuView.h" #import "UIConfirmationDialog.h" diff --git a/Classes/RecordingsListTableView.h b/Classes/RecordingsListTableView.h index 45e32626b..97b672d11 100644 --- a/Classes/RecordingsListTableView.h +++ b/Classes/RecordingsListTableView.h @@ -18,5 +18,6 @@ } - (void)loadData; - (void)removeAllRecordings; +- (void)setSelected:(NSString *)filepath; @end diff --git a/Classes/RecordingsListTableView.m b/Classes/RecordingsListTableView.m index 66f22450b..52b4f2ab4 100644 --- a/Classes/RecordingsListTableView.m +++ b/Classes/RecordingsListTableView.m @@ -63,13 +63,6 @@ - (void)loadData { LOGI(@"====>>>> Load recording list - Start"); - //Clear recording cells - for (NSInteger j = 0; j < [self.tableView numberOfSections]; ++j){ - for (NSInteger i = 0; i < [self.tableView numberOfRowsInSection:j]; ++i) - { - [[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:j]] setRecording:nil]; - } - } recordings = [NSMutableDictionary dictionary]; NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:writablePath error:NULL]; for (NSString *file in directoryContent) { @@ -217,6 +210,29 @@ forRowAtIndexPath:(NSIndexPath *)indexPath { }]; } +- (void)setSelected:(NSString *)filepath { + NSArray *parsedName = [LinphoneUtils parseRecordingName:filepath]; + NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; + [dateFormat setDateFormat:@"EEEE, MMM d, yyyy"]; + NSString *dayPretty = [dateFormat stringFromDate:[parsedName objectAtIndex:1]]; + NSUInteger section; + NSArray *keys = [recordings allKeys]; + for (section = 0; section < [keys count]; ++section) { + if ([dayPretty isEqualToString:(NSString *)[keys objectAtIndex:section]]) { + break; + } + } + NSUInteger row; + NSArray *recs = [recordings objectForKey:dayPretty]; + for (row = 0; row < [recs count]; ++row) { + if ([filepath isEqualToString:(NSString *)[recs objectAtIndex:row]]) { + break; + } + } + NSUInteger indexes[] = {section, row}; + [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathWithIndexes:indexes length:2] animated:TRUE scrollPosition:UITableViewScrollPositionNone]; +} + #pragma mark - Utilities - (NSArray *)getSortedKeys { diff --git a/Classes/RecordingsListView.m b/Classes/RecordingsListView.m index f44d49f1a..dc5abd220 100644 --- a/Classes/RecordingsListView.m +++ b/Classes/RecordingsListView.m @@ -58,7 +58,6 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; - if (tableController.isEditing) { tableController.editing = NO; }