NCTrash+SelectTabBarDelegate.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. import UIKit
  23. extension NCTrash: NCTrashSelectTabBarDelegate {
  24. func onListSelected() {
  25. if layoutForView?.layout == NCGlobal.shared.layoutGrid {
  26. layoutForView?.layout = NCGlobal.shared.layoutList
  27. self.database.setLayoutForView(account: session.account, key: layoutKey, serverUrl: "", layout: layoutForView?.layout)
  28. self.collectionView.reloadData()
  29. self.collectionView.setCollectionViewLayout(self.listLayout, animated: true)
  30. }
  31. }
  32. func onGridSelected() {
  33. if layoutForView?.layout == NCGlobal.shared.layoutList {
  34. layoutForView?.layout = NCGlobal.shared.layoutGrid
  35. self.database.setLayoutForView(account: session.account, key: layoutKey, serverUrl: "", layout: layoutForView?.layout)
  36. self.collectionView.reloadData()
  37. self.collectionView.setCollectionViewLayout(self.gridLayout, animated: true)
  38. }
  39. }
  40. func selectAll() {
  41. guard let datasource else { return }
  42. if !selectOcId.isEmpty, datasource.count == selectOcId.count {
  43. selectOcId = []
  44. } else {
  45. selectOcId = datasource.compactMap({ $0.fileId })
  46. }
  47. tabBarSelect.update(selectOcId: selectOcId)
  48. collectionView.reloadData()
  49. }
  50. func recover() {
  51. selectOcId.forEach(restoreItem)
  52. setEditMode(false)
  53. }
  54. func delete() {
  55. selectOcId.forEach(deleteItem)
  56. setEditMode(false)
  57. }
  58. func setEditMode(_ editMode: Bool) {
  59. isEditMode = editMode
  60. selectOcId.removeAll()
  61. setNavigationRightItems()
  62. navigationController?.interactivePopGestureRecognizer?.isEnabled = !editMode
  63. navigationItem.hidesBackButton = editMode
  64. collectionView.reloadData()
  65. }
  66. }