<commit_before>//
//  ManageFriendsViewController.swift
//  CriticalMaps
//
//  Created by <NAME> on 22.09.19.
//  Copyright © 2019 Pokus Labs. All rights reserved.
//

import UIKit

class ManageFriendsViewController: UIViewController, IBConstructable, UITableViewDataSource, UITableViewDelegate {
    @IBOutlet var tableView: UITableView!
    private var dataStore: DataStore!
    private var idProvider: IDProvider!

    enum Section: Int, CaseIterable {
        case friends
        case settings

        var title: String? {
            switch self {
            case .friends:
                return nil
            case .settings:
                return "Settings"
            }
        }
    }

    init(dataStore: DataStore, idProvider: IDProvider) {
        self.dataStore = dataStore
        self.idProvider = idProvider
        super.init(nibName: ManageFriendsViewController.nibName, bundle: ManageFriendsViewController.bundle)
    }

    required init?(coder _: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        configureNavigationBar()
        configureNotifications()
        
        if let backgroundColor = ThemeController().currentTheme?.style.backgroundColor{
             tableView.backgroundColor = backgroundColor
        }
        tableView.register(cellType: FriendTableViewCell.self)
        tableView.register(cellType: FriendSettingsTableViewCell.self)
        tableView.register(viewType: SettingsTableSectionHeader.self)
        
        let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap))
        tapGestureRecognizer.cancelsTouchesInView = false
        view.addGestureRecognizer(tapGestureRecognizer)
    }

    private func configureNavigationBar() {
        title = "Friends"
        let addFriendBarButtonItem = UIBarButtonItem(title: "Show ID", style: .plain, target: self, action: #selector(addFriendButtonTapped))
        navigationItem.rightBarButtonItem = addFriendBarButtonItem
    }

    private func configureNotifications() {
        NotificationCenter.default.addObserver(self, selector: #selector(onNewData), name: Notification.positionOthersChanged, object: nil)
    }

    @objc private func addFriendButtonTapped() {
        let viewController = FollowFriendsViewController(name: dataStore.userName, token: idProvider.token)
        navigationController?.pushViewController(viewController, animated: true)
    }
    
    @objc private func handleTap() {
        view.endEditing(true)
    }

    private func update(name: String) {
        dataStore.userName = name<commit_msg>added night mode background color<commit_after>//
//  ManageFriendsViewController.swift
//  CriticalMaps
//
//  Created by <NAME> on 22.09.19.
//  Copyright © 2019 Pokus Labs. All rights reserved.
//

import UIKit

class ManageFriendsViewController: UIViewController, IBConstructable, UITableViewDataSource, UITableViewDelegate {
    @IBOutlet var tableView: UITableView!
    private var dataStore: DataStore!
    private var idProvider: IDProvider!

    enum Section: Int, CaseIterable {
        case friends
        case settings

        var title: String? {
            switch self {
            case .friends:
                return nil
            case .settings:
                return "Settings"
            }
        }
    }

    init(dataStore: DataStore, idProvider: IDProvider) {
        self.dataStore = dataStore
        self.idProvider = idProvider
        super.init(nibName: ManageFriendsViewController.nibName, bundle: ManageFriendsViewController.bundle)
    }

    required init?(coder _: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        configureNavigationBar()
        configureNotifications()
        
        tableView.register(cellType: FriendTableViewCell.self)
        tableView.register(cellType: FriendSettingsTableViewCell.self)
        tableView.register(viewType: SettingsTableSectionHeader.self)
        
        let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap))
        tapGestureRecognizer.cancelsTouchesInView = false
        view.addGestureRecognizer(tapGestureRecognizer)
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if let backgroundColor = ThemeController().currentTheme?.style.backgroundColor{
            tableView.backgroundColor = backgroundColor
            self.view.backgroundColor = backgroundColor
        }
    }

    private func configureNavigationBar() {
        title = "Friends"
        let addFriendBarButtonItem = UIBarButtonItem(title: "Show ID", style: .plain, target: self, action: #selector(addFriendButtonTapped))
        navigationItem.rightBarButtonItem = addFriendBarButtonItem
    }

    private func configureNotifications() {
        NotificationCenter.default.addObserver(self, selector: #selector(onNewData), name: Notification.positionOthersChanged, object: nil)
    }

    @objc private func addFriendButtonTapped() {
        let viewController = FollowFriendsViewController(name: dataStore.userName, token: idProvider.token)
        navigationController?.pushViewController(viewController, animated: true)
    }
    
    @objc private func handleTap() {
        view.endEditing(true)
    }

    private func update(name: String) {
        dataStore.userName = name
{'fraction_non_alphanumeric': 0.07925281102647806, 'fraction_numerical': 0.003627130939426913, 'mean_word_length': 2.9421015010721945, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5927783', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1430, 'n_words': 323}