NCTrash+Menu.swift 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. actions.append(
  30. NCMenuAction(
  31. title: NSLocalizedString("_trash_restore_all_", comment: "")
  32. icon: NCUtility.shared.loadImage(named: "restore"),
  33. action: { _ in
  34. self.datasource.forEach({ self.restoreItem(with: $0.fileId) })
  35. }
  36. )
  37. )
  38. actions.append(
  39. NCMenuAction(
  40. title: NSLocalizedString("_trash_delete_all_", comment: ""),
  41. icon: NCUtility.shared.loadImage(named: "trash"),
  42. action: { _ in
  43. let alert = UIAlertController(title: NSLocalizedString("_trash_delete_all_", comment: ""), message: "", preferredStyle: .alert)
  44. alert.addAction(UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .destructive, handler: { _ in
  45. self.emptyTrash()
  46. }))
  47. alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
  48. }))
  49. self.present(alert, animated: true, completion: nil)
  50. }
  51. )
  52. )
  53. presentMenu(with: actions)
  54. }
  55. func toggleMenuMoreList(with objectId: String, image: UIImage?) {
  56. var actions: [NCMenuAction] = []
  57. guard let tableTrash = NCManageDatabase.shared.getTrashItem(fileId: objectId, account: appDelegate.account) else {
  58. return
  59. }
  60. var iconHeader: UIImage!
  61. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
  62. iconHeader = icon
  63. } else {
  64. if tableTrash.directory {
  65. iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.gray, size: 50)
  66. } else {
  67. iconHeader = UIImage(named: tableTrash.iconName)
  68. }
  69. }
  70. actions.append(
  71. NCMenuAction(
  72. title: tableTrash.trashbinFileName,
  73. icon: iconHeader,
  74. action: nil
  75. )
  76. )
  77. actions.append(
  78. NCMenuAction(
  79. title: NSLocalizedString("_delete_", comment: ""),
  80. icon: NCUtility.shared.loadImage(named: "trash"),
  81. action: { _ in
  82. self.deleteItem(with: objectId)
  83. }
  84. )
  85. )
  86. self.presentMenu(with: actions)
  87. }
  88. func toggleMenuMoreGrid(with objectId: String, namedButtonMore: String, image: UIImage?) {
  89. var actions: [NCMenuAction] = []
  90. guard let tableTrash = NCManageDatabase.shared.getTrashItem(fileId: objectId, account: appDelegate.account) else {
  91. return
  92. }
  93. var iconHeader: UIImage!
  94. if let icon = UIImage(contentsOfFile: CCUtility.getDirectoryProviderStorageIconOcId(tableTrash.fileId, etag: tableTrash.fileName)) {
  95. iconHeader = icon
  96. } else {
  97. if tableTrash.directory {
  98. iconHeader = UIImage(named: "folder")!.image(color: NCBrandColor.shared.gray, size: 50)
  99. } else {
  100. iconHeader = UIImage(named: tableTrash.iconName)
  101. }
  102. }
  103. actions.append(
  104. NCMenuAction(
  105. title: tableTrash.trashbinFileName,
  106. icon: iconHeader,
  107. action: nil
  108. )
  109. )
  110. actions.append(
  111. NCMenuAction(
  112. title: NSLocalizedString("_restore_", comment: ""),
  113. icon: UIImage(named: "restore")!.image(color: NCBrandColor.shared.gray, size: 50),
  114. action: { _ in
  115. self.restoreItem(with: objectId)
  116. }
  117. )
  118. )
  119. actions.append(
  120. NCMenuAction(
  121. title: NSLocalizedString("_delete_", comment: ""),
  122. icon: NCUtility.shared.loadImage(named: "trash"),
  123. action: { _ in
  124. self.deleteItem(with: objectId)
  125. }
  126. )
  127. )
  128. presentMenu(with: actions)
  129. }
  130. }