Skip to content

Commit

Permalink
Merge pull request #507 from Piwigo/v2.10
Browse files Browse the repository at this point in the history
v2.10
  • Loading branch information
EddyLB authored May 22, 2022
2 parents c0b3b48 + 4c0520d commit 791754f
Show file tree
Hide file tree
Showing 185 changed files with 7,486 additions and 4,221 deletions.
2 changes: 1 addition & 1 deletion Supporting Targets/piwigoKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>449</string>
<string>462</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Supporting Targets/piwigoWebAPI/piwigoWebAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class piwigoWebAPI: XCTestCase {
XCTAssertEqual(result.errorMessage, "")

XCTAssertEqual(result.data[0].name, "version")
XCTAssertEqual(result.data[0].value, "11.5.0")
XCTAssertEqual(result.data[0].value?.stringValue, "12.2.0")
}


Expand Down
5 changes: 3 additions & 2 deletions Supporting Targets/piwigoWebAPI/pwg/pwg.getInfos.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ SELECT
{
"stat":"ok",
"result":{
"infos": [{"name":"version","value":"11.5.0"},
"infos": [{"name":"version","value":"12.2.0"},
{"name":"nb_elements","value":"339"},
{"name":"nb_categories","value":"28"},
{"name":"nb_virtual","value":"28"},
Expand All @@ -19,7 +19,8 @@ SELECT
{"name":"nb_users","value":"7"},
{"name":"nb_groups","value":"1"},
{"name":"nb_comments","value":"0"},
{"name":"first_date","value":"2017-08-31 22:44:11"}
{"name":"first_date","value":"2017-08-31 22:44:11"},
{"name":"cache_size","value":4242}
]
}
}
Expand Down
154 changes: 91 additions & 63 deletions piwigo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion piwigo/Album/AlbumImagesViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ FOUNDATION_EXPORT NSString * const kPiwigoNotificationCancelDownload;
//@property (nonatomic, strong) ImageAnimatedTransitioning *animator; // Image cell animator

-(instancetype)initWithAlbumId:(NSInteger)albumId;
-(void)checkDataSourceWithChangedCategories:(BOOL)didChange;
-(void)checkDataSourceWithChangedCategories:(BOOL)didChange onCompletion:(void (^)(void))completion;
-(void)updateSubCategoryWithId:(NSInteger)albumId;
-(void)addImageWithId:(NSInteger)imageId;
-(void)removeImageWithId:(NSInteger)imageId;
Expand Down
131 changes: 71 additions & 60 deletions piwigo/Album/AlbumImagesViewController.m

Large diffs are not rendered by default.

180 changes: 134 additions & 46 deletions piwigo/Album/Cells/AlbumCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ class AlbumCollectionViewCell: UICollectionViewCell
@objc var albumData: PiwigoAlbumData?

private var tableView: UITableView?
private var categoryAction: UIAlertAction?
private var renameAlert: UIAlertController?
private var renameAction: UIAlertAction?
private var deleteAction: UIAlertAction?
private enum textFieldTag: Int {
case albumName = 1000, albumDescription, nberOfImages
}

override init(frame: CGRect) {
super.init(frame: frame)
Expand All @@ -42,8 +46,10 @@ class AlbumCollectionViewCell: UICollectionViewCell
}
contentView.addConstraints(NSLayoutConstraint.constraintFillSize(tableView)!)

NotificationCenter.default.addObserver(self, selector: #selector(autoUploadUpdated(_:)), name: PwgNotifications.autoUploadEnabled, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(autoUploadUpdated(_:)), name: PwgNotifications.autoUploadDisabled, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(autoUploadUpdated(_:)),
name: .pwgAutoUploadEnabled, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(autoUploadUpdated(_:)),
name: .pwgAutoUploadDisabled, object: nil)
}

@objc
Expand Down Expand Up @@ -72,9 +78,14 @@ class AlbumCollectionViewCell: UICollectionViewCell
cell?.refreshButtons(true)
}


deinit {
renameAction = nil
NotificationCenter.default.removeObserver(self, name: .pwgAutoUploadEnabled, object: nil)
NotificationCenter.default.removeObserver(self, name: .pwgAutoUploadDisabled, object: nil)
}

// MARK: - Move Category
func moveCategory() {
private func moveCategory() {
guard let albumData = albumData else { return }

let moveSB = UIStoryboard(name: "SelectCategoryViewController", bundle: nil)
Expand All @@ -88,21 +99,18 @@ class AlbumCollectionViewCell: UICollectionViewCell


// MARK: - Rename Category
func renameCategory() {
private func renameCategory() {
guard let albumData = albumData else { return }

// Determine the present view controller
var topViewController = UIApplication.shared.keyWindow?.rootViewController
while topViewController?.presentedViewController != nil {
topViewController = topViewController?.presentedViewController
}
let topViewController = window?.topMostViewController()

let alert = UIAlertController(
renameAlert = UIAlertController(
title: NSLocalizedString("renameCategory_title", comment: "Rename Album"),
message: String(format: "%@ (%@):", NSLocalizedString("renameCategory_message", comment: "Enter a new name for this album"), albumData.name ?? "?"),
preferredStyle: .alert)

alert.addTextField(configurationHandler: { [self] textField in
renameAlert?.addTextField(configurationHandler: { [self] textField in
textField.placeholder = NSLocalizedString("createNewAlbum_placeholder", comment: "Album Name")
textField.text = albumData.name ?? "?"
textField.clearButtonMode = .always
Expand All @@ -112,9 +120,10 @@ class AlbumCollectionViewCell: UICollectionViewCell
textField.autocorrectionType = .yes
textField.returnKeyType = .continue
textField.delegate = self
textField.tag = textFieldTag.albumName.rawValue
})

alert.addTextField(configurationHandler: { [self] textField in
renameAlert?.addTextField(configurationHandler: { [self] textField in
textField.placeholder = NSLocalizedString("createNewAlbumDescription_placeholder", comment: "Description")
textField.text = albumData.comment ?? ""
textField.clearButtonMode = .always
Expand All @@ -124,6 +133,7 @@ class AlbumCollectionViewCell: UICollectionViewCell
textField.autocorrectionType = .yes
textField.returnKeyType = .continue
textField.delegate = self
textField.tag = textFieldTag.albumDescription.rawValue
})

let cancelAction = UIAlertAction(
Expand All @@ -134,34 +144,63 @@ class AlbumCollectionViewCell: UICollectionViewCell
cell?.hideSwipe(animated: true)
})

categoryAction = UIAlertAction(
renameAction = UIAlertAction(
title: NSLocalizedString("renameCategory_button", comment: "Rename"),
style: .default, handler: { [self] action in
// Rename album if possible
if (alert.textFields?.first?.text?.count ?? 0) > 0 {
renameCategory(withName: alert.textFields?.first?.text,
comment: alert.textFields?.last?.text,
if (self.renameAlert?.textFields?.first?.text?.count ?? 0) > 0 {
renameCategory(withName: self.renameAlert?.textFields?.first?.text,
comment: self.renameAlert?.textFields?.last?.text,
andViewController: topViewController)
}
})

alert.addAction(cancelAction)
if let categoryAction = categoryAction {
alert.addAction(categoryAction)
renameAlert?.addAction(cancelAction)
if let renameAction = renameAction {
renameAlert?.addAction(renameAction)
}
alert.view.tintColor = UIColor.piwigoColorOrange()
renameAlert?.view.tintColor = UIColor.piwigoColorOrange()
if #available(iOS 13.0, *) {
alert.overrideUserInterfaceStyle = AppVars.shared.isDarkPaletteActive ? .dark : .light
renameAlert?.overrideUserInterfaceStyle = AppVars.shared.isDarkPaletteActive ? .dark : .light
} else {
// Fallback on earlier versions
}
topViewController?.present(alert, animated: true) {
// Bugfix: iOS9 - Tint not fully Applied without Reapplying
alert.view.tintColor = UIColor.piwigoColorOrange()
if let alert = renameAlert {
topViewController?.present(alert, animated: true) { [self] in
// Bugfix: iOS9 - Tint not fully Applied without Reapplying
renameAlert?.view.tintColor = UIColor.piwigoColorOrange()
}
}
}

func renameCategory(withName albumName: String?, comment albumComment: String?, andViewController topViewController: UIViewController?) {
private func shouldEnableActionWith(newName: String?, newDescription: String?) -> Bool {
// Renaming the album is not possible with a nil or an empty string.
guard let newAlbumName = newName, newAlbumName.isEmpty == false else {
return false
}
// Get the old album name
guard let oldAlbumName = albumData?.name else {
// Old album name is nil (should never happen)
return true
}
// Compare with the old album name
if newAlbumName != oldAlbumName {
return true
}
// Changing the album description is not possible with a nil.
guard let newAlbumDesc = newDescription else {
return false
}
// Get the old album description
guard let oldAlbumDesc = albumData?.comment else {
// Old album description is nil
return newAlbumDesc.isEmpty ? false : true
}
// Compare the old and new album descriptions
return (oldAlbumDesc != newAlbumDesc)
}

private func renameCategory(withName albumName: String?, comment albumComment: String?, andViewController topViewController: UIViewController?) {
guard let albumData = albumData else { return }

// Display HUD during the update
Expand Down Expand Up @@ -203,14 +242,11 @@ class AlbumCollectionViewCell: UICollectionViewCell


// MARK: - Delete Category
func deleteCategory() {
private func deleteCategory() {
guard let albumData = albumData else { return }

// Determine the present view controller
var topViewController = UIApplication.shared.keyWindow?.rootViewController
while topViewController?.presentedViewController != nil {
topViewController = topViewController?.presentedViewController
}
let topViewController = topMostController()

let alert = UIAlertController(
title: NSLocalizedString("deleteCategory_title", comment: "DELETE ALBUM"),
Expand Down Expand Up @@ -292,7 +328,7 @@ class AlbumCollectionViewCell: UICollectionViewCell
}
}

func confirmCategoryDeletion(withNumberOfImages number: Int, deletionMode: String, andViewController topViewController: UIViewController?) {
private func confirmCategoryDeletion(withNumberOfImages number: Int, deletionMode: String, andViewController topViewController: UIViewController?) {
guard let albumData = albumData else { return }

// Are you sure?
Expand All @@ -307,6 +343,7 @@ class AlbumCollectionViewCell: UICollectionViewCell
textField.clearButtonMode = .always
textField.keyboardType = .numberPad
textField.delegate = self
textField.tag = textFieldTag.nberOfImages.rawValue
})

let defaultAction = UIAlertAction(
Expand Down Expand Up @@ -342,7 +379,7 @@ class AlbumCollectionViewCell: UICollectionViewCell
}
}

func prepareDeletion(withNumberOfImages number: Int, deletionMode: String, andViewController topViewController: UIViewController?) {
private func prepareDeletion(withNumberOfImages number: Int, deletionMode: String, andViewController topViewController: UIViewController?) {
guard let albumData = albumData else { return }

// Check provided number of iamges
Expand Down Expand Up @@ -377,7 +414,8 @@ class AlbumCollectionViewCell: UICollectionViewCell
}
}

func getMissingImages(beforeDeletingInMode deletionMode: String, with topViewController: UIViewController?) {
private func getMissingImages(beforeDeletingInMode deletionMode: String,
with topViewController: UIViewController?) {
guard let albumData = albumData else { return }

let sortDesc = CategoryImageSort.getPiwigoSortDescription(for: kPiwigoSort(rawValue: AlbumVars.shared.defaultSort)!)
Expand Down Expand Up @@ -414,8 +452,8 @@ class AlbumCollectionViewCell: UICollectionViewCell
})
}

func deleteCategory(withDeletionMode deletionMode: String,
andViewController topViewController: UIViewController?) {
private func deleteCategory(withDeletionMode deletionMode: String,
andViewController topViewController: UIViewController?) {
guard let albumData = albumData else { return }

// Stores image data before category deletion
Expand Down Expand Up @@ -567,25 +605,75 @@ extension AlbumCollectionViewCell: MGSwipeTableCellDelegate
extension AlbumCollectionViewCell: UITextFieldDelegate
{
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
// Disable Add/Delete Category action
categoryAction?.isEnabled = false
deleteAction?.isEnabled = false
switch textFieldTag(rawValue: textField.tag) {
case .albumName, .albumDescription:
// Check both text fields
let newName = renameAlert?.textFields?.first?.text
let newDescription = renameAlert?.textFields?.last?.text
renameAction?.isEnabled = shouldEnableActionWith(newName: newName,
newDescription: newDescription)
case .nberOfImages:
// The album deletion cannot be requested if a number of images is not provided.
if let _ = Int(textField.text ?? "") {
deleteAction?.isEnabled = true
} else {
deleteAction?.isEnabled = false
}
case .none:
renameAction?.isEnabled = false
deleteAction?.isEnabled = false
}
return true
}

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange,
replacementString string: String) -> Bool {
// Enable Add/Delete Category action if text field not empty
let finalString = (textField.text as NSString?)?.replacingCharacters(in: range, with: string)
categoryAction?.isEnabled = (finalString?.count ?? 0) >= 1
deleteAction?.isEnabled = (finalString?.count ?? 0) >= 1
switch textFieldTag(rawValue: textField.tag) {
case .albumName:
// Check both text fields
let newName = (textField.text as NSString?)?.replacingCharacters(in: range, with: string)
let newDescription = renameAlert?.textFields?.last?.text
renameAction?.isEnabled = shouldEnableActionWith(newName: newName,
newDescription: newDescription)
case .albumDescription:
// Check both text fields
let newName = renameAlert?.textFields?.first?.text
let newDescription = (textField.text as NSString?)?.replacingCharacters(in: range, with: string)
renameAction?.isEnabled = shouldEnableActionWith(newName: newName,
newDescription: newDescription)
case .nberOfImages:
// The album deletion cannot be requested if a number of images is not provided.
if let nberAsText = (textField.text as NSString?)?.replacingCharacters(in: range, with: string),
let _ = Int(nberAsText) {
deleteAction?.isEnabled = true
} else {
deleteAction?.isEnabled = false
}
case .none:
renameAction?.isEnabled = false
deleteAction?.isEnabled = false
}
return true
}

func textFieldShouldClear(_ textField: UITextField) -> Bool {
// Disable Add/Delete Category action
categoryAction?.isEnabled = false
deleteAction?.isEnabled = false
switch textFieldTag(rawValue: textField.tag) {
case .albumName:
// The album cannot be renamed with an empty string.
renameAction?.isEnabled = false
case .albumDescription:
// The album cannot be renamed with an empty string or the same name.
// Check both text fields
let newName = renameAlert?.textFields?.first?.text
renameAction?.isEnabled = shouldEnableActionWith(newName: newName,
newDescription: "")
case .nberOfImages:
// The album deletion cannot be requested if a number of images is not provided.
deleteAction?.isEnabled = false
case .none:
renameAction?.isEnabled = false
deleteAction?.isEnabled = false
}
return true
}

Expand Down
Loading

0 comments on commit 791754f

Please sign in to comment.