feat: add select button and delete function in media title screen
This commit is contained in:
parent
99989f9944
commit
a162f324b1
|
@ -18,10 +18,13 @@ public class AllMediaViewController: UIViewController, UIPageViewControllerDataS
|
||||||
TabBar.Tab(title: MediaStrings.media) { [weak self] in
|
TabBar.Tab(title: MediaStrings.media) { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
self.pageVC.setViewControllers([ self.pages[0] ], direction: .forward, animated: false, completion: nil)
|
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
|
TabBar.Tab(title: MediaStrings.document) { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
self.pageVC.setViewControllers([ self.pages[1] ], direction: .forward, animated: false, completion: nil)
|
self.pageVC.setViewControllers([ self.pages[1] ], direction: .forward, animated: false, completion: nil)
|
||||||
|
self.endSelectMode()
|
||||||
|
self.navigationItem.rightBarButtonItem = nil
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
return TabBar(tabs: tabs)
|
return TabBar(tabs: tabs)
|
||||||
|
@ -99,6 +102,24 @@ public class AllMediaViewController: UIViewController, UIPageViewControllerDataS
|
||||||
@objc public func didPressDismissButton() {
|
@objc public func didPressDismissButton() {
|
||||||
dismiss(animated: true, completion: nil)
|
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
|
// MARK: - UIDocumentInteractionControllerDelegate
|
||||||
|
@ -138,6 +159,29 @@ extension AllMediaViewController: MediaTileViewControllerDelegate {
|
||||||
public func presentdetailViewController(_ detailViewController: UIViewController, animated: Bool) {
|
public func presentdetailViewController(_ detailViewController: UIViewController, animated: Bool) {
|
||||||
self.present(detailViewController, animated: animated)
|
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
|
// MARK: - MediaPresentationContextProvider
|
||||||
|
|
|
@ -271,6 +271,7 @@ public class MediaTileViewController: UIViewController, UICollectionViewDataSour
|
||||||
guard hasLoadedInitialData else {
|
guard hasLoadedInitialData else {
|
||||||
self.hasLoadedInitialData = true
|
self.hasLoadedInitialData = true
|
||||||
self.viewModel.updateGalleryData(updatedGalleryData)
|
self.viewModel.updateGalleryData(updatedGalleryData)
|
||||||
|
self.updateSelectButton(updatedData: updatedGalleryData, inBatchSelectMode: isInBatchSelectMode)
|
||||||
|
|
||||||
UIView.performWithoutAnimation {
|
UIView.performWithoutAnimation {
|
||||||
self.collectionView.reloadData()
|
self.collectionView.reloadData()
|
||||||
|
@ -586,26 +587,7 @@ public class MediaTileViewController: UIViewController, UICollectionViewDataSour
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateSelectButton(updatedData: [MediaGalleryViewModel.SectionModel], inBatchSelectMode: Bool) {
|
func updateSelectButton(updatedData: [MediaGalleryViewModel.SectionModel], inBatchSelectMode: Bool) {
|
||||||
guard !updatedData.isEmpty else {
|
delegate?.updateSelectButton(updatedData: updatedData, inBatchSelectMode: inBatchSelectMode)
|
||||||
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)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func didTapSelect(_ sender: Any) {
|
@objc func didTapSelect(_ sender: Any) {
|
||||||
|
@ -620,13 +602,6 @@ public class MediaTileViewController: UIViewController, UICollectionViewDataSour
|
||||||
// Ensure toolbar doesn't cover bottom row.
|
// Ensure toolbar doesn't cover bottom row.
|
||||||
self?.collectionView.contentInset.bottom += MediaTileViewController.footerBarHeight
|
self?.collectionView.contentInset.bottom += MediaTileViewController.footerBarHeight
|
||||||
}, completion: nil)
|
}, 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) {
|
@objc func didCancelSelect(_ sender: Any) {
|
||||||
|
@ -646,8 +621,6 @@ public class MediaTileViewController: UIViewController, UICollectionViewDataSour
|
||||||
self?.collectionView.contentInset.bottom -= MediaTileViewController.footerBarHeight
|
self?.collectionView.contentInset.bottom -= MediaTileViewController.footerBarHeight
|
||||||
}, completion: nil)
|
}, completion: nil)
|
||||||
|
|
||||||
self.navigationItem.hidesBackButton = false
|
|
||||||
|
|
||||||
// Deselect any selected
|
// Deselect any selected
|
||||||
collectionView.indexPathsForSelectedItems?.forEach { collectionView.deselectItem(at: $0, animated: false)}
|
collectionView.indexPathsForSelectedItems?.forEach { collectionView.deselectItem(at: $0, animated: false)}
|
||||||
}
|
}
|
||||||
|
@ -924,4 +897,5 @@ extension MediaTileViewController: MediaPresentationContextProvider {
|
||||||
|
|
||||||
public protocol MediaTileViewControllerDelegate: AnyObject {
|
public protocol MediaTileViewControllerDelegate: AnyObject {
|
||||||
func presentdetailViewController(_ detailViewController: UIViewController, animated: Bool)
|
func presentdetailViewController(_ detailViewController: UIViewController, animated: Bool)
|
||||||
|
func updateSelectButton(updatedData: [MediaGalleryViewModel.SectionModel], inBatchSelectMode: Bool)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue