NCTrash+SelectTabBarDelegate.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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()
  64. navigationController?.interactivePopGestureRecognizer?.isEnabled = !editMode
  65. navigationItem.hidesBackButton = editMode
  66. collectionView.reloadData()
  67. }
  68. }