<commit_before>//
//  SettingTableViewController.swift
//  MT_iOS
//
//  Created by CHEEBOW on 2015/05/19.
//  Copyright (c) 2015年 Six Apart, Ltd. All rights reserved.
//

import UIKit
import SVProgressHUD
import SwiftyJSON

class SettingTableViewController: BaseTableViewController {
    enum Section: Int {
        case Item = 0,
        Logout,
        _Num
    }
    
    enum Item: Int {
        case Help = 0,
        License,
        ReportBug,
        _Num
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
        
        self.title = NSLocalizedString("Setting", comment: "Setting")
        self.tableView.backgroundColor = Color.tableBg

        self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "btn_close"), left: true, target: self, action: "closeButtonPushed:")
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Potentially incomplete method implementation.
        // Return the number of sections.
        return Section._Num.rawValue
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete method implementation.
        // Return the number of rows in the section.
        switch section {
        case Section.Item.rawValue:
            return Item._Num.rawValue
        case Section.Logout.rawValue:
            return 1
        default:
            return 0
        }
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell = UITableViewCell()

        switch indexPath.section {
        case Section.Item.rawValue:
            cell = tableView.dequeueReusableCellWithIdentifier("ItemCell", forIndexPath: indexPath) 

            self.adjustCellLayoutMargins(cell)

            switch indexPath.row {
            case Item.Help.rawValue:
                cell.textLabel?.text = NSLocalizedString("Help", comment: "Help")
            case Item.License.rawValue:
                cell.textLabel?.text = NSLocalizedString("License", comment: "License")
            case Item.ReportBug.rawValue:
                cell.textLabel?.text = NSLocalizedString("Report bug", comment: "Report bug")
            default:
                break
            }
        case Section.Logout.rawValue:
            cell = tableView.dequeueReusableCellWithIdentifier("LogoutCell", forIndexPath: indexPath) 
            cell.textLabel?.text = NSLocalizedString("Logout", comment: "Logout")
        default:
            break
        }

        // Configure the cell...

        return cell
    }
    
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        switch indexPath.section {
        case Section.Item.rawValue:
            return 58.0
        case Section.Logout.rawValue:
            return 58.0
        default:
            return 0.0
        }
    }
    
    override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        if section == Section.Logout.rawValue {
            return 50.0
        }
        
        return 0.0
    }
    
    override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        if section == Section.Logout.rawValue {
            let label = UILabel()
            label.font = UIFont.systemFontOfSize(14.0)
            label.textColor = Color.placeholderText
            label.textAlignment = NSTextAlignment.Center
            if let version = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as? String {
                label.text = NSLocalizedString("Movable Type for iOS ver. ", comment: "Movable Type for iOS ver. ") +  version
            }
            return label
        }
        
        return nil
    }

    /*
    // Override to support conditional editing of the table view.
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return NO if you do not want the specified item to be editable.
        return true
    }
    */

    /*
    // Override to support editing the table view.
    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == .Delete {
            // Delete the row from the data source
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        } else if editingStyle == .Insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }
    */

    /*
    // Override to support rearranging the table view.
    override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {

    }
    */

    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return NO if you do not want the item to be re-orderable.
        return true
    }
    */
    
    // MARK: - Table view delegte
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let lang = Utils.preferredLanguage()
        let isJP = (lang as NSString).substringToIndex(2) == "ja" ? true : false
        switch indexPath.section {
        case Section.Item.rawValue:
            switch indexPath.row {
            case Item.Help.rawValue:
                let vc = CommonWebViewController()
                vc.urlString = HELP_URL
                if !isJP {
                    vc.urlString += "en"
                }
                self.navigationController?.pushViewController(vc, animated: true)
            case Item.License.rawValue:
                let vc = CommonWebViewController()
                let path = NSBundle.mainBundle().pathForResource("license", ofType: "html")
                vc.filePath = path!
                self.navigationController?.pushViewController(vc, animated: true)
            case Item.ReportBug.rawValue:
                let vc = CommonWebViewController()
                vc.urlString = REPORT_BUG_URL
                if !isJP {
                    vc.urlString += "/en"
                }
                self.navigationController?.pushViewController(vc, animated: true)
            default:
                break
            }
        case Section.Logout.rawValue:
            let app = UIApplication.sharedApplication().delegate as! AppDelegate
            app.logout()
        default:
            break
        }<commit_msg>iOS8: Cannot display Licence page #240<commit_after>//
//  SettingTableViewController.swift
//  MT_iOS
//
//  Created by CHEEBOW on 2015/05/19.
//  Copyright (c) 2015年 Six Apart, Ltd. All rights reserved.
//

import UIKit
import SVProgressHUD
import SwiftyJSON

class SettingTableViewController: BaseTableViewController {
    enum Section: Int {
        case Item = 0,
        Logout,
        _Num
    }
    
    enum Item: Int {
        case Help = 0,
        License,
        ReportBug,
        _Num
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
        
        self.title = NSLocalizedString("Setting", comment: "Setting")
        self.tableView.backgroundColor = Color.tableBg

        self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "btn_close"), left: true, target: self, action: "closeButtonPushed:")
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // MARK: - Table view data source

    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        // #warning Potentially incomplete method implementation.
        // Return the number of sections.
        return Section._Num.rawValue
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete method implementation.
        // Return the number of rows in the section.
        switch section {
        case Section.Item.rawValue:
            return Item._Num.rawValue
        case Section.Logout.rawValue:
            return 1
        default:
            return 0
        }
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cell = UITableViewCell()

        switch indexPath.section {
        case Section.Item.rawValue:
            cell = tableView.dequeueReusableCellWithIdentifier("ItemCell", forIndexPath: indexPath) 

            self.adjustCellLayoutMargins(cell)

            switch indexPath.row {
            case Item.Help.rawValue:
                cell.textLabel?.text = NSLocalizedString("Help", comment: "Help")
            case Item.License.rawValue:
                cell.textLabel?.text = NSLocalizedString("License", comment: "License")
            case Item.ReportBug.rawValue:
                cell.textLabel?.text = NSLocalizedString("Report bug", comment: "Report bug")
            default:
                break
            }
        case Section.Logout.rawValue:
            cell = tableView.dequeueReusableCellWithIdentifier("LogoutCell", forIndexPath: indexPath) 
            cell.textLabel?.text = NSLocalizedString("Logout", comment: "Logout")
        default:
            break
        }

        // Configure the cell...

        return cell
    }
    
    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        switch indexPath.section {
        case Section.Item.rawValue:
            return 58.0
        case Section.Logout.rawValue:
            return 58.0
        default:
            return 0.0
        }
    }
    
    override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        if section == Section.Logout.rawValue {
            return 50.0
        }
        
        return 0.0
    }
    
    override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        if section == Section.Logout.rawValue {
            let label = UILabel()
            label.font = UIFont.systemFontOfSize(14.0)
            label.textColor = Color.placeholderText
            label.textAlignment = NSTextAlignment.Center
            if let version = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as? String {
                label.text = NSLocalizedString("Movable Type for iOS ver. ", comment: "Movable Type for iOS ver. ") +  version
            }
            return label
        }
        
        return nil
    }

    /*
    // Override to support conditional editing of the table view.
    override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return NO if you do not want the specified item to be editable.
        return true
    }
    */

    /*
    // Override to support editing the table view.
    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if editingStyle == .Delete {
            // Delete the row from the data source
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
        } else if editingStyle == .Insert {
            // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
        }    
    }
    */

    /*
    // Override to support rearranging the table view.
    override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {

    }
    */

    /*
    // Override to support conditional rearranging of the table view.
    override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        // Return NO if you do not want the item to be re-orderable.
        return true
    }
    */
    
    // MARK: - Table view delegte
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let lang = Utils.preferredLanguage()
        let isJP = (lang as NSString).substringToIndex(2) == "ja" ? true : false
        switch indexPath.section {
        case Section.Item.rawValue:
            switch indexPath.row {
            case Item.Help.rawValue:
                let vc = CommonWebViewController()
                vc.urlString = HELP_URL
                if !isJP {
                    vc.urlString += "en"
                }
                self.navigationController?.pushViewController(vc, animated: true)
            case Item.License.rawValue:
                let vc = CommonWebViewController()
                let path = NSBundle(forClass: self.dynamicType).pathForResource("license", ofType: "html")
                vc.filePath = path!
                self.navigationController?.pushViewController(vc, animated: true)
            case Item.ReportBug.rawValue:
                let vc = CommonWebViewController()
                vc.urlString = REPORT_BUG_URL
                if !isJP {
                    vc.urlString += "/en"
                }
                self.navigationController?.pushViewController(vc, animated: true)
            default:
                break
            }
        case Section.Logout.rawValue:
            let app = UIApplication.sharedApplication().delegate as! AppDelegate
            app.logout()
        default:
            break
        }
{'fraction_non_alphanumeric': 0.07881136950904392, 'fraction_numerical': 0.004759961920304637, 'mean_word_length': 2.0518779829840215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '17110', 'n_tokens_mistral': 3995, 'n_tokens_neox': 3697, 'n_words': 1043}