NCTrash+Menu.swift 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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: { _ 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: { _ 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: { _ in
  96. self.deleteItem(with: objectId)
  97. }
  98. )
  99. )
  100. self.presentMenu(with: actions)
  101. }
  102. func toggleMenuMoreGrid(with objectId: String, namedButtonMore: String, image: UIImage?) {
  103. var actions: [NCMenuAction] = []
  104. guard let tableTrash = NCManageDatabase.shared.getTrashItem(fileId: objectId, account: appDelegate.account) else {
  105. return
  106. }
  107. var iconHeader: UIImage!
  108. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
  109. iconHeader = icon
  110. } else {
  111. if tableTrash.directory {
  112. iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.gray, size: 50)
  113. } else {
  114. iconHeader = UIImage(named: tableTrash.iconName)
  115. }
  116. }
  117. actions.append(
  118. NCMenuAction(
  119. title: tableTrash.trashbinFileName,
  120. icon: iconHeader,
  121. action: nil
  122. )
  123. )
  124. actions.append(
  125. NCMenuAction(
  126. title: NSLocalizedString("_restore_", comment: ""),
  127. icon: UIImage(named: "restore")!.image(color: NCBrandColor.shared.gray, size: 50),
  128. action: { _ in
  129. self.restoreItem(with: objectId)
  130. }
  131. )
  132. )
  133. actions.append(
  134. NCMenuAction(
  135. title: NSLocalizedString("_delete_", comment: ""),
  136. icon: NCUtility.shared.loadImage(named: "trash"),
  137. action: { _ in
  138. self.deleteItem(with: objectId)
  139. }
  140. )
  141. )
  142. presentMenu(with: actions)
  143. }
  144. }