NCTrash+Menu.swift 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. 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. presentMenu(with: actions)
  68. }
  69. func toggleMenuMoreList(with objectId: String, image: UIImage?) {
  70. var actions: [NCMenuAction] = []
  71. guard let tableTrash = NCManageDatabase.shared.getTrashItem(fileId: objectId, account: appDelegate.account) else {
  72. return
  73. }
  74. var iconHeader: UIImage!
  75. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
  76. iconHeader = icon
  77. } else {
  78. if(tableTrash.directory) {
  79. iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.gray, size: 50)
  80. } else {
  81. iconHeader = UIImage(named: tableTrash.iconName)
  82. }
  83. }
  84. actions.append(
  85. NCMenuAction(
  86. title: tableTrash.trashbinFileName,
  87. icon: iconHeader,
  88. action: nil
  89. )
  90. )
  91. actions.append(
  92. NCMenuAction(
  93. title: NSLocalizedString("_delete_", comment: ""),
  94. icon: NCUtility.shared.loadImage(named: "trash"),
  95. action: { menuAction in
  96. self.deleteItem(with: objectId)
  97. }
  98. )
  99. )
  100. menuViewController.actions = actions
  101. let menuPanelController = NCMenuPanelController()
  102. menuPanelController.parentPresenter = self
  103. menuPanelController.delegate = menuViewController
  104. menuPanelController.set(contentViewController: menuViewController)
  105. menuPanelController.track(scrollView: menuViewController.tableView)
  106. self.present(menuPanelController, animated: true, completion: nil)
  107. }
  108. func toggleMenuMoreGrid(with objectId: String, namedButtonMore: String, image: UIImage?) {
  109. var actions: [NCMenuAction] = []
  110. guard let tableTrash = NCManageDatabase.shared.getTrashItem(fileId: objectId, account: appDelegate.account) else {
  111. return
  112. }
  113. var iconHeader: UIImage!
  114. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
  115. iconHeader = icon
  116. } else {
  117. if(tableTrash.directory) {
  118. iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.gray, size: 50)
  119. } else {
  120. iconHeader = UIImage(named: tableTrash.iconName)
  121. }
  122. }
  123. actions.append(
  124. NCMenuAction(
  125. title: tableTrash.trashbinFileName,
  126. icon: iconHeader,
  127. action: nil
  128. )
  129. )
  130. actions.append(
  131. NCMenuAction(
  132. title: NSLocalizedString("_restore_", comment: ""),
  133. icon: UIImage(named: "restore")!.image(color: NCBrandColor.shared.gray, size: 50),
  134. action: { menuAction in
  135. self.restoreItem(with: objectId)
  136. }
  137. )
  138. )
  139. actions.append(
  140. NCMenuAction(
  141. title: NSLocalizedString("_delete_", comment: ""),
  142. icon: NCUtility.shared.loadImage(named: "trash"),
  143. action: { menuAction in
  144. self.deleteItem(with: objectId)
  145. }
  146. )
  147. )
  148. presentMenu(with: actions)
  149. }
  150. }