Skip to content

Commit bf284ac

Browse files
Project (#3867)
* isAppInBackground LivePhoto Signed-off-by: Marino Faggiana <[email protected]> * clean Signed-off-by: Marino Faggiana <[email protected]> * proj Signed-off-by: Marino Faggiana <[email protected]> * prj Signed-off-by: Marino Faggiana <[email protected]> * prj Signed-off-by: Marino Faggiana <[email protected]> * proj Signed-off-by: Marino Faggiana <[email protected]> * proj Signed-off-by: Marino Faggiana <[email protected]> * proj Signed-off-by: Marino Faggiana <[email protected]> * proj Signed-off-by: Marino Faggiana <[email protected]> * prj Signed-off-by: Marino Faggiana <[email protected]> * proj Signed-off-by: Marino Faggiana <[email protected]> * prj Signed-off-by: Marino Faggiana <[email protected]> * prj Signed-off-by: Marino Faggiana <[email protected]> --------- Signed-off-by: Marino Faggiana <[email protected]>
1 parent 138830f commit bf284ac

13 files changed

+92
-407
lines changed

Nextcloud.xcodeproj/project.pbxproj

Lines changed: 11 additions & 181 deletions
Large diffs are not rendered by default.

iOSClient/Data/NCManageDatabase.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ final class NCManageDatabase: @unchecked Sendable {
117117
return
118118
}
119119
let databaseFileUrl = dirGroup.appendingPathComponent(NCGlobal.shared.appDatabaseNextcloud + "/" + databaseName)
120-
let bundleUrl: URL = Bundle.main.bundleURL
121-
var objectTypes = [
120+
let objectTypes = [
122121
NCKeyValue.self, tableMetadata.self, tableLocalFile.self,
123122
tableDirectory.self, tableTag.self, tableAccount.self,
124123
tableCapabilities.self, tableE2eEncryption.self, tableE2eEncryptionLock.self,

iOSClient/Data/NCMetadataTranfersSuccess.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ actor NCMetadataTranfersSuccess {
8585
let accounts = Set(metadatasLivePhoto.map { $0.account })
8686
for account in accounts {
8787
await NCNetworking.shared.setLivePhoto(account: account)
88+
if isAppInBackground {
89+
return
90+
}
8891
}
8992
}
9093
#endif

iOSClient/Extensions/UIFont+Extension.swift

Lines changed: 0 additions & 32 deletions
This file was deleted.

iOSClient/Extensions/UIView+Extension.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,9 @@ import Foundation
2525
import UIKit
2626

2727
extension UIView {
28-
29-
// Source
30-
// https://stackoverflow.com/questions/18680028/prevent-screen-capture-in-an-ios-app/67054892#67054892
31-
//
32-
// private weak var scrollView: UIScrollView! (it's an outlet)
33-
// self.view.preventScreenshot(for: self.scrollView)
34-
//
35-
func preventScreenshot(for view: UIView) {
36-
let textField = UITextField()
37-
textField.isSecureTextEntry = true
38-
textField.isUserInteractionEnabled = false
39-
guard let hiddenView = textField.layer.sublayers?.first?.delegate as? UIView else {
40-
return
41-
}
42-
hiddenView.subviews.forEach { $0.removeFromSuperview() }
43-
hiddenView.translatesAutoresizingMaskIntoConstraints = false
44-
self.addSubview(hiddenView)
45-
hiddenView.fillSuperview()
46-
hiddenView.addSubview(view)
47-
}
48-
4928
func makeCircularBackground(withColor backgroundColor: UIColor) {
5029
self.backgroundColor = backgroundColor
5130
self.layer.cornerRadius = self.frame.size.width / 2
5231
self.layer.masksToBounds = true
5332
}
54-
55-
var parentTabBarController: UITabBarController? {
56-
var responder: UIResponder? = self
57-
while let nextResponder = responder?.next {
58-
if let tabBarController = nextResponder as? UITabBarController {
59-
return tabBarController
60-
}
61-
responder = nextResponder
62-
}
63-
return nil
64-
}
6533
}

iOSClient/NCImageCache.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class NCImageCache: @unchecked Sendable {
3030
public var controller: UITabBarController?
3131

3232
init() {
33-
observerToken = NotificationCenter.default.addObserver(forName: LRUCacheMemoryWarningNotification, object: nil, queue: nil) { _ in
33+
observerToken = NotificationCenter.default.addObserver(forName: UIApplication.didReceiveMemoryWarningNotification, object: nil, queue: nil) { _ in
3434
self.cache.removeAll()
3535
self.cache = LRUCache<String, UIImage>(countLimit: self.countLimit)
3636
}

iOSClient/Networking/NCNetworking+LivePhoto.swift

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,83 @@ extension NCNetworking {
1717
}
1818

1919
for result in results {
20-
2120
// VIDEO PART
2221
//
23-
let resultLivePhotoVideo = await NextcloudKit.shared.setLivephotoAsync(serverUrlfileNamePath: result.serverUrlFileNameVideo, livePhotoFile: result.fileIdImage, account: account) { task in
24-
Task {
25-
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: account,
26-
path: result.serverUrlFileNameVideo,
27-
name: "setLivephoto")
28-
await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task)
29-
}
22+
let resultLivePhotoVideo = await NextcloudKit.shared.setLivephotoAsync(
23+
serverUrlfileNamePath: result.serverUrlFileNameVideo,
24+
livePhotoFile: result.fileIdImage,
25+
account: account) { task in
26+
Task {
27+
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(
28+
account: account,
29+
path: result.serverUrlFileNameVideo,
30+
name: "setLivephoto")
31+
await NCNetworking.shared.networkingTasks.track(
32+
identifier: identifier,
33+
task: task)
34+
}
3035
}
3136
guard resultLivePhotoVideo.error == .success else {
3237
if resultLivePhotoVideo.error.errorCode == 404 {
3338
await NCManageDatabase.shared.deleteLivePhoto(account: account, serverUrlFileNameNoExt: result.serverUrlFileNameNoExt)
3439
continue
3540
} else {
3641
nkLog(error: "Upload set LivePhoto Video with error \(resultLivePhotoVideo.error.errorCode)")
37-
await NCManageDatabase.shared.setLivePhotoError(account: account, serverUrlFileNameNoExt: result.serverUrlFileNameNoExt)
42+
await NCManageDatabase.shared.setLivePhotoError(
43+
account: account,
44+
serverUrlFileNameNoExt: result.serverUrlFileNameNoExt)
3845
return false
3946
}
4047
}
4148

4249
// IMAGE PART
4350
//
44-
let resultLivePhotoImage = await NextcloudKit.shared.setLivephotoAsync(serverUrlfileNamePath: result.serverUrlFileNameImage, livePhotoFile: result.fileIdVideo, account: account) { task in
45-
Task {
46-
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(account: account,
47-
path: result.serverUrlFileNameImage,
48-
name: "setLivephoto")
49-
await NCNetworking.shared.networkingTasks.track(identifier: identifier, task: task)
50-
}
51+
let resultLivePhotoImage = await NextcloudKit.shared.setLivephotoAsync(
52+
serverUrlfileNamePath: result.serverUrlFileNameImage,
53+
livePhotoFile: result.fileIdVideo,
54+
account: account) { task in
55+
Task {
56+
let identifier = await NCNetworking.shared.networkingTasks.createIdentifier(
57+
account: account,
58+
path: result.serverUrlFileNameImage,
59+
name: "setLivephoto")
60+
await NCNetworking.shared.networkingTasks.track(
61+
identifier: identifier,
62+
task: task)
63+
}
5164
}
5265
guard resultLivePhotoImage.error == .success else {
5366
if resultLivePhotoImage.error.errorCode == 404 {
54-
await NCManageDatabase.shared.deleteLivePhoto(account: account, serverUrlFileNameNoExt: result.serverUrlFileNameNoExt)
67+
await NCManageDatabase.shared.deleteLivePhoto(
68+
account: account,
69+
serverUrlFileNameNoExt: result.serverUrlFileNameNoExt)
5570
continue
5671
} else {
5772
nkLog(error: "Upload set LivePhoto Image with error \(resultLivePhotoImage.error.errorCode)")
58-
await NCManageDatabase.shared.setLivePhotoError(account: account, serverUrlFileNameNoExt: result.serverUrlFileNameNoExt)
73+
await NCManageDatabase.shared.setLivePhotoError(
74+
account: account,
75+
serverUrlFileNameNoExt: result.serverUrlFileNameNoExt)
5976
return false
6077
}
6178
}
6279

6380
// Update metadata livePhotoFile
64-
await NCManageDatabase.shared.setLivePhotoFile(fileId: result.fileIdVideo, livePhotoFile: result.fileIdImage)
65-
await NCManageDatabase.shared.setLivePhotoFile(fileId: result.fileIdImage, livePhotoFile: result.fileIdVideo)
81+
await NCManageDatabase.shared.setLivePhotoFile(
82+
fileId: result.fileIdVideo,
83+
livePhotoFile: result.fileIdImage)
84+
await NCManageDatabase.shared.setLivePhotoFile(
85+
fileId: result.fileIdImage,
86+
livePhotoFile: result.fileIdVideo)
6687
// Remove tableLivePhoto
67-
await NCManageDatabase.shared.deleteLivePhoto(account: account, serverUrlFileNameNoExt: result.serverUrlFileNameNoExt)
88+
await NCManageDatabase.shared.deleteLivePhoto(
89+
account: account,
90+
serverUrlFileNameNoExt: result.serverUrlFileNameNoExt)
6891

6992
setLivePhoto = true
93+
94+
if isAppInBackground {
95+
return setLivePhoto
96+
}
7097
}
7198

7299
return setLivePhoto

iOSClient/Networking/NCNetworking+NextcloudKitDelegate.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@ import UIKit
77
import NextcloudKit
88
import Alamofire
99

10-
extension NCNetworking: NextcloudKitDelegate {
10+
extension NCNetworking {
11+
12+
#if !EXTENSION_FILE_PROVIDER_EXTENSION
13+
func networkReachabilityObserver(_ typeReachability: NKTypeReachability) {
14+
if typeReachability == NKTypeReachability.reachableCellular || typeReachability == NKTypeReachability.reachableEthernetOrWiFi {
15+
lastReachability = true
16+
} else {
17+
if lastReachability {
18+
let error = NKError(errorCode: global.errorNetworkNotAvailable, errorDescription: "")
19+
NCContentPresenter().messageNotification("_network_not_available_", error: error, delay: global.dismissAfterSecond, type: NCContentPresenter.messageType.info)
20+
}
21+
lastReachability = false
22+
}
23+
networkReachability = typeReachability
24+
NotificationCenter.default.postOnMainThread(name: self.global.notificationCenterNetworkReachability, userInfo: nil)
25+
}
26+
#endif
1127

1228
// MARK: - Download NextcloudKitDelegate
1329

@@ -22,7 +38,7 @@ extension NCNetworking: NextcloudKitDelegate {
2238
Task {
2339
await progressQuantizer.clear(serverUrlFileName: serverUrl + "/" + fileName)
2440

25-
#if EXTENSION_FILE_PROVIDER_EXTENSION || EXTENSION_FILE_PROVIDER_EXTENSION_UI
41+
#if EXTENSION_FILE_PROVIDER_EXTENSION
2642
await FileProviderData.shared.downloadComplete(fileName: fileName,
2743
serverUrl: serverUrl,
2844
etag: etag,
@@ -132,10 +148,12 @@ extension NCNetworking: NextcloudKitDelegate {
132148
etag: etag,
133149
date: date)
134150
} else {
151+
#if !EXTENSION
135152
await NCNetworking.shared.metadataTranfersSuccess.append(metadata: metadata,
136153
ocId: ocId,
137154
date: date,
138155
etag: etag)
156+
#endif
139157
}
140158
} else {
141159
await NCManageDatabase.shared.deleteMetadataAsync(predicate: NSPredicate(format: "fileName == %@ AND serverUrl == %@", fileName, serverUrl))

iOSClient/Networking/NCNetworking+ServerError.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ extension NCNetworking {
4444
groupDefaults.synchronize()
4545
}
4646

47-
#if !EXTENSION
4847
func checkServerError(account: String, controller: NCMainTabBarController?) async {
4948
guard let groupDefaults = UserDefaults(suiteName: NextcloudKit.shared.nkCommonInstance.groupIdentifier)
5049
else {
@@ -89,5 +88,4 @@ extension NCNetworking {
8988
await NCNetworking.shared.termsOfService(account: account)
9089
}
9190
}
92-
#endif
9391
}

iOSClient/Networking/NCNetworking+Upload.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ extension NCNetworking {
284284
}
285285
if let livePhoto = results.livePhoto {
286286
await NCManageDatabase.shared.setLivePhotoVideo(metadatas: [livePhoto])
287+
#if !EXTENSION
287288
await NCNetworking.shared.setLivePhoto(account: metadata.account)
289+
#endif
288290
}
289291

290292
await self.transferDispatcher.notifyAllDelegates { delegate in
@@ -315,7 +317,7 @@ extension NCNetworking {
315317
sessionError: error.errorDescription,
316318
status: self.global.metadataStatusUploadError,
317319
errorCode: error.errorCode)
318-
#if !EXTENSION
320+
#if !EXTENSION
319321
let capabilities = await NKCapabilities.shared.getCapabilities(for: metadata.account)
320322
if !isAppInBackground {
321323
if capabilities.termsOfService {
@@ -324,7 +326,7 @@ extension NCNetworking {
324326
await uploadForbidden(metadata: metadata, error: error)
325327
}
326328
}
327-
#endif
329+
#endif
328330
} else {
329331
if let metadata = await NCManageDatabase.shared.setMetadataSessionAsync(ocId: metadata.ocId,
330332
sessionTaskIdentifier: 0,

0 commit comments

Comments
 (0)