You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
7.6KB

  1. @interface PUCollectionView : UICollectionView
  2. @property(assign,nonatomic) id delegate;
  3. @property(assign,nonatomic) NSArray* visibleCells;
  4. @property(assign,nonatomic) NSArray* indexPathsForVisibleItems;
  5. -(id) idexPathForItemAtPoint:(id) arg1;
  6. -(id) cellForItemAtIndexPath:(id) arg1;
  7. -(id) indexPathForCell:(id) arg1;
  8. -(void) _updateVisibleCellsNow:(BOOL) arg1;
  9. @end
  10. @interface PUPhotosGridViewController
  11. @property(assign,nonatomic)id assetCollection;
  12. @property(assign,nonatomic)id assetCollectionAssets;
  13. @property(assign, nonatomic)id dataSource;
  14. @property(assign, nonatomic) id collectionView;
  15. @property(assign, nonatomic) UINavigationItem *navigationItem;
  16. -(void) handleToggleSelectionOfItemAtIndexPath:(NSIndexPath*) arg1;
  17. -(void) setSelected:(BOOL) arg1 itemsAtIndexes:(id) arg2 inSection:(long long) arg3 animated:(BOOL) arg4;
  18. -(BOOL) isEditing;
  19. -(NSInteger) collectionView:(id) arg1 numberOfItemsInSection:(NSInteger) arg2;
  20. //custom elememnts
  21. @property(assign,nonatomic) BOOL ctrlEnabled;
  22. @property(assign,nonatomic) NSIndexPath* ctrlFirstIndexPath;
  23. @property(assign,nonatomic) UIBarButtonItem* ctrlButton;
  24. @property(assign,nonatomic) UITapGestureRecognizer* ctrlTapRecognizer;
  25. @property(assign,nonatomic) UIImageView* ctrlSelectOverlayView;
  26. -(void)updateCtrlButton;
  27. @end
  28. @interface PUPhotosGridCell : UIView
  29. @property(assign, nonatomic) id photoContentView;
  30. -(void) prepareForReuse;
  31. //custom elements
  32. @property(retain, nonatomic) UIImageView *ctrlSelectOverlayView;
  33. -(void) removeSelectOverlayViewImage;
  34. @end
  35. %group Tweak
  36. %hook PUPhotosGridViewController
  37. %property(assign,nonatomic) BOOL ctrlEnabled;
  38. %property(assign,nonatomic) NSIndexPath* ctrlFirstIndexPath;
  39. %property(assign, nonatomic) UIBarButtonItem* ctrlButton;
  40. %property(assign, nonatomic) UITapGestureRecognizer* ctrlTapRecognizer;
  41. %property(assign,nonatomic) UIImageView* ctrlSelectOverlayView;
  42. %new
  43. -(void) updateCtrlButton{
  44. if ([self ctrlEnabled]){
  45. [[self ctrlButton] setTintColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.5]];
  46. [self ctrlTapRecognizer].cancelsTouchesInView = YES;
  47. } else {
  48. [[self ctrlButton] setTintColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0]];
  49. [self ctrlTapRecognizer].cancelsTouchesInView = NO;
  50. }
  51. }
  52. %new
  53. -(void) ctrlButtonPressed{
  54. if (![self ctrlEnabled]){
  55. [self setCtrlEnabled:YES];
  56. } else {
  57. [self setCtrlEnabled:NO];
  58. }
  59. [self updateCtrlButton];
  60. [self setCtrlFirstIndexPath:nil];
  61. }
  62. -(void) updateNavigationBarAnimated:(BOOL) arg1{
  63. %orig;
  64. UINavigationItem* navItem = [self navigationItem];
  65. if ([self isEditing]){
  66. UIBarButtonItem* ctrlButton = [self ctrlButton];
  67. [navItem setLeftBarButtonItem:ctrlButton];
  68. } else {
  69. [navItem setLeftBarButtonItem:nil];
  70. [self setCtrlEnabled:NO];
  71. }
  72. [self updateCtrlButton];
  73. }
  74. -(void) viewDidLoad{
  75. %orig;
  76. [self setCtrlEnabled:NO];
  77. [self setCtrlFirstIndexPath:nil];
  78. id collectionView = [self collectionView];
  79. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:collectionView action:@selector(ctrlScreenTapRecognized:)];
  80. tap.numberOfTapsRequired = 1;
  81. tap.cancelsTouchesInView = NO;
  82. [collectionView addGestureRecognizer:tap];
  83. [self setCtrlTapRecognizer:tap];
  84. [tap release];
  85. UIBarButtonItem* ctrlButton = [[UIBarButtonItem alloc] initWithTitle:@"Ctrl" style:UIBarButtonItemStylePlain target:self action:@selector(ctrlButtonPressed)];
  86. [self setCtrlButton:ctrlButton];
  87. }
  88. %end
  89. %hook PUCollectionView
  90. %new
  91. -(void)ctrlScreenTapRecognized:(id) sender {
  92. id gvController = [self delegate];
  93. if ([gvController ctrlEnabled]){
  94. CGPoint tapPoint = [sender locationInView:self];
  95. NSIndexPath *nextIndexPath = [self indexPathForItemAtPoint:tapPoint];
  96. if (![gvController ctrlFirstIndexPath]){
  97. [gvController setCtrlFirstIndexPath:nextIndexPath];
  98. PUPhotosGridCell* firstSelectedCell = [self cellForItemAtIndexPath:nextIndexPath];
  99. firstSelectedCell.ctrlSelectOverlayView = [[UIImageView alloc] init];
  100. firstSelectedCell.ctrlSelectOverlayView.frame = CGRectMake(0,0,31,31);
  101. firstSelectedCell.ctrlSelectOverlayView.image = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/PhotoCtrl/check.png"];
  102. [firstSelectedCell addSubview:firstSelectedCell.ctrlSelectOverlayView];
  103. } else {
  104. //PUPhotosGridCell* firstSelectedCell = [self cellForItemAtIndexPath:[gvController ctrlFirstIndexPath]];
  105. //[firstSelectedCell.ctrlSelectOverlayView removeFromSuperview];
  106. //firstSelectedCell.ctrlSelectOverlayView = nil;
  107. NSRange indexRange;
  108. NSInteger firstRow = [gvController ctrlFirstIndexPath].row;
  109. NSInteger firstSection = [gvController ctrlFirstIndexPath].section;
  110. NSInteger nextRow = nextIndexPath.row;
  111. NSInteger nextSection = nextIndexPath.section;
  112. NSInteger lowRow = 0;
  113. NSInteger highRow = 0;
  114. NSInteger lowSection = 0;
  115. NSInteger highSection = 0;
  116. NSInteger sectionItemCount = 0;
  117. if (firstRow == nextRow && nextSection == firstSection){
  118. [gvController setCtrlFirstIndexPath:nil];
  119. } else {
  120. if (nextSection == firstSection){
  121. if (firstRow < nextRow){
  122. indexRange = NSMakeRange(firstRow, nextRow - firstRow + 1);
  123. } else {
  124. indexRange = NSMakeRange(nextRow, firstRow - nextRow + 1);
  125. }
  126. [gvController setSelected:YES itemsAtIndexes:[%c(NSIndexSet) indexSetWithIndexesInRange:indexRange] inSection:(long long)firstSection animated:NO];
  127. } else {
  128. if (nextSection > firstSection){
  129. lowRow = firstRow;
  130. lowSection = firstSection;
  131. highRow = nextRow;
  132. highSection = nextSection;
  133. } else if (nextSection < firstSection){
  134. lowRow = nextRow;
  135. lowSection = nextSection;
  136. highRow = firstRow;
  137. highSection = firstSection;
  138. }
  139. for (NSInteger i = lowSection; i <= highSection; i++){
  140. sectionItemCount = [gvController collectionView:self numberOfItemsInSection:i];
  141. if (i == lowSection){
  142. indexRange = NSMakeRange(lowRow, sectionItemCount - lowRow);
  143. } else if (i == highSection){
  144. indexRange = NSMakeRange(0, highRow+1);
  145. } else {
  146. indexRange = NSMakeRange(0, sectionItemCount);
  147. }
  148. [gvController setSelected:YES itemsAtIndexes:[%c(NSIndexSet) indexSetWithIndexesInRange:indexRange] inSection:(long long)i animated:NO];
  149. }
  150. }
  151. [gvController handleToggleSelectionOfItemAtIndexPath:nextIndexPath];
  152. [gvController setCtrlEnabled:NO];
  153. }
  154. }
  155. }
  156. [gvController updateCtrlButton];
  157. }
  158. -(id) dequeueReusableCellWithReuseIdentifier: (id) arg1 forIndexPath:(id) arg2{
  159. id orig = %orig;
  160. id gvController = [self delegate];
  161. if ([orig ctrlSelectOverlayView]){
  162. [orig ctrlSelectOverlayView].image = nil;
  163. if ([gvController ctrlEnabled] && [gvController ctrlFirstIndexPath]){
  164. NSIndexPath* firstIndexPath = [gvController ctrlFirstIndexPath];
  165. NSIndexPath* thisIndexPath = arg2;
  166. HBLogDebug(@"firstIndexPath: %ld-%ld thisIndexPath: %ld-%ld", (long)firstIndexPath.section, (long)firstIndexPath.row, (long)thisIndexPath.section, (long)thisIndexPath.row);
  167. if ( firstIndexPath.section == thisIndexPath.section && firstIndexPath.row == thisIndexPath.row){
  168. [orig ctrlSelectOverlayView].image = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/PhotoCtrl/check.png"];
  169. }
  170. }
  171. }
  172. return orig;
  173. }
  174. %end
  175. %hook PUPhotosGridCell
  176. %property(retain,nonatomic) UIImageView* ctrlSelectOverlayView;
  177. %end
  178. %end
  179. %ctor{
  180. @autoreleasepool{
  181. %init(Tweak);
  182. }
  183. }