<commit_before>//
//  BRCSortedViewController.swift
//  iBurn
//
//  Created by <NAME> on 8/17/15.
//  Copyright (c) 2015 Burning Man Earth. All rights reserved.
//

import UIKit

public enum EmptyListLabelText: String {
    case Loading = "Loading...",
    Nothing = "Nothing Here"
}

public enum ObjectType: String {
    case Events = "Events",
    Camps = "Camps",
    Art = "Art"
}


public class TableViewSection {
    let objects: [BRCDataObject]
    let sectionTitle: ObjectType
    public init(objects: [BRCDataObject], sectionTitle: ObjectType) {
        self.objects = objects
        self.sectionTitle = sectionTitle
    }
}

extension CLLocation {
    static var currentLocation: CLLocation? {
        let appDelegate = BRCAppDelegate.shared
        let currentLocation = appDelegate.locationManager.location
        return currentLocation
    }
}

extension UIViewController {
    /** Adds current geocoded playa address to navigation bar title */
    func geocodeNavigationBar() {
        guard let location = CLLocation.currentLocation else { return }
        BRCGeocoder.shared.asyncReverseLookup(location.coordinate, completionQueue: DispatchQueue.main) { locationString in
            if let locationString = locationString, locationString.count > 0 {
                let attrString = (locationString as NSString).brc_attributedLocationStringWithCrosshairs
                let label = UILabel()
                label.attributedText = attrString
                label.sizeToFit()
                self.navigationItem.titleView = label
            } else {
                self.navigationItem.title = self.title
            }
        }
    }
}


@objc(BRCSortedViewController)
public class SortedViewController: UITableViewController {

    var sections: [TableViewSection] = []
    var extensionRegistered: Bool = false
    var extensionName: String = ""
    var emptyListText = EmptyListLabelText.Loading
    var emptyDetailText: String = ""
    
    public override init(style: UITableViewStyle) {
        super.init(style: style)
    }
    
    @objc public required init(style: UITableViewStyle, extensionName ext: String) {
        super.init(style: style)
        extensionName = ext
        BRCDatabaseManager.shared.readConnection.read { (transaction: YapDatabaseReadTransaction) -> Void in
            let ext: AnyObject? = transaction.ext(self.extensionName)
            if (ext != nil) {
                self.extensionRegistered = true
            }
        }
        NotificationCenter.default.addObserver(self, selector: NSSelectorFromString("databaseExtensionRegistered:"), name: NSNotification.Name.BRCDatabaseExtensionRegistered, object: BRCDatabaseManager.shared);
        NotificationCenter.default.addObserver(self, selector: #selector(audioPlayerChangeNotification(_:)), name: NSNotification.Name(rawValue: BRCAudioPlayer.BRCAudioPlayerChangeNotification), object: BRCAudioPlayer.sharedInstance)
    }
    
    fileprivate override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: Bundle!) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }

    public required init!(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    // MARK: - View cycle
    
    open override func viewDidLoad() {
        super.viewDidLoad()
        setupTableView()
        // Apple bug: https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8/issues/10#issuecomment-69694089
        self.tableView.reloadData()
        self.tableView.setNeedsLayout()
        self.tableView.layoutIfNeeded()
        self.tableView.reloadData()
    }
    
    func setupTableView() {
        tableView.estimatedRowHeight = 120
        tableView.rowHeight = UITableViewAutomaticDimension
        // register table cell classes
        tableView.registerCustomCellClasses()
        tableView.register(SubtitleCell.self, forCellReuseIdentifier: SubtitleCell.kReuseIdentifier)
    }
    
    func databaseExtensionRegistered(_ notification: Notification) {
        if let extensionName = notification.userInfo?["extensionName"] as? String {
            if extensionName == self.extensionName {
                NSLog("databaseExtensionRegistered: %@", extensionName)
                extensionRegistered = true
                refreshTableItems({ () -> Void in
                    self.tableView.reloadData()
                })
            }
        }
    }
    
    @objc open func audioPlayerChangeNotification(_ notification: Notification) {
        self.tableView.reloadData()
    }
    <commit_msg>Fix objc crash<commit_after>//
//  BRCSortedViewController.swift
//  iBurn
//
//  Created by <NAME> on 8/17/15.
//  Copyright (c) 2015 Burning Man Earth. All rights reserved.
//

import UIKit

public enum EmptyListLabelText: String {
    case Loading = "Loading...",
    Nothing = "Nothing Here"
}

public enum ObjectType: String {
    case Events = "Events",
    Camps = "Camps",
    Art = "Art"
}


public class TableViewSection {
    let objects: [BRCDataObject]
    let sectionTitle: ObjectType
    public init(objects: [BRCDataObject], sectionTitle: ObjectType) {
        self.objects = objects
        self.sectionTitle = sectionTitle
    }
}

extension CLLocation {
    static var currentLocation: CLLocation? {
        let appDelegate = BRCAppDelegate.shared
        let currentLocation = appDelegate.locationManager.location
        return currentLocation
    }
}

extension UIViewController {
    /** Adds current geocoded playa address to navigation bar title */
    func geocodeNavigationBar() {
        guard let location = CLLocation.currentLocation else { return }
        BRCGeocoder.shared.asyncReverseLookup(location.coordinate, completionQueue: DispatchQueue.main) { locationString in
            if let locationString = locationString, locationString.count > 0 {
                let attrString = (locationString as NSString).brc_attributedLocationStringWithCrosshairs
                let label = UILabel()
                label.attributedText = attrString
                label.sizeToFit()
                self.navigationItem.titleView = label
            } else {
                self.navigationItem.title = self.title
            }
        }
    }
}


@objc(BRCSortedViewController)
public class SortedViewController: UITableViewController {

    var sections: [TableViewSection] = []
    var extensionRegistered: Bool = false
    var extensionName: String = ""
    var emptyListText = EmptyListLabelText.Loading
    var emptyDetailText: String = ""
    
    public override init(style: UITableViewStyle) {
        super.init(style: style)
    }
    
    @objc public required init(style: UITableViewStyle, extensionName ext: String) {
        super.init(style: style)
        extensionName = ext
        BRCDatabaseManager.shared.readConnection.read { (transaction: YapDatabaseReadTransaction) -> Void in
            let ext: AnyObject? = transaction.ext(self.extensionName)
            if (ext != nil) {
                self.extensionRegistered = true
            }
        }
        NotificationCenter.default.addObserver(self, selector: NSSelectorFromString("databaseExtensionRegistered:"), name: NSNotification.Name.BRCDatabaseExtensionRegistered, object: BRCDatabaseManager.shared);
        NotificationCenter.default.addObserver(self, selector: #selector(audioPlayerChangeNotification(_:)), name: NSNotification.Name(rawValue: BRCAudioPlayer.BRCAudioPlayerChangeNotification), object: BRCAudioPlayer.sharedInstance)
    }
    
    fileprivate override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: Bundle!) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }

    public required init!(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    // MARK: - View cycle
    
    open override func viewDidLoad() {
        super.viewDidLoad()
        setupTableView()
        // Apple bug: https://github.com/smileyborg/TableViewCellWithAutoLayoutiOS8/issues/10#issuecomment-69694089
        self.tableView.reloadData()
        self.tableView.setNeedsLayout()
        self.tableView.layoutIfNeeded()
        self.tableView.reloadData()
    }
    
    func setupTableView() {
        tableView.estimatedRowHeight = 120
        tableView.rowHeight = UITableViewAutomaticDimension
        // register table cell classes
        tableView.registerCustomCellClasses()
        tableView.register(SubtitleCell.self, forCellReuseIdentifier: SubtitleCell.kReuseIdentifier)
    }
    
    @objc func databaseExtensionRegistered(_ notification: Notification) {
        if let extensionName = notification.userInfo?["extensionName"] as? String {
            if extensionName == self.extensionName {
                NSLog("databaseExtensionRegistered: %@", extensionName)
                extensionRegistered = true
                refreshTableItems({ () -> Void in
                    self.tableView.reloadData()
                })
            }
        }
    }
    
    @objc open func audioPlayerChangeNotification(_ notification: Notification) {
        self.tableView.reloadData()
    }
    
{'fraction_non_alphanumeric': 0.0845858475041141, 'fraction_numerical': 0.005266044980800877, 'mean_word_length': 2.739130434782609, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '1534374', 'n_tokens_mistral': 2507, 'n_tokens_neox': 2368, 'n_words': 529}