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

BIN
.DS_Store vendored Normal file

Binary file not shown.

View file

@ -124,9 +124,6 @@
<constraint firstItem="pg4-aQ-7qW" firstAttribute="top" secondItem="yUK-od-5YZ" secondAttribute="top" id="mEw-ej-VSR"/>
<constraint firstAttribute="trailing" secondItem="HFo-GV-TO9" secondAttribute="trailing" id="rF7-vW-wgF"/>
</constraints>
<connections>
<outletCollection property="gestureRecognizers" destination="TmC-iG-UPj" appends="YES" id="MmM-Jr-ywe"/>
</connections>
</view>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
@ -231,9 +228,6 @@
<constraint firstAttribute="centerX" secondItem="L87-yV-XGk" secondAttribute="centerX" id="vMM-Hu-UkI"/>
<constraint firstAttribute="centerX" secondItem="lTG-14-OWN" secondAttribute="centerX" id="weT-lI-eKE"/>
</constraints>
<connections>
<outletCollection property="gestureRecognizers" destination="bv4-jS-RnJ" appends="YES" id="ZPg-Ay-HeL"/>
</connections>
</view>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="default-profile.png" translatesAutoresizingMaskIntoConstraints="NO" id="mks-jh-AiZ" customClass="CustomImageView">
<rect key="frame" x="552" y="5" width="40" height="40"/>
@ -519,16 +513,6 @@
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="94y-cU-qQD" userLabel="First Responder" sceneMemberID="firstResponder"/>
<pongPressGestureRecognizer allowableMovement="10" minimumPressDuration="0.5" id="TmC-iG-UPj">
<connections>
<action selector="onProgressLongTap:" destination="msb-ol-2LB" id="no2-Q3-7ya"/>
</connections>
</pongPressGestureRecognizer>
<pongPressGestureRecognizer allowableMovement="10" minimumPressDuration="0.5" id="bv4-jS-RnJ">
<connections>
<action selector="onProgressLongTap:" destination="msb-ol-2LB" id="8ks-us-qqh"/>
</connections>
</pongPressGestureRecognizer>
</objects>
<point key="canvasLocation" x="1595" y="75"/>
</scene>

BIN
matrixConsole/View/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -27,7 +27,6 @@
}
- (void)updateProgressUI:(NSDictionary*)downloadStatsDict {
self.progressView.hidden = NO;
NSString* downloadRate = [downloadStatsDict valueForKey:kMediaLoaderProgressDownloadRateKey];
@ -40,14 +39,12 @@
[text appendString:progressString];
}
if (remaingTime) {
[text appendFormat:@" (%@)", remaingTime];
if (downloadRate) {
[text appendFormat:@"\n%@", downloadRate];
}
[text appendString:@"\n "];
if (downloadRate) {
[text appendFormat:@"%@", downloadRate];
if (remaingTime) {
[text appendFormat:@"\n%@", remaingTime];
}
self.statsLabel.text = text;
@ -171,6 +168,7 @@
}
}
-(void)stopAnimating {
[[NSNotificationCenter defaultCenter] removeObserver:self name:kMediaUploadProgressNotification object:nil];
[self.activityIndicator stopAnimating];
@ -182,7 +180,7 @@
NSString* url = notif.object;
if ([url isEqualToString:self.message.thumbnailURL] || [url isEqualToString:self.message.attachmentURL]) {
self.activityIndicator.hidden = YES;
[self updateProgressUI:notif.userInfo];
// the upload is ended

View file

@ -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