mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-22 06:03:45 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
protocol WikiDescriptionViewControllerDelegate: AnyObject {
|
||||
func didPressMore()
|
||||
}
|
||||
|
||||
class WikiDescriptionViewController: UIViewController {
|
||||
@IBOutlet var descriptionTextView: UITextView!
|
||||
@IBOutlet var moreButton: UIButton!
|
||||
|
||||
var descriptionHtml: String? {
|
||||
didSet{
|
||||
updateDescription()
|
||||
}
|
||||
}
|
||||
weak var delegate: WikiDescriptionViewControllerDelegate?
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
descriptionTextView.textContainerInset = .zero
|
||||
updateDescription()
|
||||
}
|
||||
|
||||
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
||||
super.traitCollectionDidChange(previousTraitCollection)
|
||||
guard traitCollection.userInterfaceStyle != previousTraitCollection?.userInterfaceStyle else { return }
|
||||
updateDescription()
|
||||
}
|
||||
|
||||
private func updateDescription() {
|
||||
guard let descriptionHtml = descriptionHtml else { return }
|
||||
|
||||
DispatchQueue.global().async {
|
||||
let font = UIFont.regular14()
|
||||
let color = UIColor.blackPrimaryText()
|
||||
let paragraphStyle = NSMutableParagraphStyle()
|
||||
paragraphStyle.lineSpacing = 4
|
||||
|
||||
let attributedString: NSAttributedString
|
||||
if let str = NSMutableAttributedString(htmlString: descriptionHtml, baseFont: font, paragraphStyle: paragraphStyle) {
|
||||
str.addAttribute(NSAttributedString.Key.foregroundColor,
|
||||
value: color,
|
||||
range: NSRange(location: 0, length: str.length))
|
||||
attributedString = str;
|
||||
} else {
|
||||
attributedString = NSAttributedString(string: descriptionHtml,
|
||||
attributes: [NSAttributedString.Key.font : font,
|
||||
NSAttributedString.Key.foregroundColor: color,
|
||||
NSAttributedString.Key.paragraphStyle: paragraphStyle])
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
if attributedString.length > 500 {
|
||||
self.descriptionTextView.attributedText = attributedString.attributedSubstring(from: NSRange(location: 0,
|
||||
length: 500))
|
||||
} else {
|
||||
self.descriptionTextView.attributedText = attributedString
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func onMore(_ sender: UIButton) {
|
||||
delegate?.didPressMore()
|
||||
}
|
||||
|
||||
override func applyTheme() {
|
||||
super.applyTheme()
|
||||
updateDescription()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user