<commit_before>//
//  HomeViewController.swift
//  Gank
//
//  Created by Maru on 2016/12/1.
//  Copyright © 2016年 Maru. All rights reserved.
//

import UIKit
import SwiftWebVC
import HMSegmentedControl
import EZSwiftExtensions
import Then
import SnapKit
import Reusable
import RxSwift
import RxCocoa
import Kingfisher
import NoticeBar
import PullToRefresh

final class HomeViewController: UIViewController {
    
    let tableView = UITableView().then {
        $0.register(cellType: HomeTableViewCell.self)
    }
    
    let refreshControl = PullToRefresh()
    
    let homeVM = HomeViewModel()
        
    // MARK: - Life Cycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setup()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

extension HomeViewController {
    
    // MARK: - Private Method
    
    fileprivate func setup() {
        
        do /** UI Config */ {
            
            title = "Gank"
            
            tableView.estimatedRowHeight = 100
            tableView.addPullToRefresh(refreshControl, action: {})
            
            view.addSubview(tableView)
            
            tableView.snp.makeConstraints { (make) in
                make.edges.equalTo(view)
            }
            
        }
        
        do /** Rx Config */ {
        
            // Input

            NotificationCenter.default.rx.notification(Notification.Name.category)
                .map({ (notification) -> Int in
                    let indexPath = (notification.object as? IndexPath) ?? IndexPath(item: 0, section: 0)
                    return indexPath.row
                })
                .observeOn(MainScheduler.instance)
                .do(onNext: { (idx) in
                    print(idx)
                    self.tableView.startRefreshing(at: .top)
                }, onError: nil, onCompleted: nil, onSubscribe:nil,onDispose: nil)
                .bindTo(homeVM.refreshCommand)
                .addDisposableTo(rx_disposeBag)
            
            // Output
            
            homeVM.section
                .drive(tableView.rx.items(dataSource: homeVM.dataSource))
                .addDisposableTo(rx_disposeBag)
            
            tableView.rx.setDelegate(self)
                .addDisposableTo(rx_disposeBag)<commit_msg>finish the basic function;<commit_after>//
//  HomeViewController.swift
//  Gank
//
//  Created by Maru on 2016/12/1.
//  Copyright © 2016年 Maru. All rights reserved.
//

import UIKit
import SwiftWebVC
import HMSegmentedControl
import EZSwiftExtensions
import Then
import SnapKit
import Reusable
import RxSwift
import RxCocoa
import Kingfisher
import NoticeBar
import SideMenu
import PullToRefresh

final class HomeViewController: UIViewController {
    
    let tableView = UITableView().then {
        $0.register(cellType: HomeTableViewCell.self)
    }
    
    let refreshControl = PullToRefresh()
    
    let homeVM = HomeViewModel()
        
    // MARK: - Life Cycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setup()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

extension HomeViewController {
    
    // MARK: - Private Method
    
    fileprivate func setup() {
        
        do /** UI Config */ {
            
            title = "Gank"
            
            tableView.estimatedRowHeight = 100
            tableView.addPullToRefresh(refreshControl, action: {})
            
            view.addSubview(tableView)
            
            tableView.snp.makeConstraints { (make) in
                make.edges.equalTo(view)
            }
            
        }
        
        do /** Rx Config */ {
        
            // Input

            NotificationCenter.default.rx.notification(Notification.Name.category)
                .map({ (notification) -> Int in
                    let indexPath = (notification.object as? IndexPath) ?? IndexPath(item: 0, section: 0)
                    return indexPath.row
                })
                .observeOn(MainScheduler.instance)
                .do(onNext: { (idx) in
                    print(idx)
                    SideMenuManager.menuLeftNavigationController?.dismiss(animated: true, completion: nil)
                    self.tableView.startRefreshing(at: .top)
                }, onError: nil, onCompleted: nil, onSubscribe:nil,onDispose: nil)
                .bindTo(homeVM.refreshCommand)
                .addDisposableTo(rx_disposeBag)
            
            // Output
            
            homeVM.section
                .drive(tableView.rx.items(dataSource: homeVM.dataSource))
                .addDisposableTo(rx_disposeBag)
            
            tableView.rx.setDelegate(self)
                .addDisposableTo(rx_disposeBag)
{'fraction_non_alphanumeric': 0.08303886925795052, 'fraction_numerical': 0.006674519042010208, 'mean_word_length': 1.6235839340885685, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5316596', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1336, 'n_words': 280}