<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import Foundation
import Shared

@available(iOS 11.0, *)
class ContentBlockerSettingViewController: SettingsTableViewController {
    let prefs: Prefs
    let EnabledStates = ContentBlockerHelper.EnabledState.allOptions
    let BlockingStrengths = ContentBlockerHelper.BlockingStrength.allOptions
    var currentEnabledState: ContentBlockerHelper.EnabledState
    var currentBlockingStrength: ContentBlockerHelper.BlockingStrength

    init(prefs: Prefs) {
        self.prefs = prefs
        currentEnabledState = ContentBlockerHelper.EnabledState(rawValue: prefs.stringForKey(ContentBlockerHelper.PrefKeyEnabledState) ?? "") ?? .onInPrivateBrowsing
        currentBlockingStrength = ContentBlockerHelper.BlockingStrength(rawValue: prefs.stringForKey(ContentBlockerHelper.PrefKeyStrength) ?? "") ?? .basic
        
        super.init(nibName: nil, bundle: nil)
        self.title = Strings.SettingsTrackingProtectionSectionName
        hasSectionSeparatorLine = false
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func generateSettings() -> [SettingSection] {
        let enabledSetting: [CheckmarkSetting] = EnabledStates.map { option in
            return CheckmarkSetting(title: NSAttributedString(string: option.settingTitle), subtitle: nil, isEnabled: {
                return option == self.currentEnabledState
            }, onChanged: {
                self.currentEnabledState = option
                self.prefs.setString(self.currentEnabledState.rawValue, forKey: ContentBlockerHelper.PrefKeyEnabledState)
                self.tableView.reloadData()
                ContentBlockerHelper.prefsChanged()

                LeanplumIntegration.sharedInstance.track(eventName: .trackingProtectionSettings, withParameters: ["Enabled option": option.rawValue as AnyObject])
            })
        }

        let strengthSetting: [CheckmarkSetting] = BlockingStrengths.map { option in<commit_msg>Bug 1398143: TP settings tableview now .grouped (fix footer pinning) (#3146)<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import Foundation
import Shared

@available(iOS 11.0, *)
class ContentBlockerSettingViewController: SettingsTableViewController {
    let prefs: Prefs
    let EnabledStates = ContentBlockerHelper.EnabledState.allOptions
    let BlockingStrengths = ContentBlockerHelper.BlockingStrength.allOptions
    var currentEnabledState: ContentBlockerHelper.EnabledState
    var currentBlockingStrength: ContentBlockerHelper.BlockingStrength

    init(prefs: Prefs) {
        self.prefs = prefs
        currentEnabledState = ContentBlockerHelper.EnabledState(rawValue: prefs.stringForKey(ContentBlockerHelper.PrefKeyEnabledState) ?? "") ?? .onInPrivateBrowsing
        currentBlockingStrength = ContentBlockerHelper.BlockingStrength(rawValue: prefs.stringForKey(ContentBlockerHelper.PrefKeyStrength) ?? "") ?? .basic
        
        super.init(style: .grouped)

        self.title = Strings.SettingsTrackingProtectionSectionName
        hasSectionSeparatorLine = false
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func generateSettings() -> [SettingSection] {
        let enabledSetting: [CheckmarkSetting] = EnabledStates.map { option in
            return CheckmarkSetting(title: NSAttributedString(string: option.settingTitle), subtitle: nil, isEnabled: {
                return option == self.currentEnabledState
            }, onChanged: {
                self.currentEnabledState = option
                self.prefs.setString(self.currentEnabledState.rawValue, forKey: ContentBlockerHelper.PrefKeyEnabledState)
                self.tableView.reloadData()
                ContentBlockerHelper.prefsChanged()

                LeanplumIntegration.sharedInstance.track(eventName: .trackingProtectionSettings, withParameters: ["Enabled option": option.rawValue as AnyObject])
            })
        }

        let strengthSetting: [CheckmarkSetting] = BlockingStrengths.map { option in
{'fraction_non_alphanumeric': 0.08016121809225257, 'fraction_numerical': 0.005597850425436633, 'mean_word_length': 3.5581632653061224, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2278290', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1153, 'n_words': 267}