CCFavorites+Menu.swift 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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(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(
  26. MenuAction(
  27. title: NSLocalizedString("_remove_favorites_", comment: ""),
  28. icon: CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.yellowFavorite),
  29. action: { menuAction in
  30. self.settingFavorite(metadata, favorite: false)
  31. }
  32. )
  33. )
  34. }
  35. actions.append(
  36. MenuAction(
  37. title: NSLocalizedString("_details_", comment: ""),
  38. icon: CCGraphics.changeThemingColorImage(UIImage(named: "details"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  39. action: { menuAction in
  40. NCMainCommon.sharedInstance.openShare(ViewController: self, metadata: metadata, indexPage: 0)
  41. }
  42. )
  43. )
  44. if(!metadata.directory && !NCBrandOptions.sharedInstance.disable_openin_file) {
  45. actions.append(
  46. MenuAction(
  47. title: NSLocalizedString("_open_in_", comment: ""),
  48. icon: CCGraphics.changeThemingColorImage(UIImage(named: "openFile"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  49. action: { menuAction in
  50. self.tableView.setEditing(false, animated: true)
  51. NCMainCommon.sharedInstance.downloadOpen(metadata: metadata, selector: selectorOpenIn)
  52. }
  53. )
  54. )
  55. }
  56. actions.append(
  57. MenuAction(
  58. title: NSLocalizedString("_delete_", comment: ""),
  59. icon: CCGraphics.changeThemingColorImage(UIImage(named: "trash"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon),
  60. action: { menuAction in
  61. self.actionDelete(indexPath)
  62. }
  63. )
  64. )
  65. return actions
  66. }
  67. @objc func toggleMoreMenu(viewController: UIViewController, indexPath: IndexPath, metadata: tableMetadata) {
  68. let mainMenuViewController = UIStoryboard.init(name: "Menu", bundle: nil).instantiateViewController(withIdentifier: "MainMenuTableViewController") as! MainMenuTableViewController
  69. mainMenuViewController.actions = self.initMoreMenu(indexPath: indexPath, metadata: metadata)
  70. let menuPanelController = MenuPanelController()
  71. menuPanelController.panelWidth = Int(viewController.view.frame.width)
  72. menuPanelController.delegate = mainMenuViewController
  73. menuPanelController.set(contentViewController: mainMenuViewController)
  74. menuPanelController.track(scrollView: mainMenuViewController.tableView)
  75. viewController.present(menuPanelController, animated: true, completion: nil)
  76. }
  77. }