NCCollectionViewCommon+MediaLayout.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // NCCollectionViewCommon+MediaLayout.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 13/07/24.
  6. // Copyright © 2024 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 Foundation
  24. import UIKit
  25. import NextcloudKit
  26. extension NCCollectionViewCommon: NCMediaLayoutDelegate {
  27. func getColumnCount() -> Int {
  28. if let column = self.layoutForView?.columnPhoto, column > 0 {
  29. return column
  30. }
  31. self.layoutForView?.columnPhoto = 3
  32. return 3
  33. }
  34. func getLayout() -> String? {
  35. return NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewFiles, serverUrl: serverUrl)?.layout
  36. }
  37. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float {
  38. return Float(sizeForHeaderInSection(section: section).height)
  39. }
  40. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForFooterInSection section: Int) -> Float {
  41. return Float(sizeForFooterInSection(section: section).height)
  42. }
  43. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForSection section: Int) -> UIEdgeInsets {
  44. return .zero
  45. }
  46. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForHeaderInSection section: Int) -> UIEdgeInsets {
  47. return .zero
  48. }
  49. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForFooterInSection section: Int) -> UIEdgeInsets {
  50. return .zero
  51. }
  52. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float {
  53. return 1.0
  54. }
  55. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize {
  56. let size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount))
  57. if typeLayout == NCGlobal.shared.layoutPhotoRatio {
  58. let metadata = self.dataSource.metadatas[indexPath.row]
  59. if metadata.imageSize != CGSize.zero {
  60. return metadata.imageSize
  61. } else if let size = NCImageCache.shared.getPreviewSizeCache(ocId: metadata.ocId, etag: metadata.etag) {
  62. return size
  63. }
  64. }
  65. return size
  66. }
  67. }