Skip to content

Commit

Permalink
Recommended review NC 31 (#3275)
Browse files Browse the repository at this point in the history
Signed-off-by: Marino Faggiana <[email protected]>
  • Loading branch information
marinofaggiana authored Jan 20, 2025
1 parent 6aab75a commit ee8f7a6
Show file tree
Hide file tree
Showing 21 changed files with 395 additions and 234 deletions.
10 changes: 10 additions & 0 deletions Nextcloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,10 @@
F7EE66AD2A20B226009AE765 /* UILabel+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7EE66AC2A20B226009AE765 /* UILabel+Extension.swift */; };
F7EFA47825ADBA500083159A /* NCViewerProviderContextMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7EFA47725ADBA500083159A /* NCViewerProviderContextMenu.swift */; };
F7EFC0CD256BF8DD00461AAD /* NCUserStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7EFC0CC256BF8DD00461AAD /* NCUserStatus.swift */; };
F7F3E58B2D3BB65600A32B14 /* NCNetworking+Recommendations.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F3E58A2D3BB65000A32B14 /* NCNetworking+Recommendations.swift */; };
F7F3E58C2D3BB65600A32B14 /* NCNetworking+Recommendations.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F3E58A2D3BB65000A32B14 /* NCNetworking+Recommendations.swift */; };
F7F3E58D2D3BB65600A32B14 /* NCNetworking+Recommendations.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F3E58A2D3BB65000A32B14 /* NCNetworking+Recommendations.swift */; };
F7F3E58E2D3BB65600A32B14 /* NCNetworking+Recommendations.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F3E58A2D3BB65000A32B14 /* NCNetworking+Recommendations.swift */; };
F7F4F10527ECDBDB008676F9 /* Inconsolata-SemiBold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F7F4F0FD27ECDBDB008676F9 /* Inconsolata-SemiBold.ttf */; };
F7F4F10627ECDBDB008676F9 /* Inconsolata-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F7F4F0FE27ECDBDB008676F9 /* Inconsolata-Medium.ttf */; };
F7F4F10727ECDBDB008676F9 /* Inconsolata-Black.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F7F4F0FF27ECDBDB008676F9 /* Inconsolata-Black.ttf */; };
Expand Down Expand Up @@ -1734,6 +1738,7 @@
F7EE66AC2A20B226009AE765 /* UILabel+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UILabel+Extension.swift"; sourceTree = "<group>"; };
F7EFA47725ADBA500083159A /* NCViewerProviderContextMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCViewerProviderContextMenu.swift; sourceTree = "<group>"; };
F7EFC0CC256BF8DD00461AAD /* NCUserStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCUserStatus.swift; sourceTree = "<group>"; };
F7F3E58A2D3BB65000A32B14 /* NCNetworking+Recommendations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCNetworking+Recommendations.swift"; sourceTree = "<group>"; };
F7F4F0FD27ECDBDB008676F9 /* Inconsolata-SemiBold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Inconsolata-SemiBold.ttf"; sourceTree = "<group>"; };
F7F4F0FE27ECDBDB008676F9 /* Inconsolata-Medium.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Inconsolata-Medium.ttf"; sourceTree = "<group>"; };
F7F4F0FF27ECDBDB008676F9 /* Inconsolata-Black.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Inconsolata-Black.ttf"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2279,6 +2284,7 @@
F713FBE42C31645200F10760 /* NCNetworking+AsyncAwait.swift */,
F7327E1F2B73A42F00A462C7 /* NCNetworking+Download.swift */,
F7327E342B73AEDE00A462C7 /* NCNetworking+LivePhoto.swift */,
F7F3E58A2D3BB65000A32B14 /* NCNetworking+Recommendations.swift */,
F7327E3C2B73B92800A462C7 /* NCNetworking+Synchronization.swift */,
F74230F22C79B57200CA1ACA /* NCNetworking+Task.swift */,
F7327E272B73A53400A462C7 /* NCNetworking+Upload.swift */,
Expand Down Expand Up @@ -4029,6 +4035,7 @@
F7A0D1362591FBC5008F8A13 /* String+Extension.swift in Sources */,
F7EDE4D6262D7B9600414FE6 /* NCListCell.swift in Sources */,
F7327E372B73AEDE00A462C7 /* NCNetworking+LivePhoto.swift in Sources */,
F7F3E58D2D3BB65600A32B14 /* NCNetworking+Recommendations.swift in Sources */,
F73EF7D22B0225BA0087E6E9 /* NCManageDatabase+Tag.swift in Sources */,
F74B6D982A7E239A00F03C5F /* NCManageDatabase+Chunk.swift in Sources */,
F737DA9F2B7B8AB90063BAFC /* NCLoginNavigationController.swift in Sources */,
Expand Down Expand Up @@ -4155,6 +4162,7 @@
F711A4E92AF9327600095DD8 /* UIImage+animatedGIF.m in Sources */,
F73EF7D02B0225BA0087E6E9 /* NCManageDatabase+Tag.swift in Sources */,
F783030228B4C4B800B84583 /* NCUtility.swift in Sources */,
F7F3E58C2D3BB65600A32B14 /* NCNetworking+Recommendations.swift in Sources */,
F711D63128F44801003F43C8 /* IntentHandler.swift in Sources */,
F39170AE2CB82024006127BC /* FileAutoRenamer+Extensions.swift in Sources */,
F76DEE9728F808AF0041B1C9 /* LockscreenData.swift in Sources */,
Expand Down Expand Up @@ -4264,6 +4272,7 @@
F73EF7CB2B0225610087E6E9 /* NCManageDatabase+PhotoLibrary.swift in Sources */,
F7A5DF052C3FD11800753FC4 /* FileProviderExtension+NetworkingDelegate.swift in Sources */,
F33EE6F62BF4C9B200CA1A51 /* PKCS12.swift in Sources */,
F7F3E58B2D3BB65600A32B14 /* NCNetworking+Recommendations.swift in Sources */,
F73EF7C32B02250B0087E6E9 /* NCManageDatabase+GPS.swift in Sources */,
F7C9B9212B582F550064EA91 /* NCManageDatabase+SecurityGuard.swift in Sources */,
F359D86B2A7D03420023F405 /* NCUtility+Exif.swift in Sources */,
Expand Down Expand Up @@ -4450,6 +4459,7 @@
F3BB46542A3A1E9D00461F6E /* CCCellMore.swift in Sources */,
AF68326A27BE65A90010BF0B /* NCMenuAction.swift in Sources */,
F7682FE023C36B0500983A04 /* NCMainTabBar.swift in Sources */,
F7F3E58E2D3BB65600A32B14 /* NCNetworking+Recommendations.swift in Sources */,
F7A0D1352591FBC5008F8A13 /* String+Extension.swift in Sources */,
F7CEE6012BA9A5C9003EFD89 /* NCTrashGridCell.swift in Sources */,
F7F9D1BB25397CE000D9BFF5 /* NCViewer.swift in Sources */,
Expand Down
3 changes: 1 addition & 2 deletions iOSClient/Data/NCManageDatabase+Capabilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ extension NCManageDatabase {
capabilities.capabilityForbiddenFileNameCharacters = data.capabilities.files?.forbiddenFileNameCharacters ?? []
capabilities.capabilityForbiddenFileNameExtensions = data.capabilities.files?.forbiddenFileNameExtensions ?? []

// TODO: not yet available (IN TEST)
// capabilities.capabilityRecommendations = data.capabilities.recommendations?.enabled ?? false
capabilities.capabilityRecommendations = data.capabilities.recommendations?.enabled ?? false

NCCapabilities.shared.appendCapabilities(account: account, capabilities: capabilities)

Expand Down
14 changes: 13 additions & 1 deletion iOSClient/Data/NCManageDatabase+RecommendedFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extension NCManageDatabase {
func getRecommendedFiles(account: String) -> [tableRecommendedFiles] {
do {
let realm = try Realm()
let results = realm.objects(tableRecommendedFiles.self).filter("account == %@", account)
let results = realm.objects(tableRecommendedFiles.self).filter("account == %@", account).sorted(byKeyPath: "timestamp", ascending: false)

return Array(results.map { tableRecommendedFiles.init(value: $0) })
} catch let error {
Expand All @@ -68,4 +68,16 @@ extension NCManageDatabase {

return []
}

func deleteAllRecommendedFiles(account: String) {
do {
let realm = try Realm()

try realm.write {
realm.delete(realm.objects(tableRecommendedFiles.self).filter("account == %@", account))
}
} catch let error {
NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not access database: \(error)")
}
}
}
48 changes: 4 additions & 44 deletions iOSClient/Files/NCFiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,10 @@ class NCFiles: NCCollectionViewCommon {
return false
}

///
/// Recommended files
///
if self.serverUrl == self.utilityFileSystem.getHomeServer(session: self.session),
NCCapabilities.shared.getCapabilities(account: self.session.account).capabilityRecommendations {
let options = NKRequestOptions(queue: NextcloudKit.shared.nkCommonInstance.backgroundQueue)

NextcloudKit.shared.getRecommendedFiles(account: self.session.account, options: options) { _, recommendations, _, error in
if error == .success,
let recommendations,
!recommendations.isEmpty {
Task.detached {
await self.createRecommendations(recommendations)
}
} else {
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadRecommendedFiles, userInfo: nil)
}
/// Recommendation
if isRecommendationActived {
Task.detached {
await NCNetworking.shared.createRecommendations(session: self.session)
}
}

Expand Down Expand Up @@ -368,33 +355,6 @@ class NCFiles: NCCollectionViewCommon {
}
}

private func createRecommendations(_ recommendations: [NKRecommendation]) async {
let home = self.utilityFileSystem.getHomeServer(session: self.session)
var recommendationsToInsert: [NKRecommendation] = []

for recommendation in recommendations {
var metadata = database.getResultMetadataFromFileId(recommendation.id)
if metadata == nil || metadata?.fileName != recommendation.name {
let serverUrlFileName = home + recommendation.directory + recommendation.name
let results = await NCNetworking.shared.readFileOrFolder(serverUrlFileName: serverUrlFileName, depth: "0", showHiddenFiles: NCKeychain().showHiddenFiles, account: session.account)

if results.error == .success, let file = results.files?.first {
let isDirectoryE2EE = self.utilityFileSystem.isDirectoryE2EE(file: file)
let metadataConverted = self.database.convertFileToMetadata(file, isDirectoryE2EE: isDirectoryE2EE)
metadata = metadataConverted

self.database.addMetadata(metadataConverted)
recommendationsToInsert.append(recommendation)
}
} else {
recommendationsToInsert.append(recommendation)
}
}

self.database.createRecommendedFiles(account: session.account, recommendations: recommendationsToInsert)
NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterReloadRecommendedFiles, userInfo: nil)
}

// MARK: - NCAccountSettingsModelDelegate

override func accountSettingsDidDismiss(tableAccount: tableAccount?, controller: NCMainTabBarController?) {
Expand Down
25 changes: 12 additions & 13 deletions iOSClient/Main/Collection Common/Cell/NCRecommendationsCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import UIKit

protocol NCRecommendationsCellDelegate: AnyObject {
func touchUpInsideButtonMenu(with metadata: tableMetadata, image: UIImage?)
func longPressGestureRecognized(with metadata: tableMetadata, image: UIImage?)
}

class NCRecommendationsCell: UICollectionViewCell, UIGestureRecognizerDelegate {
Expand All @@ -22,6 +21,7 @@ class NCRecommendationsCell: UICollectionViewCell, UIGestureRecognizerDelegate {
var delegate: NCRecommendationsCellDelegate?
var metadata: tableMetadata = tableMetadata()
var recommendedFiles: tableRecommendedFiles = tableRecommendedFiles()
var id: String = ""

override func awakeFromNib() {
super.awakeFromNib()
Expand All @@ -42,25 +42,24 @@ class NCRecommendationsCell: UICollectionViewCell, UIGestureRecognizerDelegate {
buttonMenu.layer.shadowOffset = CGSize(width: 2, height: 2)
buttonMenu.layer.shadowRadius = 4

let longPressedGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPress(gestureRecognizer:)))
longPressedGesture.minimumPressDuration = 0.5
longPressedGesture.delegate = self
longPressedGesture.delaysTouchesBegan = true
self.addGestureRecognizer(longPressedGesture)
image.image = nil
labelFilename.text = ""
labelInfo.text = ""
}

func setImageBorder() {
func setImageCorner(withBorder: Bool) {
image.layer.cornerRadius = 10
image.layer.masksToBounds = true
image.layer.borderWidth = 0.5
image.layer.borderColor = UIColor.separator.cgColor
if withBorder {
image.layer.borderWidth = 0.5
image.layer.borderColor = UIColor.separator.cgColor
} else {
image.layer.borderWidth = 0
image.layer.borderColor = UIColor.clear.cgColor
}
}

@IBAction func touchUpInsideButtonMenu(_ sender: Any) {
self.delegate?.touchUpInsideButtonMenu(with: self.metadata, image: image.image)
}

@objc func longPress(gestureRecognizer: UILongPressGestureRecognizer) {
self.delegate?.longPressGestureRecognized(with: metadata, image: image.image)
}
}
Loading

0 comments on commit ee8f7a6

Please sign in to comment.