CCFavorites+Menu.swift 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // CCFavorites+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Philippe Weidmann on 24.01.20.
  6. // Copyright © 2020 TWS. All rights reserved.
  7. //
  8. import FloatingPanel
  9. extension CCFavorites {
  10. private func initMoreMenu(indexPath: IndexPath, metadata: tableMetadata) -> [MenuAction] {
  11. var actions = [MenuAction]()
  12. var iconHeader: UIImage!
  13. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileNameView)) {
  14. iconHeader = icon
  15. } else {
  16. if(metadata.directory){
  17. iconHeader = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)
  18. } else {
  19. iconHeader = UIImage(named: metadata.iconName)
  20. }
  21. }
  22. actions.append(MenuAction(title: metadata.fileNameView, icon: iconHeader, action: { menuAction in
  23. }))
  24. if(self.serverUrl == nil) {
  25. actions.append(MenuAction(title: NSLocalizedString("_remove_favorites_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite), action: { menuAction in
  26. self.settingFavorite(metadata, favorite: false)
  27. }))
  28. }
  29. actions.append(MenuAction(title: NSLocalizedString("_details_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  30. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  31. }))
  32. if(!metadata.directory && !NCBrandOptions.sharedInstance.disable_openin_file) {
  33. actions.append(MenuAction(title: NSLocalizedString("_open_in_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  34. self.tableView.setEditing(false, animated: true)
  35. NCMainCommon.sharedInstance.downloadOpen(metadata: metadata, selector: selectorOpenIn)
  36. }))
  37. }
  38. actions.append(MenuAction(title: NSLocalizedString("_delete_", comment: ""), icon: CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon), action: { menuAction in
  39. self.actionDelete(indexPath)
  40. }))
  41. return actions
  42. }
  43. @objc func toggleMoreMenu(viewController: UIViewController, indexPath: IndexPath, metadata: tableMetadata) {
  44. let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
  45. mainMenuViewController.actions = self.initMoreMenu(indexPath: indexPath, metadata: metadata)
  46. let menuPanelController = MenuPanelController()
  47. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  48. menuPanelController.delegate = mainMenuViewController
  49. menuPanelController.set(contentViewController: mainMenuViewController)
  50. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  51. viewController.present(menuPanelController, animated: true, completion: nil)
  52. }
  53. }