Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Sync of photos wifiOnly #1313

Open
wants to merge 4 commits into
base: Update-feature-wifi-only
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions kDrive/Resources/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Project: kDrive
* Locale: de, German
* Tagged: ios
* Exported by: Matthieu Déglon
* Exported at: Thu, 03 Oct 2024 08:22:20 +0200
* Exported by: Baptiste Griva
* Exported at: Tue, 01 Oct 2024 12:54:40 +0200
*/

/* loco:610a8791fa12ab20713c09e4 */
Expand Down Expand Up @@ -2155,6 +2155,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 @@ -2155,6 +2155,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
Expand Up @@ -3,8 +3,8 @@
* Project: kDrive
* Locale: es, Spanish
* Tagged: ios
* Exported by: Matthieu Déglon
* Exported at: Thu, 03 Oct 2024 08:22:20 +0200
* Exported by: Baptiste Griva
* Exported at: Tue, 01 Oct 2024 12:54:40 +0200
*/

/* loco:610a8791fa12ab20713c09e4 */
Expand Down Expand Up @@ -2155,6 +2155,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
Expand Up @@ -3,8 +3,8 @@
* Project: kDrive
* Locale: fr, French
* Tagged: ios
* Exported by: Matthieu Déglon
* Exported at: Thu, 03 Oct 2024 08:22:20 +0200
* Exported by: Baptiste Griva
* Exported at: Tue, 01 Oct 2024 12:54:40 +0200
*/

/* loco:610a8791fa12ab20713c09e4 */
Expand Down Expand Up @@ -2155,6 +2155,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
Expand Up @@ -3,8 +3,8 @@
* Project: kDrive
* Locale: it, Italian
* Tagged: ios
* Exported by: Matthieu Déglon
* Exported at: Thu, 03 Oct 2024 08:22:20 +0200
* Exported by: Baptiste Griva
* Exported at: Tue, 01 Oct 2024 12:54:40 +0200
*/

/* loco:610a8791fa12ab20713c09e4 */
Expand Down Expand Up @@ -2155,6 +2155,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
70 changes: 70 additions & 0 deletions kDrive/UI/Controller/Menu/OfflineSyncSettingsViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Infomaniak kDrive - iOS App
Copyright (C) 2021 Infomaniak Network SA

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import kDriveCore
import UIKit

class OfflineSyncSettingsViewController: BaseGroupedTableViewController {
private var tableContent: [SyncMode] = SyncMode.allCases
private var selectedOfflineMod: SyncMode!
Copy link
Contributor

@adrien-coye adrien-coye Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should not use force unwrap. You could provide a default value for instance or make it lazy / computed property to make it work.


weak var delegate: SelectPhotoFormatDelegate?

override func viewDidLoad() {
super.viewDidLoad()
tableView.register(cellView: ParameterSyncTableViewCell.self)
selectedOfflineMod = UserDefaults.shared.syncOfflineMod
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
MatomoUtils.track(view: [MatomoUtils.Views.menu.displayName, MatomoUtils.Views.settings.displayName, "selectOfflineMod"])
}

override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableContent.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(type: ParameterSyncTableViewCell.self, for: indexPath)
cell.initWithPositionAndShadow(isFirst: true, isLast: true)
let currentMod = tableContent[indexPath.row]
cell.syncTitleLabel.text = currentMod.title
cell.syncDetailLabel.text = currentMod.selectionTitle
if currentMod == selectedOfflineMod {
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
}
return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let mod = tableContent[indexPath.row]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mode

MatomoUtils.track(eventWithCategory: .settings, name: "mod\(mod.rawValue.capitalized)")
UserDefaults.shared.syncOfflineMod = mod
if mod == .onlyWifi {
UserDefaults.shared.isWifiOnly = true
} else {
UserDefaults.shared.isWifiOnly = false
}
navigationController?.popViewController(animated: true)
}
}
14 changes: 7 additions & 7 deletions kDrive/UI/Controller/Menu/ParameterTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ParameterTableViewController: BaseGroupedTableViewController {
case theme
case notifications
case security
case wifi
case offlineSync
case storage
case about
case deleteAccount
Expand All @@ -50,7 +50,7 @@ class ParameterTableViewController: BaseGroupedTableViewController {
return KDriveResourcesStrings.Localizable.notificationTitle
case .security:
return KDriveResourcesStrings.Localizable.securityTitle
case .wifi:
case .offlineSync:
return KDriveResourcesStrings.Localizable.syncWifiSettingsTitle
case .storage:
return KDriveResourcesStrings.Localizable.manageStorageTitle
Expand Down Expand Up @@ -137,11 +137,11 @@ class ParameterTableViewController: BaseGroupedTableViewController {
cell.titleLabel.text = row.title
return cell

case .wifi:
case .offlineSync:
let cell = tableView.dequeueReusableCell(type: AboutDetailTableViewCell.self, for: indexPath)
cell.initWithPositionAndShadow(isFirst: indexPath.row == 0, isLast: indexPath.row == tableContent.count - 1)
cell.titleLabel.text = UserDefaults.shared.syncMode.title
cell.detailLabel.text = UserDefaults.shared.syncMode.selectionTitle
cell.titleLabel.text = KDriveResourcesStrings.Localizable.syncWifiSettingsTitle
cell.detailLabel.text = UserDefaults.shared.syncOfflineMod.title
return cell
}
}
Expand All @@ -161,8 +161,8 @@ class ParameterTableViewController: BaseGroupedTableViewController {
navigationController?.pushViewController(NotificationsSettingsTableViewController(), animated: true)
case .security:
navigationController?.pushViewController(SecurityTableViewController(), animated: true)
case .wifi:
navigationController?.pushViewController(WifiSyncSettingsViewController(), animated: true)
case .offlineSync:
navigationController?.pushViewController(OfflineSyncSettingsViewController(), animated: true)
case .about:
navigationController?.pushViewController(AboutTableViewController(), animated: true)
case .deleteAccount:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ extension PhotoSyncSettingsViewController {
let cell = tableView.dequeueReusableCell(type: AboutDetailTableViewCell.self, for: indexPath)
cell.initWithPositionAndShadow(isFirst: indexPath.row == 0, isLast: indexPath.row == settingsRows.count - 1)
cell.titleLabel.text = KDriveResourcesStrings.Localizable.syncWifiPicturesTitle
cell.detailLabel.text = UserDefaults.shared.syncMode.title
cell.detailLabel.text = newSyncSettings.wifiSync.title
return cell
}
case .syncDenied:
Expand Down
15 changes: 6 additions & 9 deletions kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController {

tableView.register(cellView: ParameterSyncTableViewCell.self)
tableView.allowsMultipleSelection = false

selectedMode = UserDefaults.shared.syncMode
}

static func instantiate(selectedMode: SyncMode) -> WifiSyncSettingsViewController {
Expand All @@ -66,19 +64,18 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(type: ParameterSyncTableViewCell.self, for: indexPath)
cell.initWithPositionAndShadow(isFirst: true, isLast: true)
let currentMode = tableContent[indexPath.row]
if currentMode == selectedMode {
let currentMod = tableContent[indexPath.row]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mode

cell.syncTitleLabel.text = currentMod.title
cell.syncDetailLabel.text = currentMod.selectionTitle
if currentMod == selectedMode {
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
}
cell.syncTitleLabel.text = currentMode.title
cell.syncDetailLabel.text = currentMode.selectionTitle
return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let mode = tableContent[indexPath.row]
MatomoUtils.track(eventWithCategory: .settings, name: "mode\(mode.rawValue.capitalized)")
UserDefaults.shared.syncMode = mode
let mod = tableContent[indexPath.row]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mode

MatomoUtils.track(eventWithCategory: .settings, name: "mod\(mod.rawValue.capitalized)")
delegate?.didSelectSyncMode(tableContent[indexPath.row])
navigationController?.popViewController(animated: true)
}
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
13 changes: 13 additions & 0 deletions kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,22 @@
*/

import InfomaniakCoreUIKit
import kDriveResources
import UIKit

class ParameterSyncTableViewCell: InsetTableViewCell {
@IBOutlet var syncTitleLabel: UILabel!
@IBOutlet var syncDetailLabel: UILabel!

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

contentInsetView.backgroundColor = KDriveResourcesAsset.backgroundCardViewColor.color
if selected {
contentInsetView.borderColor = KDriveResourcesAsset.infomaniakColor.color
contentInsetView.borderWidth = 2
} else {
contentInsetView.borderWidth = 0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public class DriveFileManagerConstants {

// Migration to add syncWifi
if oldSchemaVersion < 22 {
migration.enumerateObjects(ofType: UploadFile.className()) { _, newObject in
migration.enumerateObjects(ofType: PhotoSyncSettings.className()) { _, newObject in
guard let newObject else {
return
}
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not found of this, can we keep it in UploadQueue ? We do not want to put each upload in error, do we ?

The behaviour until now was the upload queue would not start. We need to discuss this together at least.

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
Loading
Loading