NCTrash+Menu.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. // Copyright © 2022 Henrik Storch. All rights reserved.
  8. //
  9. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  10. // Author Henrik Storch <henrik.storch@nextcloud.com>
  11. //
  12. // This program is free software: you can redistribute it and/or modify
  13. // it under the terms of the GNU General Public License as published by
  14. // the Free Software Foundation, either version 3 of the License, or
  15. // (at your option) any later version.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of the GNU General Public License
  23. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. //
  25. import UIKit
  26. import FloatingPanel
  27. import NCCommunication
  28. extension NCTrash {
  29. func toggleMenuMoreHeader() {
  30. var actions: [NCMenuAction] = []
  31. actions.append(
  32. NCMenuAction(
  33. title: NSLocalizedString("_trash_restore_all_", comment: ""),
  34. icon: NCUtility.shared.loadImage(named: "restore"),
  35. action: { _ in
  36. self.datasource.forEach({ self.restoreItem(with: $0.fileId) })
  37. }
  38. )
  39. )
  40. actions.append(
  41. NCMenuAction(
  42. title: NSLocalizedString("_trash_delete_all_", comment: ""),
  43. icon: NCUtility.shared.loadImage(named: "trash"),
  44. action: { _ in
  45. let alert = UIAlertController(title: NSLocalizedString("_trash_delete_all_", comment: ""), message: "", preferredStyle: .alert)
  46. alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .destructive, handler: { _ in
  47. self.emptyTrash()
  48. }))
  49. alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel))
  50. self.present(alert, animated: true, completion: nil)
  51. }
  52. )
  53. )
  54. presentMenu(with: actions)
  55. }
  56. func toggleMenuMoreList(with objectId: String, image: UIImage?) {
  57. var actions: [NCMenuAction] = []
  58. guard let tableTrash = NCManageDatabase.shared.getTrashItem(fileId: objectId, account: appDelegate.account) else {
  59. return
  60. }
  61. var iconHeader: UIImage!
  62. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
  63. iconHeader = icon
  64. } else {
  65. if tableTrash.directory {
  66. iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.gray, size: 50)
  67. } else {
  68. iconHeader = UIImage(named: tableTrash.iconName)
  69. }
  70. }
  71. actions.append(
  72. NCMenuAction(
  73. title: tableTrash.trashbinFileName,
  74. icon: iconHeader,
  75. action: nil
  76. )
  77. )
  78. actions.append(
  79. NCMenuAction(
  80. title: NSLocalizedString("_delete_", comment: ""),
  81. icon: NCUtility.shared.loadImage(named: "trash"),
  82. action: { _ in
  83. self.deleteItem(with: objectId)
  84. }
  85. )
  86. )
  87. self.presentMenu(with: actions)
  88. }
  89. func toggleMenuMoreGrid(with objectId: String, namedButtonMore: String, image: UIImage?) {
  90. var actions: [NCMenuAction] = []
  91. guard let tableTrash = NCManageDatabase.shared.getTrashItem(fileId: objectId, account: appDelegate.account) else {
  92. return
  93. }
  94. var iconHeader: UIImage!
  95. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
  96. iconHeader = icon
  97. } else {
  98. if tableTrash.directory {
  99. iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.gray, size: 50)
  100. } else {
  101. iconHeader = UIImage(named: tableTrash.iconName)
  102. }
  103. }
  104. actions.append(
  105. NCMenuAction(
  106. title: tableTrash.trashbinFileName,
  107. icon: iconHeader,
  108. action: nil
  109. )
  110. )
  111. actions.append(
  112. NCMenuAction(
  113. title: NSLocalizedString("_restore_", comment: ""),
  114. icon: UIImage(named: "restore")!.image(color: NCBrandColor.shared.gray, size: 50),
  115. action: { _ in
  116. self.restoreItem(with: objectId)
  117. }
  118. )
  119. )
  120. actions.append(
  121. NCMenuAction(
  122. title: NSLocalizedString("_delete_", comment: ""),
  123. icon: NCUtility.shared.loadImage(named: "trash"),
  124. action: { _ in
  125. self.deleteItem(with: objectId)
  126. }
  127. )
  128. )
  129. presentMenu(with: actions)
  130. }
  131. }