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.

284 lines
8.0KB

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