NCMedia+MediaLayout.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. if self.numberOfColumns == 0,
  35. let layoutForView = database.getLayoutForView(account: session.account, key: global.layoutViewMedia, serverUrl: "") {
  36. if layoutForView.columnPhoto > 0 {
  37. self.numberOfColumns = layoutForView.columnPhoto
  38. } else {
  39. self.numberOfColumns = 3
  40. }
  41. }
  42. return self.numberOfColumns
  43. }
  44. func getLayout() -> String? {
  45. return self.layoutType
  46. }
  47. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float {
  48. var height: Double = 0
  49. if dataSource.metadatas.count == 0 {
  50. height = utility.getHeightHeaderEmptyData(view: view, portraitOffset: 0, landscapeOffset: -20)
  51. }
  52. return Float(height)
  53. }
  54. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForFooterInSection section: Int) -> Float {
  55. if dataSource.metadatas.count == 0 {
  56. return .zero
  57. } else {
  58. return 70.0
  59. }
  60. }
  61. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForSection section: Int) -> UIEdgeInsets {
  62. return .zero
  63. }
  64. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForHeaderInSection section: Int) -> UIEdgeInsets {
  65. return .zero
  66. }
  67. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForFooterInSection section: Int) -> UIEdgeInsets {
  68. return .zero
  69. }
  70. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float {
  71. return 1.0
  72. }
  73. func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath, columnCount: Int, typeLayout: String) -> CGSize {
  74. if typeLayout == global.mediaLayoutSquare {
  75. return CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount))
  76. } else {
  77. guard let metadata = dataSource.getMetadata(indexPath: indexPath) else { return .zero }
  78. if metadata.imageSize != CGSize.zero {
  79. return metadata.imageSize
  80. } else {
  81. return CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount))
  82. }
  83. }
  84. }
  85. }