<commit_before>//
//  ReceiptsView.swift
//  SmartReceipts
//
//  Created by <NAME> on 18/06/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit
import Viperit

//MARK: - Public Interface Protocol
protocol ReceiptsViewInterface {
    func setup(trip: WBTrip)
    func setup(fetchedModelAdapter: FetchedModelAdapter)
    var createReceiptButton: UIBarButtonItem { get }
    var createPhotoReceiptButton: UIBarButtonItem { get }
    var distancesButton: UIBarButtonItem { get }
    var generateReportButton: UIBarButtonItem { get }
}

//MARK: ReceiptsView Class
final class ReceiptsView: FetchedCollectionViewControllerSwift {
    
    static var sharedInputCache = [String: Date]()
    
    @IBOutlet weak var distanceButton: UIBarButtonItem!
    @IBOutlet weak var cameraButton: UIBarButtonItem!
    @IBOutlet weak var createButton: UIBarButtonItem!
    @IBOutlet weak var shareButton: UIBarButtonItem!
    
    private static let CELL_ID = "Cell"
    
    private var _imageForCreatorSegue: UIImage!
    private var _receiptForCreatorSegue: WBReceipt!
    private var _priceWidth: CGFloat = 0
    private var tapped: WBReceipt!
    private var dateFormatter = WBDateFormatter()
    private var showReceiptDate = false
    private var showReceiptCategory = false
    private var lastDateSeparator: String!
    private var showAttachmentMarker = false
    
    var receiptsCount: Int { get{ return numberOfItems() } }
    override var placeholderTitle: String { get { return LocalizedString("fetched.placeholder.receipts.title") } }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        ReceiptsView.sharedInputCache = [String: Date]()
        AppTheme.customizeOnViewDidLoad(self)
        
        showReceiptDate = WBPreferences.layoutShowReceiptDate()
        showReceiptCategory = WBPreferences.layoutShowReceiptCategory()
        showAttachmentMarker = WBPreferences.layoutShowReceiptAttachmentMarker()
        
        navigationItem.rightBarButtonItem = editButtonItem
        
        setPresentationCellNib(ReceiptSummaryCell.viewNib())
        
        updateEditButton()
        updateTitle()
        
        lastDateSeparator = WBPreferences.dateSeparator()
        
        NotificationCenter.default.addObserver(self, selector: #selector(tripUpdated(_:)), name: NSNotification.Name.DatabaseDidUpdateModel, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(settingsSaved), name: NSNotification.Name.SmartReceiptsSettingsSaved, object: nil)
    }
    
    func tripUpdated(_ notification: Notification) {
        if let trip = notification.object as? WBTrip {
            Logger.debug("Updated Trip: \(trip.description)")
        
            if self.trip != trip { return }
        
            //TODO jaanus: check posting already altered object
            self.trip = Database.sharedInstance().tripWithName(self.trip!.name)
            self.updateTitle()
        }<commit_msg>[Fix] Receipts Title after screen rotation<commit_after>//
//  ReceiptsView.swift
//  SmartReceipts
//
//  Created by <NAME> on 18/06/2017.
//  Copyright © 2017 <NAME>. All rights reserved.
//

import UIKit
import Viperit

//MARK: - Public Interface Protocol
protocol ReceiptsViewInterface {
    func setup(trip: WBTrip)
    func setup(fetchedModelAdapter: FetchedModelAdapter)
    var createReceiptButton: UIBarButtonItem { get }
    var createPhotoReceiptButton: UIBarButtonItem { get }
    var distancesButton: UIBarButtonItem { get }
    var generateReportButton: UIBarButtonItem { get }
}

//MARK: ReceiptsView Class
final class ReceiptsView: FetchedCollectionViewControllerSwift {
    
    static var sharedInputCache = [String: Date]()
    
    @IBOutlet weak var distanceButton: UIBarButtonItem!
    @IBOutlet weak var cameraButton: UIBarButtonItem!
    @IBOutlet weak var createButton: UIBarButtonItem!
    @IBOutlet weak var shareButton: UIBarButtonItem!
    
    private static let CELL_ID = "Cell"
    
    private var _imageForCreatorSegue: UIImage!
    private var _receiptForCreatorSegue: WBReceipt!
    private var _priceWidth: CGFloat = 0
    private var tapped: WBReceipt!
    private var dateFormatter = WBDateFormatter()
    private var showReceiptDate = false
    private var showReceiptCategory = false
    private var lastDateSeparator: String!
    private var showAttachmentMarker = false
    
    var receiptsCount: Int { get{ return numberOfItems() } }
    override var placeholderTitle: String { get { return LocalizedString("fetched.placeholder.receipts.title") } }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        ReceiptsView.sharedInputCache = [String: Date]()
        AppTheme.customizeOnViewDidLoad(self)
        
        showReceiptDate = WBPreferences.layoutShowReceiptDate()
        showReceiptCategory = WBPreferences.layoutShowReceiptCategory()
        showAttachmentMarker = WBPreferences.layoutShowReceiptAttachmentMarker()
        
        navigationItem.rightBarButtonItem = editButtonItem
        
        setPresentationCellNib(ReceiptSummaryCell.viewNib())
        
        updateEditButton()
        updateTitle()
        
        lastDateSeparator = WBPreferences.dateSeparator()
        
        NotificationCenter.default.addObserver(self, selector: #selector(tripUpdated(_:)), name: NSNotification.Name.DatabaseDidUpdateModel, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(settingsSaved), name: NSNotification.Name.SmartReceiptsSettingsSaved, object: nil)
    }
    
    override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
        updateTitle()
    }
    
    func tripUpdated(_ notification: Notification) {
        if let trip = notification.object as? WBTrip {
            Logger.debug("Updated Trip: \(trip.description)")
        
            if self.trip != trip { return }
        
            //TODO jaanus: check posting already altered object
            self.trip = Database.sharedInstance().tripWithName(self.trip!.name)
            updateTitle()
        }
{'fraction_non_alphanumeric': 0.07704918032786885, 'fraction_numerical': 0.0042622950819672135, 'mean_word_length': 3.207586206896552, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5556572', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1671, 'n_words': 403}