<commit_before>//
//  BasicTableViewController.swift
//  pass
//
//  Created by <NAME> on 9/2/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit
import SafariServices
import MessageUI


enum CellDataType {
    case link, segue, empty, detail
}

enum CellDataStyle {
    case value1, defaultStyle
}

enum CellDataKey {
    case style, type, title, link, accessoryType, detailDisclosureAction, detailDisclosureData, detailText, action
}

class BasicStaticTableViewController: UITableViewController, MFMailComposeViewControllerDelegate {
    var tableData = [[Dictionary<CellDataKey, Any>]]()
    var navigationItemTitle: String?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        if navigationItemTitle != nil {
            navigationItem.title = navigationItemTitle
        }
    }
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        return tableData.count
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return tableData[section].count
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cellData = tableData[indexPath.section][indexPath.row]
        let cellDataStyle = cellData[CellDataKey.style] as? CellDataStyle
        var cell: UITableViewCell?
        
        switch cellDataStyle ?? .defaultStyle {
        case .value1:
            cell = UITableViewCell(style: .value1, reuseIdentifier: "value1 cell")
            cell?.selectionStyle = .none
        default:
            cell = UITableViewCell(style: .default, reuseIdentifier: "default cell")
        }
        
        if let detailText = cellData[CellDataKey.detailText] as? String {
            cell?.detailTextLabel?.text = detailText
        }
        if let accessoryType = cellData[CellDataKey.accessoryType] as? UITableViewCellAccessoryType {
            cell?.accessoryType = accessoryType
        } else {
            cell?.accessoryType = .disclosureIndicator
            cell?.selectionStyle = .default
        }
        
        cell?.textLabel?.text = cellData[CellDataKey.title] as? String
        return cell ?? UITableViewCell()
    }
    
    override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
        let cellData = tableData[indexPath.section][indexPath.row]
        let selector = cellData[CellDataKey.detailDisclosureAction] as? Selector
        perform(selector, with: cellData[CellDataKey.detailDisclosureData])
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        let cellData = tableData[indexPath.section][indexPath.row]
        let cellDataAction = cellData[CellDataKey.action] as? String
        switch cellDataAction ?? "" {
        case "segue":
            let link = cellData[CellDataKey.link] as? String
            performSegue(withIdentifier: link!, sender: self)
        case "link":
            let link = cellData[CellDataKey.link] as! String
            let url = URL(string: link)!
            switch url.scheme! {
            case "mailto":
                let urlComponents = URLComponents(string: link)!
                let subject = urlComponents.queryItems![0].value ?? ""
                if MFMailComposeViewController.canSendMail() {
                    sendEmail(toRecipients: [urlComponents.path], subject: subject)
                }
            case "http", "https":
                let svc = SFSafariViewController(url: URL(string: link)!, entersReaderIfAvailable: false)
                    self.present(svc, animated: true, completion: nil)
            default:
                break
            }
        default:
            break<commit_msg>Show and copy developer email if failed to open the Mail App<commit_after>//
//  BasicTableViewController.swift
//  pass
//
//  Created by <NAME> on 9/2/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit
import SafariServices
import MessageUI


enum CellDataType {
    case link, segue, empty, detail
}

enum CellDataStyle {
    case value1, defaultStyle
}

enum CellDataKey {
    case style, type, title, link, accessoryType, detailDisclosureAction, detailDisclosureData, detailText, action
}

class BasicStaticTableViewController: UITableViewController, MFMailComposeViewControllerDelegate {
    var tableData = [[Dictionary<CellDataKey, Any>]]()
    var navigationItemTitle: String?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        if navigationItemTitle != nil {
            navigationItem.title = navigationItemTitle
        }
    }
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        return tableData.count
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return tableData[section].count
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cellData = tableData[indexPath.section][indexPath.row]
        let cellDataStyle = cellData[CellDataKey.style] as? CellDataStyle
        var cell: UITableViewCell?
        
        switch cellDataStyle ?? .defaultStyle {
        case .value1:
            cell = UITableViewCell(style: .value1, reuseIdentifier: "value1 cell")
            cell?.selectionStyle = .none
        default:
            cell = UITableViewCell(style: .default, reuseIdentifier: "default cell")
        }
        
        if let detailText = cellData[CellDataKey.detailText] as? String {
            cell?.detailTextLabel?.text = detailText
        }
        if let accessoryType = cellData[CellDataKey.accessoryType] as? UITableViewCellAccessoryType {
            cell?.accessoryType = accessoryType
        } else {
            cell?.accessoryType = .disclosureIndicator
            cell?.selectionStyle = .default
        }
        
        cell?.textLabel?.text = cellData[CellDataKey.title] as? String
        return cell ?? UITableViewCell()
    }
    
    override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
        let cellData = tableData[indexPath.section][indexPath.row]
        let selector = cellData[CellDataKey.detailDisclosureAction] as? Selector
        perform(selector, with: cellData[CellDataKey.detailDisclosureData])
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        let cellData = tableData[indexPath.section][indexPath.row]
        let cellDataAction = cellData[CellDataKey.action] as? String
        switch cellDataAction ?? "" {
        case "segue":
            let link = cellData[CellDataKey.link] as? String
            performSegue(withIdentifier: link!, sender: self)
        case "link":
            let link = cellData[CellDataKey.link] as! String
            let url = URL(string: link)!
            switch url.scheme! {
            case "mailto":
                let urlComponents = URLComponents(string: link)!
                let subject = urlComponents.queryItems![0].value ?? ""
                if MFMailComposeViewController.canSendMail() {
                    sendEmail(toRecipients: [urlComponents.path], subject: subject)
                } else {
                    let email = urlComponents.path
                    let alertTitle = "Cannot open Mail App"
                    let alertMessage = "Email copied: \(email)"
                    Utils.copyToPasteboard(textToCopy: email)
                    Utils.alert(title: alertTitle, message: alertMessage, controller: self, completion: nil)
                }
            case "http", "https":
                let svc = SFSafariViewController(url: URL(string: link)!, entersReaderIfAvailable: false)
                    self.present(svc, animated: true, completion: nil)
            default:
                break
            }
        default:
            break
{'fraction_non_alphanumeric': 0.08451369216241737, 'fraction_numerical': 0.0035410764872521247, 'mean_word_length': 2.427588996763754, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 15, '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': '2270563', 'n_tokens_mistral': 2305, 'n_tokens_neox': 2176, 'n_words': 562}