NCTrash+Menu.swift 5.0 KB

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