-
-
Notifications
You must be signed in to change notification settings - Fork 896
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5142d4a
commit fe920b4
Showing
144 changed files
with
1,075 additions
and
482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// SPDX-FileCopyrightText: Nextcloud GmbH | ||
// SPDX-FileCopyrightText: 2024 Marino Faggiana | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
import Foundation | ||
import RealmSwift | ||
import NextcloudKit | ||
|
||
class tableRecommendedFiles: Object { | ||
@Persisted var account = "" | ||
@Persisted var id = "" | ||
@Persisted(primaryKey: true) var primaryKey = "" | ||
@Persisted var timestamp: Date? | ||
@Persisted var name: String = "" | ||
@Persisted var directory: String = "" | ||
@Persisted var extensionType: String = "" | ||
@Persisted var mimeType: String = "" | ||
@Persisted var hasPreview: Bool = false | ||
@Persisted var reason: String = "" | ||
|
||
convenience init(account: String, id: String, timestamp: Date?, name: String, directory: String, extensionType: String, mimeType: String, hasPreview: Bool, reason: String) { | ||
self.init() | ||
|
||
self.account = account | ||
self.id = id | ||
self.primaryKey = account + id | ||
self.timestamp = timestamp | ||
self.name = name | ||
self.directory = directory | ||
self.extensionType = extensionType | ||
self.mimeType = mimeType | ||
self.hasPreview = hasPreview | ||
self.reason = reason | ||
} | ||
} | ||
|
||
extension NCManageDatabase { | ||
func createRecommendedFiles(account: String, recommendations: [NKRecommendation]) { | ||
do { | ||
let realm = try Realm() | ||
|
||
try realm.write { | ||
// Removed all objct for account | ||
let results = realm.objects(tableRecommendedFiles.self).filter("account == %@", account) | ||
|
||
realm.delete(results) | ||
|
||
// Added the new recommendations | ||
for recommendation in recommendations { | ||
let recommendedFile = tableRecommendedFiles(account: account, id: recommendation.id, timestamp: recommendation.timestamp, name: recommendation.name, directory: recommendation.directory, extensionType: recommendation.extensionType, mimeType: recommendation.mimeType, hasPreview: recommendation.hasPreview, reason: recommendation.reason) | ||
realm.add(recommendedFile) | ||
} | ||
} | ||
} catch let error { | ||
NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not write to database: \(error)") | ||
} | ||
} | ||
|
||
func getRecommendedFiles(account: String) -> [tableRecommendedFiles] { | ||
do { | ||
let realm = try Realm() | ||
let results = realm.objects(tableRecommendedFiles.self).filter("account == %@", account) | ||
|
||
return Array(results.map { tableRecommendedFiles.init(value: $0) }) | ||
} catch let error { | ||
NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not access database: \(error)") | ||
} | ||
|
||
return [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// UIButton+Extension.swift | ||
// Nextcloud | ||
// | ||
// Created by Milen Pivchev on 17.12.24. | ||
// Copyright © 2024 Marino Faggiana. All rights reserved. | ||
// | ||
|
||
extension UIButton { | ||
func hideButtonAndShowSpinner(tint: UIColor = .white) { | ||
self.isHidden = true | ||
|
||
let spinnerTag = Int(bitPattern: Unmanaged.passUnretained(self).toOpaque()) | ||
if self.superview?.subviews.first(where: { view -> Bool in | ||
return view.isKind(of: UIActivityIndicatorView.self) && view.tag == spinnerTag | ||
}) != nil { | ||
return | ||
} | ||
|
||
let spinner = UIActivityIndicatorView(style: .medium) | ||
spinner.tag = spinnerTag | ||
spinner.color = tint | ||
spinner.startAnimating() | ||
spinner.center = self.center | ||
self.superview?.addSubview(spinner) | ||
spinner.translatesAutoresizingMaskIntoConstraints = false | ||
spinner.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true | ||
spinner.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true | ||
} | ||
|
||
func hideSpinnerAndShowButton() { | ||
let spinnerTag = Int(bitPattern: Unmanaged.passUnretained(self).toOpaque()) | ||
let spinner = self.superview?.subviews.first(where: { view -> Bool in | ||
return view.isKind(of: UIActivityIndicatorView.self) && view.tag == spinnerTag | ||
}) | ||
|
||
spinner?.removeFromSuperview() | ||
self.isHidden = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.