2021-01-29 09:47:32 +01:00
|
|
|
//
|
|
|
|
// ActiveLabel.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/1/29.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Foundation
|
|
|
|
import ActiveLabel
|
2021-02-01 11:06:29 +01:00
|
|
|
import os.log
|
2021-01-29 09:47:32 +01:00
|
|
|
|
|
|
|
extension ActiveLabel {
|
|
|
|
|
|
|
|
enum Style {
|
|
|
|
case `default`
|
2021-05-07 12:25:57 +02:00
|
|
|
case statusHeader
|
|
|
|
case statusName
|
2021-04-01 08:39:15 +02:00
|
|
|
case profileField
|
2021-01-29 09:47:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
convenience init(style: Style) {
|
|
|
|
self.init()
|
|
|
|
|
|
|
|
numberOfLines = 0
|
2021-02-23 08:16:55 +01:00
|
|
|
lineSpacing = 5
|
|
|
|
mentionColor = Asset.Colors.Label.highlight.color
|
|
|
|
hashtagColor = Asset.Colors.Label.highlight.color
|
|
|
|
URLColor = Asset.Colors.Label.highlight.color
|
2021-05-07 12:25:57 +02:00
|
|
|
emojiPlaceholderColor = .systemFill
|
2021-04-01 08:39:15 +02:00
|
|
|
#if DEBUG
|
2021-01-29 09:47:32 +01:00
|
|
|
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
|
2021-04-01 08:39:15 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
switch style {
|
|
|
|
case .default:
|
|
|
|
font = .preferredFont(forTextStyle: .body)
|
|
|
|
textColor = Asset.Colors.Label.primary.color
|
2021-05-07 12:25:57 +02:00
|
|
|
case .statusHeader:
|
2021-05-10 12:54:08 +02:00
|
|
|
font = UIFontMetrics(forTextStyle: .footnote).scaledFont(for: .systemFont(ofSize: 13, weight: .medium), maximumPointSize: 17)
|
2021-05-07 12:25:57 +02:00
|
|
|
textColor = Asset.Colors.Label.secondary.color
|
|
|
|
numberOfLines = 1
|
|
|
|
case .statusName:
|
|
|
|
font = .systemFont(ofSize: 17, weight: .semibold)
|
|
|
|
textColor = Asset.Colors.Label.primary.color
|
|
|
|
numberOfLines = 1
|
2021-04-01 08:39:15 +02:00
|
|
|
case .profileField:
|
|
|
|
font = .preferredFont(forTextStyle: .body)
|
|
|
|
textColor = Asset.Colors.Label.primary.color
|
|
|
|
numberOfLines = 1
|
|
|
|
}
|
2021-01-29 09:47:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension ActiveLabel {
|
2021-04-01 08:39:15 +02:00
|
|
|
/// status content
|
2021-05-07 12:25:57 +02:00
|
|
|
func configure(content: String, emojiDict: MastodonStatusContent.EmojiDict) {
|
2021-02-23 12:18:34 +01:00
|
|
|
activeEntities.removeAll()
|
2021-05-07 12:25:57 +02:00
|
|
|
|
|
|
|
if let parseResult = try? MastodonStatusContent.parse(content: content, emojiDict: emojiDict) {
|
2021-02-01 11:06:29 +01:00
|
|
|
text = parseResult.trimmed
|
|
|
|
activeEntities = parseResult.activeEntities
|
2021-02-23 12:18:34 +01:00
|
|
|
} else {
|
|
|
|
text = ""
|
2021-02-01 11:06:29 +01:00
|
|
|
}
|
2021-01-29 09:47:32 +01:00
|
|
|
}
|
2021-04-01 08:39:15 +02:00
|
|
|
|
|
|
|
/// account note
|
2021-05-07 12:25:57 +02:00
|
|
|
func configure(note: String, emojiDict: MastodonStatusContent.EmojiDict) {
|
|
|
|
configure(content: note, emojiDict: emojiDict)
|
2021-04-01 08:39:15 +02:00
|
|
|
}
|
2021-01-29 09:47:32 +01:00
|
|
|
}
|
|
|
|
|
2021-04-01 08:39:15 +02:00
|
|
|
extension ActiveLabel {
|
|
|
|
/// account field
|
|
|
|
func configure(field: String) {
|
|
|
|
activeEntities.removeAll()
|
2021-04-06 10:43:08 +02:00
|
|
|
let parseResult = MastodonField.parse(field: field)
|
|
|
|
text = parseResult.value
|
|
|
|
activeEntities = parseResult.activeEntities
|
2021-04-01 08:39:15 +02:00
|
|
|
}
|
|
|
|
}
|