<commit_before>//
//  PasswordDetailTableViewController.swift
//  pass
//
//  Created by <NAME> on 2/2/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit
import FavIcon
import SVProgressHUD
import passKit

class PasswordDetailTableViewController: UITableViewController, UIGestureRecognizerDelegate {
    var passwordEntity: PasswordEntity?
    private var password: Password?
    private var passwordImage: UIImage?
    private var oneTimePasswordIndexPath : IndexPath?
    private var shouldPopCurrentView = false
    private let passwordStore = PasswordStore.shared
    
    private let indicator: UIActivityIndicatorView = {
        let indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
        indicator.center = CGPoint(x: UIScreen.main.bounds.width / 2, y: UIScreen.main.bounds.height * 0.382)
        return indicator
    }()
    
    private lazy var editUIBarButtonItem: UIBarButtonItem = {
        let uiBarButtonItem = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(pressEdit(_:)))
        return uiBarButtonItem
    }()

    private struct TableCell {
        var title: String
        var content: String
        init() {
            title = ""
            content = ""
        }
        
        init(title: String) {
            self.title = title
            self.content = ""
        }
        
        init(title: String, content: String) {
            self.title = title
            self.content = content
        }
    }
    
    private struct TableSection {
        var type: PasswordDetailTableViewControllerSectionType
        var header: String?
        var item: Array<TableCell>
        init(type: PasswordDetailTableViewControllerSectionType) {
            self.type = type
            header = nil
            item = [TableCell]()
        }
        
        init(type: PasswordDetailTableViewControllerSectionType, header: String) {
            self.init(type: type)
            self.header = header
        }
    }
    
    private var tableData = Array<TableSection>()
    
    private enum PasswordDetailTableViewControllerSectionType {
        case name, main, addition, misc
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.register(UINib(nibName: "LabelTableViewCell", bundle: nil), forCellReuseIdentifier: "labelCell")
        tableView.register(UINib(nibName: "PasswordDetailTitleTableViewCell", bundle: nil), forCellReuseIdentifier: "passwordDetailTitleTableViewCell")
        
        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(PasswordDetailTableViewController.tapMenu(recognizer:)))
        tapGesture.cancelsTouchesInView = false
        tableView.addGestureRecognizer(tapGesture)
        tapGesture.delegate = self
        
        tableView.contentInset = UIEdgeInsetsMake(-36, 0, 44, 0);
        tableView.rowHeight = UITableViewAutomaticDimension
        tableView.estimatedRowHeight = 52
        
        indicator.startAnimating()
        tableView.addSubview(indicator)
        editUIBarButtonItem.isEnabled = false
        navigationItem.rightBarButtonItem = editUIBarButtonItem
        
        if let imageData = passwordEntity?.image {
            let image = UIImage(data: imageData as Data)
            passwordImage = image
        }
        self.decryptThenShowPassword()
        self.setupOneTimePasswordAutoRefresh()
        
        // pop the current view because this password might be "discarded"
        NotificationCenter.default.addObserver(self, selector: #selector(setShouldPopCurrentView), name: .passwordStoreChangeDiscarded, object: nil)
        
        // reset the data table if some password (maybe another one) has been updated
        NotificationCenter.default.addObserver(self, selector: #selector(decryptThenShowPassword), name: .passwordStoreUpdated, object: nil)<commit_msg>Never use large titles in password details<commit_after>//
//  PasswordDetailTableViewController.swift
//  pass
//
//  Created by <NAME> on 2/2/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit
import FavIcon
import SVProgressHUD
import passKit

class PasswordDetailTableViewController: UITableViewController, UIGestureRecognizerDelegate {
    var passwordEntity: PasswordEntity?
    private var password: Password?
    private var passwordImage: UIImage?
    private var oneTimePasswordIndexPath : IndexPath?
    private var shouldPopCurrentView = false
    private let passwordStore = PasswordStore.shared
    
    private let indicator: UIActivityIndicatorView = {
        let indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
        indicator.center = CGPoint(x: UIScreen.main.bounds.width / 2, y: UIScreen.main.bounds.height * 0.382)
        return indicator
    }()
    
    private lazy var editUIBarButtonItem: UIBarButtonItem = {
        let uiBarButtonItem = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(pressEdit(_:)))
        return uiBarButtonItem
    }()

    private struct TableCell {
        var title: String
        var content: String
        init() {
            title = ""
            content = ""
        }
        
        init(title: String) {
            self.title = title
            self.content = ""
        }
        
        init(title: String, content: String) {
            self.title = title
            self.content = content
        }
    }
    
    private struct TableSection {
        var type: PasswordDetailTableViewControllerSectionType
        var header: String?
        var item: Array<TableCell>
        init(type: PasswordDetailTableViewControllerSectionType) {
            self.type = type
            header = nil
            item = [TableCell]()
        }
        
        init(type: PasswordDetailTableViewControllerSectionType, header: String) {
            self.init(type: type)
            self.header = header
        }
    }
    
    private var tableData = Array<TableSection>()
    
    private enum PasswordDetailTableViewControllerSectionType {
        case name, main, addition, misc
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.register(UINib(nibName: "LabelTableViewCell", bundle: nil), forCellReuseIdentifier: "labelCell")
        tableView.register(UINib(nibName: "PasswordDetailTitleTableViewCell", bundle: nil), forCellReuseIdentifier: "passwordDetailTitleTableViewCell")
        
        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(PasswordDetailTableViewController.tapMenu(recognizer:)))
        tapGesture.cancelsTouchesInView = false
        tableView.addGestureRecognizer(tapGesture)
        tapGesture.delegate = self
        
        tableView.contentInset = UIEdgeInsetsMake(-36, 0, 44, 0);
        tableView.rowHeight = UITableViewAutomaticDimension
        tableView.estimatedRowHeight = 52
        
        indicator.startAnimating()
        tableView.addSubview(indicator)
        editUIBarButtonItem.isEnabled = false
        navigationItem.rightBarButtonItem = editUIBarButtonItem
        if #available(iOS 11.0, *) {
            navigationItem.largeTitleDisplayMode = .never
        }
        
        if let imageData = passwordEntity?.image {
            let image = UIImage(data: imageData as Data)
            passwordImage = image
        }
        self.decryptThenShowPassword()
        self.setupOneTimePasswordAutoRefresh()
        
        // pop the current view because this password might be "discarded"
        NotificationCenter.default.addObserver(self, selector: #selector(setShouldPopCurrentView), name: .passwordStoreChangeDiscarded, object: nil)
        
        // reset the data table if some password (maybe another one) has been updated
        NotificationCenter.default.addObserver(self, selector: #selector(decryptThenShowPassword), name: .passwordStoreUpdated, object: nil)
{'fraction_non_alphanumeric': 0.07685512367491167, 'fraction_numerical': 0.006183745583038869, 'mean_word_length': 2.6470317533364014, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6015631', 'n_tokens_mistral': 2142, 'n_tokens_neox': 2049, 'n_words': 490}