Skip to content

Commit

Permalink
feat: Sync photos wifiOnly
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptGrv committed Oct 1, 2024
1 parent e84c2b6 commit d49749b
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 14 deletions.
7 changes: 5 additions & 2 deletions kDrive/Resources/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Loco ios export: iOS Localizable.strings
* Loco ios export: Xcode Strings (legacy)
* Project: kDrive
* Locale: de, German
* Tagged: ios
* Exported by: Baptiste Griva
* Exported at: Thu, 26 Sep 2024 10:46:53 +0200
* Exported at: Tue, 01 Oct 2024 12:54:40 +0200
*/

/* loco:610a8791fa12ab20713c09e4 */
Expand Down Expand Up @@ -2149,6 +2149,9 @@
/* loco:6049df4d5c2c3a04bc397a8c */
"uploadNetworkErrorWifiRequired" = "Warten auf WLAN";

/* loco:66fbba74682fe9a0990df012 */
"uploadOverDataRestrictedError" = "Warten auf Wi-Fi";

/* loco:60928fcf72952001716b86d2 */
"uploadPausedDescription" = "Einige Uploads sind in kDrive noch im Gange. Öffnen Sie die App und lassen Sie das Gerät verbunden, um den Upload zu beschleunigen.";

Expand Down
7 changes: 5 additions & 2 deletions kDrive/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Loco ios export: iOS Localizable.strings
* Loco ios export: Xcode Strings (legacy)
* Project: kDrive
* Locale: en, English
* Tagged: ios
* Exported by: Baptiste Griva
* Exported at: Thu, 26 Sep 2024 10:46:53 +0200
* Exported at: Tue, 01 Oct 2024 12:54:40 +0200
*/

/* loco:610a8791fa12ab20713c09e4 */
Expand Down Expand Up @@ -2149,6 +2149,9 @@
/* loco:6049df4d5c2c3a04bc397a8c */
"uploadNetworkErrorWifiRequired" = "Waiting for WiFi network";

/* loco:66fbba74682fe9a0990df012 */
"uploadOverDataRestrictedError" = "Waiting for Wi-Fi";

/* loco:60928fcf72952001716b86d2 */
"uploadPausedDescription" = "Some uploads are still in progress in kDrive. Open the app and keep the device connected to speed up the upload.";

Expand Down
7 changes: 5 additions & 2 deletions kDrive/Resources/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Loco ios export: iOS Localizable.strings
* Loco ios export: Xcode Strings (legacy)
* Project: kDrive
* Locale: es, Spanish
* Tagged: ios
* Exported by: Baptiste Griva
* Exported at: Thu, 26 Sep 2024 10:46:53 +0200
* Exported at: Tue, 01 Oct 2024 12:54:40 +0200
*/

/* loco:610a8791fa12ab20713c09e4 */
Expand Down Expand Up @@ -2149,6 +2149,9 @@
/* loco:6049df4d5c2c3a04bc397a8c */
"uploadNetworkErrorWifiRequired" = "A la espera de red WiFi";

/* loco:66fbba74682fe9a0990df012 */
"uploadOverDataRestrictedError" = "A la espera de Wi-Fi";

/* loco:60928fcf72952001716b86d2 */
"uploadPausedDescription" = "Algunas subidas siguen en curso en kDrive. Abre la aplicación y mantén el dispositivo conectado para acelerar la carga.";

Expand Down
7 changes: 5 additions & 2 deletions kDrive/Resources/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Loco ios export: iOS Localizable.strings
* Loco ios export: Xcode Strings (legacy)
* Project: kDrive
* Locale: fr, French
* Tagged: ios
* Exported by: Baptiste Griva
* Exported at: Thu, 26 Sep 2024 10:46:53 +0200
* Exported at: Tue, 01 Oct 2024 12:54:40 +0200
*/

/* loco:610a8791fa12ab20713c09e4 */
Expand Down Expand Up @@ -2149,6 +2149,9 @@
/* loco:6049df4d5c2c3a04bc397a8c */
"uploadNetworkErrorWifiRequired" = "En attente de réseau Wi-Fi";

/* loco:66fbba74682fe9a0990df012 */
"uploadOverDataRestrictedError" = "En attente de Wi-Fi";

/* loco:60928fcf72952001716b86d2 */
"uploadPausedDescription" = "Des importations sont toujours en cours dans kDrive. Ouvrez l’app et gardez l’appareil branché pour accélérer l’upload.";

Expand Down
7 changes: 5 additions & 2 deletions kDrive/Resources/it.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* Loco ios export: iOS Localizable.strings
* Loco ios export: Xcode Strings (legacy)
* Project: kDrive
* Locale: it, Italian
* Tagged: ios
* Exported by: Baptiste Griva
* Exported at: Thu, 26 Sep 2024 10:46:53 +0200
* Exported at: Tue, 01 Oct 2024 12:54:40 +0200
*/

/* loco:610a8791fa12ab20713c09e4 */
Expand Down Expand Up @@ -2149,6 +2149,9 @@
/* loco:6049df4d5c2c3a04bc397a8c */
"uploadNetworkErrorWifiRequired" = "In attesa di connessione alla rete Wi-Fi";

/* loco:66fbba74682fe9a0990df012 */
"uploadOverDataRestrictedError" = "In attesa del Wi-Fi";

/* loco:60928fcf72952001716b86d2 */
"uploadPausedDescription" = "Alcuni caricamenti sono ancora in corso in kDrive. Aprite l’app e mantenete il dispositivo connesso per accelerare il caricamento.";

Expand Down
9 changes: 7 additions & 2 deletions kDrive/UI/View/Files/Upload/UploadTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,13 @@ final class UploadTableViewCell: InsetTableViewCell {

if let error = uploadFile.error, error != .taskRescheduled {
cardContentView.retryButton?.isHidden = false
cardContentView.detailsLabel.text = KDriveResourcesStrings.Localizable
.errorUpload + " (\(error.localizedDescription))"
if error.localizedDescription == KDriveResourcesStrings.Localizable.uploadOverDataRestrictedError {
cardContentView.detailsLabel.text = error.localizedDescription
} else {
cardContentView.detailsLabel.text = KDriveResourcesStrings.Localizable
.errorUpload + " (\(error.localizedDescription))"
}

} else {
cardContentView.retryButton?
.isHidden = (uploadFile.maxRetryCount > 0) // Display retry for uploads that reached automatic retry limit
Expand Down
7 changes: 6 additions & 1 deletion kDriveCore/Data/Models/DriveError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ public struct DriveError: Error, Equatable {
localizedString: KDriveResourcesStrings.Localizable.errorCache)
public static let unknownError = DriveError(type: .localError, code: "unknownError")

public static let uploadOverDataRestrictedError = DriveError(type: .localError,
code: "uploadOverDataRestrictedError",
localizedString: KDriveResourcesStrings.Localizable.uploadOverDataRestrictedError)

// MARK: - Server

public static let refreshToken = DriveError(type: .serverError, code: "refreshToken")
Expand Down Expand Up @@ -261,7 +265,8 @@ public struct DriveError: Error, Equatable {
uploadTokenIsNotValid,
fileAlreadyExistsError,
errorDeviceStorage,
limitExceededError]
limitExceededError,
uploadOverDataRestrictedError]

private static let encoder = JSONEncoder()
private static let decoder = JSONDecoder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ extension UploadOperation {
// Silently stop if an UploadFile is no longer in base
// _not_ overriding file.error
self.cancel()
case .uploadOverDataRestrictedError:
file.error = DriveError.uploadOverDataRestrictedError
}

errorHandled = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import Foundation
import InfomaniakCore

extension UploadOperation {
func getPhAssetIfNeeded() async throws {
Expand Down Expand Up @@ -56,4 +57,22 @@ extension UploadOperation {
file.pathURL = url
}
}

func checkForRestrictedUploadOverDataMode() throws {
let file = try readOnlyFile()

guard file.type == .phAsset else {
// This UploadFile is not a PHAsset, return silently
return
}

let status = ReachabilityListener.instance.currentStatus
let canUpload = !(status == .cellular && photoLibraryUploader.frozenSettings?.wifiSync == .onlyWifi)

guard !canUpload else {
return
}

throw ErrorDomain.uploadOverDataRestrictedError
}
}
5 changes: 5 additions & 0 deletions kDriveCore/Data/UploadQueue/Operation/UploadOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public final class UploadOperation: AsynchronousOperation, UploadOperationable {
case operationFinished
/// Cannot decrease further retry count, already zero
case retryCountIsZero
/// Cannot upload image because we are not in wifi
case uploadOverDataRestrictedError
}

// MARK: - Attributes
Expand Down Expand Up @@ -127,6 +129,9 @@ public final class UploadOperation: AsynchronousOperation, UploadOperationable {
// Clean existing error if any
try self.cleanUploadFileError()

// Pause the upload depending on the status
try self.checkForRestrictedUploadOverDataMode()

// Fetch content from local library if needed
try await self.getPhAssetIfNeeded()

Expand Down
2 changes: 1 addition & 1 deletion kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public final class UploadQueue: ParallelismHeuristicDelegate {
}

let status = ReachabilityListener.instance.currentStatus
return status == .offline || (status != .wifi && UserDefaults.shared.isWifiOnly)
return status == .offline
}

/// Should suspend operation queue based on explicit `suspendAllOperations()` call
Expand Down

0 comments on commit d49749b

Please sign in to comment.