From 1f3579a6f4578f4defd95b3a525b6b73b65cf4a3 Mon Sep 17 00:00:00 2001 From: Jed Fox Date: Thu, 25 Jun 2020 20:12:00 -0400 Subject: [PATCH] Make URL entries tappable --- Clip/History/ClippingTableViewCell.swift | 8 +++++ Clip/History/ClippingTableViewCell.xib | 44 +++++++++++++++++------- Clip/History/HistoryViewController.swift | 12 ++++++- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/Clip/History/ClippingTableViewCell.swift b/Clip/History/ClippingTableViewCell.swift index c963c22..5ec4535 100644 --- a/Clip/History/ClippingTableViewCell.swift +++ b/Clip/History/ClippingTableViewCell.swift @@ -16,10 +16,13 @@ class ClippingTableViewCell: UITableViewCell @IBOutlet var titleLabel: UILabel! @IBOutlet var dateLabel: UILabel! @IBOutlet var contentLabel: UILabel! + @IBOutlet weak var contentButton: UIButton! @IBOutlet var contentImageView: UIImageView! @IBOutlet var bottomConstraint: NSLayoutConstraint! + var onButtonPressed: (() -> Void)? + override func awakeFromNib() { super.awakeFromNib() @@ -30,4 +33,9 @@ class ClippingTableViewCell: UITableViewCell self.contentImageView.layer.cornerRadius = 10 self.contentImageView.layer.masksToBounds = true } + + @IBAction func buttonPressed(_ sender: UIButton) + { + self.onButtonPressed?() + } } diff --git a/Clip/History/ClippingTableViewCell.xib b/Clip/History/ClippingTableViewCell.xib index f86e4b1..0bbdbd0 100644 --- a/Clip/History/ClippingTableViewCell.xib +++ b/Clip/History/ClippingTableViewCell.xib @@ -6,6 +6,7 @@ + @@ -15,40 +16,40 @@ - + - + - + - + - + - + - + - + - + + - + @@ -112,11 +123,18 @@ + + + + + + + diff --git a/Clip/History/HistoryViewController.swift b/Clip/History/HistoryViewController.swift index d7922ac..36d29b1 100644 --- a/Clip/History/HistoryViewController.swift +++ b/Clip/History/HistoryViewController.swift @@ -220,6 +220,7 @@ private extension HistoryViewController dataSource.cellConfigurationHandler = { [weak self] (cell, item, indexPath) in let cell = cell as! ClippingTableViewCell cell.contentLabel.isHidden = false + cell.contentButton.isHidden = true cell.contentImageView.isHidden = true self?.updateDate(for: cell, item: item) @@ -232,7 +233,16 @@ private extension HistoryViewController { case .text: cell.contentLabel.text = representation.stringValue case .attributedText: cell.contentLabel.text = representation.attributedStringValue?.string - case .url: cell.contentLabel.text = representation.urlValue?.absoluteString + case .url: + cell.contentLabel.isHidden = true + cell.contentButton.isHidden = false + cell.contentButton.setTitle(representation.urlValue?.absoluteString, for: .normal) + cell.onButtonPressed = { + if let url = representation.urlValue + { + UIApplication.shared.open(url, options: [:], completionHandler: nil) + } + } case .image: cell.contentLabel.isHidden = true cell.contentImageView.isHidden = false