NCTrash+SelectTabBarDelegate.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // NCTrash+SelectTabBarDelegate.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 18/03/24.
  6. // Copyright © 2024 Marino Faggiana. All rights reserved.
  7. //
  8. // This program is free software: you can redistribute it and/or modify
  9. // it under the terms of the GNU General Public License as published by
  10. // the Free Software Foundation, either version 3 of the License, or
  11. // (at your option) any later version.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU General Public License
  19. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. //
  21. import Foundation
  22. extension NCTrash: NCTrashSelectTabBarDelegate {
  23. func onListSelected() {
  24. if layoutForView?.layout == NCGlobal.shared.layoutGrid {
  25. // list layout
  26. layoutForView?.layout = NCGlobal.shared.layoutList
  27. NCManageDatabase.shared.setLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: "", layout: layoutForView?.layout)
  28. self.collectionView.reloadData()
  29. self.collectionView.collectionViewLayout.invalidateLayout()
  30. self.collectionView.setCollectionViewLayout(self.listLayout, animated: true)
  31. }
  32. }
  33. func onGridSelected() {
  34. if layoutForView?.layout == NCGlobal.shared.layoutList {
  35. // grid layout
  36. layoutForView?.layout = NCGlobal.shared.layoutGrid
  37. NCManageDatabase.shared.setLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: "", layout: layoutForView?.layout)
  38. self.collectionView.reloadData()
  39. self.collectionView.collectionViewLayout.invalidateLayout()
  40. self.collectionView.setCollectionViewLayout(self.gridLayout, animated: true)
  41. }
  42. }
  43. func selectAll() {
  44. if !selectOcId.isEmpty, datasource.count == selectOcId.count {
  45. selectOcId = []
  46. } else {
  47. selectOcId = self.datasource.compactMap({ $0.fileId })
  48. }
  49. tabBarSelect.update(selectOcId: selectOcId)
  50. collectionView.reloadData()
  51. }
  52. func recover() {
  53. selectOcId.forEach(restoreItem)
  54. setEditMode(false)
  55. }
  56. func delete() {
  57. selectOcId.forEach(deleteItem)
  58. setEditMode(false)
  59. }
  60. func setEditMode(_ editMode: Bool) {
  61. isEditMode = editMode
  62. selectOcId.removeAll()
  63. setNavigationRightItems(enableMenu: !editMode)
  64. collectionView.reloadData()
  65. }
  66. }