Skip to content

Commit

Permalink
Merge pull request #548 from Piwigo/3.0.2
Browse files Browse the repository at this point in the history
v3.0.2
  • Loading branch information
EddyLB authored Jul 15, 2023
2 parents b8e18a4 + ded3c57 commit 47f0dc5
Show file tree
Hide file tree
Showing 30 changed files with 366 additions and 553 deletions.
6 changes: 1 addition & 5 deletions piwigo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,6 @@
AD18C74127F22B1B002CD05C /* LockOptionsViewController.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LockOptionsViewController.storyboard; sourceTree = "<group>"; };
AD196AA02438D2D5006C492A /* ShareMetadataViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShareMetadataViewController.swift; sourceTree = "<group>"; };
AD1AC30929746F9E00CEA7A9 /* ImageSessionErrors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageSessionErrors.swift; sourceTree = "<group>"; };
AD1B92792703A78D0089C5F4 /* AlbumViewController+TransitioningDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AlbumViewController+TransitioningDelegate.swift"; sourceTree = "<group>"; };
AD1B927B2703AAD90089C5F4 /* ImageAnimatedTransitioning.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageAnimatedTransitioning.swift; sourceTree = "<group>"; };
AD1BB5EA29ADCE330041E24E /* DataModel 0B (Image).xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "DataModel 0B (Image).xcdatamodel"; sourceTree = "<group>"; };
AD1BB5EB29AE82E50041E24E /* MappingModel_0A_to_0B.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = MappingModel_0A_to_0B.xcmappingmodel; sourceTree = "<group>"; };
AD1BFE3D2745A15800858145 /* UIImageView+AppTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImageView+AppTools.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1391,8 +1389,6 @@
ADC69F1A285A4C30009BF9AF /* AlbumViewController+Favorites.swift */,
ADBABA352847F4FF00EF39B0 /* AlbumViewController+Search.swift */,
AD98FB952843A2F100F6C0C5 /* AlbumViewController+Tagged.swift */,
AD1B92792703A78D0089C5F4 /* AlbumViewController+TransitioningDelegate.swift */,
AD1B927B2703AAD90089C5F4 /* ImageAnimatedTransitioning.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -1570,12 +1566,12 @@
ADD981F528737EFD007213AE /* DataModel.xcdatamodeld */,
AD129E6328C34F4E007A2A52 /* Migration Tools */,
AD129E6428C34F8E007A2A52 /* Extensions */,
AD41BEC8223E9BB200A5DEE3 /* Location Data */,
ADF35E7628B2834F009F3ECE /* Server Data */,
AD98E52F28BB8B34008C846A /* User Data */,
ADDC36B928CCA46400E5AE4B /* Album Data */,
ADDC36BA28CCC0C800E5AE4B /* Image Data */,
ADF4001C266D6FBA004352B9 /* Tag Data */,
AD41BEC8223E9BB200A5DEE3 /* Location Data */,
AD23A1EF2427C94000F662AB /* Upload Data */,
AD018D7E28D7284B0003D5DB /* AttributeTransformers */,
);
Expand Down
100 changes: 70 additions & 30 deletions piwigo/Album/AlbumViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ class AlbumViewController: UIViewController, UICollectionViewDelegate, UICollect
var imageDetailView: ImageViewController?
private var updateOperations = [BlockOperation]()

// See https://medium.com/@tungfam/custom-uiviewcontroller-transitions-in-swift-d1677e5aa0bf
//@property (nonatomic, strong) ImageCollectionViewCell *selectedCell; // Cell that was selected
//@property (nonatomic, strong) UIView *selectedCellImageViewSnapshot; // Snapshot of the image view
//@property (nonatomic, strong) ImageAnimatedTransitioning *animator; // Image cell animator

init(albumId: Int32) {
super.init(nibName: nil, bundle: nil)

Expand Down Expand Up @@ -129,6 +124,20 @@ class AlbumViewController: UIViewController, UICollectionViewDelegate, UICollect
}()


// MARK: - Core Data Providers
private lazy var userProvider: UserProvider = {
return UserProvider.shared
}()

lazy var albumProvider: AlbumProvider = {
return AlbumProvider.shared
}()

lazy var imageProvider: ImageProvider = {
return ImageProvider.shared
}()


// MARK: - Core Data Object Contexts
lazy var mainContext: NSManagedObjectContext = {
let context:NSManagedObjectContext = DataController.shared.mainContext
Expand All @@ -141,23 +150,6 @@ class AlbumViewController: UIViewController, UICollectionViewDelegate, UICollect
}()


// MARK: - Core Data Providers
private lazy var userProvider: UserProvider = {
let provider : UserProvider = UserProvider.shared
return provider
}()

lazy var albumProvider: AlbumProvider = {
let provider : AlbumProvider = AlbumProvider.shared
return provider
}()

lazy var imageProvider: ImageProvider = {
let provider : ImageProvider = ImageProvider.shared
return provider
}()


// MARK: - Core Data Source
lazy var user: User = {
guard let user = userProvider.getUserAccount(inContext: mainContext) else {
Expand Down Expand Up @@ -1443,15 +1435,63 @@ class AlbumViewController: UIViewController, UICollectionViewDelegate, UICollect


// MARK: - AlbumCollectionViewCellDelegate Methods (+ PushView:)
func deleteCategory(_ albumId: Int32, inParent parentID: Int32,
inMode mode: pwgAlbumDeletionMode) {
// Delete album, sub-albums and images from presistent cache
DispatchQueue.global(qos: .userInitiated).async { [unowned self] in
self.albumProvider.deleteAlbum(albumId, inParent: parentID, inMode: mode)
func didDeleteCategory(withError error: NSError?, viewController topViewController: UIViewController?) {
guard let error = error else {
// Remember that the app is fetching all album data
AlbumVars.shared.isFetchingAlbumData.insert(0)

// Use the AlbumProvider to fetch album data. On completion,
// handle general UI updates and error alerts on the main queue.
let thumnailSize = pwgImageSize(rawValue: AlbumVars.shared.defaultAlbumThumbnailSize) ?? .medium
albumProvider.fetchAlbums(forUser: user, inParentWithId: 0, recursively: true,
thumbnailSize: thumnailSize) { [self] error in
// ► Remove current album from list of album being fetched
AlbumVars.shared.isFetchingAlbumData.remove(0)

// Check error
guard let error = error as? NSError else {
// No error ► Hide HUD, update
DispatchQueue.main.async { [self] in
topViewController?.updatePiwigoHUDwithSuccess() {
topViewController?.hidePiwigoHUD(afterDelay: kDelayPiwigoHUD) {
// Update number of images in footer
self.updateNberOfImagesInFooter()
}
}
}
return
}

// Show the error
DispatchQueue.main.async { [self] in
topViewController?.hidePiwigoHUD {
// Display error alert after trying to share image
self.deleteCategoryError(error, viewController: topViewController)
}
}
}
return
}

// Show the error
DispatchQueue.main.async { [self] in
topViewController?.hidePiwigoHUD {
// Display error alert after trying to share image
self.deleteCategoryError(error, viewController: topViewController)
}
}
}

private func deleteCategoryError(_ error: NSError, viewController topViewController: UIViewController?) {
DispatchQueue.main.async {
let title = NSLocalizedString("loadingHUD_label", comment: "Loading…")
let message = NSLocalizedString("CoreDataFetch_AlbumError", comment: "Fetch albums error!")
topViewController?.hidePiwigoHUD() {
topViewController?.dismissPiwigoError(withTitle: title, message: message,
errorMessage: error.localizedDescription) {
}
}
}

// Update number of images in footer
updateNberOfImagesInFooter()
}

@objc
Expand Down
34 changes: 13 additions & 21 deletions piwigo/Album/Cells/AlbumCollectionViewCell+Delete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,44 +201,36 @@ extension AlbumCollectionViewCell {
guard let albumData = albumData else { return }

// Delete the category
NetworkUtilities.checkSession(ofUser: user) {
AlbumUtilities.delete(albumData.pwgID, inMode: deletionMode) {

NetworkUtilities.checkSession(ofUser: user) { [self] in
AlbumUtilities.delete(albumData.pwgID, inMode: deletionMode) { [self] in
// Hide swipe buttons
DispatchQueue.main.async {
completion(true)
}

// Remove this album from the auto-upload destination
if UploadVars.autoUploadCategoryId == albumData.pwgID {
UploadVars.autoUploadCategoryId = Int32.min
}

// Close HUD, hide swipe button, remove album and images from cache
topViewController?.updatePiwigoHUDwithSuccess() { [self] in
topViewController?.hidePiwigoHUD(afterDelay: kDelayPiwigoHUD) { [self] in
// Hide swipe buttons
completion(true)

// Delete album and images from cache and update UI
categoryDelegate?.deleteCategory(albumData.pwgID, inParent: albumData.parentId,
inMode: deletionMode)
}
}
// Delete album and images from cache and update UI
self.categoryDelegate?.didDeleteCategory(withError: nil,
viewController: topViewController)
} failure: { error in
self.deleteCategoryError(error, viewController: topViewController,
completion: completion)
self.deleteCategoryError(error, viewController: topViewController)
}
} failure: { error in
self.deleteCategoryError(error, viewController: topViewController,
completion: completion)
self.deleteCategoryError(error, viewController: topViewController)
}
}

private func deleteCategoryError(_ error: NSError, viewController topViewController: UIViewController?,
completion: @escaping (Bool) -> Void) {
private func deleteCategoryError(_ error: NSError, viewController topViewController: UIViewController?) {
DispatchQueue.main.async {
let title = NSLocalizedString("deleteCategoryError_title", comment: "Delete Fail")
let message = NSLocalizedString("deleteCategoryError_message", comment: "Failed to delete your album")
topViewController?.hidePiwigoHUD() {
topViewController?.dismissPiwigoError(withTitle: title, message: message,
errorMessage: error.localizedDescription) {
completion(true)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions piwigo/Album/Cells/AlbumCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import piwigoKit
protocol AlbumCollectionViewCellDelegate: NSObjectProtocol {
func pushCategoryView(_ viewController: UIViewController?,
completion: @escaping (Bool) -> Void)
func deleteCategory(_ albumId: Int32, inParent parentID: Int32,
inMode mode: pwgAlbumDeletionMode)
func didDeleteCategory(withError error: NSError?,
viewController topViewController: UIViewController?)
}

class AlbumCollectionViewCell: UICollectionViewCell
Expand Down
70 changes: 34 additions & 36 deletions piwigo/Album/Extensions/AlbumViewController+Buttons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -547,44 +547,42 @@ extension AlbumViewController
// Title is name of category
setTitleViewFromAlbumData(whileUpdating: false)

// When using several scenes on iPad, buttons might have to be relocated.
// Buttons might have to be relocated:
/// - when using several scenes on iPad
/// - when launching the app in landscape mode on iPhone and returning to the root album in portrait mode
if #available(iOS 13.0, *) {
let sizeOfScreen = UIScreen.main.bounds.size
let sizeOfView = view.bounds.size
if sizeOfView.equalTo(sizeOfScreen) == false {
// Calculate reference position
let xPos = view.bounds.size.width - 3 * kRadius
let yPos = view.bounds.size.height - 3 * kRadius
var newFrame = CGRect(x: xPos, y: yPos, width: 2 * kRadius, height: 2 * kRadius)

// Relocate the "Add" button if needed
if addButton.frame.equalTo(newFrame) == false {
addButton.frame = newFrame
}

// Relocate the "Upload Queue" button if needed
newFrame = getUploadQueueButtonFrame(isHidden: uploadQueueButton.isHidden)
if uploadQueueButton.frame.equalTo(newFrame) == false {
uploadQueueButton.frame = newFrame
}
// Calculate reference position
let xPos = view.bounds.size.width - 3 * kRadius
let yPos = view.bounds.size.height - 3 * kRadius
var newFrame = CGRect(x: xPos, y: yPos, width: 2 * kRadius, height: 2 * kRadius)

// Relocate the "Add" button if needed
if addButton.frame.equalTo(newFrame) == false {
addButton.frame = newFrame
}

// Relocate the "Upload Queue" button if needed
newFrame = getUploadQueueButtonFrame(isHidden: uploadQueueButton.isHidden)
if uploadQueueButton.frame.equalTo(newFrame) == false {
uploadQueueButton.frame = newFrame
}

// Relocate the "Home Album" button if needed
newFrame = getHomeAlbumButtonFrame(isHidden: homeAlbumButton.isHidden)
if homeAlbumButton.frame.equalTo(newFrame) == false {
homeAlbumButton.frame = newFrame
}

// Relocate "Create Album" button if needed
newFrame = getCreateAlbumButtonFrame(isHidden: createAlbumButton.isHidden)
if createAlbumButton.frame.equalTo(newFrame) == false {
createAlbumButton.frame = newFrame
}

// Relocate "Upload Images" button if needed
newFrame = getUploadImagesButtonFrame(isHidden: uploadImagesButton.isHidden)
if uploadImagesButton.frame.equalTo(newFrame) == false {
uploadImagesButton.frame = newFrame
}
// Relocate the "Home Album" button if needed
newFrame = getHomeAlbumButtonFrame(isHidden: homeAlbumButton.isHidden)
if homeAlbumButton.frame.equalTo(newFrame) == false {
homeAlbumButton.frame = newFrame
}

// Relocate "Create Album" button if needed
newFrame = getCreateAlbumButtonFrame(isHidden: createAlbumButton.isHidden)
if createAlbumButton.frame.equalTo(newFrame) == false {
createAlbumButton.frame = newFrame
}

// Relocate "Upload Images" button if needed
newFrame = getUploadImagesButtonFrame(isHidden: uploadImagesButton.isHidden)
if uploadImagesButton.frame.equalTo(newFrame) == false {
uploadImagesButton.frame = newFrame
}
}
}
Expand Down
13 changes: 3 additions & 10 deletions piwigo/Album/Extensions/AlbumViewController+DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,9 @@ extension AlbumViewController
AlbumVars.shared.isFetchingAlbumData.remove(pwgSmartAlbum.favorites.rawValue)

// Save changes
do {
try bckgContext.save()
DispatchQueue.main.async {
try? self.mainContext.save()
}
}
catch let error as NSError {
// Remove favorite album from list of album being fetched
AlbumVars.shared.isFetchingAlbumData.remove(pwgSmartAlbum.favorites.rawValue)
print("Could not fetch \(error), \(error.userInfo)")
bckgContext.saveIfNeeded()
DispatchQueue.main.async {
self.mainContext.saveIfNeeded()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions piwigo/Album/Extensions/AlbumViewController+Favorites.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension AlbumViewController
func addImageToFavorites() {
guard let imageId = selectedImageIds.first else {
// Save changes
try? bckgContext.save()
bckgContext.saveIfNeeded()
// Close HUD with success
updatePiwigoHUDwithSuccess() { [self] in
hidePiwigoHUD(afterDelay: kDelayPiwigoHUD) { [self] in
Expand Down Expand Up @@ -105,7 +105,7 @@ extension AlbumViewController
func removeImageFromFavorites() {
guard let imageId = selectedImageIds.first else {
// Save changes
try? bckgContext.save()
bckgContext.saveIfNeeded()
// Close HUD with success
updatePiwigoHUDwithSuccess() { [self] in
hidePiwigoHUD(afterDelay: kDelayPiwigoHUD) { [self] in
Expand Down

This file was deleted.

Loading

0 comments on commit 47f0dc5

Please sign in to comment.