Fetch license content via URL

This commit is contained in:
Davide De Rosa 2018-11-26 17:18:58 +01:00
parent a486cb4265
commit 8270c20179
2 changed files with 21 additions and 2 deletions

View File

@ -58,10 +58,17 @@ class CreditsViewController: UITableViewController, TableModelHost {
guard let vc = segue.destination as? LabelViewController else {
return
}
guard let cell = sender as? SettingTableViewCell else {
guard let cell = sender as? SettingTableViewCell, let indexPath = tableView.indexPath(for: cell) else {
return
}
vc.title = cell.leftText
switch model.row(at: indexPath) {
case .license:
vc.url = licenses[indexPath.row].url
case .notice:
vc.text = notices[indexPath.row].statement
}
}
}

View File

@ -32,6 +32,8 @@ class LabelViewController: UIViewController {
var text: String?
var url: URL?
override func awakeFromNib() {
super.awakeFromNib()
@ -41,7 +43,17 @@ class LabelViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if let url = url {
label?.text = nil
DispatchQueue(label: LabelViewController.description(), qos: .background).async { [weak self] in
let urlText = try? String(contentsOf: url)
DispatchQueue.main.async {
self?.label?.text = urlText
}
}
} else {
label?.text = text
}
scrollView?.applyPrimaryBackground(Theme.current)
label?.applyLight(Theme.current)