<commit_before>//
//  Copyright (c) 2015 Actor LLC. <https://actor.im>
//

import UIKit

class AABubbleDocumentCell: AABubbleBaseFileCell {
    
    // MARK: -
    // MARK: Private vars
    
    private let progressBg = UIImageView()
    private let circullarNode = CircullarNode()
    private let fileIcon = UIImageView()
    
    private let titleLabel = UILabel()
    private let sizeLabel = UILabel()
    
    private let dateLabel = UILabel()
    private let statusView = UIImageView()
    
    private var bindedExt = ""
    
    // MARK: -
    // MARK: Constructors
    
    init(reuseId: String, peer: AMPeer) {
        super.init(reuseId: reuseId, peer: peer, isFullSize: false)
        
        dateLabel.font = UIFont(name: "HelveticaNeue-Italic", size: 11)
        dateLabel.lineBreakMode = .ByClipping
        dateLabel.numberOfLines = 1
        dateLabel.contentMode = UIViewContentMode.TopLeft
        dateLabel.textAlignment = NSTextAlignment.Right
        dateLabel.textColor = MainAppTheme.bubbles.textDateOut
        
        statusView.contentMode = UIViewContentMode.Center
        
        titleLabel.font = UIFont.systemFontOfSize(16.0)
        titleLabel.textColor = MainAppTheme.bubbles.textOut
        titleLabel.text = " "
        titleLabel.sizeToFit()
        titleLabel.lineBreakMode = NSLineBreakMode.ByTruncatingTail
        
        sizeLabel.font = UIFont.systemFontOfSize(13.0)
        sizeLabel.textColor = MainAppTheme.bubbles.textOut
        sizeLabel.text = " "
        sizeLabel.sizeToFit()
        
        progressBg.image = Imaging.roundedImage(UIColor(red: 0, green: 0, blue: 0, alpha: 0x64/255.0), size: CGSizeMake(CGFloat(64.0),CGFloat(64.0)), radius: CGFloat(32.0))
        
        contentView.addSubview(titleLabel)
        contentView.addSubview(sizeLabel)
        
        contentView.addSubview(dateLabel)
        contentView.addSubview(statusView)
        
        contentView.addSubview(progressBg)
        contentView.addSubview(fileIcon)
        contentView.addSubview(circullarNode.view)
        
        self.bubbleInsets = UIEdgeInsets(
            top: 3,
            left: 10,
            bottom: 3,
            right: 10)
        self.contentInsets = UIEdgeInsetsMake(0, 0, 0, 0)        
    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: -
    // MARK: Bind
    
    override func bind(message: AMMessage, reuse: Bool, isPreferCompact: Bool) {
        let document = message.getContent() as! AMDocumentContent
        
        if (!reuse) {
            if (isOut) {
                bindBubbleType(.MediaOut, isCompact: false)
                dateLabel.textColor = MainAppTheme.bubbles.textDateOut
            } else {
                bindBubbleType(.MediaIn, isCompact: false)
                dateLabel.textColor = MainAppTheme.bubbles.textDateIn
            }
            
            titleLabel.text = document.getName()
            bindedExt = document.getExt().lowercaseString
            sizeLabel.text = MSG.getFormatter().formatFileSizeWithInt(document.getSource().getSize())
            
            // Reset progress
            circullarNode.hidden = true
            circullarNode.setProgress(0, animated: false)
            UIView.animateWithDuration(0, animations: { () -> Void in
                self.circullarNode.alpha = 0
                self.fileIcon.alpha = 0
                self.progressBg.alpha = 0
            })
            
            // Bind file
            fileBind(message, autoDownload: false)
        }
        
        // Always update date and state
        dateLabel.text = formatDate(message.getDate())
        if (isOut) {
            switch(UInt(message.getMessageState().ordinal())) {
            case AMMessageState.PENDING.rawValue:
                self.statusView.image = Resources.iconClock
                self.statusView.tintColor = MainAppTheme.bubbles.statusSending
                break
            case AMMessageState.SENT.rawValue:
                self.statusView.image = Resources.iconCheck1
                self.statusView.tintColor = MainAppTheme.bubbles.statusSent
                break
            case AMMessageState.RECEIVED.rawValue:
                self.statusView.image = Resources.iconCheck2
                self.statusView.tintColor = MainAppTheme.bubbles.statusReceived
                break
            case AMMessageState.READ.rawValue:
                self.statusView.image = Resources.iconCheck2
                self.statusView.tintColor = MainAppTheme.bubbles.statusRead
                break
            case AMMessageState.ERROR.rawValue:
                self.statusView.image = Resources.iconError
                self.statusView.tintColor = MainAppTheme.bubbles.statusError
                break
            default:
                self.statusView.image = Resources.iconClock<commit_msg>feat(iOS): Enabled auto-download of small documents<commit_after>//
//  Copyright (c) 2015 Actor LLC. <https://actor.im>
//

import UIKit

class AABubbleDocumentCell: AABubbleBaseFileCell {
    
    // MARK: -
    // MARK: Private vars
    
    private let progressBg = UIImageView()
    private let circullarNode = CircullarNode()
    private let fileIcon = UIImageView()
    
    private let titleLabel = UILabel()
    private let sizeLabel = UILabel()
    
    private let dateLabel = UILabel()
    private let statusView = UIImageView()
    
    private var bindedExt = ""
    
    // MARK: -
    // MARK: Constructors
    
    init(reuseId: String, peer: AMPeer) {
        super.init(reuseId: reuseId, peer: peer, isFullSize: false)
        
        dateLabel.font = UIFont(name: "HelveticaNeue-Italic", size: 11)
        dateLabel.lineBreakMode = .ByClipping
        dateLabel.numberOfLines = 1
        dateLabel.contentMode = UIViewContentMode.TopLeft
        dateLabel.textAlignment = NSTextAlignment.Right
        dateLabel.textColor = MainAppTheme.bubbles.textDateOut
        
        statusView.contentMode = UIViewContentMode.Center
        
        titleLabel.font = UIFont.systemFontOfSize(16.0)
        titleLabel.textColor = MainAppTheme.bubbles.textOut
        titleLabel.text = " "
        titleLabel.sizeToFit()
        titleLabel.lineBreakMode = NSLineBreakMode.ByTruncatingTail
        
        sizeLabel.font = UIFont.systemFontOfSize(13.0)
        sizeLabel.textColor = MainAppTheme.bubbles.textOut
        sizeLabel.text = " "
        sizeLabel.sizeToFit()
        
        progressBg.image = Imaging.roundedImage(UIColor(red: 0, green: 0, blue: 0, alpha: 0x64/255.0), size: CGSizeMake(CGFloat(64.0),CGFloat(64.0)), radius: CGFloat(32.0))
        
        contentView.addSubview(titleLabel)
        contentView.addSubview(sizeLabel)
        
        contentView.addSubview(dateLabel)
        contentView.addSubview(statusView)
        
        contentView.addSubview(progressBg)
        contentView.addSubview(fileIcon)
        contentView.addSubview(circullarNode.view)
        
        self.bubbleInsets = UIEdgeInsets(
            top: 3,
            left: 10,
            bottom: 3,
            right: 10)
        self.contentInsets = UIEdgeInsetsMake(0, 0, 0, 0)        
    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: -
    // MARK: Bind
    
    override func bind(message: AMMessage, reuse: Bool, isPreferCompact: Bool) {
        let document = message.getContent() as! AMDocumentContent
        
        if (!reuse) {
            if (isOut) {
                bindBubbleType(.MediaOut, isCompact: false)
                dateLabel.textColor = MainAppTheme.bubbles.textDateOut
            } else {
                bindBubbleType(.MediaIn, isCompact: false)
                dateLabel.textColor = MainAppTheme.bubbles.textDateIn
            }
            
            titleLabel.text = document.getName()
            bindedExt = document.getExt().lowercaseString
            sizeLabel.text = MSG.getFormatter().formatFileSizeWithInt(document.getSource().getSize())
            
            // Reset progress
            circullarNode.hidden = true
            circullarNode.setProgress(0, animated: false)
            UIView.animateWithDuration(0, animations: { () -> Void in
                self.circullarNode.alpha = 0
                self.fileIcon.alpha = 0
                self.progressBg.alpha = 0
            })
            
            // Bind file
            fileBind(message, autoDownload: document.getSource().getSize() < 1024 * 1025 * 1024)
        }
        
        // Always update date and state
        dateLabel.text = formatDate(message.getDate())
        if (isOut) {
            switch(UInt(message.getMessageState().ordinal())) {
            case AMMessageState.PENDING.rawValue:
                self.statusView.image = Resources.iconClock
                self.statusView.tintColor = MainAppTheme.bubbles.statusSending
                break
            case AMMessageState.SENT.rawValue:
                self.statusView.image = Resources.iconCheck1
                self.statusView.tintColor = MainAppTheme.bubbles.statusSent
                break
            case AMMessageState.RECEIVED.rawValue:
                self.statusView.image = Resources.iconCheck2
                self.statusView.tintColor = MainAppTheme.bubbles.statusReceived
                break
            case AMMessageState.READ.rawValue:
                self.statusView.image = Resources.iconCheck2
                self.statusView.tintColor = MainAppTheme.bubbles.statusRead
                break
            case AMMessageState.ERROR.rawValue:
                self.statusView.image = Resources.iconError
                self.statusView.tintColor = MainAppTheme.bubbles.statusError
                break
            default:
                self.statusView.image = Resources.iconClock
{'fraction_non_alphanumeric': 0.08575757575757575, 'fraction_numerical': 0.011313131313131313, 'mean_word_length': 1.9249630723781388, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5217720', 'n_tokens_mistral': 2938, 'n_tokens_neox': 2767, 'n_words': 491}