The long tap to cancel the download was broken (weird behaviour when the long tap gesture listener is created by the storyboard)

This commit is contained in:
ylecollen
2015-01-09 11:33:32 +01:00
parent 7ed285e19d
commit 75f91820aa
5 changed files with 38 additions and 34 deletions
@@ -343,17 +343,28 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
if ([view isKindOfClass:[RoomMessageTableCell class]]) {
__weak typeof(self) weakSelf = self;
NSString* url = ((RoomMessageTableCell*)view).message.attachmentURL;
MediaLoader *loader = [MediaManager mediaLoaderForURL:url];
self.actionMenu = [[CustomAlert alloc] initWithTitle:nil message:@"Cancel the download ?" style:CustomAlertStyleAlert];
self.actionMenu.cancelButtonIndex = [self.actionMenu addActionWithTitle:@"Cancel" style:CustomAlertActionStyleDefault handler:^(CustomAlert *alert) {
weakSelf.actionMenu = nil;
}];
self.actionMenu.cancelButtonIndex = [self.actionMenu addActionWithTitle:@"OK" style:CustomAlertActionStyleDefault handler:^(CustomAlert *alert) {
[(RoomMessageTableCell*)view cancelDownload];
weakSelf.actionMenu = nil;
}];
[self.actionMenu showInViewController:self];
// offer to cancel a download only if there is a pending one
if (loader) {
self.actionMenu = [[CustomAlert alloc] initWithTitle:nil message:@"Cancel the download ?" style:CustomAlertStyleAlert];
self.actionMenu.cancelButtonIndex = [self.actionMenu addActionWithTitle:@"Cancel" style:CustomAlertActionStyleDefault handler:^(CustomAlert *alert) {
weakSelf.actionMenu = nil;
}];
self.actionMenu.cancelButtonIndex = [self.actionMenu addActionWithTitle:@"OK" style:CustomAlertActionStyleDefault handler:^(CustomAlert *alert) {
// get again the loader, the cell could have been reused.
MediaLoader *loader = [MediaManager mediaLoaderForURL:url];
if (loader) {
[loader cancel];
}
weakSelf.actionMenu = nil;
}];
[self.actionMenu showInViewController:self];
}
}
}
}
@@ -1429,6 +1440,17 @@ NSString *const kCmdResetUserPowerLevel = @"/deop";
cell.messageTextView.attributedText = message.attributedTextMessage;
}
// add a long tap gesture on the progressView
// manage it in the storyboard does not work properly
// -> The gesture view is always the same i.e. the latest composed one.
while (cell.progressView.gestureRecognizers.count) {
[cell.progressView removeGestureRecognizer:cell.progressView.gestureRecognizers[0]];
}
// only the download can be cancelled
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onProgressLongTap:)];
[cell.progressView addGestureRecognizer:longPress];
// Handle timestamp display
if (dateFormatter) {
// Add datetime label for each component