<commit_before>//
//  PreferencesViewController.swift
//  Rocket.Chat
//
//  Created by <NAME> on 14/02/17.
//  Copyright © 2017 Rocket.Chat. All rights reserved.
//

import UIKit
import MessageUI
import SafariServices

#if BETA || DEBUG
import FLEX
#endif

final class PreferencesViewController: UITableViewController {

    private let viewModel = PreferencesViewModel()

    @IBOutlet weak var labelProfile: UILabel! {
        didSet {
            labelProfile.text = viewModel.profile
        }
    }

    @IBOutlet weak var labelContactUs: UILabel! {
        didSet {
            labelContactUs.text = viewModel.contactus
        }
    }

    @IBOutlet weak var labelLicense: UILabel! {
        didSet {
            labelLicense.text = viewModel.license
        }
    }

    @IBOutlet weak var labelVersion: UILabel! {
        didSet {
            labelVersion.text = viewModel.formattedVersion
        }
    }

    @IBOutlet weak var labelLanguage: UILabel! {
        didSet {
            labelLanguage.text = viewModel.language
        }
    }

    @IBOutlet weak var labelApp: UILabel! {
        didSet {
            labelApp.text = viewModel.appicon
        }
    }

    @IBOutlet weak var labelWebBrowser: UILabel! {
        didSet {
            labelWebBrowser.text = viewModel.webBrowser
        }
    }

    @IBOutlet weak var labelDefaultWebBrowser: UILabel! {
        didSet {
            labelDefaultWebBrowser.text = WebBrowserManager.browser.name
        }
    }

    override var navigationController: PreferencesNavigationController? {
        return super.navigationController as? PreferencesNavigationController
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        title = viewModel.title
    }

    @IBAction func buttonCloseDidPressed(_ sender: Any) {
        dismiss(animated: true) {
            UserReviewManager.shared.requestReview()
        }
    }

    private func cellTermsOfServiceDidPressed() {
        guard let url = viewModel.licenseURL else { return }
        WebBrowserManager.open(url: url)
    }

    private func cellContactDidPressed() {
        if !MFMailComposeViewController.canSendMail() {
            Alert(
                key: "alert.settings.set_mail_app"
            ).present()
            return
        }

        let controller = MFMailComposeViewController()
        controller.mailComposeDelegate = self
        controller.setToRecipients([viewModel.supportEmail])
        controller.setSubject(viewModel.supportEmailSubject)
        controller.setMessageBody(viewModel.supportEmailBody, isHTML: true)
        present(controller, animated: true, completion: nil)
    }

    // MARK: Navigation

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let webBrowser = segue.destination as? WebBrowserTableViewController {
            webBrowser.updateDefaultWebBrowser = { [weak self] in
                self?.labelDefaultWebBrowser.text = WebBrowserManager.browser.name
            }
        }
    }

    private func cellAppIconDidPressed() {
        performSegue(withIdentifier: "AppIcon", sender: nil)
    }

    private func cellLanguageDidPressed() {
        performSegue(withIdentifier: "Language", sender: nil)
    }

    // MARK: UITableViewDelegate

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.section == 1 {
            if indexPath.row == 0 {
                cellContactDidPressed()
            } else if indexPath.row == 1 {
                cellLanguageDidPressed()
            } else if indexPath.row == 2 {
                cellAppIconDidPressed()
            }
        } else if indexPath.section == 2 {
            if indexPath.row == 0 {
                cellTermsOfServiceDidPressed()
            }
        } else if indexPath.section == 2, indexPath.row == 0 {<commit_msg>Fixed: FLEX cell wasnt working<commit_after>//
//  PreferencesViewController.swift
//  Rocket.Chat
//
//  Created by <NAME> on 14/02/17.
//  Copyright © 2017 Rocket.Chat. All rights reserved.
//

import UIKit
import MessageUI
import SafariServices

#if BETA || DEBUG
import FLEX
#endif

final class PreferencesViewController: UITableViewController {

    private let kSectionProfile = 0
    private let kSectionSettings = 1
    private let kSectionInformation = 2
    private let kSectionFlex = 3

    private let viewModel = PreferencesViewModel()

    @IBOutlet weak var labelProfile: UILabel! {
        didSet {
            labelProfile.text = viewModel.profile
        }
    }

    @IBOutlet weak var labelContactUs: UILabel! {
        didSet {
            labelContactUs.text = viewModel.contactus
        }
    }

    @IBOutlet weak var labelLicense: UILabel! {
        didSet {
            labelLicense.text = viewModel.license
        }
    }

    @IBOutlet weak var labelVersion: UILabel! {
        didSet {
            labelVersion.text = viewModel.formattedVersion
        }
    }

    @IBOutlet weak var labelLanguage: UILabel! {
        didSet {
            labelLanguage.text = viewModel.language
        }
    }

    @IBOutlet weak var labelApp: UILabel! {
        didSet {
            labelApp.text = viewModel.appicon
        }
    }

    @IBOutlet weak var labelWebBrowser: UILabel! {
        didSet {
            labelWebBrowser.text = viewModel.webBrowser
        }
    }

    @IBOutlet weak var labelDefaultWebBrowser: UILabel! {
        didSet {
            labelDefaultWebBrowser.text = WebBrowserManager.browser.name
        }
    }

    override var navigationController: PreferencesNavigationController? {
        return super.navigationController as? PreferencesNavigationController
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        title = viewModel.title
    }

    @IBAction func buttonCloseDidPressed(_ sender: Any) {
        dismiss(animated: true) {
            UserReviewManager.shared.requestReview()
        }
    }

    private func cellTermsOfServiceDidPressed() {
        guard let url = viewModel.licenseURL else { return }
        WebBrowserManager.open(url: url)
    }

    private func cellContactDidPressed() {
        if !MFMailComposeViewController.canSendMail() {
            Alert(
                key: "alert.settings.set_mail_app"
            ).present()
            return
        }

        let controller = MFMailComposeViewController()
        controller.mailComposeDelegate = self
        controller.setToRecipients([viewModel.supportEmail])
        controller.setSubject(viewModel.supportEmailSubject)
        controller.setMessageBody(viewModel.supportEmailBody, isHTML: true)
        present(controller, animated: true, completion: nil)
    }

    // MARK: Navigation

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let webBrowser = segue.destination as? WebBrowserTableViewController {
            webBrowser.updateDefaultWebBrowser = { [weak self] in
                self?.labelDefaultWebBrowser.text = WebBrowserManager.browser.name
            }
        }
    }

    private func cellAppIconDidPressed() {
        performSegue(withIdentifier: "AppIcon", sender: nil)
    }

    private func cellLanguageDidPressed() {
        performSegue(withIdentifier: "Language", sender: nil)
    }

    // MARK: UITableViewDelegate

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.section == kSectionSettings {
            if indexPath.row == 0 {
                cellContactDidPressed()
            } else if indexPath.row == 1 {
                cellLanguageDidPressed()
            } else if indexPath.row == 2 {
                cellAppIconDidPressed()
            }
        } else if indexPath.section == kSectionInformation {
            if indexPath.row == 0 {
                cellTermsOfServiceDidPressed()
            }
        } else if indexPath.section == kSectionFlex, indexPath.row == 0 {
{'fraction_non_alphanumeric': 0.07913940613990941, 'fraction_numerical': 0.004655259184700554, 'mean_word_length': 2.1898073836276084, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5106679', 'n_tokens_mistral': 2241, 'n_tokens_neox': 2103, 'n_words': 486}