<commit_before>//
//  RecordingsTableViewController.swift
//  Harekaze
//
//  Created by <NAME> on 2016/07/10.
//  Copyright © 2016年 <NAME>. All rights reserved.
//


import UIKit
import Material
import APIKit

private struct Item {
	var text: String
	var image: UIImage?
}

class RecordingsTableViewController: UITableViewController {

	// MARK: - Private instance fileds
	private var dataSource: [Program] = []

	// MARK: - Interface Builder outlets
	@IBOutlet weak var menuButton: IconButton!
	@IBOutlet weak var searchButton: IconButton!
	@IBOutlet weak var castButton: IconButton!
	@IBOutlet weak var moreButton: IconButton!
	
	// MARK: - View initialization

	override func viewDidLoad() {
		super.viewDidLoad()

		// Refresh data stored list
		refreshDataSource()

		// Set navigation title
		navigationItem.title = "Recordings"
		navigationItem.titleLabel.textAlignment = .Left
		navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
		navigationItem.titleLabel.textColor = MaterialColor.white

		// Set navigation bar buttons
		menuButton.addTarget(self, action: #selector(handleMenuButton), forControlEvents: .TouchUpInside)
		navigationItem.leftControls = [menuButton]
		navigationItem.rightControls = [searchButton, castButton, moreButton]

		// Table
		self.tableView.registerNib(UINib(nibName: "ProgramItemMaterialTableViewCell", bundle: nil), forCellReuseIdentifier: "ProgramItemCell")

		tableView.separatorStyle = .SingleLine
		tableView.separatorInset = UIEdgeInsetsZero

		// 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()
	}


	override func viewDidAppear(animated: Bool) {
		super.viewDidAppear(animated)

		// Close navigation drawer
		navigationDrawerController?.closeLeftView()
	}

	// MARK: - Memory/resource management

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


	// MARK: - Event handler

	internal func handleMenuButton() {
		navigationDrawerController?.openLeftView()
	}

	// MARK: - Resource updater

	internal func refreshDataSource() {
		ChinachuAPI.wuiAddress = "http://chinachu.local:10772"
		let request = ChinachuAPI.RecordingRequest()
		Session.sendRequest(request) { result in
			switch result {
			case .Success(let data):
				self.dataSource = data.reverse()
				self.tableView.reloadData()
			case .Failure(let error):
				print("error: \(error)")
			}<commit_msg>Add status bar background view<commit_after>//
//  RecordingsTableViewController.swift
//  Harekaze
//
//  Created by <NAME> on 2016/07/10.
//  Copyright © 2016年 <NAME>. All rights reserved.
//


import UIKit
import Material
import APIKit

private struct Item {
	var text: String
	var image: UIImage?
}

class RecordingsTableViewController: UITableViewController {

	// MARK: - Private instance fileds
	private var dataSource: [Program] = []
	private var statusBarView: MaterialView!

	// MARK: - Interface Builder outlets
	@IBOutlet weak var menuButton: IconButton!
	@IBOutlet weak var searchButton: IconButton!
	@IBOutlet weak var castButton: IconButton!
	@IBOutlet weak var moreButton: IconButton!
	
	// MARK: - View initialization

	override func viewDidLoad() {
		super.viewDidLoad()

		// Refresh data stored list
		refreshDataSource()

		// Set status bar
		statusBarView = MaterialView()
		statusBarView.zPosition = 3000
		statusBarView.backgroundColor = MaterialColor.black.colorWithAlphaComponent(0.12)
		self.navigationController?.view.layout(statusBarView).top(0).horizontally().height(20)

		// Set navigation title
		navigationItem.title = "Recordings"
		navigationItem.titleLabel.textAlignment = .Left
		navigationItem.titleLabel.font = RobotoFont.mediumWithSize(20)
		navigationItem.titleLabel.textColor = MaterialColor.white

		// Set navigation bar buttons
		menuButton.addTarget(self, action: #selector(handleMenuButton), forControlEvents: .TouchUpInside)
		navigationItem.leftControls = [menuButton]
		navigationItem.rightControls = [searchButton, castButton, moreButton]

		// Table
		self.tableView.registerNib(UINib(nibName: "ProgramItemMaterialTableViewCell", bundle: nil), forCellReuseIdentifier: "ProgramItemCell")

		tableView.separatorStyle = .SingleLine
		tableView.separatorInset = UIEdgeInsetsZero

		// 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()
	}


	override func viewDidAppear(animated: Bool) {
		super.viewDidAppear(animated)

		// Close navigation drawer
		navigationDrawerController?.closeLeftView()
	}

	// MARK: - Memory/resource management

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

	// MARK: - Layout methods
	override func viewWillLayoutSubviews() {
		super.viewWillLayoutSubviews()
		statusBarView.hidden = MaterialDevice.isLandscape && .iPhone == MaterialDevice.type
	}

	// MARK: - Event handler

	internal func handleMenuButton() {
		navigationDrawerController?.openLeftView()
	}

	// MARK: - Resource updater

	internal func refreshDataSource() {
		ChinachuAPI.wuiAddress = "http://chinachu.local:10772"
		let request = ChinachuAPI.RecordingRequest()
		Session.sendRequest(request) { result in
			switch result {
			case .Success(let data):
				self.dataSource = data.reverse()
				self.tableView.reloadData()
			case .Failure(let error):
				print("error: \(error)")
			}
{'fraction_non_alphanumeric': 0.09454358270418668, 'fraction_numerical': 0.008236101578586136, 'mean_word_length': 4.442577030812325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6200585', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1641, 'n_words': 433}