Browse Source

playlist table: improve reliability for folder reordering

Felix Paul Kühne 11 years ago
parent
commit
c271db9bc9
2 changed files with 36 additions and 29 deletions
  1. 36 0
      Sources/VLCPlaylistTableViewCell.m
  2. 0 29
      Sources/VLCPlaylistViewController.m

+ 36 - 0
Sources/VLCPlaylistTableViewCell.m

@@ -17,6 +17,13 @@
 #import "VLCThumbnailsCache.h"
 #import <MediaLibraryKit/MLAlbum.h>
 
+@interface VLCPlaylistTableViewCell ()
+{
+    UILongPressGestureRecognizer *_longPress;
+}
+
+@end
+
 @implementation VLCPlaylistTableViewCell
 
 + (VLCPlaylistTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
@@ -94,6 +101,15 @@
 {
     [super setEditing:editing animated:animated];
     [self _updatedDisplayedInformationForKeyPath:@"editing"];
+
+    if (editing) {
+        if (_longPress)
+            [self removeGestureRecognizer:_longPress];
+    } else {
+        if (!_longPress)
+            _longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTouchGestureAction:)];
+        [self addGestureRecognizer:_longPress];
+    }
 }
 
 - (void)_updatedDisplayedInformationForKeyPath:(NSString *)keyPath
@@ -278,4 +294,24 @@
     }
 }
 
+- (void)longTouchGestureAction:(UIGestureRecognizer *)recognizer
+{
+    CGRect frame = self.frame;
+    if (frame.size.height > 90.)
+        frame.size.height = 90.;
+    else if (recognizer.state == UIGestureRecognizerStateBegan)
+        frame.size.height = 180;
+
+    void (^animationBlock)() = ^() {
+        self.frame = frame;
+    };
+
+    void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
+        self.frame = frame;
+    };
+
+    NSTimeInterval animationDuration = .2;
+    [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
+}
+
 @end

+ 0 - 29
Sources/VLCPlaylistViewController.m

@@ -81,11 +81,6 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
         _tableView.dataSource = self;
         _tableView.opaque = YES;
         self.view = _tableView;
-
-        if (SYSTEM_RUNS_IOS7_OR_LATER) {
-            UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tableViewLongTouchGestureAction:)];
-            [self.view addGestureRecognizer:gestureRecognizer];
-        }
     } else {
         _folderLayout = [[VLCFolderCollectionViewFlowLayout alloc] init];
         _collectionView = [[UICollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:_folderLayout];
@@ -540,30 +535,6 @@ static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutoria
 }
 
 #pragma mark - table view gestures
-- (void)tableViewLongTouchGestureAction:(UIGestureRecognizer *)recognizer
-{
-    NSIndexPath *path = [(UITableView *)self.view indexPathForRowAtPoint:[recognizer locationInView:self.view]];
-    UITableViewCell *cell = [(UITableView *)self.view cellForRowAtIndexPath:path];
-
-    CGRect frame = cell.frame;
-    if (frame.size.height > 90.)
-        frame.size.height = 90.;
-    else if (recognizer.state == UIGestureRecognizerStateBegan)
-        frame.size.height = 180;
-
-    void (^animationBlock)() = ^() {
-        cell.frame = frame;
-    };
-
-    void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
-        cell.frame = frame;
-        [self.tableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionNone animated:YES];
-    };
-
-    NSTimeInterval animationDuration = .2;
-    [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
- }
-
 - (void)swipeRightGestureAction:(UIGestureRecognizer *)recognizer
 {
     if ([[self.editButtonItem title] isEqualToString:NSLocalizedString(@"BUTTON_CANCEL",@"")])