Skip to content

Commit

Permalink
Allows to preview searched images and then edit, delete, copy and sha…
Browse files Browse the repository at this point in the history
…re it.
  • Loading branch information
EddyLB committed Jun 23, 2019
1 parent 3dd8ed9 commit 397520d
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 58 deletions.
5 changes: 5 additions & 0 deletions piwigo/Albums/Album Thumbnail/AllCategoriesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,11 @@ -(void)buildCategoryArray
// Look for categories which are not already displayed
for(PiwigoAlbumData *category in allCategories)
{
// Search album should not be proposed
if (category.albumId == kPiwigoSearchCategoryId) {
continue;
}

// Non-admin Community users can only upload in specific albums
if (![Model sharedInstance].hasAdminRights && !category.hasUploadRights) {
continue;
Expand Down
64 changes: 28 additions & 36 deletions piwigo/Albums/AlbumImagesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,35 +195,33 @@ -(void)viewDidLoad
{
[super viewDidLoad];

// Initialise search controller
SearchImagesViewController *resultsCollectionController = [[SearchImagesViewController alloc] init];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:resultsCollectionController];
self.searchController.delegate = self;
self.searchController.hidesNavigationBarDuringPresentation = YES;
self.searchController.searchResultsUpdater = self;

[self.searchController.searchBar setTintColor:[UIColor piwigoOrange]];
self.searchController.searchBar.showsCancelButton = NO;
self.searchController.searchBar.showsSearchResultsButton = NO;
// self.searchController.searchBar.placeholder = NSLocalizedString(@"searchBarServer_placeholder", @"Search on Piwigo server");
self.searchController.searchBar.delegate = self;
self.definesPresentationContext = YES;

for (UIView *subView in self.searchController.searchBar.subviews)
{
if ([subView isKindOfClass: [UITextField class]])
{
[(UITextField *)subView setKeyboardAppearance:[Model sharedInstance].isDarkPaletteActive ? UIKeyboardAppearanceDark : UIKeyboardAppearanceDefault];
}
}

// For iOS 11 and later: place search bar in navigation bar or root album
if (@available(iOS 11.0, *)) {
// For iOS 11 and later, place the search bar in the navigation bar.
self.navigationItem.searchController = self.searchController;
}
else {
// For iOS 10 and earlier, place the search controller's search bar in the navigation bar titleview.
// self.navigationItem.titleView = self.searchController.searchBar;
// Initialise search controller when displaying root album
if (self.categoryId == 0) {
SearchImagesViewController *resultsCollectionController = [[SearchImagesViewController alloc] init];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:resultsCollectionController];
self.searchController.delegate = self;
self.searchController.hidesNavigationBarDuringPresentation = YES;
self.searchController.searchResultsUpdater = self;

[self.searchController.searchBar setTintColor:[UIColor piwigoOrange]];
self.searchController.searchBar.showsCancelButton = NO;
self.searchController.searchBar.showsSearchResultsButton = NO;
self.searchController.searchBar.delegate = self;
self.definesPresentationContext = YES;

// Place the search bar in the navigation bar.
self.navigationItem.searchController = self.searchController;

// for (UIView *subView in self.searchController.searchBar.subviews)
// {
// if ([subView isKindOfClass: [UITextField class]])
// {
// [(UITextField *)subView setKeyboardAppearance:[Model sharedInstance].isDarkPaletteActive ? UIKeyboardAppearanceDark : UIKeyboardAppearanceDefault];
// }
// }
}
}
}

Expand Down Expand Up @@ -1760,7 +1758,7 @@ -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSec
switch (section) {
case 0: // Albums
numberOfItems = [[CategoriesData sharedInstance] getCategoriesForParentCategory:self.categoryId].count;
numberOfItems -= [self isSearchCategoryInCache]; // Don't display Search album
numberOfItems -= [[CategoriesData sharedInstance] isSearchCategoryInCache]; // Don't display Search album
break;

default: // Images
Expand Down Expand Up @@ -1850,7 +1848,7 @@ -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellFo
case 0: // Albums (see XIB file)
{
// Bypass Search category if exists
if ([self isSearchCategoryInCache]) {
if ([[CategoriesData sharedInstance] isSearchCategoryInCache]) {
indexPath = [NSIndexPath indexPathForItem:(indexPath.item + 1)
inSection:indexPath.section];
}
Expand Down Expand Up @@ -2224,12 +2222,6 @@ -(void)updateSearchResultsForSearchController:(UISearchController *)searchContro
}
}

-(BOOL)isSearchCategoryInCache
{
PiwigoAlbumData *searchAlbum = [[CategoriesData sharedInstance] getCategoryById:kPiwigoSearchCategoryId];
return (searchAlbum != nil);
}


#pragma mark - UISearchBarDelegate

Expand Down
15 changes: 13 additions & 2 deletions piwigo/Albums/Images/Image Detail/ImageDetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,10 @@ -(void)deleteImage
// Add actions
[alert addAction:cancelAction];
[alert addAction:deleteAction];
if ([self.imageData.categoryIds count] > 1) {
// This image is used in another album!
if (([self.imageData.categoryIds count] > 1) &&
(self.categoryId != kPiwigoSearchCategoryId)) {
// This image is used in another album
// Proposes to remove it from the current album, unless it was selected from a Search
[alert addAction:removeAction];
}

Expand Down Expand Up @@ -817,6 +819,15 @@ -(void)setAsAlbumImage

-(void)addImageToCategory
{
// If image selected from Search, immediatley propose to copy it
if (self.categoryId == kPiwigoSearchCategoryId) {
MoveImageViewController *moveImageVC = [[MoveImageViewController alloc] initWithSelectedImageIds:nil orSingleImageData:self.imageData inCategoryId:self.categoryId atIndex:[self indexOfSelectedImage] andCopyOption:YES];
moveImageVC.moveImageDelegate = self;
[self pushView:moveImageVC];
return;
}

// Image selected from album collection
UIAlertController* alert = [UIAlertController
alertControllerWithTitle:nil message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
Expand Down
5 changes: 5 additions & 0 deletions piwigo/Albums/Images/Image Move/MoveImageViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,11 @@ -(void)buildCategoryArray
// Look for categories which are not already displayed
for(PiwigoAlbumData *category in allCategories)
{
// Search album should not be proposed
if (category.albumId == kPiwigoSearchCategoryId) {
continue;
}

// Non-admin Community users can only upload in specific albums
if (![Model sharedInstance].hasAdminRights && !category.hasUploadRights) {
continue;
Expand Down
61 changes: 58 additions & 3 deletions piwigo/Albums/SearchImagesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
#import "CategoryCollectionViewCell.h"
#import "CategoryHeaderReusableView.h"
#import "ImageCollectionViewCell.h"
#import "ImageDetailViewController.h"
#import "ImagesCollection.h"
#import "Model.h"
#import "NoImagesHeaderCollectionReusableView.h"
#import "SearchImagesViewController.h"

@interface SearchImagesViewController () <UICollectionViewDelegate, UICollectionViewDataSource>
@interface SearchImagesViewController () <UICollectionViewDelegate, UICollectionViewDataSource, ImageDetailDelegate>

@property (nonatomic, strong) AlbumData *albumData;
@property (nonatomic, strong) NSIndexPath *imageOfInterest;
Expand All @@ -35,6 +36,7 @@ @interface SearchImagesViewController () <UICollectionViewDelegate, UICollection
//@property (nonatomic, strong) NSMutableArray *touchedImageIds;

@property (nonatomic, assign) kPiwigoSortCategory currentSortCategory;
@property (nonatomic, strong) ImageDetailViewController *imageDetailView;

@end

Expand Down Expand Up @@ -148,8 +150,8 @@ -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
// Returns number of images
NSLog(@"items: %ld", [[CategoriesData sharedInstance] getCategoryById:kPiwigoSearchCategoryId].imageList.count);
NSLog(@"items: %ld", self.albumData.images.count);
// NSLog(@"items: %ld", [[CategoriesData sharedInstance] getCategoryById:kPiwigoSearchCategoryId].imageList.count);
// NSLog(@"items: %ld", self.albumData.images.count);
return [[CategoriesData sharedInstance] getCategoryById:kPiwigoSearchCategoryId].imageList.count;
}

Expand Down Expand Up @@ -224,5 +226,58 @@ -(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellFo
}


#pragma mark - UICollectionViewDelegate Methods

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
// Avoid rare crashes…
if ((indexPath.row < 0) || (indexPath.row >= [self.albumData.images count])) {
// forget this call!
return;
}

// Display full screen image
if (@available(iOS 11.0, *)) {
self.imageDetailView = [[ImageDetailViewController alloc] initWithCategoryId:kPiwigoSearchCategoryId atImageIndex:indexPath.row withArray:[self.albumData.images copy]];
self.imageDetailView.hidesBottomBarWhenPushed = YES;
self.imageDetailView.imgDetailDelegate = self;
[self.presentingViewController.navigationController pushViewController:self.imageDetailView animated:YES];
}
}


#pragma mark - ImageDetailDelegate Methods

-(void)didFinishPreviewOfImageWithId:(NSInteger)imageId
{
NSInteger index = 0;
for (PiwigoImageData *image in self.albumData.images) {
if ([image.imageId integerValue] == imageId) break;
index++;
}
if (index < [self.albumData.images count])
self.imageOfInterest = [NSIndexPath indexPathForItem:index inSection:1];
}

-(void)didDeleteImage:(PiwigoImageData *)image atIndex:(NSInteger)index
{
[self.albumData removeImage:image];
index = MAX(0, index-1); // index must be > 0
index = MIN(index, [self.albumData.images count] - 1); // index must be < nber images
self.imageOfInterest = [NSIndexPath indexPathForItem:index inSection:0];
[self.imagesCollection reloadData];
}

-(void)needToLoadMoreImages
{
[self.albumData loadMoreImagesOnCompletion:^{
if(self.imageDetailView != nil)
{
self.imageDetailView.images = [self.albumData.images mutableCopy];
}
[self.imagesCollection reloadData];
}];
}


@end
12 changes: 7 additions & 5 deletions piwigo/Data Cache/Categories Data/CategoriesData.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ FOUNDATION_EXPORT NSString * const kPiwigoNotificationChangedCurrentCategory;
@property (nonatomic, readonly) NSArray *allCategories;
@property (nonatomic, readonly) NSArray *communityCategoriesForUploadOnly;

-(void)clearCache;
-(void)deleteCategory:(NSInteger)categoryId;
-(void)replaceAllCategories:(NSArray*)categories;
-(void)updateCategories:(NSArray*)categories;
-(void)addCommunityCategoryWithUploadRights:(PiwigoAlbumData *)category;

-(PiwigoAlbumData*)getCategoryById:(NSInteger)categoryId;
-(NSArray*)getCategoriesForParentCategory:(NSInteger)parentCategory;

-(PiwigoImageData*)getImageForCategory:(NSInteger)category andIndex:(NSInteger)index;
-(PiwigoImageData*)getImageForCategory:(NSInteger)category andId:(NSString*)imageId;
-(void)removeImage:(PiwigoImageData*)image;

-(NSArray*)getCategoriesForParentCategory:(NSInteger)parentCategory;

-(void)addCommunityCategoryWithUploadRights:(PiwigoAlbumData *)category;
-(void)deleteCategory:(NSInteger)categoryId;
-(void)clearCache;
-(BOOL)isSearchCategoryInCache;

@end
42 changes: 30 additions & 12 deletions piwigo/Data Cache/Categories Data/CategoriesData.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ +(CategoriesData*)sharedInstance
return instance;
}


# pragma mark - Update cache

-(void)clearCache
{
self.allCategories = [NSArray new];
Expand Down Expand Up @@ -217,6 +220,9 @@ -(void)addCommunityCategoryWithUploadRights:(PiwigoAlbumData *)category;
[[NSNotificationCenter defaultCenter] postNotificationName:kPiwigoNotificationCategoryDataUpdated object:nil];
}


# pragma mark - Get categories from cache

-(PiwigoAlbumData*)getCategoryById:(NSInteger)categoryId
{
for(PiwigoAlbumData *existingCategory in self.allCategories)
Expand All @@ -230,6 +236,24 @@ -(PiwigoAlbumData*)getCategoryById:(NSInteger)categoryId
return nil;
}

-(NSArray*)getCategoriesForParentCategory:(NSInteger)parentCategory
{
NSMutableArray *categories = [NSMutableArray new];

for(PiwigoAlbumData *category in self.allCategories)
{
if(category.parentAlbumId == parentCategory)
{
[categories addObject:category];
}
}

return categories;
}


# pragma mark - Get and remove images from cache

-(PiwigoImageData*)getImageForCategory:(NSInteger)category andIndex:(NSInteger)index
{
PiwigoAlbumData *selectedCategory = [self getCategoryById:category];
Expand Down Expand Up @@ -267,19 +291,13 @@ -(void)removeImage:(PiwigoImageData*)image
}
}

-(NSArray*)getCategoriesForParentCategory:(NSInteger)parentCategory

# pragma mark - Cached Search category

-(BOOL)isSearchCategoryInCache
{
NSMutableArray *categories = [NSMutableArray new];

for(PiwigoAlbumData *category in self.allCategories)
{
if(category.parentAlbumId == parentCategory)
{
[categories addObject:category];
}
}

return categories;
PiwigoAlbumData *searchAlbum = [self getCategoryById:kPiwigoSearchCategoryId];
return (searchAlbum != nil);
}

@end

0 comments on commit 397520d

Please sign in to comment.