feat: add select button and delete function in media title screen

This commit is contained in:
ryanzhao 2022-08-10 13:32:53 +10:00
parent 99989f9944
commit a162f324b1
2 changed files with 47 additions and 29 deletions

View File

@ -18,10 +18,13 @@ public class AllMediaViewController: UIViewController, UIPageViewControllerDataS
TabBar.Tab(title: MediaStrings.media) { [weak self] in
guard let self = self else { return }
self.pageVC.setViewControllers([ self.pages[0] ], direction: .forward, animated: false, completion: nil)
self.updateSelectButton(updatedData: self.mediaTitleViewController.viewModel.galleryData, inBatchSelectMode: self.mediaTitleViewController.isInBatchSelectMode)
},
TabBar.Tab(title: MediaStrings.document) { [weak self] in
guard let self = self else { return }
self.pageVC.setViewControllers([ self.pages[1] ], direction: .forward, animated: false, completion: nil)
self.endSelectMode()
self.navigationItem.rightBarButtonItem = nil
}
]
return TabBar(tabs: tabs)
@ -99,6 +102,24 @@ public class AllMediaViewController: UIViewController, UIPageViewControllerDataS
@objc public func didPressDismissButton() {
dismiss(animated: true, completion: nil)
}
// MARK: Batch Selection
@objc func didTapSelect(_ sender: Any) {
self.mediaTitleViewController.didTapSelect(sender)
// Don't allow the user to leave mid-selection, so they realized they have
// to cancel (lose) their selection if they leave.
self.navigationItem.hidesBackButton = true
}
@objc func didCancelSelect(_ sender: Any) {
endSelectMode()
}
func endSelectMode() {
self.mediaTitleViewController.endSelectMode()
self.navigationItem.hidesBackButton = false
}
}
// MARK: - UIDocumentInteractionControllerDelegate
@ -138,6 +159,29 @@ extension AllMediaViewController: MediaTileViewControllerDelegate {
public func presentdetailViewController(_ detailViewController: UIViewController, animated: Bool) {
self.present(detailViewController, animated: animated)
}
public func updateSelectButton(updatedData: [MediaGalleryViewModel.SectionModel], inBatchSelectMode: Bool) {
guard !updatedData.isEmpty else {
self.navigationItem.rightBarButtonItem = nil
return
}
if inBatchSelectMode {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(
barButtonSystemItem: .cancel,
target: self,
action: #selector(didCancelSelect)
)
}
else {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(
title: "BUTTON_SELECT".localized(),
style: .plain,
target: self,
action: #selector(didTapSelect)
)
}
}
}
// MARK: - MediaPresentationContextProvider

View File

@ -271,6 +271,7 @@ public class MediaTileViewController: UIViewController, UICollectionViewDataSour
guard hasLoadedInitialData else {
self.hasLoadedInitialData = true
self.viewModel.updateGalleryData(updatedGalleryData)
self.updateSelectButton(updatedData: updatedGalleryData, inBatchSelectMode: isInBatchSelectMode)
UIView.performWithoutAnimation {
self.collectionView.reloadData()
@ -586,26 +587,7 @@ public class MediaTileViewController: UIViewController, UICollectionViewDataSour
}
func updateSelectButton(updatedData: [MediaGalleryViewModel.SectionModel], inBatchSelectMode: Bool) {
guard !updatedData.isEmpty else {
self.navigationItem.rightBarButtonItem = nil
return
}
if inBatchSelectMode {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(
barButtonSystemItem: .cancel,
target: self,
action: #selector(didCancelSelect)
)
}
else {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(
title: "BUTTON_SELECT".localized(),
style: .plain,
target: self,
action: #selector(didTapSelect)
)
}
delegate?.updateSelectButton(updatedData: updatedData, inBatchSelectMode: inBatchSelectMode)
}
@objc func didTapSelect(_ sender: Any) {
@ -620,13 +602,6 @@ public class MediaTileViewController: UIViewController, UICollectionViewDataSour
// Ensure toolbar doesn't cover bottom row.
self?.collectionView.contentInset.bottom += MediaTileViewController.footerBarHeight
}, completion: nil)
// disabled until at least one item is selected
self.deleteButton.isEnabled = false
// Don't allow the user to leave mid-selection, so they realized they have
// to cancel (lose) their selection if they leave.
self.navigationItem.hidesBackButton = true
}
@objc func didCancelSelect(_ sender: Any) {
@ -646,8 +621,6 @@ public class MediaTileViewController: UIViewController, UICollectionViewDataSour
self?.collectionView.contentInset.bottom -= MediaTileViewController.footerBarHeight
}, completion: nil)
self.navigationItem.hidesBackButton = false
// Deselect any selected
collectionView.indexPathsForSelectedItems?.forEach { collectionView.deselectItem(at: $0, animated: false)}
}
@ -924,4 +897,5 @@ extension MediaTileViewController: MediaPresentationContextProvider {
public protocol MediaTileViewControllerDelegate: AnyObject {
func presentdetailViewController(_ detailViewController: UIViewController, animated: Bool)
func updateSelectButton(updatedData: [MediaGalleryViewModel.SectionModel], inBatchSelectMode: Bool)
}