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
3 changes: 2 additions & 1 deletion iOSClient/Data/NCManageDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ class NCManageDatabase: NSObject {
let bundlePathExtension: String = bundleUrl.pathExtension
let bundleFileName: String = (bundleUrl.path as NSString).lastPathComponent
let isAppex: Bool = bundlePathExtension == "appex"
var objectTypesAppex = [tableMetadata.self,
var objectTypesAppex = [NCKeyValue.self,
tableMetadata.self,
tableLocalFile.self,
tableDirectory.self,
tableTag.self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,101 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
return self.dataSource.numberOfItemsInSection(section)
}

func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
guard let metadata = self.dataSource.getMetadata(indexPath: indexPath),
let cell = (cell as? NCCellProtocol) else { return }
let existsPreview = utility.existsImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt1024)
let ext = global.getSizeExtension(width: self.sizeImage.width)

func downloadAvatar(fileName: String, user: String, dispalyName: String?) {
if let image = database.getImageAvatarLoaded(fileName: fileName) {
cell.fileAvatarImageView?.contentMode = .scaleAspectFill
cell.fileAvatarImageView?.image = image
} else {
NCNetworking.shared.downloadAvatar(user: user, dispalyName: dispalyName, fileName: fileName, account: metadata.account, cell: cell, view: collectionView)
}
}
/// CONTENT MODE
cell.filePreviewImageView?.layer.borderWidth = 0
if isLayoutPhoto {
if metadata.isImageOrVideo, existsPreview {
cell.filePreviewImageView?.contentMode = .scaleAspectFill
} else {
cell.filePreviewImageView?.contentMode = .scaleAspectFit
}
} else {
if existsPreview {
cell.filePreviewImageView?.contentMode = .scaleAspectFill
} else {
cell.filePreviewImageView?.contentMode = .scaleAspectFit
}
}
cell.fileAvatarImageView?.contentMode = .center
/// THUMBNAIL
if !metadata.directory {
if metadata.hasPreviewBorder {
cell.filePreviewImageView?.layer.borderWidth = 0.2
cell.filePreviewImageView?.layer.borderColor = UIColor.lightGray.cgColor
}

if metadata.name == global.appName {

if let image = NCImageCache.shared.getImageCache(ocId: metadata.ocId, etag: metadata.etag, ext: ext) {
cell.filePreviewImageView?.image = image
} else if let image = utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext) {
cell.filePreviewImageView?.image = image
}

if cell.filePreviewImageView?.image == nil {
if metadata.iconName.isEmpty {
cell.filePreviewImageView?.image = NCImageCache.shared.getImageFile()
} else {
cell.filePreviewImageView?.image = utility.loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account)
}
if metadata.hasPreview && metadata.status == global.metadataStatusNormal && !existsPreview {
for case let operation as NCCollectionViewDownloadThumbnail in NCNetworking.shared.downloadThumbnailQueue.operations where operation.metadata.ocId == metadata.ocId { return }
NCNetworking.shared.downloadThumbnailQueue.addOperation(NCCollectionViewDownloadThumbnail(metadata: metadata, collectionView: collectionView, ext: NCGlobal.shared.getSizeExtension(width: self.sizeImage.width)))
}
}
} else {
/// APP NAME - UNIFIED SEARCH
switch metadata.iconName {
case let str where str.contains("contacts"):
cell.filePreviewImageView?.image = utility.loadImage(named: "person.crop.rectangle.stack", colors: [NCBrandColor.shared.iconImageColor])
case let str where str.contains("conversation"):
cell.filePreviewImageView?.image = UIImage(named: "talk-template")!.image(color: NCBrandColor.shared.getElement(account: metadata.account))
case let str where str.contains("calendar"):
cell.filePreviewImageView?.image = utility.loadImage(named: "calendar", colors: [NCBrandColor.shared.iconImageColor])
case let str where str.contains("deck"):
cell.filePreviewImageView?.image = utility.loadImage(named: "square.stack.fill", colors: [NCBrandColor.shared.iconImageColor])
case let str where str.contains("mail"):
cell.filePreviewImageView?.image = utility.loadImage(named: "mail", colors: [NCBrandColor.shared.iconImageColor])
case let str where str.contains("talk"):
cell.filePreviewImageView?.image = UIImage(named: "talk-template")!.image(color: NCBrandColor.shared.getElement(account: metadata.account))
case let str where str.contains("confirm"):
cell.filePreviewImageView?.image = utility.loadImage(named: "arrow.right", colors: [NCBrandColor.shared.iconImageColor])
case let str where str.contains("pages"):
cell.filePreviewImageView?.image = utility.loadImage(named: "doc.richtext", colors: [NCBrandColor.shared.iconImageColor])
default:
cell.filePreviewImageView?.image = utility.loadImage(named: "doc", colors: [NCBrandColor.shared.iconImageColor])
}
if !metadata.iconUrl.isEmpty {
if let ownerId = getAvatarFromIconUrl(metadata: metadata) {
let fileName = NCSession.shared.getFileName(urlBase: metadata.urlBase, user: ownerId)
downloadAvatar(fileName: fileName, user: ownerId, dispalyName: nil)
}
}
}
}
/// AVATAR
if !metadata.ownerId.isEmpty,
metadata.ownerId != metadata.userId {
// appDelegate.account == metadata.account {
let fileName = NCSession.shared.getFileName(urlBase: metadata.urlBase, user: metadata.ownerId)
downloadAvatar(fileName: fileName, user: metadata.ownerId, dispalyName: metadata.ownerDisplayName)
}
}

func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if !collectionView.indexPathsForVisibleItems.contains(indexPath) {
guard let metadata = self.dataSource.getMetadata(indexPath: indexPath) else { return }
Expand All @@ -49,18 +144,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
var isShare = false
var isMounted = false
var a11yValues: [String] = []
let ext = NCGlobal.shared.getSizeExtension(width: self.sizeImage.width)
let metadata = self.dataSource.getMetadata(indexPath: indexPath) ?? tableMetadata()
let existsPreview = utility.existsImage(ocId: metadata.ocId, etag: metadata.etag, ext: NCGlobal.shared.previewExt1024)

func downloadAvatar(fileName: String, user: String, dispalyName: String?) {
if let image = database.getImageAvatarLoaded(fileName: fileName) {
cell.fileAvatarImageView?.contentMode = .scaleAspectFill
cell.fileAvatarImageView?.image = image
} else {
NCNetworking.shared.downloadAvatar(user: user, dispalyName: dispalyName, fileName: fileName, account: metadata.account, cell: cell, view: collectionView)
}
}

// LAYOUT PHOTO
if isLayoutPhoto {
Expand All @@ -84,8 +168,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
listCell.listCellDelegate = self
cell = listCell
}
guard let metadata = self.dataSource.getMetadata(indexPath: indexPath),
let filePreviewImageView = cell.filePreviewImageView else { return cell }
guard let metadata = self.dataSource.getMetadata(indexPath: indexPath) else { return cell }

defer {
if !metadata.isSharable() || NCCapabilities.shared.disableSharesView(account: metadata.account) {
Expand All @@ -103,6 +186,8 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
cell.fileFavoriteImage?.image = nil
cell.fileSharedImage?.image = nil
cell.fileMoreImage?.image = nil
cell.filePreviewImageView?.image = nil
cell.filePreviewImageView?.backgroundColor = nil
cell.fileAccount = metadata.account
cell.fileOcId = metadata.ocId
cell.fileOcIdTransfer = metadata.ocIdTransfer
Expand All @@ -120,23 +205,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {

cell.titleInfoTrailingDefault()

/// CONTENT MODE
///
filePreviewImageView.layer.borderWidth = 0
if isLayoutPhoto {
if metadata.isImageOrVideo, existsPreview {
filePreviewImageView.contentMode = .scaleAspectFill
} else {
filePreviewImageView.contentMode = .scaleAspectFit
}
} else {
if existsPreview {
filePreviewImageView.contentMode = .scaleAspectFill
} else {
filePreviewImageView.contentMode = .scaleAspectFit
}
}

if isSearchingMode {
cell.fileTitleLabel?.text = metadata.fileName
cell.fileTitleLabel?.lineBreakMode = .byTruncatingTail
Expand Down Expand Up @@ -191,73 +259,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
// color folder
cell.filePreviewImageView?.image = cell.filePreviewImageView?.image?.colorizeFolder(metadata: metadata, tableDirectory: tableDirectory)
} else {

/// THUMBNAIL
///
filePreviewImageView.image = nil

if metadata.hasPreviewBorder {
filePreviewImageView.layer.borderWidth = 0.2
filePreviewImageView.layer.borderColor = UIColor.lightGray.cgColor
}

if metadata.name == global.appName {
var image = self.imageCache.getImageCache(ocId: metadata.ocId, etag: metadata.etag, ext: ext)

if image == nil {
image = self.utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext)
if let image {
self.imageCache.addImageCache(ocId: metadata.ocId, etag: metadata.etag, image: image, ext: ext)
} else {
if metadata.iconName.isEmpty {
image = self.imageCache.getImageFile()
} else {
image = self.utility.loadImage(named: metadata.iconName, useTypeIconFile: true, account: metadata.account)
}
if metadata.hasPreview,
metadata.status == self.global.metadataStatusNormal,
!existsPreview,
NCNetworking.shared.downloadThumbnailQueue.operations.filter({ ($0 as? NCMediaDownloadThumbnail)?.metadata.ocId == metadata.ocId }).isEmpty {

NCNetworking.shared.downloadThumbnailQueue.addOperation(NCCollectionViewDownloadThumbnail(metadata: metadata, collectionView: collectionView, ext: ext))
}
}
}

filePreviewImageView.image = image

} else {

/// APP NAME - UNIFIED SEARCH
///
switch metadata.iconName {
case let str where str.contains("contacts"):
filePreviewImageView.image = utility.loadImage(named: "person.crop.rectangle.stack", colors: [NCBrandColor.shared.iconImageColor])
case let str where str.contains("conversation"):
filePreviewImageView.image = UIImage(named: "talk-template")!.image(color: NCBrandColor.shared.getElement(account: metadata.account))
case let str where str.contains("calendar"):
filePreviewImageView.image = utility.loadImage(named: "calendar", colors: [NCBrandColor.shared.iconImageColor])
case let str where str.contains("deck"):
filePreviewImageView.image = utility.loadImage(named: "square.stack.fill", colors: [NCBrandColor.shared.iconImageColor])
case let str where str.contains("mail"):
filePreviewImageView.image = utility.loadImage(named: "mail", colors: [NCBrandColor.shared.iconImageColor])
case let str where str.contains("talk"):
filePreviewImageView.image = UIImage(named: "talk-template")!.image(color: NCBrandColor.shared.getElement(account: metadata.account))
case let str where str.contains("confirm"):
filePreviewImageView.image = utility.loadImage(named: "arrow.right", colors: [NCBrandColor.shared.iconImageColor])
case let str where str.contains("pages"):
filePreviewImageView.image = utility.loadImage(named: "doc.richtext", colors: [NCBrandColor.shared.iconImageColor])
default:
filePreviewImageView.image = utility.loadImage(named: "doc", colors: [NCBrandColor.shared.iconImageColor])
}
if !metadata.iconUrl.isEmpty {
if let ownerId = getAvatarFromIconUrl(metadata: metadata) {
let fileName = NCSession.shared.getFileName(urlBase: metadata.urlBase, user: ownerId)
downloadAvatar(fileName: fileName, user: ownerId, dispalyName: nil)
}
}
}

let tableLocalFile = database.getResultsTableLocalFile(predicate: NSPredicate(format: "ocId == %@", metadata.ocId))?.first
// image local
if let tableLocalFile, tableLocalFile.offline {
Expand All @@ -268,15 +269,6 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
}
}

// avatar
cell.fileAvatarImageView?.contentMode = .center
if !metadata.ownerId.isEmpty,
metadata.ownerId != metadata.userId {
// appDelegate.account == metadata.account {
let fileName = NCSession.shared.getFileName(urlBase: metadata.urlBase, user: metadata.ownerId)
downloadAvatar(fileName: fileName, user: metadata.ownerId, dispalyName: metadata.ownerDisplayName)
}

// image Favorite
if metadata.favorite {
cell.fileFavoriteImage?.image = imageCache.getImageFavorite()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
// Created by Marino Faggiana on 16/09/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 Foundation
import UIKit
Expand All @@ -13,11 +28,10 @@ extension NCCollectionViewCommon: UICollectionViewDataSourcePrefetching {
func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {
guard !isSearchingMode else { return }
let ext = global.getSizeExtension(width: self.sizeImage.width)
let metadatas = self.dataSource.getMetadatas(indexPaths: indexPaths)

DispatchQueue.global(qos: .userInteractive).async {
let metadatas = self.dataSource.getResultMetadatas(indexPaths: indexPaths)

metadatas.forEach { metadata in
for metadata in metadatas where metadata.isImageOrVideo {
if self.imageCache.getImageCache(ocId: metadata.ocId, etag: metadata.etag, ext: ext) == nil,
let image = self.utility.getImage(ocId: metadata.ocId, etag: metadata.etag, ext: ext) {
self.imageCache.addImageCache(ocId: metadata.ocId, etag: metadata.etag, image: image, ext: ext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,13 @@ class NCCollectionViewDataSource: NSObject {
return nil
}

func getResultMetadatas(indexPaths: [IndexPath]) -> [tableMetadata] {
func getMetadatas(indexPaths: [IndexPath]) -> [tableMetadata] {
var metadatas: [tableMetadata] = []
let validMetadatas = metadatas.filter { !$0.isInvalidated }
let validMetadatas = self.metadatas.filter { !$0.isInvalidated }

for indexPath in indexPaths {
if indexPath.row < validMetadatas.count {
metadatas.append(validMetadatas[indexPath.row])
metadatas.append(tableMetadata(value: validMetadatas[indexPath.row]))
}
}
return metadatas
Expand Down
4 changes: 2 additions & 2 deletions iOSClient/NCGlobal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ class NCGlobal: NSObject {
guard let width else { return previewExt512 }

switch (width * 3) {
case 0...120:
case 0...119:
return previewExt64
case 121...192:
case 120...192:
return previewExt128
case 193...384:
return previewExt256
Expand Down