Skip to content

Commit

Permalink
feat: Link syncOffline with back
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptGrv committed Sep 27, 2024
1 parent 4ab109d commit e84c2b6
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 17 deletions.
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: [SyncMod] = SyncMod.allCases
private var selectedOfflineMod: SyncMod!

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]
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.syncMod.title
cell.detailLabel.text = UserDefaults.shared.syncMod.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.syncMod.title
cell.detailLabel.text = newSyncSettings.wifiSync.title
return cell
}
case .syncDenied:
Expand Down
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

selectedMod = UserDefaults.shared.syncMod
}

static func instantiate(selectedMod: SyncMod) -> WifiSyncSettingsViewController {
Expand Down Expand Up @@ -78,7 +76,6 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController {
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let mod = tableContent[indexPath.row]
MatomoUtils.track(eventWithCategory: .settings, name: "mod\(mod.rawValue.capitalized)")
UserDefaults.shared.syncMod = mod
delegate?.didSelectSyncMod(tableContent[indexPath.row])
navigationController?.popViewController(animated: true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
*/

import InfomaniakCoreUI
import UIKit
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)

Expand Down
8 changes: 4 additions & 4 deletions kDriveCore/Utils/DriveUserDefaults+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension UserDefaults.Keys {
static let selectedHomeIndex = UserDefaults.Keys(rawValue: "selectedHomeIndex")
static let fpStorageVersion = UserDefaults.Keys(rawValue: "fpStorageVersion")
static let importPhotoFormat = UserDefaults.Keys(rawValue: "importPhotoFormat")
static let syncMod = UserDefaults.Keys(rawValue: "syncMod")
static let synOfflineMod = UserDefaults.Keys(rawValue: "synOfflineMod")
}

public extension UserDefaults {
Expand Down Expand Up @@ -338,16 +338,16 @@ public extension UserDefaults {
}
}

var syncMod: SyncMod {
var syncOfflineMod: SyncMod {
get {
if let rawValue = object(forKey: key(.syncMod)) as? String,
if let rawValue = object(forKey: key(.synOfflineMod)) as? String,
let mod = SyncMod(rawValue: rawValue) {
return mod
}
return .onlyWifi
}
set {
set(newValue.rawValue, forKey: key(.syncMod))
set(newValue.rawValue, forKey: key(.synOfflineMod))
}
}
}

0 comments on commit e84c2b6

Please sign in to comment.