@@ -42,7 +42,7 @@ class SettingsViewController: UIViewController {
4242 tableView. tableFooterView = UIView ( frame: . zero)
4343
4444 segmentedControl. selectedSegmentIndex = 0
45- segmentedControl. addTarget ( self , action: #selector( segmentedControlAction ( _: ) ) , for: . valueChanged)
45+ segmentedControl. addTarget ( self , action: #selector( onSegmentControlValueChange ( _: ) ) , for: . valueChanged)
4646 navigationItem. titleView = segmentedControl
4747
4848 let resetBarButton = UIBarButtonItem ( title: " Reset " , style: . plain, target: self , action: #selector( resetButtonAction ( _: ) ) )
@@ -55,6 +55,9 @@ class SettingsViewController: UIViewController {
5555 case 0 :
5656 ApplicationSettings . shared. isRfidEnabled = false
5757 ApplicationSettings . shared. useCustomRfidController = false
58+
59+ initApplicationSettings ( )
60+ sectionsData = applicationGroups
5861 case 1 :
5962 let scenario = DocReader . shared. selectedScenario ( )
6063 let defaultProcessParams = ProcessParams ( )
@@ -63,14 +66,17 @@ class SettingsViewController: UIViewController {
6366 let defaultFunctionality = Functionality ( )
6467 ApplicationSettings . shared. functionality = defaultFunctionality
6568 DocReader . shared. functionality = defaultFunctionality
69+
70+ initAPISettings ( )
71+ sectionsData = apiGroups
6672 default :
6773 break
6874 }
6975 tableView. reloadData ( )
7076 }
7177
72- @objc func segmentedControlAction ( _ sender: UISegmentedControl ) {
73- switch sender . selectedSegmentIndex {
78+ @objc func onSegmentControlValueChange ( _ sender: UISegmentedControl ) {
79+ switch segmentedControl . selectedSegmentIndex {
7480 case 0 :
7581 sectionsData = applicationGroups
7682 case 1 :
@@ -82,6 +88,8 @@ class SettingsViewController: UIViewController {
8288 }
8389
8490 private func initApplicationSettings( ) {
91+ self . applicationGroups. removeAll ( )
92+
8593 let settings = ApplicationSettings . shared
8694
8795 // 1. RFID
@@ -97,6 +105,8 @@ class SettingsViewController: UIViewController {
97105 }
98106
99107 private func initAPISettings( ) {
108+ self . apiGroups. removeAll ( )
109+
100110 let functionality = DocReader . shared. functionality
101111 let params = DocReader . shared. processParams
102112
@@ -337,7 +347,7 @@ class SettingsViewController: UIViewController {
337347 guard let self = self else { return }
338348 let currentValue = params. forceDocFormat. map { $0. intValue } . flatMap { DocFormat ( rawValue: $0) ? . description } ?? " nil "
339349 let options : [ String ] = DocFormat . allCases. map { $0. description } + [ " nil " ]
340- self . showOptionsPicker ( title: " Force Doc Format " , current: currentValue, options: options) { ( result) in
350+ self . showOptionsPicker ( title: " Force Doc Format " , current: [ currentValue] , options: options) { ( result) in
341351 let param = DocFormat ( result) . map { NSNumber ( value: $0. rawValue) }
342352 DocReader . shared. processParams. forceDocFormat = param
343353 self . tableView. reloadData ( )
@@ -352,13 +362,24 @@ class SettingsViewController: UIViewController {
352362
353363 let mrzFormatsFilter = SettingsActionItem ( title: " MRZ Formats Filter " ) { [ weak self] in
354364 guard let self = self else { return }
355- self . showIntegerArrayEditor ( title: " MRZ Formats Filter " , inputArray: DocReader . shared. processParams. mrzFormatsFilter as? [ Int ] ) { output in
356- DocReader . shared. processParams. mrzFormatsFilter = output
365+ let currentValue = params. mrzFormatsFilter? . map { $0. intValue } . compactMap { MRZFormat ( rawValue: $0) ? . description } ?? [ ]
366+ let options : [ String ] = MRZFormat . allCases. map { $0. description }
367+ self . showOptionsPicker ( title: " MRZ Formats Filter " , current: currentValue, options: options) { ( result) in
368+ guard let param = MRZFormat ( result) . map ( { NSNumber ( value: $0. rawValue) } ) else { return }
369+
370+ var filters = params. mrzFormatsFilter ?? [ ]
371+ if let paramIndex = filters. firstIndex ( of: param) {
372+ filters. remove ( at: paramIndex)
373+ } else {
374+ filters. append ( param)
375+ }
376+
377+ DocReader . shared. processParams. mrzFormatsFilter = filters
357378 self . tableView. reloadData ( )
358379 }
359380 } state: {
360381 let currentList = DocReader . shared. processParams. mrzFormatsFilter ?? [ ]
361- let value = currentList. compactMap { $0. stringValue } . joined ( separator: " , " )
382+ let value = currentList. compactMap { MRZFormat ( rawValue : $0. intValue ) ? . description } . joined ( separator: " , " )
362383 return value. isEmpty ? " nil " : value
363384 }
364385
@@ -534,20 +555,24 @@ class SettingsViewController: UIViewController {
534555 present ( actionSheet, animated: true , completion: nil )
535556 }
536557
537- private func showOptionsPicker( title: String , current: String , options: [ String ] , completion: @escaping ( String ) -> Void ) {
538- let actionSheet = UIAlertController ( title: nil , message: title, preferredStyle: self . alertStyleForDevice ( ) )
539- for option in options {
540- let action = UIAlertAction ( title: option, style: . default) { _ in
541- completion ( option)
542- }
543- if option == current {
544- action. setValue ( true , forKey: " checked " )
545- }
546- actionSheet. addAction ( action)
547- }
548- actionSheet. addAction ( UIAlertAction . init ( title: " Cancel " , style: . cancel, handler: nil ) )
549- present ( actionSheet, animated: true , completion: nil )
550- }
558+ private func showOptionsPicker( title: String , current: [ String ] , options: [ String ] , completion: @escaping ( String ) -> Void ) {
559+ let actionSheet = UIAlertController ( title: nil , message: title, preferredStyle: self . alertStyleForDevice ( ) )
560+
561+ for option in options {
562+ let action = UIAlertAction ( title: option, style: . default) { _ in
563+ completion ( option)
564+ }
565+
566+ for selected in current where selected == option {
567+ action. setValue ( true , forKey: " checked " )
568+ }
569+
570+ actionSheet. addAction ( action)
571+ }
572+
573+ actionSheet. addAction ( UIAlertAction . init ( title: " Cancel " , style: . cancel, handler: nil ) )
574+ present ( actionSheet, animated: true , completion: nil )
575+ }
551576
552577 private func showCaptureModeList( _ completion: VoidClosure ? = nil ) {
553578 let modes : [ CaptureMode ] = [ . auto, . captureVideo, . captureFrame]
0 commit comments