NCCollectionViewCommon+MediaLayout.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 self.numberOfColumns == 0,
  29. let layoutForView = database.getLayoutForView(account: session.account, key: NCGlobal.shared.layoutViewFiles, serverUrl: self.serverUrl) {
  30. if layoutForView.columnPhoto > 0 {
  31. self.numberOfColumns = layoutForView.columnPhoto
  32. } else {
  33. self.numberOfColumns = 3
  34. }
  35. }
  36. return self.numberOfColumns
  37. }
  38. func getLayout() -> String? {
  39. return self.layoutType
  40. }
  41. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float {
  42. return Float(sizeForHeaderInSection(section: section).height)
  43. }
  44. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForFooterInSection section: Int) -> Float {
  45. return Float(sizeForFooterInSection(section: section).height)
  46. }
  47. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForSection section: Int) -> UIEdgeInsets {
  48. return .zero
  49. }
  50. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForHeaderInSection section: Int) -> UIEdgeInsets {
  51. return .zero
  52. }
  53. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForFooterInSection section: Int) -> UIEdgeInsets {
  54. return .zero
  55. }
  56. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float {
  57. return 1.0
  58. }
  59. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath, columnCount: Int, typeLayout: String) -> CGSize {
  60. if typeLayout == NCGlobal.shared.layoutPhotoSquare {
  61. return CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount))
  62. } else {
  63. guard let metadata = dataSource.getMetadata(indexPath: indexPath) else { return .zero }
  64. if metadata.imageSize != CGSize.zero {
  65. return metadata.imageSize
  66. } else if metadata.classFile == NKCommon.TypeClassFile.document.rawValue {
  67. let ext = NCGlobal.shared.getSizeExtension(column: self.numberOfColumns)
  68. if let image = self.utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext) {
  69. return image.size
  70. }
  71. }
  72. return CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount))
  73. }
  74. }
  75. }