<commit_before>//
//  DropdownMenuTableView.swift
//  AnimatedDropdownMenu
//
//  Created by JonyFang on 17/2/27.
//  Copyright © 2017年 JonyFang. All rights reserved.
//

import UIKit

class DropdownMenuTableView: UITableView {
    
    public struct Item {
        public let title: String
        public let icon: UIImage
        public let iconLight: UIImage
    }
    
    public var selectRowAtIndexPathHandler: ((_ indexPath: Int) -> ())?
    
    fileprivate var selectedIndexPath: Int?
    fileprivate var items: [Item] = []
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    init(frame: CGRect, items: [Item], selectedIndexPath: Int) {
        super.init(frame: frame, style: .plain)
        
        self.items = items
        self.selectedIndexPath = selectedIndexPath
        
        delegate = self
        dataSource = self
        separatorStyle = .none
    }
}

extension DropdownMenuTableView: UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        //TODO: Configure cell
        let cell = UITableViewCell()
        return cell
    }
}

extension DropdownMenuTableView: UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        //TODO: guard indexPath
        selectedIndexPath = indexPath.row
        selectRowAtIndexPathHandler!(indexPath.row)
        reloadData()
    }
    
    func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        //TODO: Configure Deselected Cell
    }
    
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        //TODO: Configure tableViewCell
    }
}
<commit_msg>Configure DropdownMenuTableViewCell in DropdownMenuTableView<commit_after>//
//  DropdownMenuTableView.swift
//  AnimatedDropdownMenu
//
//  Created by JonyFang on 17/2/27.
//  Copyright © 2017年 JonyFang. All rights reserved.
//

import UIKit

class DropdownMenuTableView: UITableView {
    
    public struct Item {
        public let title: String
        public let icon: UIImage
        public let iconLight: UIImage
    }
    
    public var selectRowAtIndexPathHandler: ((_ indexPath: Int) -> ())?
    
    fileprivate var selectedIndexPath: Int?
    fileprivate var items: [Item] = []
    fileprivate var dropdownMenuConfig: DropdownMenuConfig!
    fileprivate let kDropdownMenuTableViewCell = "DropdownMenuTableViewCell"
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    init(frame: CGRect, items: [Item], selectedIndexPath: Int, config: DropdownMenuConfig) {
        super.init(frame: frame, style: .plain)
        
        self.items = items
        self.selectedIndexPath = selectedIndexPath
        self.dropdownMenuConfig = config
        
        delegate = self
        dataSource = self
        separatorStyle = .none
        backgroundColor = .clear
    }
}

extension DropdownMenuTableView: UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = DropdownMenuTableViewCell(style: .default, reuseIdentifier: kDropdownMenuTableViewCell, config: dropdownMenuConfig)
        cell.textLabel?.text = items[indexPath.row].title
        
        return cell
    }
}

extension DropdownMenuTableView: UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return dropdownMenuConfig.cellHeight
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        selectedIndexPath = indexPath.row
        selectRowAtIndexPathHandler!(indexPath.row)
        reloadData()
        
//        let cell = tableView.cellForRow(at: indexPath) as? DropdownMenuTableViewCell
//        cell?.contentView.backgroundColor = dropdownMenuConfig.cellSelectionColor
//        cell?.textLabel?.textColor = dropdownMenuConfig.cellTextLabelSelectedColor
    }
    
    func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        
//        let cell = tableView.cellForRow(at: indexPath) as? DropdownMenuTableViewCell
//        cell?.contentView.backgroundColor = dropdownMenuConfig.cellBackgroundColor
//        cell?.textLabel?.textColor = dropdownMenuConfig.cellTextLabelColor
    }
    
    func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        
        guard dropdownMenuConfig.shouldKeepSelectedCellColor! else {
            return
        }
        
        let tableCell = cell as! DropdownMenuTableViewCell
        
        tableCell.textLabel?.textColor = (indexPath.row == selectedIndexPath) ?
            dropdownMenuConfig.cellTextLabelSelectedColor :
            dropdownMenuConfig.cellTextLabelColor
        tableCell.iconImageView?.image = (indexPath.row == selectedIndexPath) ? items[indexPath.row].iconLight : items[indexPath.row].icon
    }
}

{'fraction_non_alphanumeric': 0.07867711053089643, 'fraction_numerical': 0.0038294168842471716, 'mean_word_length': 2.7335932423651723, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '255670', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1577, 'n_words': 378}