NCMedia+MediaLayout.swift 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // NCMedia+MediaLayout.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 16/07/24.
  6. // Copyright © 2024 Marino Faggiana. All rights reserved.
  7. //
  8. // NCMedia+CollectionViewDelegate.swift
  9. // Nextcloud
  10. //
  11. // Created by Marino Faggiana on 16/07/24.
  12. // Copyright © 2024 Marino Faggiana. All rights reserved.
  13. //
  14. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  15. //
  16. // This program is free software: you can redistribute it and/or modify
  17. // it under the terms of the GNU General Public License as published by
  18. // the Free Software Foundation, either version 3 of the License, or
  19. // (at your option) any later version.
  20. //
  21. // This program is distributed in the hope that it will be useful,
  22. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. // GNU General Public License for more details.
  25. //
  26. // You should have received a copy of the GNU General Public License
  27. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. //
  29. import UIKit
  30. import NextcloudKit
  31. import RealmSwift
  32. extension NCMedia: NCMediaLayoutDelegate {
  33. func getColumnCount() -> Int {
  34. let layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "")
  35. if let column = layoutForView?.columnPhoto, column > 0 {
  36. return column
  37. }
  38. return 3
  39. }
  40. func getLayout() -> String? {
  41. return self.layoutType
  42. }
  43. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float {
  44. var height: Double = 0
  45. if metadatas?.count ?? 0 == 0 {
  46. height = NCGlobal.shared.getHeightHeaderEmptyData(view: view, portraitOffset: 0, landscapeOffset: -20)
  47. }
  48. return Float(height)
  49. }
  50. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForFooterInSection section: Int) -> Float {
  51. return .zero
  52. }
  53. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForSection section: Int) -> UIEdgeInsets {
  54. return .zero
  55. }
  56. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForHeaderInSection section: Int) -> UIEdgeInsets {
  57. return .zero
  58. }
  59. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForFooterInSection section: Int) -> UIEdgeInsets {
  60. return .zero
  61. }
  62. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float {
  63. return 1.0
  64. }
  65. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize {
  66. let size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount))
  67. if typeLayout == NCGlobal.shared.mediaLayoutRatio {
  68. guard let metadatas = self.metadatas,
  69. let metadata = metadatas[indexPath.row] else { return size }
  70. if metadata.imageSize != CGSize.zero {
  71. return metadata.imageSize
  72. } else if let size = imageCache.getPreviewSizeCache(ocId: metadata.ocId, etag: metadata.etag) {
  73. return size
  74. }
  75. }
  76. return size
  77. }
  78. }