Add opening URLs in SFSafariViewController

This commit is contained in:
Shadowfacts 2018-08-27 15:23:59 -04:00
parent 03c87105d3
commit 02fcea8675
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 33 additions and 3 deletions

View File

@ -9,6 +9,7 @@
import UIKit import UIKit
import MastodonKit import MastodonKit
import SwiftSoup import SwiftSoup
import SafariServices
class TimelineTableViewController: UITableViewController { class TimelineTableViewController: UITableViewController {
@ -90,6 +91,8 @@ class TimelineTableViewController: UITableViewController {
let status = statuses[indexPath.row] let status = statuses[indexPath.row]
cell.updateUI(for: status) cell.updateUI(for: status)
cell.delegate = self
return cell return cell
} }
@ -123,3 +126,18 @@ class TimelineTableViewController: UITableViewController {
} }
} }
extension TimelineTableViewController: StatusTableViewCellDelegate {
func selected(mention: Mention) {
}
func selected(tag: MastodonKit.Tag) {
}
func selected(url: URL) {
let vc = SFSafariViewController(url: url)
present(vc, animated: true)
}
}

View File

@ -10,8 +10,20 @@ import UIKit
import MastodonKit import MastodonKit
import SwiftSoup import SwiftSoup
protocol StatusTableViewCellDelegate {
func selected(mention: Mention)
func selected(tag: MastodonKit.Tag)
func selected(url: URL)
}
class StatusTableViewCell: UITableViewCell { class StatusTableViewCell: UITableViewCell {
var delegate: StatusTableViewCellDelegate?
@IBOutlet weak var displayNameLabel: UILabel! @IBOutlet weak var displayNameLabel: UILabel!
@IBOutlet weak var usernameLabel: UILabel! @IBOutlet weak var usernameLabel: UILabel!
@IBOutlet weak var contentLabel: StatusContentLabel! @IBOutlet weak var contentLabel: StatusContentLabel!
@ -64,15 +76,15 @@ class StatusTableViewCell: UITableViewCell {
extension StatusTableViewCell: StatusContentLabelDelegate { extension StatusTableViewCell: StatusContentLabelDelegate {
func selected(mention: Mention) { func selected(mention: Mention) {
print("selected mention: \(mention.acct)") delegate?.selected(mention: mention)
} }
func selected(tag: MastodonKit.Tag) { func selected(tag: MastodonKit.Tag) {
print("selected tag: \(tag.name)") delegate?.selected(tag: tag)
} }
func selected(url: URL) { func selected(url: URL) {
print("selected url: \(url)") delegate?.selected(url: url)
} }
} }