mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
add size label for file type attachment
This commit is contained in:
parent
5e521a8192
commit
300f6f50cf
3 changed files with 17 additions and 7 deletions
|
@ -4,7 +4,7 @@ final class DocumentView : UIView {
|
|||
private let textColor: UIColor
|
||||
|
||||
// MARK: Settings
|
||||
private static let iconImageViewSize: CGSize = CGSize(width: 26, height: 40)
|
||||
private static let iconImageViewSize: CGSize = CGSize(width: 31, height: 40)
|
||||
|
||||
// MARK: Lifecycle
|
||||
init(viewItem: ConversationViewItem, textColor: UIColor) {
|
||||
|
@ -36,11 +36,21 @@ final class DocumentView : UIView {
|
|||
titleLabel.lineBreakMode = .byTruncatingTail
|
||||
titleLabel.text = attachment.sourceFilename ?? "File"
|
||||
titleLabel.textColor = textColor
|
||||
titleLabel.font = .systemFont(ofSize: Values.mediumFontSize, weight: .light)
|
||||
titleLabel.font = .systemFont(ofSize: Values.smallFontSize, weight: .light)
|
||||
// Size label
|
||||
let sizeLabel = UILabel()
|
||||
sizeLabel.lineBreakMode = .byTruncatingTail
|
||||
sizeLabel.text = OWSFormat.formatFileSize(UInt(attachment.byteCount))
|
||||
sizeLabel.textColor = textColor
|
||||
sizeLabel.font = .systemFont(ofSize: Values.verySmallFontSize)
|
||||
// Label stack view
|
||||
let labelStackView = UIStackView(arrangedSubviews: [ titleLabel, sizeLabel ])
|
||||
labelStackView.axis = .vertical
|
||||
// Stack view
|
||||
let stackView = UIStackView(arrangedSubviews: [ imageView, titleLabel ])
|
||||
let stackView = UIStackView(arrangedSubviews: [ imageView, labelStackView ])
|
||||
stackView.axis = .horizontal
|
||||
stackView.spacing = Values.verySmallSpacing
|
||||
stackView.alignment = .center
|
||||
addSubview(stackView)
|
||||
stackView.pin(to: self)
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -31,11 +31,11 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
const unsigned long kOneKilobyte = 1024;
|
||||
const unsigned long kOneMegabyte = kOneKilobyte * kOneKilobyte;
|
||||
|
||||
if (fileSize > kOneMegabyte * 10) {
|
||||
return [[formatter stringFromNumber:@((int)round(fileSize / (CGFloat)kOneMegabyte))]
|
||||
if (fileSize > kOneMegabyte) {
|
||||
return [[formatter stringFromNumber:@((double)lround(fileSize * 100 / (CGFloat)kOneMegabyte) / 100)]
|
||||
stringByAppendingString:@" MB"];
|
||||
} else if (fileSize > kOneKilobyte * 10) {
|
||||
return [[formatter stringFromNumber:@((int)round(fileSize / (CGFloat)kOneKilobyte))]
|
||||
} else if (fileSize > kOneKilobyte) {
|
||||
return [[formatter stringFromNumber:@((double)lround(fileSize * 100 / (CGFloat)kOneKilobyte) / 100)]
|
||||
stringByAppendingString:@" KB"];
|
||||
} else {
|
||||
return [NSString stringWithFormat:@"%lu Bytes", fileSize];
|
||||
|
|
Loading…
Reference in a new issue