|
@@ -29,45 +29,32 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
|
|
|
@IBOutlet weak var collectionView : UICollectionView!
|
|
|
|
|
|
private var mediaCommandView: NCMediaCommandView?
|
|
|
-
|
|
|
- //Grid control buttons
|
|
|
- private var plusButton: UIBarButtonItem!
|
|
|
- private var separatorButton: UIBarButtonItem!
|
|
|
- private var minusButton: UIBarButtonItem!
|
|
|
- private var gridButton: UIBarButtonItem!
|
|
|
-
|
|
|
+ private var gridLayout: NCGridMediaLayout!
|
|
|
+
|
|
|
private let appDelegate = UIApplication.shared.delegate as! AppDelegate
|
|
|
+
|
|
|
public var metadatas: [tableMetadata] = []
|
|
|
-
|
|
|
private var metadataPush: tableMetadata?
|
|
|
+
|
|
|
private var isEditMode = false
|
|
|
private var selectocId: [String] = []
|
|
|
|
|
|
private var filterTypeFileImage = false;
|
|
|
private var filterTypeFileVideo = false;
|
|
|
-
|
|
|
- private var autoUploadFileName = ""
|
|
|
- private var autoUploadDirectory = ""
|
|
|
-
|
|
|
- private var gridLayout: NCGridMediaLayout!
|
|
|
-
|
|
|
- private let sectionHeaderHeight: CGFloat = 10
|
|
|
- private let footerHeight: CGFloat = 50
|
|
|
-
|
|
|
+
|
|
|
private var stepImageWidth: CGFloat = 10
|
|
|
private let kMaxImageGrid: CGFloat = 5
|
|
|
|
|
|
- private var isDistantPast = false
|
|
|
-
|
|
|
private var oldInProgress = false
|
|
|
private var newInProgress = false
|
|
|
-
|
|
|
|
|
|
struct cacheImages {
|
|
|
static var cellPlayImage = UIImage()
|
|
|
static var cellFavouriteImage = UIImage()
|
|
|
}
|
|
|
|
|
|
+ // MARK: - View Life Cycle
|
|
|
+
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
|
super.init(coder: aDecoder)
|
|
|
|
|
@@ -79,15 +66,8 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
|
|
|
|
- // Cell
|
|
|
collectionView.register(UINib.init(nibName: "NCGridMediaCell", bundle: nil), forCellWithReuseIdentifier: "gridCell")
|
|
|
|
|
|
- // Header
|
|
|
- collectionView.register(UINib.init(nibName: "NCSectionMediaHeader", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "sectionHeader")
|
|
|
-
|
|
|
- // Footer
|
|
|
- collectionView.register(UINib.init(nibName: "NCSectionFooter", bundle: nil), forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: "sectionFooter")
|
|
|
-
|
|
|
collectionView.alwaysBounceVertical = true
|
|
|
collectionView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 50, right: 0);
|
|
|
|
|
@@ -111,9 +91,7 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: k_notificationCenter_changeTheming), object: nil)
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(moveFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_moveFile), object: nil)
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(renameFile(_:)), name: NSNotification.Name(rawValue: k_notificationCenter_renameFile), object: nil)
|
|
|
-
|
|
|
- self.navigationItem.leftBarButtonItem = gridButton
|
|
|
-
|
|
|
+
|
|
|
mediaCommandView = Bundle.main.loadNibNamed("NCMediaCommandView", owner: self, options: nil)?.first as? NCMediaCommandView
|
|
|
self.view.addSubview(mediaCommandView!)
|
|
|
mediaCommandView?.mediaView = self
|
|
@@ -132,6 +110,40 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
|
|
|
changeTheming()
|
|
|
}
|
|
|
|
|
|
+ override func viewWillAppear(_ animated: Bool) {
|
|
|
+ super.viewWillAppear(animated)
|
|
|
+ }
|
|
|
+
|
|
|
+ override func viewDidAppear(_ animated: Bool) {
|
|
|
+ super.viewDidAppear(animated)
|
|
|
+
|
|
|
+ mediaCommandTitle()
|
|
|
+ removeDeletedFile()
|
|
|
+ searchNewPhotoVideo()
|
|
|
+ }
|
|
|
+
|
|
|
+ override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
|
|
+ super.viewWillTransition(to: size, with: coordinator)
|
|
|
+
|
|
|
+ coordinator.animate(alongsideTransition: nil) { _ in
|
|
|
+ self.reloadDataThenPerform { }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override var preferredStatusBarStyle: UIStatusBarStyle {
|
|
|
+ return .lightContent
|
|
|
+ }
|
|
|
+
|
|
|
+ //MARK: - Command
|
|
|
+
|
|
|
+ func mediaCommandTitle() {
|
|
|
+ if let cell = collectionView?.visibleCells.first as? NCGridMediaCell {
|
|
|
+ if cell.date != nil {
|
|
|
+ mediaCommandView!.title.text = CCUtility.getTitleSectionDate(cell.date)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@objc func zoomOutGrid() {
|
|
|
UIView.animate(withDuration: 0.0, animations: {
|
|
|
if(self.gridLayout.itemPerLine + 1 < self.kMaxImageGrid) {
|
|
@@ -162,23 +174,105 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- override func viewWillAppear(_ animated: Bool) {
|
|
|
- super.viewWillAppear(animated)
|
|
|
- }
|
|
|
-
|
|
|
- override func viewDidAppear(_ animated: Bool) {
|
|
|
- super.viewDidAppear(animated)
|
|
|
-
|
|
|
- mediaCommandTitle()
|
|
|
- searchNewPhotoVideo()
|
|
|
+ @objc func touchUpInsideMenuButtonSwitch(_ sender: Any) {
|
|
|
+
|
|
|
+ UIView.animate(withDuration: 0.0, animations: {
|
|
|
+ if(self.gridLayout.itemPerLine + 1 < self.kMaxImageGrid && self.gridLayout.increasing) {
|
|
|
+ self.gridLayout.itemPerLine+=1
|
|
|
+ } else {
|
|
|
+ self.gridLayout.increasing = false
|
|
|
+ self.gridLayout.itemPerLine-=1
|
|
|
+ }
|
|
|
+ if(self.gridLayout.itemPerLine == 0) {
|
|
|
+ self.gridLayout.increasing = true
|
|
|
+ self.gridLayout.itemPerLine = 2
|
|
|
+ }
|
|
|
+
|
|
|
+ self.collectionView.collectionViewLayout.invalidateLayout()
|
|
|
+ CCUtility.setMediaWidthImage(Int(self.gridLayout.itemPerLine))
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
- override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
|
|
- super.viewWillTransition(to: size, with: coordinator)
|
|
|
-
|
|
|
- coordinator.animate(alongsideTransition: nil) { _ in
|
|
|
- self.reloadDataThenPerform { }
|
|
|
+ @objc func touchUpInsideMenuButtonMore(_ sender: Any) {
|
|
|
+ let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
|
|
|
+ var actions: [NCMenuAction] = []
|
|
|
+
|
|
|
+ if !isEditMode {
|
|
|
+ actions.append(
|
|
|
+ NCMenuAction(
|
|
|
+ title: NSLocalizedString("_select_", comment: ""),
|
|
|
+ icon: CCGraphics.changeThemingColorImage(UIImage(named: "selectFull"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
|
|
|
+ action: { menuAction in
|
|
|
+ self.isEditMode = true
|
|
|
+ }
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ actions.append(
|
|
|
+ NCMenuAction(
|
|
|
+ title: NSLocalizedString(filterTypeFileImage ? "_media_viewimage_show_" : "_media_viewimage_hide_", comment: ""),
|
|
|
+ icon: CCGraphics.changeThemingColorImage(UIImage(named: filterTypeFileImage ? "imageno" : "imageyes"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
|
|
|
+ action: { menuAction in
|
|
|
+ self.filterTypeFileImage = !self.filterTypeFileImage
|
|
|
+ self.reloadDataSource()
|
|
|
+ }
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ actions.append(
|
|
|
+ NCMenuAction(
|
|
|
+ title: NSLocalizedString(filterTypeFileVideo ? "_media_viewvideo_show_" : "_media_viewvideo_hide_", comment: ""),
|
|
|
+ icon: CCGraphics.changeThemingColorImage(UIImage(named: filterTypeFileVideo ? "videono" : "videoyes"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
|
|
|
+ action: { menuAction in
|
|
|
+ self.filterTypeFileVideo = !self.filterTypeFileVideo
|
|
|
+ self.reloadDataSource()
|
|
|
+ }
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ actions.append(
|
|
|
+ NCMenuAction(
|
|
|
+ title: NSLocalizedString("_deselect_", comment: ""),
|
|
|
+ icon: CCGraphics.changeThemingColorImage(UIImage(named: "cancel"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
|
|
|
+ action: { menuAction in
|
|
|
+ self.isEditMode = false
|
|
|
+ self.selectocId.removeAll()
|
|
|
+ self.reloadDataThenPerform { }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ actions.append(
|
|
|
+ NCMenuAction(
|
|
|
+ title: NSLocalizedString("_delete_", comment: ""),
|
|
|
+ icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
|
|
|
+ action: { menuAction in
|
|
|
+ self.isEditMode = false
|
|
|
+ // copy in arrayDeleteMetadata
|
|
|
+ for ocId in self.selectocId {
|
|
|
+ if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "ocId == %@", ocId)) {
|
|
|
+ self.appDelegate.arrayDeleteMetadata.add(metadata)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if let metadata = self.appDelegate.arrayDeleteMetadata.firstObject {
|
|
|
+ self.appDelegate.arrayDeleteMetadata.removeObject(at: 0)
|
|
|
+ NCNetworking.shared.deleteMetadata(metadata as! tableMetadata, account: self.appDelegate.activeAccount, url: self.appDelegate.activeUrl) { (errorCode, errorDescription) in }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ )
|
|
|
}
|
|
|
+
|
|
|
+ mainMenuViewController.actions = actions
|
|
|
+ let menuPanelController = NCMenuPanelController()
|
|
|
+ menuPanelController.parentPresenter = self
|
|
|
+ menuPanelController.delegate = mainMenuViewController
|
|
|
+ menuPanelController.set(contentViewController: mainMenuViewController)
|
|
|
+ menuPanelController.track(scrollView: mainMenuViewController.tableView)
|
|
|
+
|
|
|
+ self.present(menuPanelController, animated: true, completion: nil)
|
|
|
}
|
|
|
|
|
|
//MARK: - NotificationCenter
|
|
@@ -191,10 +285,6 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
|
|
|
|
|
|
self.navigationController?.setNavigationBarHidden(true, animated: false)
|
|
|
}
|
|
|
-
|
|
|
- override var preferredStatusBarStyle: UIStatusBarStyle {
|
|
|
- return .lightContent
|
|
|
- }
|
|
|
|
|
|
@objc func deleteFile(_ notification: NSNotification) {
|
|
|
if let userInfo = notification.userInfo as NSDictionary? {
|
|
@@ -278,100 +368,6 @@ class NCMedia: UIViewController, DropdownMenuDelegate, DZNEmptyDataSetSource, DZ
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
- // MARK: IBAction
|
|
|
-
|
|
|
- @objc func touchUpInsideMenuButtonSwitch(_ sender: Any) {
|
|
|
-
|
|
|
- UIView.animate(withDuration: 0.0, animations: {
|
|
|
- if(self.gridLayout.itemPerLine + 1 < self.kMaxImageGrid && self.gridLayout.increasing) {
|
|
|
- self.gridLayout.itemPerLine+=1
|
|
|
- } else {
|
|
|
- self.gridLayout.increasing = false
|
|
|
- self.gridLayout.itemPerLine-=1
|
|
|
- }
|
|
|
- if(self.gridLayout.itemPerLine == 0) {
|
|
|
- self.gridLayout.increasing = true
|
|
|
- self.gridLayout.itemPerLine = 2
|
|
|
- }
|
|
|
-
|
|
|
- self.collectionView.collectionViewLayout.invalidateLayout()
|
|
|
- CCUtility.setMediaWidthImage(Int(self.gridLayout.itemPerLine))
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- @objc func touchUpInsideMenuButtonMore(_ sender: Any) {
|
|
|
- let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
|
|
|
- var actions: [NCMenuAction] = []
|
|
|
-
|
|
|
- if !isEditMode {
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString("_select_", comment: ""),
|
|
|
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "selectFull"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
|
|
|
- action: { menuAction in
|
|
|
- self.isEditMode = true
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
-
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString(filterTypeFileImage ? "_media_viewimage_show_" : "_media_viewimage_hide_", comment: ""),
|
|
|
- icon: CCGraphics.changeThemingColorImage(UIImage(named: filterTypeFileImage ? "imageno" : "imageyes"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
|
|
|
- action: { menuAction in
|
|
|
- self.filterTypeFileImage = !self.filterTypeFileImage
|
|
|
- self.reloadDataSource()
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
-
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString(filterTypeFileVideo ? "_media_viewvideo_show_" : "_media_viewvideo_hide_", comment: ""),
|
|
|
- icon: CCGraphics.changeThemingColorImage(UIImage(named: filterTypeFileVideo ? "videono" : "videoyes"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
|
|
|
- action: { menuAction in
|
|
|
- self.filterTypeFileVideo = !self.filterTypeFileVideo
|
|
|
- self.reloadDataSource()
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString("_deselect_", comment: ""),
|
|
|
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "cancel"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
|
|
|
- action: { menuAction in
|
|
|
- self.isEditMode = false
|
|
|
- self.selectocId.removeAll()
|
|
|
- self.reloadDataThenPerform {
|
|
|
- }
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
-
|
|
|
- actions.append(
|
|
|
- NCMenuAction(
|
|
|
- title: NSLocalizedString("_delete_", comment: ""),
|
|
|
- icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: .red),
|
|
|
- action: { menuAction in
|
|
|
- self.deleteItems()
|
|
|
- }
|
|
|
- )
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- mainMenuViewController.actions = actions
|
|
|
- let menuPanelController = NCMenuPanelController()
|
|
|
- menuPanelController.parentPresenter = self
|
|
|
- menuPanelController.delegate = mainMenuViewController
|
|
|
- menuPanelController.set(contentViewController: mainMenuViewController)
|
|
|
- menuPanelController.track(scrollView: mainMenuViewController.tableView)
|
|
|
-
|
|
|
- self.present(menuPanelController, animated: true, completion: nil)
|
|
|
- }
|
|
|
-
|
|
|
// MARK: SEGUE
|
|
|
|
|
|
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
|
@@ -452,53 +448,6 @@ extension NCMedia: UICollectionViewDataSource {
|
|
|
CATransaction.commit()
|
|
|
}
|
|
|
|
|
|
- func mediaCommandTitle() {
|
|
|
- if let cell = collectionView?.visibleCells.first as? NCGridMediaCell {
|
|
|
- if cell.date != nil {
|
|
|
- mediaCommandView!.title.text = CCUtility.getTitleSectionDate(cell.date)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /*
|
|
|
- func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
|
|
-
|
|
|
- switch kind {
|
|
|
- case UICollectionView.elementKindSectionFooter:
|
|
|
- let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionFooter", for: indexPath) as! NCSectionFooter
|
|
|
- footer.setTitleLabel(sectionDatasource: sectionDatasource)
|
|
|
- return footer
|
|
|
-
|
|
|
- default:
|
|
|
- return UICollectionReusableView()
|
|
|
- }
|
|
|
- /*
|
|
|
-
|
|
|
- let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "sectionHeader", for: indexPath) as! NCSectionMediaHeader
|
|
|
-
|
|
|
- header.setTitleLabel(sectionDatasource: sectionDatasource, section: indexPath.section)
|
|
|
- header.labelSection.textColor = .white
|
|
|
- header.labelHeightConstraint.constant = 20
|
|
|
- header.labelSection.layer.cornerRadius = 10
|
|
|
- header.labelSection.layer.backgroundColor = UIColor(red: 152.0/255.0, green: 167.0/255.0, blue: 181.0/255.0, alpha: 0.8).cgColor
|
|
|
- let width = header.labelSection.intrinsicContentSize.width + 30
|
|
|
- let leading = collectionView.bounds.width / 2 - width / 2
|
|
|
- header.labelWidthConstraint.constant = width
|
|
|
- header.labelLeadingConstraint.constant = leading
|
|
|
-
|
|
|
- return header
|
|
|
-
|
|
|
- */
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
- /*
|
|
|
- func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
|
- let sections = sectionDatasource.sectionArrayRow.allKeys.count
|
|
|
- return sections
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
|
|
|
return metadatas.count
|
|
@@ -563,7 +512,7 @@ extension NCMedia: UICollectionViewDataSource {
|
|
|
extension NCMedia: UICollectionViewDelegateFlowLayout {
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
|
|
|
- return CGSize(width: collectionView.frame.width, height: sectionHeaderHeight)
|
|
|
+ return CGSize(width: collectionView.frame.width, height: 0)
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
|
|
@@ -694,26 +643,6 @@ extension NCMedia {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func deleteItems() {
|
|
|
-
|
|
|
- self.isEditMode = false
|
|
|
-
|
|
|
- if (appDelegate.activeAccount == nil || appDelegate.activeAccount.count == 0 || appDelegate.maintenanceMode == true) {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // copy in arrayDeleteMetadata
|
|
|
- for ocId in selectocId {
|
|
|
- if let metadata = NCManageDatabase.sharedInstance.getMetadata(predicate: NSPredicate(format: "ocId == %@", ocId)) {
|
|
|
- appDelegate.arrayDeleteMetadata.add(metadata)
|
|
|
- }
|
|
|
- }
|
|
|
- if let metadata = appDelegate.arrayDeleteMetadata.firstObject {
|
|
|
- appDelegate.arrayDeleteMetadata.removeObject(at: 0)
|
|
|
- NCNetworking.shared.deleteMetadata(metadata as! tableMetadata, account: appDelegate.activeAccount, url: appDelegate.activeUrl) { (errorCode, errorDescription) in }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private func downloadThumbnail() {
|
|
|
guard let collectionView = self.collectionView else { return }
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
|