mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-05-24 08:54:10 +08:00
* Use %d over %zi to prevent a possible crash * Clean up / unify localization behavior Before, we were doing double localization (Feeding a `LocalizedString` into a `.localizedStringWithFormat`).
75 lines
2.4 KiB
Swift
75 lines
2.4 KiB
Swift
//
|
|
// IssueViewFilesCell.swift
|
|
// Freetime
|
|
//
|
|
// Created by Ryan Nystrom on 8/11/17.
|
|
// Copyright © 2017 Ryan Nystrom. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import SnapKit
|
|
|
|
final class IssueViewFilesCell: UICollectionViewCell {
|
|
|
|
private let label = UILabel()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
isAccessibilityElement = true
|
|
accessibilityTraits |= UIAccessibilityTraitButton
|
|
|
|
contentView.addSubview(label)
|
|
label.snp.makeConstraints { make in
|
|
make.left.equalTo(Styles.Sizes.gutter)
|
|
make.centerY.equalTo(contentView)
|
|
}
|
|
}
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
// MARK: Public API
|
|
|
|
func configure(changes: FileChanges) {
|
|
let attributedText = NSMutableAttributedString()
|
|
|
|
let actionFormat = NSLocalizedString("View Files (%d) ", comment: "")
|
|
attributedText.append(NSAttributedString(
|
|
string: String(format: actionFormat, changes.changedFiles),
|
|
attributes: [
|
|
.font: Styles.Fonts.secondary,
|
|
.foregroundColor: Styles.Colors.Blue.medium.color
|
|
]
|
|
))
|
|
if changes.additions > 0 {
|
|
attributedText.append(NSAttributedString(
|
|
string: "+\(changes.additions) ", // note trailing space
|
|
attributes: [
|
|
.font: Styles.Fonts.secondaryBold,
|
|
.foregroundColor: Styles.Colors.Green.medium.color
|
|
]
|
|
))
|
|
}
|
|
if changes.deletions > 0 {
|
|
attributedText.append(NSAttributedString(
|
|
string: "-\(changes.deletions)",
|
|
attributes: [
|
|
.font: Styles.Fonts.secondaryBold,
|
|
.foregroundColor: Styles.Colors.Red.medium.color
|
|
]
|
|
))
|
|
}
|
|
label.attributedText = attributedText
|
|
|
|
accessibilityLabel = NSLocalizedString(
|
|
"View Files",
|
|
comment: "The accessibility label for the View Files button in a pull request.")
|
|
let hintFormat = NSLocalizedString(
|
|
"View %zi files with %zi additions and %zi deletions.",
|
|
comment: "The accessibility hint with details of the View Files button.")
|
|
accessibilityHint = String(format: hintFormat, arguments: [changes.changedFiles, changes.additions, changes.deletions])
|
|
}
|
|
|
|
}
|