<commit_before>import UIKit

@objc(WMFArticleFullWidthImageCollectionViewCell)
open class ArticleFullWidthImageCollectionViewCell: ArticleCollectionViewCell {
    
    fileprivate let headerBackgroundView = UIView()
    
    public var headerBackgroundColor: UIColor? {
        set {
            headerBackgroundView.backgroundColor = newValue
            titleLabel.backgroundColor = newValue
            descriptionLabel.backgroundColor = newValue
        }
        get {
            return headerBackgroundView.backgroundColor
        }
    }
    
    public var isHeaderBackgroundViewHidden: Bool {
        set {
            if newValue {
                headerBackgroundView.removeFromSuperview()
            } else {
                contentView.insertSubview(headerBackgroundView, at: 0)
            }
        }
        get {
            return headerBackgroundView.superview == nil
        }
    }
    
    
    override open func setup() {
        let extractLabel = UILabel()
        extractLabel.isOpaque = true
        extractLabel.numberOfLines = 4
        addSubview(extractLabel)
        self.extractLabel = extractLabel
        super.setup()
        descriptionLabel.numberOfLines = 2
        titleLabel.numberOfLines = 0
    }
    
    open override func reset() {
        super.reset()
        spacing = 6
        imageViewDimension = 150
    }
    
    open override func updateBackgroundColorOfLabels() {
        super.updateBackgroundColorOfLabels()
        if !isHeaderBackgroundViewHidden {
            titleLabel.backgroundColor = headerBackgroundColor
            descriptionLabel.backgroundColor = headerBackgroundColor
        }
    }
    
    open override func sizeThatFits(_ size: CGSize, apply: Bool) -> CGSize {
        let widthMinusMargins = layoutWidth(for: size)
        var origin = CGPoint(x: layoutMargins.left, y: 0)
        
        if !isImageViewHidden {
            if apply {
                imageView.frame = CGRect(x: 0, y: 0, width: size.width, height: imageViewDimension)
            }
            origin.y += imageViewDimension
        }
        
        origin.y += layoutMargins.top + spacing
        
        origin.y += titleLabel.wmf_preferredHeight(at: origin, maximumWidth: widthMinusMargins, alignedBy: articleSemanticContentAttribute, spacing: spacing, apply: apply)
        origin.y += descriptionLabel.wmf_preferredHeight(at: origin, maximumWidth: widthMinusMargins, alignedBy: articleSemanticContentAttribute, spacing: spacing, apply: apply)
        
        if apply {
            titleLabel.isHidden = !titleLabel.wmf_hasText
            descriptionLabel.isHidden = !descriptionLabel.wmf_hasText
        }
        
        if !isHeaderBackgroundViewHidden && apply {
            headerBackgroundView.frame = CGRect(x: 0, y: 0, width: size.width, height: origin.y)
        }
        
        if let extractLabel = extractLabel, extractLabel.wmf_hasText {
            origin.y += spacing // double spacing before extract
            origin.y += extractLabel.wmf_preferredHeight(at: origin, maximumWidth: widthMinusMargins, alignedBy: articleSemanticContentAttribute, spacing: spacing, apply: apply)
            if apply {
                extractLabel.isHidden = false
            }
        } else if apply {
            extractLabel?.isHidden = true
        }

        if !isSaveButtonHidden {
            origin.y += spacing - 1
            let saveButtonFrame = saveButton.wmf_preferredFrame(at: origin, maximumWidth: widthMinusMargins, horizontalAlignment: isDeviceRTL ? .right : .left, apply: apply)
            origin.y += saveButtonFrame.height - 2 * saveButton.verticalPadding
        } else {
            origin.y += spacing
        }
        
        origin.y += layoutMargins.bottom
        return CGSize(width: size.width, height: origin.y)
    }<commit_msg>fix rtl for feed card `save for later` button<commit_after>import UIKit

@objc(WMFArticleFullWidthImageCollectionViewCell)
open class ArticleFullWidthImageCollectionViewCell: ArticleCollectionViewCell {
    
    fileprivate let headerBackgroundView = UIView()
    
    public var headerBackgroundColor: UIColor? {
        set {
            headerBackgroundView.backgroundColor = newValue
            titleLabel.backgroundColor = newValue
            descriptionLabel.backgroundColor = newValue
        }
        get {
            return headerBackgroundView.backgroundColor
        }
    }
    
    public var isHeaderBackgroundViewHidden: Bool {
        set {
            if newValue {
                headerBackgroundView.removeFromSuperview()
            } else {
                contentView.insertSubview(headerBackgroundView, at: 0)
            }
        }
        get {
            return headerBackgroundView.superview == nil
        }
    }
    
    
    override open func setup() {
        let extractLabel = UILabel()
        extractLabel.isOpaque = true
        extractLabel.numberOfLines = 4
        addSubview(extractLabel)
        self.extractLabel = extractLabel
        super.setup()
        descriptionLabel.numberOfLines = 2
        titleLabel.numberOfLines = 0
    }
    
    open override func reset() {
        super.reset()
        spacing = 6
        imageViewDimension = 150
    }
    
    open override func updateBackgroundColorOfLabels() {
        super.updateBackgroundColorOfLabels()
        if !isHeaderBackgroundViewHidden {
            titleLabel.backgroundColor = headerBackgroundColor
            descriptionLabel.backgroundColor = headerBackgroundColor
        }
    }
    
    open override func sizeThatFits(_ size: CGSize, apply: Bool) -> CGSize {
        let widthMinusMargins = layoutWidth(for: size)
        var origin = CGPoint(x: layoutMargins.left, y: 0)
        
        if !isImageViewHidden {
            if apply {
                imageView.frame = CGRect(x: 0, y: 0, width: size.width, height: imageViewDimension)
            }
            origin.y += imageViewDimension
        }
        
        origin.y += layoutMargins.top + spacing
        
        origin.y += titleLabel.wmf_preferredHeight(at: origin, maximumWidth: widthMinusMargins, alignedBy: articleSemanticContentAttribute, spacing: spacing, apply: apply)
        origin.y += descriptionLabel.wmf_preferredHeight(at: origin, maximumWidth: widthMinusMargins, alignedBy: articleSemanticContentAttribute, spacing: spacing, apply: apply)
        
        if apply {
            titleLabel.isHidden = !titleLabel.wmf_hasText
            descriptionLabel.isHidden = !descriptionLabel.wmf_hasText
        }
        
        if !isHeaderBackgroundViewHidden && apply {
            headerBackgroundView.frame = CGRect(x: 0, y: 0, width: size.width, height: origin.y)
        }
        
        if let extractLabel = extractLabel, extractLabel.wmf_hasText {
            origin.y += spacing // double spacing before extract
            origin.y += extractLabel.wmf_preferredHeight(at: origin, maximumWidth: widthMinusMargins, alignedBy: articleSemanticContentAttribute, spacing: spacing, apply: apply)
            if apply {
                extractLabel.isHidden = false
            }
        } else if apply {
            extractLabel?.isHidden = true
        }

        if !isSaveButtonHidden {
            origin.y += spacing - 1
            let saveButtonFrame = saveButton.wmf_preferredFrame(at: origin, maximumWidth: size.width, horizontalAlignment: isDeviceRTL ? .right : .left, apply: apply)
            origin.y += saveButtonFrame.height - 2 * saveButton.verticalPadding
        } else {
            origin.y += spacing
        }
        
        origin.y += layoutMargins.bottom
        return CGSize(width: size.width, height: origin.y)
    }
{'fraction_non_alphanumeric': 0.0719583604424203, 'fraction_numerical': 0.003903708523096942, 'mean_word_length': 2.1551724137931036, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3832734', 'n_tokens_mistral': 2041, 'n_tokens_neox': 1950, 'n_words': 446}