<commit_before>//
//  BookNameViewController.swift
//  ShaRead
//
//  Created by martin on 2016/4/26.
//  Copyright © 2016年 Frainbow. All rights reserved.
//

import UIKit
import PKHUD

class BookNameViewController: UIViewController {
    @IBOutlet weak var inputTextField: UITextField!

    var book: ShaBook?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    override func viewDidAppear(animated: Bool) {
        setTabBarVisible(true, animated: false)
    }

    override func viewWillDisappear(animated: Bool) {
        setTabBarVisible(false, animated: false)
    }

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

    @IBAction func dismissKeyboard(sender: AnyObject) {
        self.view.endEditing(true)
    }

    @IBAction func endOnExit(sender: AnyObject) {
        self.resignFirstResponder()
        
        newShaBook("9789864340729")
    }

    @IBAction func showScanner(sender: AnyObject) {
        let storyboard = UIStoryboard(name: "Search", bundle: nil)
        let controller = storyboard.instantiateViewControllerWithIdentifier("SearchScannerController") as! ScannerViewController
        
        controller.delegate = self
        
        self.navigationController?.pushViewController(controller, animated: true)
    }
    
    func newShaBook(code: String) {

        let instance = ShaManager.sharedInstance
        
        HUD.show(.Progress)
        instance.newAdminBook(code,
            success: {
                dispatch_async(dispatch_get_main_queue(), {
                    HUD.hide()
                    self.book = instance.adminBooks[instance.adminBooks.count - 1]
                    self.performSegueWithIdentifier("ShowBookConfig", sender: nil)
                })
            },
            failure: {
                HUD.flash(.Error)
            }
        )
    }

    // MARK: - TabBar
    func setTabBarVisible(visible:Bool, animated:Bool) {
        
        //* This cannot be called before viewDidLayoutSubviews(), because the frame is not set before this time<commit_msg>Change upload books flow<commit_after>//
//  BookNameViewController.swift
//  ShaRead
//
//  Created by martin on 2016/4/26.
//  Copyright © 2016年 Frainbow. All rights reserved.
//

import UIKit
import PKHUD

class BookNameViewController: UIViewController {
    @IBOutlet weak var inputTextField: UITextField!

    var book: ShaBook?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    override func viewDidAppear(animated: Bool) {
        setTabBarVisible(true, animated: false)
    }

    override func viewWillDisappear(animated: Bool) {
        setTabBarVisible(false, animated: false)
    }

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

    @IBAction func dismissKeyboard(sender: AnyObject) {
        self.view.endEditing(true)
    }

    @IBAction func endOnExit(sender: AnyObject) {
        self.resignFirstResponder()
        
        newShaBook("9789864340729")
    }

    @IBAction func showScanner(sender: AnyObject) {
        let storyboard = UIStoryboard(name: "Search", bundle: nil)
        let controller = storyboard.instantiateViewControllerWithIdentifier("SearchScannerController") as! ScannerViewController
        
        controller.delegate = self
        
        self.navigationController?.pushViewController(controller, animated: true)
    }
    
    func newShaBook(code: String) {

        let instance = ShaManager.sharedInstance
        
        HUD.show(.Progress)
        instance.newAdminBook(code,
            success: {
                dispatch_async(dispatch_get_main_queue(), {
                    HUD.hide()
                    self.book = instance.adminBooks[instance.adminBooks.count - 1]

                    // Change UI Flow
                    //self.performSegueWithIdentifier("ShowBookConfig", sender: nil)

                    self.navigationController?.popViewControllerAnimated(true)
                })
            },
            failure: {
                HUD.flash(.Error)
            }
        )
    }

    // MARK: - TabBar
    func setTabBarVisible(visible:Bool, animated:Bool) {
        
        //* This cannot be called before viewDidLayoutSubviews(), because the frame is not set before this time
{'fraction_non_alphanumeric': 0.08471978984238179, 'fraction_numerical': 0.010945709281961471, 'mean_word_length': 2.192872117400419, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7140115', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1202, 'n_words': 284}