-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: Update-feature-wifi-only
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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! | ||
|
||
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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
*/ | ||
|
||
import Foundation | ||
import InfomaniakCore | ||
|
||
extension UploadOperation { | ||
func getPhAssetIfNeeded() async throws { | ||
|
@@ -56,4 +57,22 @@ extension UploadOperation { | |
file.pathURL = url | ||
} | ||
} | ||
|
||
func checkForRestrictedUploadOverDataMode() throws { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} |
There was a problem hiding this comment.
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.