NCTrash+Menu.swift 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 UIKit
  24. import FloatingPanel
  25. import NCCommunication
  26. extension NCTrash {
  27. func toggleMenuMoreHeader() {
  28. let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  29. var actions: [NCMenuAction] = []
  30. if isEditMode {
  31. actions.append(
  32. NCMenuAction(
  33. title: NSLocalizedString("_trash_delete_selected_", comment: ""),
  34. icon: NCUtility.shared.loadImage(named: "trash"),
  35. action: { menuAction in
  36. let alert = UIAlertController(title: NSLocalizedString("_trash_delete_selected_", comment: ""), message: "", preferredStyle: .alert)
  37. alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .destructive, handler: { _ in
  38. for ocId in self.selectOcId {
  39. self.deleteItem(with: ocId)
  40. }
  41. self.isEditMode = false
  42. self.selectOcId.removeAll()
  43. self.collectionView.reloadData()
  44. }))
  45. alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
  46. }))
  47. self.present(alert, animated: true, completion: nil)
  48. }
  49. )
  50. )
  51. } else {
  52. actions.append(
  53. NCMenuAction(
  54. title: NSLocalizedString("_trash_delete_all_", comment: ""),
  55. icon: NCUtility.shared.loadImage(named: "trash"),
  56. action: { menuAction in
  57. let alert = UIAlertController(title: NSLocalizedString("_trash_delete_all_", comment: ""), message: "", preferredStyle: .alert)
  58. alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .destructive, handler: { _ in
  59. self.emptyTrash()
  60. }))
  61. alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
  62. }))
  63. self.present(alert, animated: true, completion: nil)
  64. }
  65. )
  66. )
  67. }
  68. menuViewController.actions = actions
  69. let menuPanelController = NCMenuPanelController()
  70. menuPanelController.parentPresenter = self
  71. menuPanelController.delegate = menuViewController
  72. menuPanelController.set(contentViewController: menuViewController)
  73. menuPanelController.track(scrollView: menuViewController.tableView)
  74. self.present(menuPanelController, animated: true, completion: nil)
  75. }
  76. func toggleMenuMoreList(with objectId: String, image: UIImage?) {
  77. let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  78. var actions: [NCMenuAction] = []
  79. guard let tableTrash = NCManageDatabase.shared.getTrashItem(fileId: objectId, account: appDelegate.account) else {
  80. return
  81. }
  82. var iconHeader: UIImage!
  83. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
  84. iconHeader = icon
  85. } else {
  86. if(tableTrash.directory) {
  87. iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.gray, size: 50)
  88. } else {
  89. iconHeader = UIImage(named: tableTrash.iconName)
  90. }
  91. }
  92. actions.append(
  93. NCMenuAction(
  94. title: tableTrash.trashbinFileName,
  95. icon: iconHeader,
  96. action: nil
  97. )
  98. )
  99. actions.append(
  100. NCMenuAction(
  101. title: NSLocalizedString("_delete_", comment: ""),
  102. icon: NCUtility.shared.loadImage(named: "trash"),
  103. action: { menuAction in
  104. self.deleteItem(with: objectId)
  105. }
  106. )
  107. )
  108. menuViewController.actions = actions
  109. let menuPanelController = NCMenuPanelController()
  110. menuPanelController.parentPresenter = self
  111. menuPanelController.delegate = menuViewController
  112. menuPanelController.set(contentViewController: menuViewController)
  113. menuPanelController.track(scrollView: menuViewController.tableView)
  114. self.present(menuPanelController, animated: true, completion: nil)
  115. }
  116. func toggleMenuMoreGrid(with objectId: String, namedButtonMore: String, image: UIImage?) {
  117. let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  118. var actions: [NCMenuAction] = []
  119. guard let tableTrash = NCManageDatabase.shared.getTrashItem(fileId: objectId, account: appDelegate.account) else {
  120. return
  121. }
  122. var iconHeader: UIImage!
  123. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
  124. iconHeader = icon
  125. } else {
  126. if(tableTrash.directory) {
  127. iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.gray, size: 50)
  128. } else {
  129. iconHeader = UIImage(named: tableTrash.iconName)
  130. }
  131. }
  132. actions.append(
  133. NCMenuAction(
  134. title: tableTrash.trashbinFileName,
  135. icon: iconHeader,
  136. action: nil
  137. )
  138. )
  139. actions.append(
  140. NCMenuAction(
  141. title: NSLocalizedString("_restore_", comment: ""),
  142. icon: UIImage(named: "restore")!.image(color: NCBrandColor.shared.gray, size: 50),
  143. action: { menuAction in
  144. self.restoreItem(with: objectId)
  145. }
  146. )
  147. )
  148. actions.append(
  149. NCMenuAction(
  150. title: NSLocalizedString("_delete_", comment: ""),
  151. icon: NCUtility.shared.loadImage(named: "trash"),
  152. action: { menuAction in
  153. self.deleteItem(with: objectId)
  154. }
  155. )
  156. )
  157. menuViewController.actions = actions
  158. let menuPanelController = NCMenuPanelController()
  159. menuPanelController.parentPresenter = self
  160. menuPanelController.delegate = menuViewController
  161. menuPanelController.set(contentViewController: menuViewController)
  162. menuPanelController.track(scrollView: menuViewController.tableView)
  163. self.present(menuPanelController, animated: true, completion: nil)
  164. }
  165. }