1
0
mirror of https://github.com/lint/PhotoCtrl synced 2025-07-01 02:26:47 +00:00

Fix new album crash

This commit is contained in:
lint
2019-09-20 19:09:46 -04:00
parent 4cbf301cff
commit 4298d22e15
2 changed files with 106 additions and 98 deletions

202
Tweak.xm
View File

@ -3,6 +3,8 @@
@property(assign,nonatomic) id delegate; @property(assign,nonatomic) id delegate;
@property(assign,nonatomic) NSArray* visibleCells; @property(assign,nonatomic) NSArray* visibleCells;
@property(assign,nonatomic) NSArray* indexPathsForVisibleItems; @property(assign,nonatomic) NSArray* indexPathsForVisibleItems;
@property(assign,nonatomic) id reorderDelegate;
@property(assign,nonatomic) id selectionDelegate;
-(id) idexPathForItemAtPoint:(id) arg1; -(id) idexPathForItemAtPoint:(id) arg1;
-(id) cellForItemAtIndexPath:(id) arg1; -(id) cellForItemAtIndexPath:(id) arg1;
-(id) indexPathForCell:(id) arg1; -(id) indexPathForCell:(id) arg1;
@ -126,129 +128,135 @@
%new %new
-(void)ctrlScreenTapRecognized:(id) sender { -(void)ctrlScreenTapRecognized:(id) sender {
if ([self selectionDelegate] && ![self reorderDelegate]) {
id gvController = [self delegate]; id gvController = [self delegate];
if ([gvController ctrlEnabled]){ if ([gvController ctrlEnabled]){
CGPoint tapPoint = [sender locationInView:self]; CGPoint tapPoint = [sender locationInView:self];
NSIndexPath *nextIndexPath = [self indexPathForItemAtPoint:tapPoint]; NSIndexPath *nextIndexPath = [self indexPathForItemAtPoint:tapPoint];
if (![gvController ctrlFirstIndexPath]){ if (![gvController ctrlFirstIndexPath]){
[gvController setCtrlFirstIndexPath:nextIndexPath]; [gvController setCtrlFirstIndexPath:nextIndexPath];
PUPhotosGridCell* firstSelectedCell = [self cellForItemAtIndexPath:nextIndexPath];
firstSelectedCell.ctrlSelectOverlayView = [[UIImageView alloc] init];
firstSelectedCell.ctrlSelectOverlayView.frame = CGRectMake(0,0,31,31);
firstSelectedCell.ctrlSelectOverlayView.image = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/PhotoCtrl/check.png"];
[firstSelectedCell addSubview:firstSelectedCell.ctrlSelectOverlayView];
} else {
//PUPhotosGridCell* firstSelectedCell = [self cellForItemAtIndexPath:[gvController ctrlFirstIndexPath]];
//[firstSelectedCell.ctrlSelectOverlayView removeFromSuperview];
//firstSelectedCell.ctrlSelectOverlayView = nil;
NSRange indexRange;
NSInteger firstRow = [gvController ctrlFirstIndexPath].row;
NSInteger firstSection = [gvController ctrlFirstIndexPath].section;
NSInteger nextRow = nextIndexPath.row;
NSInteger nextSection = nextIndexPath.section;
NSInteger lowRow = 0;
NSInteger highRow = 0;
NSInteger lowSection = 0;
NSInteger highSection = 0;
NSInteger sectionItemCount = 0;
if (firstRow == nextRow && nextSection == firstSection){
[gvController setCtrlFirstIndexPath:nil];
PUPhotosGridCell* firstSelectedCell = [self cellForItemAtIndexPath:nextIndexPath];
firstSelectedCell.ctrlSelectOverlayView = [[UIImageView alloc] init];
firstSelectedCell.ctrlSelectOverlayView.frame = CGRectMake(0,0,31,31);
firstSelectedCell.ctrlSelectOverlayView.image = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/PhotoCtrl/check.png"];
[firstSelectedCell addSubview:firstSelectedCell.ctrlSelectOverlayView];
} else { } else {
if (nextSection == firstSection){ //PUPhotosGridCell* firstSelectedCell = [self cellForItemAtIndexPath:[gvController ctrlFirstIndexPath]];
if (firstRow < nextRow){ //[firstSelectedCell.ctrlSelectOverlayView removeFromSuperview];
indexRange = NSMakeRange(firstRow, nextRow - firstRow + 1); //firstSelectedCell.ctrlSelectOverlayView = nil;
} else {
indexRange = NSMakeRange(nextRow, firstRow - nextRow + 1); NSRange indexRange;
} NSInteger firstRow = [gvController ctrlFirstIndexPath].row;
NSInteger firstSection = [gvController ctrlFirstIndexPath].section;
[gvController setSelected:YES itemsAtIndexes:[%c(NSIndexSet) indexSetWithIndexesInRange:indexRange] inSection:(long long)firstSection animated:NO]; NSInteger nextRow = nextIndexPath.row;
NSInteger nextSection = nextIndexPath.section;
NSInteger lowRow = 0;
NSInteger highRow = 0;
NSInteger lowSection = 0;
NSInteger highSection = 0;
NSInteger sectionItemCount = 0;
if (firstRow == nextRow && nextSection == firstSection){
[gvController setCtrlFirstIndexPath:nil];
} else { } else {
if (nextSection > firstSection){ if (nextSection == firstSection){
lowRow = firstRow; if (firstRow < nextRow){
lowSection = firstSection; indexRange = NSMakeRange(firstRow, nextRow - firstRow + 1);
highRow = nextRow;
highSection = nextSection;
} else if (nextSection < firstSection){
lowRow = nextRow;
lowSection = nextSection;
highRow = firstRow;
highSection = firstSection;
}
for (NSInteger i = lowSection; i <= highSection; i++){
sectionItemCount = [gvController collectionView:self numberOfItemsInSection:i];
if (i == lowSection){
indexRange = NSMakeRange(lowRow, sectionItemCount - lowRow);
} else if (i == highSection){
indexRange = NSMakeRange(0, highRow+1);
} else { } else {
indexRange = NSMakeRange(0, sectionItemCount); indexRange = NSMakeRange(nextRow, firstRow - nextRow + 1);
} }
[gvController setSelected:YES itemsAtIndexes:[%c(NSIndexSet) indexSetWithIndexesInRange:indexRange] inSection:(long long)i animated:NO]; [gvController setSelected:YES itemsAtIndexes:[%c(NSIndexSet) indexSetWithIndexesInRange:indexRange] inSection:(long long)firstSection animated:NO];
}
}
[gvController handleToggleSelectionOfItemAtIndexPath:nextIndexPath]; } else {
[gvController setCtrlEnabled:NO]; if (nextSection > firstSection){
lowRow = firstRow;
lowSection = firstSection;
highRow = nextRow;
highSection = nextSection;
} else if (nextSection < firstSection){
lowRow = nextRow;
lowSection = nextSection;
highRow = firstRow;
highSection = firstSection;
}
for (NSInteger i = lowSection; i <= highSection; i++){
sectionItemCount = [gvController collectionView:self numberOfItemsInSection:i];
if (i == lowSection){
indexRange = NSMakeRange(lowRow, sectionItemCount - lowRow);
} else if (i == highSection){
indexRange = NSMakeRange(0, highRow+1);
} else {
indexRange = NSMakeRange(0, sectionItemCount);
}
[gvController setSelected:YES itemsAtIndexes:[%c(NSIndexSet) indexSetWithIndexesInRange:indexRange] inSection:(long long)i animated:NO];
}
}
[gvController handleToggleSelectionOfItemAtIndexPath:nextIndexPath];
[gvController setCtrlEnabled:NO];
}
} }
} }
[gvController updateCtrlButton];
} }
[gvController updateCtrlButton];
} }
-(id) dequeueReusableCellWithReuseIdentifier: (id) arg1 forIndexPath:(id) arg2{ -(id) dequeueReusableCellWithReuseIdentifier: (id) arg1 forIndexPath:(id) arg2{
id orig = %orig; id orig = %orig;
id gvController = [self delegate]; if ([self selectionDelegate] && ![self reorderDelegate] && [orig isKindOfClass:[%c(PUPhotosGridCell) class]]) {
if ([orig ctrlSelectOverlayView]){ id gvController = [self delegate];
[orig ctrlSelectOverlayView].image = nil; if ([orig ctrlSelectOverlayView]){
if ([gvController ctrlEnabled] && [gvController ctrlFirstIndexPath]){
NSIndexPath* firstIndexPath = [gvController ctrlFirstIndexPath]; [orig ctrlSelectOverlayView].image = nil;
NSIndexPath* thisIndexPath = arg2;
if ([gvController ctrlEnabled] && [gvController ctrlFirstIndexPath]){
NSIndexPath* firstIndexPath = [gvController ctrlFirstIndexPath];
NSIndexPath* thisIndexPath = arg2;
HBLogDebug(@"firstIndexPath: %ld-%ld thisIndexPath: %ld-%ld", (long)firstIndexPath.section, (long)firstIndexPath.row, (long)thisIndexPath.section, (long)thisIndexPath.row); HBLogDebug(@"firstIndexPath: %ld-%ld thisIndexPath: %ld-%ld", (long)firstIndexPath.section, (long)firstIndexPath.row, (long)thisIndexPath.section, (long)thisIndexPath.row);
if ( firstIndexPath.section == thisIndexPath.section && firstIndexPath.row == thisIndexPath.row){ if ( firstIndexPath.section == thisIndexPath.section && firstIndexPath.row == thisIndexPath.row){
[orig ctrlSelectOverlayView].image = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/PhotoCtrl/check.png"]; [orig ctrlSelectOverlayView].image = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/PhotoCtrl/check.png"];
} }
}
} }
} }

View File

@ -1,7 +1,7 @@
Package: com.lint.photoctrl Package: com.lint.photoctrl
Name: PhotoCtrl Name: PhotoCtrl
Depends: mobilesubstrate Depends: mobilesubstrate
Version: 1.0.0 Version: 1.0.1
Architecture: iphoneos-arm Architecture: iphoneos-arm
Description: Adds a "ctrl + shift" like function for selecting photos. Description: Adds a "ctrl + shift" like function for selecting photos.
Maintainer: lint <apieceoflint@protonmail.com> Maintainer: lint <apieceoflint@protonmail.com>