Skip to content

Commit f547171

Browse files
TSI-amrutwaghmareharshada-15-tsys
authored andcommitted
NMC 1984 - Privacy setting view controller added
1 parent efee7c8 commit f547171

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
//
2+
// PrivacySettingsViewController.swift
3+
// Nextcloud
4+
//
5+
// Created by A200073704 on 25/04/23.
6+
// Copyright © 2023 Marino Faggiana. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import AppTrackingTransparency
11+
import AdSupport
12+
13+
class PrivacySettingsViewController: XLFormViewController{
14+
15+
@objc public var isShowSettingsButton: Bool = false
16+
17+
override func viewDidLoad() {
18+
super.viewDidLoad()
19+
self.title = NSLocalizedString("_privacy_settings_title_", comment: "")
20+
21+
NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: NCGlobal.shared.notificationCenterChangeTheming), object: nil)
22+
23+
let nib = UINib(nibName: "CustomSectionHeader", bundle: nil)
24+
self.tableView.register(nib, forHeaderFooterViewReuseIdentifier: "customSectionHeader")
25+
isShowSettingsButton = UserDefaults.standard.bool(forKey: "showSettingsButton")
26+
self.navigationController?.navigationBar.tintColor = NCBrandColor.shared.brand
27+
changeTheming()
28+
}
29+
30+
@objc func changeTheming() {
31+
tableView.backgroundColor = .systemGroupedBackground
32+
tableView.separatorColor = .none
33+
tableView.separatorColor = .clear
34+
tableView.reloadData()
35+
initializeForm()
36+
}
37+
38+
39+
40+
//MARK: XLForm
41+
42+
func initializeForm() {
43+
44+
let form : XLFormDescriptor = XLFormDescriptor() as XLFormDescriptor
45+
form.rowNavigationOptions = XLFormRowNavigationOptions.stopDisableRow
46+
47+
var section : XLFormSectionDescriptor
48+
var row : XLFormRowDescriptor
49+
50+
// Section: Destination Folder
51+
52+
section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("", comment: "").uppercased())
53+
section.footerTitle = " "
54+
form.addFormSection(section)
55+
56+
section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("", comment: "").uppercased())
57+
section.footerTitle = NSLocalizedString("_privacy_settings_help_text_", comment: "")
58+
form.addFormSection(section)
59+
60+
61+
//custom cell
62+
section = XLFormSectionDescriptor.formSection(withTitle: "")
63+
section.footerTitle = NSLocalizedString("_required_data_collection_help_text_", comment: "")
64+
form.addFormSection(section)
65+
66+
67+
XLFormViewController.cellClassesForRowDescriptorTypes()["RequiredDataCollectionCustomCellType"] = RequiredDataCollectionSwitch.self
68+
69+
70+
row = XLFormRowDescriptor(tag: "ButtonDestinationFolder", rowType: "RequiredDataCollectionCustomCellType", title: "")
71+
row.cellConfig["requiredDataCollectionSwitchControl.onTintColor"] = NCBrandColor.shared.brand
72+
row.cellConfig["cellLabel.textAlignment"] = NSTextAlignment.left.rawValue
73+
row.cellConfig["cellLabel.font"] = UIFont.systemFont(ofSize: 15.0)
74+
row.cellConfig["cellLabel.textColor"] = UIColor.label //photos
75+
row.cellConfig["cellLabel.text"] = NSLocalizedString("_required_data_collection_", comment: "")
76+
section.addFormRow(row)
77+
78+
section = XLFormSectionDescriptor.formSection(withTitle: NSLocalizedString("", comment: "").uppercased())
79+
section.footerTitle = NSLocalizedString("_analysis_data_acqusition_help_text_", comment: "")
80+
form.addFormSection(section)
81+
82+
XLFormViewController.cellClassesForRowDescriptorTypes()["AnalysisDataCollectionCustomCellType"] = AnalysisDataCollectionSwitch.self
83+
84+
85+
row = XLFormRowDescriptor(tag: "AnalysisDataCollectionSwitch", rowType: "AnalysisDataCollectionCustomCellType", title: "")
86+
row.cellConfig["analysisDataCollectionSwitchControl.onTintColor"] = NCBrandColor.shared.brand
87+
row.cellConfig["cellLabel.textAlignment"] = NSTextAlignment.left.rawValue
88+
row.cellConfig["cellLabel.font"] = UIFont.systemFont(ofSize: 15.0)
89+
row.cellConfig["cellLabel.textColor"] = UIColor.label //photos
90+
row.cellConfig["cellLabel.text"] = NSLocalizedString("_analysis_data_acqusition_", comment: "")
91+
if(UserDefaults.standard.bool(forKey: "isAnalysisDataCollectionSwitchOn")){
92+
row.cellConfigAtConfigure["analysisDataCollectionSwitchControl.on"] = 1
93+
}else {
94+
row.cellConfigAtConfigure["analysisDataCollectionSwitchControl.on"] = 0
95+
}
96+
97+
section.addFormRow(row)
98+
99+
100+
XLFormViewController.cellClassesForRowDescriptorTypes()["SaveSettingsButton"] = SaveSettingsCustomButtonCell.self
101+
102+
section = XLFormSectionDescriptor.formSection(withTitle: "")
103+
form.addFormSection(section)
104+
105+
106+
row = XLFormRowDescriptor(tag: "SaveSettingsButton", rowType: "SaveSettingsButton", title: "")
107+
row.cellConfig["backgroundColor"] = UIColor.clear
108+
109+
if(isShowSettingsButton){
110+
section.addFormRow(row)
111+
}
112+
113+
114+
self.form = form
115+
}
116+
117+
118+
override func formRowDescriptorValueHasChanged(_ formRow: XLFormRowDescriptor!, oldValue: Any!, newValue: Any!) {
119+
super.formRowDescriptorValueHasChanged(formRow, oldValue: oldValue, newValue: newValue)
120+
121+
if formRow.tag == "SaveSettingsButton" {
122+
print("save settings clicked")
123+
//TODO save button state and leave the page
124+
self.navigationController?.popViewController(animated: true)
125+
126+
}
127+
if formRow.tag == "AnalysisDataCollectionSwitch"{
128+
if (formRow.value! as AnyObject).boolValue {
129+
if #available(iOS 14, *) {
130+
ATTrackingManager.requestTrackingAuthorization(completionHandler: { (status) in
131+
if status == .denied {
132+
guard let url = URL(string: UIApplication.openSettingsURLString) else {
133+
return
134+
}
135+
if UIApplication.shared.canOpenURL(url) {
136+
UIApplication.shared.open(url, options: [:])
137+
}
138+
}
139+
})
140+
}
141+
}
142+
UserDefaults.standard.set((formRow.value! as AnyObject).boolValue, forKey: "isAnalysisDataCollectionSwitchOn")
143+
}
144+
145+
}
146+
147+
}

0 commit comments

Comments
 (0)