Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/nextcloud/ios into login…
Browse files Browse the repository at this point in the history
…-v2-enable
  • Loading branch information
mpivchev committed Jun 10, 2024
2 parents 7d9ab9f + 0fd93dc commit 33e6f39
Show file tree
Hide file tree
Showing 225 changed files with 4,012 additions and 4,212 deletions.
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ disabled_rules:
- shorthand_operator
- type_name
- void_function_in_ternary

- switch_case_alignment
excluded:
- Carthage
- Pods
Expand Down
2 changes: 1 addition & 1 deletion Brand/Intro/NCIntroViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class NCIntroViewController: UIViewController, UICollectionViewDataSource, UICol
@IBOutlet weak var introCollectionView: UICollectionView!
@IBOutlet weak var pageControl: UIPageControl!

@objc weak var delegate: NCIntroViewController?
weak var delegate: NCIntroViewController?

private let appDelegate = (UIApplication.shared.delegate as? AppDelegate)!
private let titles = [NSLocalizedString("_intro_1_title_", comment: ""), NSLocalizedString("_intro_2_title_", comment: ""), NSLocalizedString("_intro_3_title_", comment: ""), NSLocalizedString("_intro_4_title_", comment: "")]
Expand Down

This file was deleted.

47 changes: 10 additions & 37 deletions File Provider Extension/FileProviderEnumerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,17 @@ import FileProvider
import NextcloudKit

class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {

var enumeratedItemIdentifier: NSFileProviderItemIdentifier
var serverUrl: String?
let fpUtility = fileProviderUtility()

init(enumeratedItemIdentifier: NSFileProviderItemIdentifier) {

self.enumeratedItemIdentifier = enumeratedItemIdentifier

// Select ServerUrl
if enumeratedItemIdentifier == .rootContainer {
serverUrl = fileProviderData.shared.homeServerUrl
} else {

let metadata = fpUtility.getTableMetadataFromItemIdentifier(enumeratedItemIdentifier)
if metadata != nil {
if let directorySource = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata!.account, metadata!.serverUrl)) {
Expand All @@ -56,12 +53,10 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
}

func enumerateItems(for observer: NSFileProviderEnumerationObserver, startingAt page: NSFileProviderPage) {

var items: [NSFileProviderItemProtocol] = []

/*** WorkingSet ***/
if enumeratedItemIdentifier == .workingSet {

var itemIdentifierMetadata: [NSFileProviderItemIdentifier: tableMetadata] = [:]

// ***** Tags *****
Expand Down Expand Up @@ -103,21 +98,17 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
}

if page == NSFileProviderPage.initialPageSortedByDate as NSFileProviderPage || page == NSFileProviderPage.initialPageSortedByName as NSFileProviderPage {

self.readFileOrFolder(serverUrl: serverUrl) { metadatas in
self.completeObserver(observer, numPage: 1, metadatas: metadatas)
}

} else {

let numPage = Int(String(data: page.rawValue, encoding: .utf8)!)!
completeObserver(observer, numPage: numPage, metadatas: nil)
}
}
}

func enumerateChanges(for observer: NSFileProviderChangeObserver, from anchor: NSFileProviderSyncAnchor) {

var itemsDelete: [NSFileProviderItemIdentifier] = []
var itemsUpdate: [FileProviderItem] = []

Expand Down Expand Up @@ -166,18 +157,13 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
// --------------------------------------------------------------------------------------------

func completeObserver(_ observer: NSFileProviderEnumerationObserver, numPage: Int, metadatas: [tableMetadata]?) {

var numPage = numPage
var items: [NSFileProviderItemProtocol] = []

if metadatas != nil {

for metadata in metadatas! {

if metadata.e2eEncrypted || (!metadata.session.isEmpty && metadata.session != NCNetworking.shared.sessionUploadBackgroundExtension) { continue }

fpUtility.createocIdentifierOnFileSystem(metadata: metadata)

let parentItemIdentifier = fpUtility.getParentItemIdentifier(metadata: metadata)
if parentItemIdentifier != nil {
let item = FileProviderItem(metadata: metadata, parentItemIdentifier: parentItemIdentifier!)
Expand All @@ -197,29 +183,16 @@ class FileProviderEnumerator: NSObject, NSFileProviderEnumerator {
}

func readFileOrFolder(serverUrl: String, completionHandler: @escaping (_ metadatas: [tableMetadata]?) -> Void) {

var directoryEtag: String?

if let tableDirectory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", fileProviderData.shared.account, serverUrl)) {
directoryEtag = tableDirectory.etag
}

NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "0", showHiddenFiles: NCKeychain().showHiddenFiles) { account, files, _, error in

if directoryEtag != files.first?.etag {

NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: NCKeychain().showHiddenFiles) { account, files, _, error in

if error == .success {
DispatchQueue.global().async {
NCManageDatabase.shared.convertFilesToMetadatas(files, useFirstAsMetadataFolder: true) { _, metadatas in
let predicate = NSPredicate(format: "account == %@ AND serverUrl == %@ AND status == %d", account, serverUrl, NCGlobal.shared.metadataStatusNormal)
NCManageDatabase.shared.updateMetadatas(metadatas, predicate: predicate)
let metadatas = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", fileProviderData.shared.account, serverUrl), sorted: "fileName", ascending: true)
completionHandler(metadatas)
}
}
} else {
NextcloudKit.shared.readFileOrFolder(serverUrlFileName: serverUrl, depth: "1", showHiddenFiles: NCKeychain().showHiddenFiles) { account, files, _, error in
if error == .success {
DispatchQueue.global().async {
NCManageDatabase.shared.convertFilesToMetadatas(files, useFirstAsMetadataFolder: true) { metadataFolder, metadatas in
/// FOLDER
NCManageDatabase.shared.addMetadata(metadataFolder)
NCManageDatabase.shared.addDirectory(e2eEncrypted: metadataFolder.e2eEncrypted, favorite: metadataFolder.favorite, ocId: metadataFolder.ocId, fileId: metadataFolder.fileId, etag: metadataFolder.etag, permissions: metadataFolder.permissions, richWorkspace: metadataFolder.richWorkspace, serverUrl: serverUrl, account: metadataFolder.account)
/// FILES
let predicate = NSPredicate(format: "account == %@ AND serverUrl == %@ AND status == %d", account, serverUrl, NCGlobal.shared.metadataStatusNormal)
NCManageDatabase.shared.updateMetadatas(metadatas, predicate: predicate)
let metadatas = NCManageDatabase.shared.getMetadatas(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", fileProviderData.shared.account, serverUrl), sorted: "fileName", ascending: true)
completionHandler(metadatas)
}
Expand Down
24 changes: 0 additions & 24 deletions File Provider Extension/FileProviderExtension-Bridging-Header.h

This file was deleted.

4 changes: 2 additions & 2 deletions File Provider Extension/FileProviderExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
//

import UIKit
import UniformTypeIdentifiers
import FileProvider
import NextcloudKit
import Alamofire
Expand Down Expand Up @@ -96,8 +97,7 @@ class FileProviderExtension: NSFileProviderExtension {
// - for a directory, instantiate an enumerator of its subitems
// - for a file, instantiate an enumerator that observes changes to the file
let item = try self.item(for: containerItemIdentifier)

if item.typeIdentifier == kUTTypeFolder as String {
if item.contentType == UTType.folder {
maybeEnumerator = FileProviderEnumerator(enumeratedItemIdentifier: containerItemIdentifier)
} else {
maybeEnumerator = FileProviderEnumerator(enumeratedItemIdentifier: containerItemIdentifier)
Expand Down
Loading

0 comments on commit 33e6f39

Please sign in to comment.