Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions iOSClient/Data/NCManageDatabase+Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,18 @@ extension NCManageDatabase {
return nil
}

func getResultMetadataFromOcId(_ ocId: String?) -> tableMetadata? {
guard let ocId else { return nil }

do {
let realm = try Realm()
return realm.objects(tableMetadata.self).filter("ocId == %@", ocId).first
} catch let error as NSError {
NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not access database: \(error)")
}
return nil
}

func getMetadataFromFileName(_ fileName: String, serverUrl: String) -> tableMetadata? {
do {
let realm = try Realm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension NCCollectionViewCommon: NCMediaLayoutDelegate {
}

func getLayout() -> String? {
return NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewFiles, serverUrl: serverUrl)?.layout
return self.layoutType
}

func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float {
Expand Down
19 changes: 14 additions & 5 deletions iOSClient/Main/Collection Common/NCCollectionViewCommon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
var listLayout = NCListLayout()
var gridLayout = NCGridLayout()
var mediaLayout = NCMediaLayout()
var layoutType = NCGlobal.shared.layoutList
var literalSearch: String?
var tabBarSelect: NCCollectionViewCommonSelectTabBar!
var timerNotificationCenter: Timer?
Expand Down Expand Up @@ -171,10 +172,16 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: layoutKey, serverUrl: serverUrl)
if layoutForView?.layout == NCGlobal.shared.layoutList {
collectionView?.collectionViewLayout = listLayout
self.layoutType = NCGlobal.shared.layoutList
} else if layoutForView?.layout == NCGlobal.shared.layoutGrid {
collectionView?.collectionViewLayout = gridLayout
} else if layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio || layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare {
self.layoutType = NCGlobal.shared.layoutGrid
} else if layoutForView?.layout == NCGlobal.shared.layoutPhotoRatio {
collectionView?.collectionViewLayout = mediaLayout
self.layoutType = NCGlobal.shared.layoutPhotoRatio
} else if layoutForView?.layout == NCGlobal.shared.layoutPhotoSquare {
collectionView?.collectionViewLayout = mediaLayout
self.layoutType = NCGlobal.shared.layoutPhotoSquare
}

// FIXME: iPAD PDF landscape mode iOS 16
Expand Down Expand Up @@ -700,6 +707,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
let list = UIAction(title: NSLocalizedString("_list_", comment: ""), image: utility.loadImage(named: "list.bullet"), state: layoutForView.layout == NCGlobal.shared.layoutList ? .on : .off) { _ in
layoutForView.layout = NCGlobal.shared.layoutList
self.layoutForView = NCManageDatabase.shared.setLayoutForView(layoutForView: layoutForView)
self.layoutType = NCGlobal.shared.layoutList

self.collectionView.reloadData()
self.collectionView.collectionViewLayout.invalidateLayout()
Expand All @@ -711,6 +719,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
let grid = UIAction(title: NSLocalizedString("_icons_", comment: ""), image: utility.loadImage(named: "square.grid.2x2"), state: layoutForView.layout == NCGlobal.shared.layoutGrid ? .on : .off) { _ in
layoutForView.layout = NCGlobal.shared.layoutGrid
self.layoutForView = NCManageDatabase.shared.setLayoutForView(layoutForView: layoutForView)
self.layoutType = NCGlobal.shared.layoutGrid

self.collectionView.reloadData()
self.collectionView.collectionViewLayout.invalidateLayout()
Expand All @@ -723,6 +732,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
UIAction(title: NSLocalizedString("_media_square_", comment: ""), image: utility.loadImage(named: "square.grid.3x3"), state: layoutForView.layout == NCGlobal.shared.layoutPhotoSquare ? .on : .off) { _ in
layoutForView.layout = NCGlobal.shared.layoutPhotoSquare
self.layoutForView = NCManageDatabase.shared.setLayoutForView(layoutForView: layoutForView)
self.layoutType = NCGlobal.shared.layoutPhotoSquare

self.collectionView.reloadData()
self.collectionView.collectionViewLayout.invalidateLayout()
Expand All @@ -734,6 +744,7 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
UIAction(title: NSLocalizedString("_media_ratio_", comment: ""), image: utility.loadImage(named: "rectangle.grid.3x2"), state: layoutForView.layout == NCGlobal.shared.layoutPhotoRatio ? .on : .off) { _ in
layoutForView.layout = NCGlobal.shared.layoutPhotoRatio
self.layoutForView = NCManageDatabase.shared.setLayoutForView(layoutForView: layoutForView)
self.layoutType = NCGlobal.shared.layoutPhotoRatio

self.collectionView.reloadData()
self.collectionView.collectionViewLayout.invalidateLayout()
Expand Down Expand Up @@ -1245,10 +1256,8 @@ class NCCollectionViewCommon: UIViewController, UIGestureRecognizerDelegate, UIS
// MARK: - Header size

func isHeaderMenuTransferViewEnabled() -> Bool {
if headerMenuTransferView,
let metadata = NCManageDatabase.shared.getMetadataFromOcId(NCNetworking.shared.transferInForegorund?.ocId),
metadata.isTransferInForeground {
return true
if headerMenuTransferView {
return NCManageDatabase.shared.getResultMetadataFromOcId(NCNetworking.shared.transferInForegorund?.ocId)?.isTransferInForeground ?? false
}
return false
}
Expand Down
3 changes: 3 additions & 0 deletions iOSClient/Media/NCMedia+Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//

import Foundation
import UIKit
import NextcloudKit

extension NCMedia {
Expand Down Expand Up @@ -137,8 +138,10 @@ extension NCMedia {
let viewLayoutMenu = UIAction(title: layoutTitle, image: layoutImage) { _ in
if layout == NCGlobal.shared.mediaLayoutRatio {
NCManageDatabase.shared.setLayoutForView(account: self.appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "", layout: NCGlobal.shared.mediaLayoutSquare)
self.layoutType = NCGlobal.shared.mediaLayoutSquare
} else {
NCManageDatabase.shared.setLayoutForView(account: self.appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "", layout: NCGlobal.shared.mediaLayoutRatio)
self.layoutType = NCGlobal.shared.mediaLayoutRatio
}
self.createMenu()
self.collectionViewReloadData()
Expand Down
3 changes: 1 addition & 2 deletions iOSClient/Media/NCMedia+MediaLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ extension NCMedia: NCMediaLayoutDelegate {
}

func getLayout() -> String? {
let layoutForView = NCManageDatabase.shared.getLayoutForView(account: appDelegate.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "")
return layoutForView?.layout ?? NCGlobal.shared.mediaLayoutRatio
return self.layoutType
}

func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, heightForHeaderInSection section: Int) -> Float {
Expand Down
7 changes: 5 additions & 2 deletions iOSClient/Media/NCMedia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class NCMedia: UIViewController {
@IBOutlet weak var gradientView: UIView!

let layout = NCMediaLayout()
var layoutType = NCGlobal.shared.mediaLayoutRatio
var activeAccount = tableAccount()
var documentPickerViewController: NCDocumentPickerViewController?
var tabBarSelect: NCMediaSelectTabBar!
Expand Down Expand Up @@ -73,6 +74,7 @@ class NCMedia: UIViewController {
super.viewDidLoad()

view.backgroundColor = .systemBackground
activeAccount = NCManageDatabase.shared.getActiveAccount() ?? tableAccount()

collectionView.register(UINib(nibName: "NCSectionFirstHeaderEmptyData", bundle: nil), forSupplementaryViewOfKind: mediaSectionHeader, withReuseIdentifier: "sectionFirstHeaderEmptyData")
collectionView.register(UINib(nibName: "NCGridMediaCell", bundle: nil), forCellWithReuseIdentifier: "gridCell")
Expand All @@ -88,6 +90,7 @@ class NCMedia: UIViewController {

layout.sectionInset = UIEdgeInsets(top: 0, left: 2, bottom: 0, right: 2)
collectionView.collectionViewLayout = layout
layoutType = NCManageDatabase.shared.getLayoutForView(account: activeAccount.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "")?.layout ?? NCGlobal.shared.mediaLayoutRatio

tabBarSelect = NCMediaSelectTabBar(tabBarController: self.tabBarController, delegate: self)

Expand Down Expand Up @@ -116,8 +119,6 @@ class NCMedia: UIViewController {
gradient.colors = [UIColor.black.withAlphaComponent(UIAccessibility.isReduceTransparencyEnabled ? 0.8 : 0.4).cgColor, UIColor.clear.cgColor]
gradientView.layer.insertSublayer(gradient, at: 0)

activeAccount = NCManageDatabase.shared.getActiveAccount() ?? tableAccount()

collectionView.refreshControl = refreshControl
refreshControl.action(for: .valueChanged) { _ in
DispatchQueue.global(qos: .userInteractive).async {
Expand All @@ -128,6 +129,7 @@ class NCMedia: UIViewController {

NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeUser), object: nil, queue: nil) { _ in
self.activeAccount = NCManageDatabase.shared.getActiveAccount() ?? tableAccount()
self.layoutType = NCManageDatabase.shared.getLayoutForView(account: self.activeAccount.account, key: NCGlobal.shared.layoutViewMedia, serverUrl: "")?.layout ?? NCGlobal.shared.mediaLayoutRatio
if let metadatas = self.metadatas,
let metadata = metadatas.first {
if metadata.account != self.activeAccount.account {
Expand All @@ -148,6 +150,7 @@ class NCMedia: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)


navigationController?.setMediaAppreance()
}

Expand Down