Skip to content

Commit

Permalink
feat: SyncMod wifi or mobileData
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptGrv committed Sep 24, 2024
1 parent 94294fc commit 1b60603
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 11 deletions.
22 changes: 11 additions & 11 deletions kDrive/UI/Controller/Menu/ParameterTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,16 @@ class ParameterTableViewController: BaseGroupedTableViewController {
cell.valueLabel.text = getNotificationText()
}
return cell
case .wifi:
let cell = tableView.dequeueReusableCell(type: ParameterWifiTableViewCell.self, for: indexPath)
cell.initWithPositionAndShadow()
cell.valueSwitch.isOn = UserDefaults.shared.isWifiOnly
cell.switchHandler = { sender in
MatomoUtils.track(eventWithCategory: .settings, name: "onlyWifiTransfer", value: sender.isOn)
UserDefaults.shared.isWifiOnly = sender.isOn
}
return cell
case .security, .storage, .about, .deleteAccount:
// case .wifi:
// let cell = tableView.dequeueReusableCell(type: ParameterWifiTableViewCell.self, for: indexPath)
// cell.initWithPositionAndShadow()
// cell.valueSwitch.isOn = UserDefaults.shared.isWifiOnly
// cell.switchHandler = { sender in
// MatomoUtils.track(eventWithCategory: .settings, name: "onlyWifiTransfer", value: sender.isOn)
// UserDefaults.shared.isWifiOnly = sender.isOn
// }
// return cell
case .wifi, .security, .storage, .about, .deleteAccount:
let cell = tableView.dequeueReusableCell(type: ParameterAboutTableViewCell.self, for: indexPath)
cell.initWithPositionAndShadow(isFirst: indexPath.row == 0, isLast: indexPath.row == tableContent.count - 1)
cell.titleLabel.text = row.title
Expand All @@ -162,7 +162,7 @@ class ParameterTableViewController: BaseGroupedTableViewController {
case .security:
navigationController?.pushViewController(SecurityTableViewController(), animated: true)
case .wifi:
break
navigationController?.pushViewController(WifiSyncSettingsViewController(), animated: true)
case .about:
navigationController?.pushViewController(AboutTableViewController(), animated: true)
case .deleteAccount:
Expand Down
71 changes: 71 additions & 0 deletions kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
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 InfomaniakCoreUI
import InfomaniakDI
import kDriveCore
import kDriveResources
import UIKit

class WifiSyncSettingsViewController: BaseGroupedTableViewController {
@LazyInjectService private var appNavigable: AppNavigable

private var tableContent: [SyncMod] = SyncMod.allCases
private var selectedMod: SyncMod!

override func viewDidLoad() {
super.viewDidLoad()

title = KDriveResourcesStrings.Localizable.themeSettingsTitle

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

// selectedMod = UserDefaults.shared.syncMod
}

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

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: SelectionTableViewCell.self, for: indexPath)
let currentMod = tableContent[indexPath.row]
if currentMod == selectedMod {
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
}
cell.label.text = currentMod.selectionTitle
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.syncMod = mod
navigationController?.popViewController(animated: true)
}
}
14 changes: 14 additions & 0 deletions kDriveCore/Utils/DriveUserDefaults+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +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")
}

public extension UserDefaults {
Expand Down Expand Up @@ -336,4 +337,17 @@ public extension UserDefaults {
set(newValue.rawValue, forKey: key(.importPhotoFormat))
}
}

var syncMod: SyncMod {
get {
if let rawValue = object(forKey: key(.syncMod)) as? String,
let mod = SyncMod(rawValue: rawValue) {
return mod
}
return .onlyWifi
}
set {
set(newValue.rawValue, forKey: key(.syncMod))
}
}
}
52 changes: 52 additions & 0 deletions kDriveCore/Utils/SyncMod.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
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 kDriveResources
import UIKit

public enum SyncMod: String, CaseIterable {
case onlyWifi
case wifiAndMobileData

// public var interfaceStyle: UIUserInterfaceStyle {
// let styles: [Theme: UIUserInterfaceStyle] = [
// .light: .light,
// .dark: .dark,
// .system: .unspecified
// ]
// return styles[self] ?? .unspecified
// }

public var title: String {
switch self {
case .onlyWifi:
return KDriveResourcesStrings.Localizable.themeSettingsLightLabel
case .wifiAndMobileData:
return KDriveResourcesStrings.Localizable.themeSettingsDarkLabel
}
}

public var selectionTitle: String {
switch self {
case .onlyWifi:
return KDriveResourcesStrings.Localizable.settingsOnlyWifiSyncDescription
case .wifiAndMobileData:
return "Wifi et données mobiles (à changer)"
}
}
}

0 comments on commit 1b60603

Please sign in to comment.