@@ -14,7 +14,11 @@ class PrivacySettingsViewController: UIViewController {
1414
1515 /// Collect tracking info
1616 ///
17- private var collectInfo : Bool = true // tracking turned on by default
17+ private var collectInfo : Bool = WooAnalytics . shared. userHasOptedIn {
18+ didSet {
19+ collectInfoWasUpdated ( newValue: collectInfo)
20+ }
21+ }
1822
1923 // MARK: - Overridden Methods
2024 //
@@ -27,7 +31,6 @@ class PrivacySettingsViewController: UIViewController {
2731 configureSections ( )
2832
2933 registerTableViewCells ( )
30- getUserPreferences ( )
3134 }
3235}
3336
@@ -72,15 +75,11 @@ private extension PrivacySettingsViewController {
7275 }
7376 }
7477
75- func getUserPreferences( ) {
76- collectInfo = WooAnalytics . shared. userHasOptedIn
77- }
78-
7978 /// Cells currently configured in the order they appear on screen.
8079 ///
8180 func configure( _ cell: UITableViewCell , for row: Row , at indexPath: IndexPath ) {
8281 switch cell {
83- case let cell as BasicTableViewCell where row == . collectInfo:
82+ case let cell as SwitchTableViewCell where row == . collectInfo:
8483 configureCollectInfo ( cell: cell)
8584 case let cell as TopLeftImageTableViewCell where row == . shareInfo:
8685 configureShareInfo ( cell: cell)
@@ -99,35 +98,19 @@ private extension PrivacySettingsViewController {
9998 }
10099 }
101100
102- func configureCollectInfo( cell: BasicTableViewCell ) {
101+ func configureCollectInfo( cell: SwitchTableViewCell ) {
103102 // image
104103 cell. imageView? . image = Gridicon . iconOfType ( . stats)
105104 cell. imageView? . tintColor = StyleManager . defaultTextColor
106105
107106 // text
108- cell. textLabel ? . text = NSLocalizedString ( " Collect information " , comment: " Settings > Privacy Settings > collect info section. Label the `Collect information` toggle. " )
107+ cell. title = NSLocalizedString ( " Collect information " , comment: " Settings > Privacy Settings > collect info section. Label the `Collect information` toggle. " )
109108
110109 // switch
111- let toggleSwitch = UISwitch ( )
112- toggleSwitch. setOn ( collectInfo, animated: true )
113- toggleSwitch. onTintColor = StyleManager . wooCommerceBrandColor
114- toggleSwitch. on ( . touchUpInside) { ( toggleSwitch) in
115- self . toggleCollectInfo ( )
116- }
117- cell. accessoryView = toggleSwitch
118-
119- // action
120- let gestureRecognizer = UITapGestureRecognizer ( )
121- gestureRecognizer. on { [ weak self] gesture in
122- guard let self = self else {
123- return
124- }
125-
126- self . toggleCollectInfo ( )
127- toggleSwitch. setOn ( self . collectInfo, animated: true )
110+ cell. isOn = collectInfo
111+ cell. onChange = { newValue in
112+ self . collectInfo = newValue
128113 }
129-
130- cell. addGestureRecognizer ( gestureRecognizer)
131114 }
132115
133116 func configureShareInfo( cell: TopLeftImageTableViewCell ) {
@@ -167,15 +150,12 @@ private extension PrivacySettingsViewController {
167150
168151 // MARK: Actions
169152 //
170- func toggleCollectInfo( ) {
171- // set the user's new preference
172- collectInfo = !collectInfo
173-
153+ func collectInfoWasUpdated( newValue: Bool ) {
174154 // save the user's preference
175- WooAnalytics . shared. setUserHasOptedIn ( collectInfo )
155+ WooAnalytics . shared. setUserHasOptedIn ( newValue )
176156
177157 // Note that Crash Reporting opt-in is dependent on the Collect info setting.
178- AppDelegate . shared. fabricManager. setUserHasOptedIn ( collectInfo )
158+ AppDelegate . shared. fabricManager. setUserHasOptedIn ( newValue )
179159
180160 // this event will only report if the user has turned tracking back on
181161 WooAnalytics . shared. track ( . settingsCollectInfoToggled)
@@ -305,7 +285,7 @@ private enum Row: CaseIterable {
305285 var type : UITableViewCell . Type {
306286 switch self {
307287 case . collectInfo:
308- return BasicTableViewCell . self
288+ return SwitchTableViewCell . self
309289 case . privacyInfo:
310290 return TopLeftImageTableViewCell . self
311291 case . privacyPolicy:
0 commit comments