Added comments to SettingsViewHousekeeperSettingsViewModel.

This commit is contained in:
eduardopietre 2022-05-08 19:22:32 -03:00
parent 3184affe76
commit 1ff963799c
1 changed files with 9 additions and 2 deletions

View File

@ -10,6 +10,7 @@ import Foundation
import UIKit
/// Enum used for each row of HousekeeperSettings.
fileprivate enum Setting: Int, CaseIterable {
// For how many days should we store BgReadings, Calibrations and Treatments, in days
@ -21,8 +22,11 @@ fileprivate enum Setting: Int, CaseIterable {
}
/// SettingsViewHousekeeperSettingsViewModel defines the settings section for Housekeeper.
/// Implements SettingsViewModelProtocol.
struct SettingsViewHousekeeperSettingsViewModel: SettingsViewModelProtocol {
/// Instance of coreDataManager
private var coreDataManager: CoreDataManager?
init(coreDataManager: CoreDataManager?) {
@ -87,13 +91,16 @@ struct SettingsViewHousekeeperSettingsViewModel: SettingsViewModelProtocol {
guard let setting = Setting(rawValue: index) else { fatalError("Unexpected Section") }
switch setting {
/// When housekeeperRetentionPeriod is selected, display a popup asking for the new retention period.
case .housekeeperRetentionPeriod:
return SettingsSelectedRowAction.askText(title: Texts_SettingsView.settingsviews_housekeeperRetentionPeriod, message: Texts_SettingsView.settingsviews_housekeeperRetentionPeriodMessage, keyboardType: .numberPad, text: UserDefaults.standard.retentionPeriodInDays.description, placeHolder: "90", actionTitle: nil, cancelTitle: nil, actionHandler: {
(retention:String) in if let retentionInt = Int(retention) {UserDefaults.standard.retentionPeriodInDays = retentionInt}}, cancelHandler: nil, inputValidator: nil)
/// When exportAllData is selected, calls DataExporter for generating and writing the data to a file, passing the callback down to exportAllData.
case .exportAllData:
return SettingsSelectedRowAction.callFunctionAndShareFile { callback in
/// coreDataManager must not be nil.
if let coreDataManager = coreDataManager {
DataExporter(coreDataManager: coreDataManager).exportAllData(callback: callback)
}