1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- //
- // NCMedia+MediaLayout.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 16/07/24.
- // Copyright © 2024 Marino Faggiana. All rights reserved.
- //
- // NCMedia+CollectionViewDelegate.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 16/07/24.
- // Copyright © 2024 Marino Faggiana. All rights reserved.
- //
- // Author Marino Faggiana <marino.faggiana@nextcloud.com>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- import UIKit
- import NextcloudKit
- import RealmSwift
- extension NCMedia: NCMediaLayoutDelegate {
- func getColumnCount() -> Int {
- let layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "")
- if let column = layoutForView?.columnPhoto, column > 0 {
- return column
- }
- return 3
- }
- func getLayout() -> String? {
- return self.layoutType
- }
- func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float {
- var height: Double = 0
- if metadatas?.count ?? 0 == 0 {
- height = NCGlobal.shared.getHeightHeaderEmptyData(view: view, portraitOffset: 0, landscapeOffset: -20)
- }
- return Float(height)
- }
- func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForFooterInSection section: Int) -> Float {
- return .zero
- }
- func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForSection section: Int) -> UIEdgeInsets {
- return .zero
- }
- func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForHeaderInSection section: Int) -> UIEdgeInsets {
- return .zero
- }
- func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, insetForFooterInSection section: Int) -> UIEdgeInsets {
- return .zero
- }
- func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, minimumInteritemSpacingForSection section: Int) -> Float {
- return 1.0
- }
- func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath, columnCount: Int, typeLayout: String) -> CGSize {
- let size = CGSize(width: collectionView.frame.width / CGFloat(columnCount), height: collectionView.frame.width / CGFloat(columnCount))
- if typeLayout == NCGlobal.shared.mediaLayoutRatio {
- guard let metadatas = self.metadatas,
- let metadata = metadatas[indexPath.row] else { return size }
- if metadata.imageSize != CGSize.zero {
- return metadata.imageSize
- } else if let size = imageCache.getPreviewSizeCache(ocId: metadata.ocId, etag: metadata.etag) {
- return size
- }
- }
- return size
- }
- }
|