Skip to content

Commit

Permalink
feat: UI for PhotoSync with explicit wifi or 4G (#1441)
Browse files Browse the repository at this point in the history
* feat: Add style on button

# Conflicts:
#	kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift

* feat: Link syncOffline with back

# Conflicts:
#	kDrive/UI/Controller/Menu/ParameterTableViewController.swift
#	kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift
#	kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift
#	kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift
#	kDriveCore/Utils/DriveUserDefaults+Extension.swift

* feat: Sync photos wifiOnly

# Conflicts:
#	kDrive/Resources/de.lproj/Localizable.strings
#	kDrive/Resources/en.lproj/Localizable.strings
#	kDrive/Resources/es.lproj/Localizable.strings
#	kDrive/Resources/fr.lproj/Localizable.strings
#	kDrive/Resources/it.lproj/Localizable.strings

* fix: Change mode

# Conflicts:
#	kDrive/UI/Controller/Menu/OfflineSyncSettingsViewController.swift
#	kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift
#	kDriveCore/Utils/DriveUserDefaults+Extension.swift

* feat: Sync wifi

# Conflicts:
#	kDrive/UI/Controller/Files/Upload/UploadQueueViewController.swift
#	kDrive/UI/Controller/Menu/MenuViewController.swift

* feat: Change cells while no Wifi

* feat: Apply requested changes + loco

# Conflicts:
#	kDrive/Resources/de.lproj/Localizable.strings
#	kDrive/Resources/en.lproj/Localizable.strings
#	kDrive/Resources/es.lproj/Localizable.strings
#	kDrive/Resources/fr.lproj/Localizable.strings
#	kDrive/Resources/it.lproj/Localizable.strings

* fix: Remove useless reloadData

* fix: Resolve issues since merge and cherry-picks

* fix: Clean the code according to review

* refactor(uploadQueue): Suspension logic

* fix: Variable name

* refactor: Merge 2 duplicated files in one

* fix: Remove literal

---------

Co-authored-by: Adrien Coye de Brunélis <[email protected]>
  • Loading branch information
BaptGrv and adrien-coye authored Feb 21, 2025
1 parent a30a605 commit eccd969
Show file tree
Hide file tree
Showing 21 changed files with 548 additions and 46 deletions.
39 changes: 28 additions & 11 deletions kDrive/UI/Controller/Files/Upload/UploadQueueViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ final class UploadQueueViewController: UIViewController {
navigationItem.hideBackButtonText()

tableView.register(cellView: UploadTableViewCell.self)
tableView.register(cellView: ErrorUploadTableViewCell.self)

retryButton.accessibilityLabel = KDriveResourcesStrings.Localizable.buttonRetry
cancelButton.accessibilityLabel = KDriveResourcesStrings.Localizable.buttonCancel
Expand Down Expand Up @@ -147,19 +148,35 @@ extension UploadQueueViewController: UITableViewDataSource {
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(type: UploadTableViewCell.self, for: indexPath)
let fileWrapper = frozenUploadingFiles[indexPath.row]
let frozenFile = fileWrapper.content

cell.initWithPositionAndShadow(isFirst: fileWrapper.isFirstInList,
isLast: fileWrapper.isLastInList)
if indexPath.row == 0 && UserDefaults.shared.isWifiOnly && ReachabilityListener.instance.currentStatus == .cellular {
let cell = tableView.dequeueReusableCell(type: ErrorUploadTableViewCell.self, for: indexPath)
cell.initWithPositionAndShadow(isFirst: true,
isLast: true)
cell.delegate = self
return cell
} else {
let cell = tableView.dequeueReusableCell(type: UploadTableViewCell.self, for: indexPath)
cell.initWithPositionAndShadow(isFirst: indexPath.row == 0,
isLast: indexPath.row == self.tableView(
tableView,
numberOfRowsInSection: indexPath.section
) - 1)

/// Make sure the file is valid
let file = frozenUploadingFiles[indexPath.row].content
if !file.isInvalidated {
let progress: CGFloat? = (file.progress != nil) ? CGFloat(file.progress!) : nil
cell.configureWith(frozenUploadFile: file, progress: progress)
}

if !frozenFile.isInvalidated {
let progress: CGFloat? = (frozenFile.progress != nil) ? CGFloat(frozenFile.progress!) : nil
cell.configureWith(frozenUploadFile: frozenFile, progress: progress)
cell.selectionStyle = .none
return cell
}
}
}

cell.selectionStyle = .none
return cell
extension UploadQueueViewController: AccessParametersDelegate {
func parameterButtonTapped() {
navigationController?.pushViewController(PhotoSyncSettingsViewController(), animated: true)
}
}
44 changes: 40 additions & 4 deletions kDrive/UI/Controller/Home/RootMenuHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class RootMenuHeaderView: UICollectionReusableView {

var onUploadCardViewTapped: (() -> Void)?

deinit {
NotificationCenter.default.removeObserver(self)
}

override func awakeFromNib() {
super.awakeFromNib()

Expand All @@ -45,16 +49,21 @@ class RootMenuHeaderView: UICollectionReusableView {
radius: 10
)

uploadCardView.titleLabel.text = KDriveResourcesStrings.Localizable.uploadInProgressTitle
uploadCardView.progressView.setInfomaniakStyle()
uploadCardView.progressView.enableIndeterminate()
updateWifiView()

uploadCardView.isHidden = true
offlineView.isHidden = true
hideIfNeeded()

let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didTapOnUploadCardView))
uploadCardView.addGestureRecognizer(tapGestureRecognizer)

NotificationCenter.default.addObserver(
self,
selector: #selector(reloadWifiView),
name: .reloadWifiView,
object: nil
)
}

func configureInCollectionView(
Expand Down Expand Up @@ -82,6 +91,10 @@ class RootMenuHeaderView: UICollectionReusableView {
}
}

@objc func reloadWifiView(_ notification: Notification) {
updateWifiView()
}

@objc func didTapOnUploadCardView() {
onUploadCardViewTapped?()
}
Expand Down Expand Up @@ -113,11 +126,34 @@ class RootMenuHeaderView: UICollectionReusableView {
guard let self else { return }

offlineView.isHidden = status != .offline
reloadHeader()

updateWifiView()
}
}
}

private func updateWifiView() {
if UserDefaults.shared.isWifiOnly && ReachabilityListener.instance.currentStatus == .cellular {
uploadCardView.titleLabel.text = KDriveResourcesStrings.Localizable.uploadPausedTitle
uploadCardView.progressView.isHidden = true
uploadCardView.iconView.image = UIImage(systemName: "exclamationmark.arrow.triangle.2.circlepath")
uploadCardView.iconView.isHidden = false
uploadCardView.iconView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
uploadCardView.iconView.widthAnchor.constraint(equalToConstant: 24),
uploadCardView.iconView.heightAnchor.constraint(equalToConstant: 24)
])
uploadCardView.iconView.tintColor = .gray
} else {
uploadCardView.titleLabel.text = KDriveResourcesStrings.Localizable.uploadInProgressTitle
uploadCardView.progressView.isHidden = false
uploadCardView.iconView.isHidden = true
uploadCardView.progressView.setInfomaniakStyle()
uploadCardView.progressView.enableIndeterminate()
}
reloadHeader()
}

private func reloadHeader() {
hideIfNeeded()

Expand Down
2 changes: 1 addition & 1 deletion kDrive/UI/Controller/Home/RootMenuHeaderView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
<color red="0.62352941176470589" green="0.62352941176470589" blue="0.62352941176470589" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="titleColor">
<color red="0.20000000000000001" green="0.20000000000000001" blue="0.20000000000000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.20000000298023224" green="0.20000000298023224" blue="0.20000000298023224" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
Expand Down
40 changes: 35 additions & 5 deletions kDrive/UI/Controller/Menu/MenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ final class MenuViewController: UITableViewController, SelectSwitchDriveDelegate
fatalError("init(coder:) has not been implemented")
}

deinit {
NotificationCenter.default.removeObserver(self)
}

override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -92,12 +96,27 @@ final class MenuViewController: UITableViewController, SelectSwitchDriveDelegate
tableView.register(cellView: MenuTableViewCell.self)
tableView.register(cellView: MenuTopTableViewCell.self)
tableView.register(cellView: UploadsInProgressTableViewCell.self)
tableView.register(cellView: UploadsPausedTableViewCell.self)
tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: UIConstants.List.paddingBottom, right: 0)

updateTableContent()

navigationItem.title = KDriveResourcesStrings.Localizable.menuTitle
navigationItem.hideBackButtonText()

NotificationCenter.default.addObserver(
self,
selector: #selector(reloadWifiView),
name: .reloadWifiView,
object: nil
)

ReachabilityListener.instance.observeNetworkChange(self) { [weak self] _ in
Task { @MainActor in
let indexPath = IndexPath(row: 0, section: 1)
self?.tableView.reloadRows(at: [indexPath], with: .automatic)
}
}
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -158,6 +177,10 @@ final class MenuViewController: UITableViewController, SelectSwitchDriveDelegate
sections.insert(.uploads, at: 1)
}
}

@objc func reloadWifiView(_ notification: Notification) {
reloadData()
}
}

// MARK: - Table view delegate
Expand Down Expand Up @@ -189,11 +212,18 @@ extension MenuViewController {
cell.switchDriveButton.addTarget(self, action: #selector(switchDriveButtonPressed(_:)), for: .touchUpInside)
return cell
} else if section == .uploads {
let cell = tableView.dequeueReusableCell(type: UploadsInProgressTableViewCell.self, for: indexPath)
cell.initWithPositionAndShadow(isFirst: true, isLast: true)
cell.progressView.enableIndeterminate()
cell.setUploadCount(uploadCountManager?.uploadCount ?? 0)
return cell
if UserDefaults.shared.isWifiOnly && ReachabilityListener.instance.currentStatus == .cellular {
let cell = tableView.dequeueReusableCell(type: UploadsPausedTableViewCell.self, for: indexPath)
cell.initWithPositionAndShadow(isFirst: true, isLast: true)
cell.setUploadCount(uploadCountManager?.uploadCount ?? 0)
return cell
} else {
let cell = tableView.dequeueReusableCell(type: UploadsInProgressTableViewCell.self, for: indexPath)
cell.initWithPositionAndShadow(isFirst: true, isLast: true)
cell.progressView.enableIndeterminate()
cell.setUploadCount(uploadCountManager?.uploadCount ?? 0)
return cell
}
} else {
let action = section.actions[indexPath.row]
let cell = tableView.dequeueReusableCell(type: MenuTableViewCell.self, for: indexPath)
Expand Down
14 changes: 7 additions & 7 deletions kDrive/UI/Controller/Menu/ParameterTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ParameterTableViewController: BaseGroupedTableViewController {
case theme
case notifications
case security
case wifi
case offlineSync
case storage
case about
case deleteAccount
Expand All @@ -92,7 +92,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 @@ -245,14 +245,14 @@ 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 == GeneralParameterRow.allCases.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.syncOfflineMode.title
return cell
}
}
Expand Down Expand Up @@ -318,9 +318,9 @@ class ParameterTableViewController: BaseGroupedTableViewController {
navigationController?.pushViewController(NotificationsSettingsTableViewController(), animated: true)
case .security:
navigationController?.pushViewController(SecurityTableViewController(), animated: true)
case .wifi:
case .offlineSync:
navigationController?.pushViewController(
WifiSyncSettingsViewController(selectedMode: UserDefaults.shared.syncMode),
WifiSyncSettingsViewController(selectedMode: UserDefaults.shared.syncOfflineMode, offlineSync: true),
animated: true
)
case .about:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,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 = liveNewSyncSettings.wifiSync.title
return cell
}
case .syncDenied:
Expand Down Expand Up @@ -455,8 +455,7 @@ extension PhotoSyncSettingsViewController {
selectPhotoFormatViewController.delegate = self
navigationController?.pushViewController(selectPhotoFormatViewController, animated: true)
case .wifiSync:
let wifiSyncSettingsViewController = WifiSyncSettingsViewController
.instantiate(selectedMode: liveNewSyncSettings.wifiSync)
let wifiSyncSettingsViewController = WifiSyncSettingsViewController(selectedMode: liveNewSyncSettings.wifiSync)
wifiSyncSettingsViewController.delegate = self
navigationController?.pushViewController(wifiSyncSettingsViewController, animated: true)
default:
Expand Down Expand Up @@ -550,9 +549,12 @@ extension PhotoSyncSettingsViewController: PhotoSyncSettingsTableViewCellDelegat
extension PhotoSyncSettingsViewController: WifiSyncSettingsDelegate {
func didSelectSyncMode(_ mode: SyncMode) {
liveNewSyncSettings.wifiSync = mode
UserDefaults.shared.isWifiOnly = (mode == .onlyWifi)
updateSaveButtonState()
tableView.reloadRows(
at: [IndexPath(row: PhotoSyncSettingsRows.wifiSync.rawValue, section: PhotoSyncSection.syncSettings.rawValue)],
with: .fade
)
NotificationCenter.default.post(name: .reloadWifiView, object: nil)
}
}
18 changes: 12 additions & 6 deletions kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController {

private var tableContent: [SyncMode] = SyncMode.allCases
private var selectedMode: SyncMode
private var offlineSync: Bool
weak var delegate: WifiSyncSettingsDelegate?

init(selectedMode: SyncMode) {
init(selectedMode: SyncMode, offlineSync: Bool = false) {
self.selectedMode = selectedMode
self.offlineSync = offlineSync
super.init()
}

Expand Down Expand Up @@ -69,19 +71,23 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController {
let cell = tableView.dequeueReusableCell(type: ParameterSyncTableViewCell.self, for: indexPath)
cell.initWithPositionAndShadow(isFirst: true, isLast: true)
let currentMode = tableContent[indexPath.row]
cell.syncTitleLabel.text = currentMode.title
cell.syncDetailLabel.text = currentMode.selectionTitle
if currentMode == 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
delegate?.didSelectSyncMode(tableContent[indexPath.row])
MatomoUtils.track(eventWithCategory: .settings, name: "mod\(mode.rawValue.capitalized)")
if !offlineSync {
delegate?.didSelectSyncMode(mode)
} else {
UserDefaults.shared.syncOfflineMode = mode
}

navigationController?.popViewController(animated: true)
}
}
40 changes: 40 additions & 0 deletions kDrive/UI/View/Files/Upload/ErrorUploadTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Infomaniak kDrive - iOS App
Copyright (C) 2024 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 InfomaniakCoreUIKit
import kDriveCore
import kDriveResources
import UIKit

protocol AccessParametersDelegate: AnyObject {
func parameterButtonTapped()
}

class ErrorUploadTableViewCell: InsetTableViewCell {
@IBOutlet var bannerView: UIView!
@IBOutlet var errorIconImageView: UIImageView!
@IBOutlet var errorTitleLabel: UILabel!
@IBOutlet var errorDetailLabel: UILabel!
@IBOutlet var settingButton: UIButton!

weak var delegate: AccessParametersDelegate?

@IBAction func updateButtonPressed(_ sender: UIButton) {
delegate?.parameterButtonTapped()
}
}
Loading

0 comments on commit eccd969

Please sign in to comment.