Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to select all media in selection mode #5685

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ protocol MediaGalleryPrimaryViewController: UIViewController {
var isEmpty: Bool { get }
var hasSelection: Bool { get }
func selectionInfo() -> (count: Int, totalSize: Int64)?
func selectAll()
func selectNone()
func disableFiltering()
func batchSelectionModeDidChange(isInBatchSelectMode: Bool)
func didEndSelectMode()
Expand Down Expand Up @@ -172,6 +174,7 @@ public class MediaGalleryAccessoriesHelper {
updateFooterBarState()
updateSelectionInfoLabel()
updateSelectionModeControls()
updateSelectAllButton()
updateDeleteButton()
updateShareButton()
}
Expand All @@ -183,6 +186,7 @@ public class MediaGalleryAccessoriesHelper {
return
}
updateSelectionInfoLabel()
updateSelectAllButton()
updateDeleteButton()
updateShareButton()
}
Expand Down Expand Up @@ -438,7 +442,7 @@ public class MediaGalleryAccessoriesHelper {
case .hidden:
return nil
case .selection:
return [ shareButton, flexibleSpace(), selectionInfoButton, flexibleSpace(), deleteButton ]
return [ shareButton, selectAllButton, flexibleSpace(), selectionInfoButton, flexibleSpace(), deleteButton ]
case .regular:
let firstItem: UIBarButtonItem
if isGridViewAllowed {
Expand Down Expand Up @@ -569,6 +573,37 @@ public class MediaGalleryAccessoriesHelper {
Logger.debug("")
viewController?.shareSelectedItems(sender)
}

// MARK: - Select All/None

private lazy var selectAllButton = UIBarButtonItem(
title: CommonStrings.selectAllButton,
style: .plain,
target: self,
action: #selector(didPressSelectAll)
)

@objc
private func didPressSelectAll(_ sender: Any) {
Logger.debug("")
if viewController?.hasSelection {
viewController?.selectNone()
} else {
viewController?.selectAll()
}
viewController?.selectAll()
} else {
viewController?.selectNone()
}

didModifySelection()
}

private func updateSelectAllButton() {
guard let viewController else { return }
selectAllButton.title =
viewController.hasSelection ? CommonStrings.selectNoneButton : CommonStrings.selectAllButton
}

// MARK: - Selection Info

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,23 @@ extension MediaTileViewController: MediaGalleryPrimaryViewController {
}
return false
}

func selectAll() {
(0..<collectionView.numberOfSections).compactMap { (section) -> [IndexPath]? in
return (0..<collectionView.numberOfItems(inSection: section)).compactMap({
(item) -> IndexPath? in
return IndexPath(item: item, section: section)
})
}.flatMap { $0 }.forEach { (indexPath) in
collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])
}
}

func selectNone() {
collectionView.indexPathsForSelectedItems?.forEach({ (indexPath) in
collectionView.deselectItem(at: indexPath, animated: true)
})
}

func selectionInfo() -> (count: Int, totalSize: Int64)? {
guard
Expand Down
6 changes: 6 additions & 0 deletions Signal/translations/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,12 @@
/* Button text to enable batch selection mode */
"BUTTON_SELECT" = "Select";

/* Button text to select all in batch selection mode */
"BUTTON_SELECT_ALL" = "Select All";

/* Button text to select none in batch selection mode */
"BUTTON_SELECT_NONE" = "Select None";

/* Label for the 'set' button. */
"BUTTON_SET" = "Set";

Expand Down
8 changes: 8 additions & 0 deletions SignalMessaging/utils/CommonStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public class CommonStrings: NSObject {
static public var selectButton: String {
OWSLocalizedString("BUTTON_SELECT", comment: "Button text to enable batch selection mode")
}

static public var selectAllButton: String {
OWSLocalizedString("BUTTON_SELECT_ALL", comment: "Button text to select all in batch selection mode")
}

static public var selectNoneButton: String {
OWSLocalizedString("BUTTON_SELECT_NONE", comment: "Button text to select none in batch selection mode")
}

static public var doneButton: String {
OWSLocalizedString("BUTTON_DONE", comment: "Label for generic done button.")
Expand Down