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

import Foundation
import UIKit

class AABubbleTextCell : AABubbleCell, TTTAttributedLabelDelegate {
    
    private static let dateFont = UIFont(name: "HelveticaNeue-Italic", size: 11)!
    
    let messageText = UILabel()
    let statusView = UIImageView();
    let senderNameLabel = UILabel();
    var needRelayout = true
    var isClanchTop:Bool = false
    var isClanchBottom:Bool = false
    
    private let dateText = UILabel()
    private var messageState: UInt = AMMessageState.UNKNOWN.rawValue
    private var cellLayout: TextCellLayout!
    
    init(frame: CGRect) {
        super.init(frame: frame, isFullSize: false)
        
        senderNameLabel.font = UIFont(name: "HelveticaNeue-Medium", size: 15)!
        
        messageText.lineBreakMode = .ByWordWrapping
        messageText.numberOfLines = 0
        // messageText.userInteractionEnabled = true
        
        dateText.font = AABubbleTextCell.dateFont
        dateText.lineBreakMode = .ByClipping
        dateText.numberOfLines = 1
        dateText.contentMode = UIViewContentMode.TopLeft
        dateText.textAlignment = NSTextAlignment.Right
        
        statusView.contentMode = UIViewContentMode.Center
        
        mainView.addSubview(messageText)
        mainView.addSubview(dateText)
        mainView.addSubview(statusView)
        
//        bubble.addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: "textDidLongPress"))
//        bubble.userInteractionEnabled = true
    }
    
    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
        if action == "copy:" {
            if (bindedMessage!.getContent() is AMTextContent) {
                return true
            }
        }
        if action == "delete:" {
            return true
        }
        return false
    }
    
    override func copy(sender: AnyObject?) {
        UIPasteboard.generalPasteboard().string = (bindedMessage!.getContent() as! AMTextContent).getText()
    }
    
//    func textDidLongPress() {
//        self.becomeFirstResponder()
//        var menuController = UIMenuController.sharedMenuController()
//        menuController.setTargetRect(bubble.frame, inView:bubble)
//        menuController.menuItems = [UIMenuItem(title: "Copy", action: "copy")]
//        menuController.setMenuVisible(true, animated: true)
//    }
//    
    func attributedLabel(label: TTTAttributedLabel!, didLongPressLinkWithURL url: NSURL!, atPoint point: CGPoint) {
        UIApplication.sharedApplication().openURL(url)
    }
    
    func attributedLabel(label: TTTAttributedLabel!, didSelectLinkWithURL url: NSURL!) {
        UIApplication.sharedApplication().openURL(url)
    }
    <commit_msg>feat(iOS): Enabling url parsing in messages<commit_after>//
//  Copyright (c) 2015 Actor LLC. <https://actor.im>
//

import Foundation
import UIKit

class AABubbleTextCell : AABubbleCell, TTTAttributedLabelDelegate {
    
    private static let dateFont = UIFont(name: "HelveticaNeue-Italic", size: 11)!
    
    let messageText = TTTAttributedLabel(frame: CGRectZero)
    let statusView = UIImageView();
    let senderNameLabel = UILabel();
    var needRelayout = true
    var isClanchTop:Bool = false
    var isClanchBottom:Bool = false
    
    private let dateText = UILabel()
    private var messageState: UInt = AMMessageState.UNKNOWN.rawValue
    private var cellLayout: TextCellLayout!
    
    init(frame: CGRect) {
        super.init(frame: frame, isFullSize: false)
        
        senderNameLabel.font = UIFont(name: "HelveticaNeue-Medium", size: 15)!
        
        messageText.font = TextCellLayout.bubbleFont
        messageText.lineBreakMode = .ByWordWrapping
        messageText.numberOfLines = 0
        messageText.userInteractionEnabled = true
        messageText.enabledTextCheckingTypes = NSTextCheckingType.Link.rawValue
        messageText.delegate = self
        messageText.linkAttributes = [kCTForegroundColorAttributeName: MainAppTheme.chat.autocompleteHighlight,
            kCTUnderlineStyleAttributeName: NSNumber(bool: true)]
        messageText.activeLinkAttributes = [kCTForegroundColorAttributeName: MainAppTheme.chat.autocompleteHighlight,
            kCTUnderlineStyleAttributeName: NSNumber(bool: true)]
        
        dateText.font = AABubbleTextCell.dateFont
        dateText.lineBreakMode = .ByClipping
        dateText.numberOfLines = 1
        dateText.contentMode = UIViewContentMode.TopLeft
        dateText.textAlignment = NSTextAlignment.Right
        
        statusView.contentMode = UIViewContentMode.Center
        
        mainView.addSubview(messageText)
        mainView.addSubview(dateText)
        mainView.addSubview(statusView)
    }
    
    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
        if action == "copy:" {
            if (bindedMessage!.getContent() is AMTextContent) {
                return true
            }
        }
        if action == "delete:" {
            return true
        }
        return false
    }
    
    override func copy(sender: AnyObject?) {
        UIPasteboard.generalPasteboard().string = (bindedMessage!.getContent() as! AMTextContent).getText()
    }
    
    func attributedLabel(label: TTTAttributedLabel!, didLongPressLinkWithURL url: NSURL!, atPoint point: CGPoint) {
        UIApplication.sharedApplication().openURL(url)
    }
    
    func attributedLabel(label: TTTAttributedLabel!, didSelectLinkWithURL url: NSURL!) {
        UIApplication.sharedApplication().openURL(url)
    }
    
{'fraction_non_alphanumeric': 0.08903291830121099, 'fraction_numerical': 0.0034112229234180454, 'mean_word_length': 2.783225806451613, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4335807', 'n_tokens_mistral': 1724, 'n_tokens_neox': 1662, 'n_words': 334}