Skip to content

Commit

Permalink
Reset Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
martenrebane committed Dec 20, 2023
1 parent d8bd188 commit ee99b3b
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 5 deletions.
4 changes: 4 additions & 0 deletions MoppApp/MoppApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
DF32A690290C983100AE5F82 /* MessageUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF32A68E290C983100AE5F82 /* MessageUtil.swift */; };
DF32A691290C983100AE5F82 /* ErrorUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF32A68F290C983100AE5F82 /* ErrorUtil.swift */; };
DF35B1922AEAE32A0018AC7E /* PersonalCodeField.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF35B1912AEAE32A0018AC7E /* PersonalCodeField.swift */; };
DF3756182AFABEB7006960C5 /* SettingsResetCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF3756172AFABEB7006960C5 /* SettingsResetCell.swift */; };
DF3950602AD766DF005D96AC /* KeychainUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF39505F2AD766DF005D96AC /* KeychainUtil.swift */; };
DF3D299D23F5ADB7007181B8 /* MimeTypeExtractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF3D299C23F5ADB7007181B8 /* MimeTypeExtractor.swift */; };
DF3D29CF23F6B3CF007181B8 /* SkSigningLib.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DF3D29CE23F6B3CF007181B8 /* SkSigningLib.framework */; };
Expand Down Expand Up @@ -519,6 +520,7 @@
DF32A68E290C983100AE5F82 /* MessageUtil.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageUtil.swift; sourceTree = "<group>"; };
DF32A68F290C983100AE5F82 /* ErrorUtil.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ErrorUtil.swift; sourceTree = "<group>"; };
DF35B1912AEAE32A0018AC7E /* PersonalCodeField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonalCodeField.swift; sourceTree = "<group>"; };
DF3756172AFABEB7006960C5 /* SettingsResetCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsResetCell.swift; sourceTree = "<group>"; };
DF39505F2AD766DF005D96AC /* KeychainUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainUtil.swift; sourceTree = "<group>"; };
DF3D299C23F5ADB7007181B8 /* MimeTypeExtractor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MimeTypeExtractor.swift; sourceTree = "<group>"; };
DF3D29CE23F6B3CF007181B8 /* SkSigningLib.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SkSigningLib.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -935,6 +937,7 @@
DF8EFB19287498B900A96DE3 /* SettingsDefaultValueCell.swift */,
DFD54CF429CDDB0600CD92C7 /* SettingsTSACertCell.swift */,
DFBDF1F127D79B8B00A5CF3C /* SettingsStateCell.swift */,
DF3756172AFABEB7006960C5 /* SettingsResetCell.swift */,
);
name = Settings;
sourceTree = "<group>";
Expand Down Expand Up @@ -1654,6 +1657,7 @@
C54EA6EB2046C3BA0039AC78 /* UITextField+Additions.swift in Sources */,
C50DCCC31FC2D54200D48E16 /* UIFont+Additions.swift in Sources */,
C50DCD051FC7125300D48E16 /* ContainerNotificationCell.swift in Sources */,
DF3756182AFABEB7006960C5 /* SettingsResetCell.swift in Sources */,
DFBEF9452434DD0C007A6762 /* UIAlertAction+Additions.swift in Sources */,
DFEE73042A151423003428E4 /* ScaledTextView.swift in Sources */,
C56C6208201A1B4C00CCC2A5 /* MenuSeparatorCell.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/LocalizationKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ enum LocKey : String
case settingsTimestampCertValidToLabel = "settings-timestamp-cert-valid-to-label"
case settingsTimestampCertAddCertificateButton = "settings-timestamp-cert-add-certificate-button"
case settingsTimestampCertShowCertificateButton = "settings-timestamp-cert-show-certificate-button"
case settingsResetButton = "settings-reset-button"
case diagnosticsTitle = "diagnostics-title"
case diagnosticsActivateOneTimeLogging = "diagnostics-activate-one-time-logging"
case diagnosticsSaveLog = "diagnostics-save-log"
Expand Down Expand Up @@ -478,4 +479,5 @@ enum LocKey : String
case voiceControlRoleCountry = "voice-control-role-country";
case voiceControlRoleZip = "voice-control-role-zip";
case voiceControlRoleAndAddress = "voice-control-role-and-address";
case voiceControlResetButton = "voice-control-reset-button";
}
33 changes: 30 additions & 3 deletions MoppApp/MoppApp/Settings.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
<objects>
<viewController storyboardIdentifier="SettingsViewController" id="Sh7-45-xtX" customClass="SettingsViewController" customModule="MoppApp" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="AZY-Pk-idj">
<rect key="frame" x="0.0" y="0.0" width="375" height="900"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="1200"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" showsHorizontalScrollIndicator="NO" bouncesZoom="NO" dataMode="prototypes" style="plain" separatorStyle="none" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" contentViewInsetsToSafeArea="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AAa-T3-Ggw">
<rect key="frame" x="0.0" y="20" width="375" height="880"/>
<rect key="frame" x="0.0" y="20" width="375" height="1180"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="SettingsHeaderCell" rowHeight="70" id="jXf-Fq-jhZ" customClass="SettingsHeaderCell" customModule="MoppApp" customModuleProvider="target">
Expand Down Expand Up @@ -381,6 +381,33 @@
<outlet property="titleLabel" destination="Iu4-8i-4zf" id="avF-7h-HkC"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="SettingsResetCell" id="1yr-XE-Rqx" customClass="SettingsResetCell" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="0.0" y="908" width="375" height="55"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="1yr-XE-Rqx" id="NK1-zD-Iv7">
<rect key="frame" x="0.0" y="0.0" width="375" height="55"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="wordWrap" translatesAutoresizingMaskIntoConstraints="NO" id="aWQ-NP-4wB" customClass="ScaledButton" customModule="MoppApp" customModuleProvider="target">
<rect key="frame" x="16" y="25" width="343" height="30"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" title="Reset settings"/>
<connections>
<action selector="resetSettings:" destination="1yr-XE-Rqx" eventType="touchUpInside" id="Gmi-gk-z8q"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="aWQ-NP-4wB" firstAttribute="leading" secondItem="NK1-zD-Iv7" secondAttribute="leading" constant="16" id="SyV-Vh-DZu"/>
<constraint firstAttribute="trailing" secondItem="aWQ-NP-4wB" secondAttribute="trailing" constant="16" id="XYY-Ha-g4u"/>
<constraint firstAttribute="bottom" secondItem="aWQ-NP-4wB" secondAttribute="bottom" id="axo-Kv-PlT"/>
<constraint firstItem="aWQ-NP-4wB" firstAttribute="top" secondItem="NK1-zD-Iv7" secondAttribute="top" constant="25" id="fYX-eh-hOh"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="resetSettingsButton" destination="aWQ-NP-4wB" id="3mW-LS-eOQ"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="Sh7-45-xtX" id="fHf-VL-4F7"/>
Expand All @@ -401,7 +428,7 @@
<constraint firstItem="AAa-T3-Ggw" firstAttribute="bottom" secondItem="fCG-eI-IFp" secondAttribute="bottom" id="w0w-Xs-w2L"/>
</constraints>
</view>
<size key="freeformSize" width="375" height="900"/>
<size key="freeformSize" width="375" height="1200"/>
<connections>
<outlet property="tableView" destination="AAa-T3-Ggw" id="Oip-3a-EBO"/>
</connections>
Expand Down
57 changes: 57 additions & 0 deletions MoppApp/MoppApp/SettingsResetCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// SettingsResetCell.swift
// MoppApp
//
/*
* Copyright 2017 - 2023 Riigi Infosüsteemi Amet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

import UIKit

protocol SettingsResetCellDelegate: AnyObject {
func didTapResetSettings()
}

class SettingsResetCell: UITableViewCell {

weak var delegate: SettingsResetCellDelegate!

@IBOutlet weak var resetSettingsButton: ScaledButton!

@IBAction func resetSettings(_ sender: ScaledButton) {
delegate.didTapResetSettings()
}

func populate(with title: String) {
resetSettingsButton.setTitle(title)
resetSettingsButton.accessibilityLabel = title.lowercased()
resetSettingsButton.accessibilityUserInputLabels = [L(.voiceControlResetButton)]
resetSettingsButton.mediumFont()
}

override func awakeFromNib() {
super.awakeFromNib()

guard let resetSettingsUIButton: ScaledButton = resetSettingsButton else {
printLog("Unable to get resetSettingsButton")
return
}

self.accessibilityElements = [resetSettingsUIButton]
}
}
6 changes: 6 additions & 0 deletions MoppApp/MoppApp/SettingsTSACertCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ class SettingsTSACertCell: UITableViewCell {
}
}

func removeCertificate() {
TSACertUtil.removeCertificate()
certificate = nil
updateUI()
}

private func showErrorMessage(errorMessage: String, topViewController: UIViewController) {
let errorDialog = AlertUtil.errorDialog(errorMessage: errorMessage, topViewController: topViewController)
topViewController.present(errorDialog, animated: true)
Expand Down
62 changes: 60 additions & 2 deletions MoppApp/MoppApp/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SettingsViewController: MoppViewController {
@IBOutlet weak var tableView: UITableView!

var isDefaultTimestampValue = true
var settingsTsaCertCell: SettingsTSACertCell?

enum Section {
case header
Expand All @@ -37,6 +38,7 @@ class SettingsViewController: MoppViewController {
case useDefault
case tsaCert
case roleAndAddress
case resetSettings
}

struct Field {
Expand All @@ -47,6 +49,7 @@ class SettingsViewController: MoppViewController {
case defaultSwitch
case tsaCert
case state
case resetButton
}

let id: FieldId
Expand Down Expand Up @@ -93,7 +96,18 @@ class SettingsViewController: MoppViewController {
title: L(.settingsTimestampCertTitle),
placeholderText: NSAttributedString(string: L(.settingsTimestampCertTitle)),
value: ""),
Field(id: .roleAndAddress, kind: .state, title: L(.roleAndAddressRoleTitle), placeholderText: NSAttributedString(string: L(.roleAndAddressRoleTitle)), value: "")
Field(
id: .roleAndAddress,
kind: .state,
title: L(.roleAndAddressRoleTitle),
placeholderText: NSAttributedString(string: L(.roleAndAddressRoleTitle)),
value: ""),
Field(
id: .resetSettings,
kind: .resetButton,
title: L(.settingsResetButton),
placeholderText: NSAttributedString(string: L(.settingsResetButton)),
value: "")
]

override func viewDidLoad() {
Expand Down Expand Up @@ -126,6 +140,7 @@ class SettingsViewController: MoppViewController {
var defaultValueCellIndex: Int = 0
var tsaCertCellIndex: Int = 0
var stateCellIndex: Int = 0
var resetCellIndex: Int = 0
for (index, cell) in tableView.visibleCells.enumerated() {
if cell is SettingsHeaderCell {
headerCellIndex = index
Expand All @@ -139,6 +154,8 @@ class SettingsViewController: MoppViewController {
tsaCertCellIndex = index
} else if cell is SettingsStateCell {
stateCellIndex = index
} else if cell is SettingsResetCell {
resetCellIndex = index
}
}

Expand Down Expand Up @@ -171,13 +188,20 @@ class SettingsViewController: MoppViewController {
return []
}

let resetCertCell = tableView.visibleCells[resetCellIndex]

guard let resetCertCellAccessibilityElements = tableView.visibleCells[resetCellIndex].accessibilityElements else {
return []
}

if timestampDefaultSwitch.isOff {
return [
timestampDefaultSwitch,
fieldCellAccessibilityElements,
timestampTextfield,
tsaCertCellAccessibilityElements,
roleSwitch,
resetCertCellAccessibilityElements,
headerCellAccessibilityElements,
timestampDefaultSwitch
]
Expand All @@ -188,10 +212,32 @@ class SettingsViewController: MoppViewController {
fieldCellAccessibilityElements,
timestampTextfield,
roleSwitch,
resetCertCellAccessibilityElements,
headerCellAccessibilityElements,
timestampDefaultSwitch
]
}

func resetSettings() {
DefaultsHelper.rpUuid = ""
DefaultsHelper.timestampUrl = MoppConfiguration.tsaUrl
DefaultsHelper.defaultSettingsSwitch = true
isDefaultTimestampValue = true

DefaultsHelper.isRoleAndAddressEnabled = false
DefaultsHelper.roleNames = []
DefaultsHelper.roleCity = ""
DefaultsHelper.roleState = ""
DefaultsHelper.roleCountry = ""
DefaultsHelper.roleZip = ""

if let tsaCertCell = settingsTsaCertCell {
tsaCertCell.removeCertificate()
}
DefaultsHelper.tsaCertFileName = ""

tableView.reloadData()
}
}

extension SettingsViewController: UITableViewDelegate, UITableViewDataSource {
Expand Down Expand Up @@ -222,7 +268,7 @@ extension SettingsViewController: UITableViewDelegate, UITableViewDataSource {
case .header:
let headerCell = tableView.dequeueReusableCell(withType: SettingsHeaderCell.self, for: indexPath)!
headerCell.delegate = self
headerCell.populate(with:L(.settingsTitle))
headerCell.populate(with: L(.settingsTitle))
return headerCell
case .fields:
let field = fields[indexPath.row]
Expand Down Expand Up @@ -260,11 +306,17 @@ extension SettingsViewController: UITableViewDelegate, UITableViewDataSource {
let tsaCertCell = tableView.dequeueReusableCell(withType: SettingsTSACertCell.self, for: indexPath)!
tsaCertCell.topViewController = getTopViewController()
tsaCertCell.populate()
settingsTsaCertCell = tsaCertCell
return tsaCertCell
case .state:
let stateCell = tableView.dequeueReusableCell(withType: SettingsStateCell.self, for: indexPath)!
stateCell.populate(with: field)
return stateCell
case .resetButton:
let resetCell = tableView.dequeueReusableCell(withType: SettingsResetCell.self, for: indexPath)!
resetCell.delegate = self
resetCell.populate(with: field.title)
return resetCell
}
}
return UITableViewCell()
Expand All @@ -284,6 +336,12 @@ extension SettingsViewController: SettingsHeaderCellDelegate {
}
}

extension SettingsViewController: SettingsResetCellDelegate {
func didTapResetSettings() {
resetSettings()
}
}

extension SettingsViewController: SettingsFieldCellDelegate {
func didEndEditingField(_ fieldId: SettingsViewController.FieldId, with value:String) {
switch fieldId {
Expand Down
7 changes: 7 additions & 0 deletions MoppApp/MoppApp/TSACertUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,11 @@ class TSACertUtil {
return nil
}
}

static func removeCertificate() {
let certLocation = getTsaCertFile()
if let certPath = certLocation, !certPath.path.isEmpty {
MoppFileManager.shared.removeFile(withPath: certPath.path)
}
}
}
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@
"settings-timestamp-cert-valid-to-label" = "Valid to:";
"settings-timestamp-cert-add-certificate-button" = "ADD CERTIFICATE";
"settings-timestamp-cert-show-certificate-button" = "SHOW CERTIFICATE";
"settings-reset-button" = "USE DEFAULT SETTINGS";
"diagnostics-title" = "Diagnostics";
"diagnostics-activate-one-time-logging" = "Enable one-time log generation";
"diagnostics-save-log" = "SAVE LOG";
Expand Down Expand Up @@ -521,3 +522,4 @@
"voice-control-role-country" = "Country";
"voice-control-role-zip" = "Zip";
"voice-control-role-and-address" = "Role and address";
"voice-control-reset-button" = "Reset settings";
2 changes: 2 additions & 0 deletions MoppApp/MoppApp/et.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@
"settings-timestamp-cert-valid-to-label" = "Kehtib kuni:";
"settings-timestamp-cert-add-certificate-button" = "LISA SERTIFIKAAT";
"settings-timestamp-cert-show-certificate-button" = "NÄITA SERTIFIKAATI";
"settings-reset-button" = "TAASTA ALGSEADED";
"diagnostics-title" = "Diagnostika";
"diagnostics-activate-one-time-logging" = "Aktiveeri ühekordne logifaili genereerimine";
"diagnostics-save-log" = "SALVESTA LOGIFAIL";
Expand Down Expand Up @@ -521,3 +522,4 @@
"voice-control-role-country" = "Country";
"voice-control-role-zip" = "Zip";
"voice-control-role-and-address" = "Role and address";
"voice-control-reset-button" = "Reset settings";
Loading

0 comments on commit ee99b3b

Please sign in to comment.