NCTrash+Menu.swift 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //
  2. // NCTrash+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 03/03/2021.
  6. // Copyright © 2021 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import FloatingPanel
  24. import NCCommunication
  25. extension NCTrash {
  26. func toggleMenuMoreHeader() {
  27. let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  28. var actions: [NCMenuAction] = []
  29. if isEditMode {
  30. actions.append(
  31. NCMenuAction(
  32. title: NSLocalizedString("_trash_delete_selected_", comment: ""),
  33. icon: NCUtility.shared.loadImage(named: "trash"),
  34. action: { menuAction in
  35. let alert = UIAlertController(title: NSLocalizedString("_trash_delete_selected_", comment: ""), message: "", preferredStyle: .alert)
  36. alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .destructive, handler: { _ in
  37. for ocId in self.selectOcId {
  38. self.deleteItem(with: ocId)
  39. }
  40. self.isEditMode = false
  41. self.selectOcId.removeAll()
  42. self.collectionView.reloadData()
  43. }))
  44. alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
  45. }))
  46. self.present(alert, animated: true, completion: nil)
  47. }
  48. )
  49. )
  50. } else {
  51. actions.append(
  52. NCMenuAction(
  53. title: NSLocalizedString("_trash_delete_all_", comment: ""),
  54. icon: NCUtility.shared.loadImage(named: "trash"),
  55. action: { menuAction in
  56. let alert = UIAlertController(title: NSLocalizedString("_trash_delete_all_", comment: ""), message: "", preferredStyle: .alert)
  57. alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .destructive, handler: { _ in
  58. self.emptyTrash()
  59. }))
  60. alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
  61. }))
  62. self.present(alert, animated: true, completion: nil)
  63. }
  64. )
  65. )
  66. }
  67. menuViewController.actions = actions
  68. let menuPanelController = NCMenuPanelController()
  69. menuPanelController.parentPresenter = self
  70. menuPanelController.delegate = menuViewController
  71. menuPanelController.set(contentViewController: menuViewController)
  72. menuPanelController.track(scrollView: menuViewController.tableView)
  73. self.present(menuPanelController, animated: true, completion: nil)
  74. }
  75. func toggleMenuMoreList(with objectId: String, image: UIImage?) {
  76. let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  77. var actions: [NCMenuAction] = []
  78. guard let tableTrash = NCManageDatabase.shared.getTrashItem(fileId: objectId, account: appDelegate.account) else {
  79. return
  80. }
  81. var iconHeader: UIImage!
  82. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
  83. iconHeader = icon
  84. } else {
  85. if(tableTrash.directory) {
  86. iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.icon, size: 50)
  87. } else {
  88. iconHeader = UIImage(named: tableTrash.iconName)
  89. }
  90. }
  91. actions.append(
  92. NCMenuAction(
  93. title: tableTrash.trashbinFileName,
  94. icon: iconHeader,
  95. action: nil
  96. )
  97. )
  98. actions.append(
  99. NCMenuAction(
  100. title: NSLocalizedString("_delete_", comment: ""),
  101. icon: NCUtility.shared.loadImage(named: "trash"),
  102. action: { menuAction in
  103. self.deleteItem(with: objectId)
  104. }
  105. )
  106. )
  107. menuViewController.actions = actions
  108. let menuPanelController = NCMenuPanelController()
  109. menuPanelController.parentPresenter = self
  110. menuPanelController.delegate = menuViewController
  111. menuPanelController.set(contentViewController: menuViewController)
  112. menuPanelController.track(scrollView: menuViewController.tableView)
  113. self.present(menuPanelController, animated: true, completion: nil)
  114. }
  115. func toggleMenuMoreGrid(with objectId: String, namedButtonMore: String, image: UIImage?) {
  116. let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  117. var actions: [NCMenuAction] = []
  118. guard let tableTrash = NCManageDatabase.shared.getTrashItem(fileId: objectId, account: appDelegate.account) else {
  119. return
  120. }
  121. var iconHeader: UIImage!
  122. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
  123. iconHeader = icon
  124. } else {
  125. if(tableTrash.directory) {
  126. iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.icon, size: 50)
  127. } else {
  128. iconHeader = UIImage(named: tableTrash.iconName)
  129. }
  130. }
  131. actions.append(
  132. NCMenuAction(
  133. title: tableTrash.trashbinFileName,
  134. icon: iconHeader,
  135. action: nil
  136. )
  137. )
  138. actions.append(
  139. NCMenuAction(
  140. title: NSLocalizedString("_restore_", comment: ""),
  141. icon: UIImage(named: "restore")!.image(color: NCBrandColor.shared.icon, size: 50),
  142. action: { menuAction in
  143. self.restoreItem(with: objectId)
  144. }
  145. )
  146. )
  147. actions.append(
  148. NCMenuAction(
  149. title: NSLocalizedString("_delete_", comment: ""),
  150. icon: NCUtility.shared.loadImage(named: "trash"),
  151. action: { menuAction in
  152. self.deleteItem(with: objectId)
  153. }
  154. )
  155. )
  156. menuViewController.actions = actions
  157. let menuPanelController = NCMenuPanelController()
  158. menuPanelController.parentPresenter = self
  159. menuPanelController.delegate = menuViewController
  160. menuPanelController.set(contentViewController: menuViewController)
  161. menuPanelController.track(scrollView: menuViewController.tableView)
  162. self.present(menuPanelController, animated: true, completion: nil)
  163. }
  164. }