[ABANDONED] Mastodon iOS client.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.7 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. //
  2. // InstanceViewController.swift
  3. // elpha-ios
  4. //
  5. // Created by Dwayne Harris on 9/17/18.
  6. // Copyright © 2018 Elpha. All rights reserved.
  7. //
  8. import Kingfisher
  9. import UIKit
  10. import SafariServices
  11. class InstanceViewController: UIViewController {
  12. @IBOutlet var thumbnailImageView: UIImageView!
  13. @IBOutlet var instanceDescriptionLabel: UILabel!
  14. @IBOutlet var webViewButton: UIButton!
  15. @IBOutlet var usersLabel: UILabel!
  16. @IBOutlet var statusesLabel: UILabel!
  17. @IBOutlet var connectionsLabel: UILabel!
  18. @IBOutlet var uptimeLabel: UILabel!
  19. var instance: ISInstanceMO?
  20. override var previewActionItems: [UIPreviewActionItem] {
  21. let action = UIPreviewAction(title: "Go to website", style: .default) { action, viewController in
  22. self.presentSafariViewController()
  23. }
  24. return [action]
  25. }
  26. @IBAction func goToWebsite(_ sender: Any) {
  27. presentSafariViewController()
  28. }
  29. @objc func presentSafariViewController() {
  30. guard let url = instance?.url else {
  31. return
  32. }
  33. let safariViewController = SFSafariViewController(url: url)
  34. safariViewController.delegate = self
  35. present(safariViewController, animated: true)
  36. }
  37. override func viewDidLoad() {
  38. super.viewDidLoad()
  39. webViewButton.layer.cornerRadius = 15
  40. if let name = instance?.name {
  41. navigationItem.title = name
  42. }
  43. navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "Globe White"), style: .plain, target: self, action: #selector(presentSafariViewController))
  44. }
  45. override func viewWillAppear(_ animated: Bool) {
  46. super.viewWillAppear(animated)
  47. guard let instance = self.instance else {
  48. fatalError("No instance")
  49. }
  50. if (instance.fullDescription ?? "").isEmpty {
  51. instanceDescriptionLabel.text = "(No description)"
  52. } else {
  53. instanceDescriptionLabel.text = instance.fullDescription
  54. }
  55. usersLabel.text = NumberFormatter.localizedString(from: NSNumber(value: instance.users), number: .decimal)
  56. statusesLabel.text = NumberFormatter.localizedString(from: NSNumber(value: instance.statuses), number: .decimal)
  57. connectionsLabel.text = NumberFormatter.localizedString(from: NSNumber(value: instance.connections), number: .decimal)
  58. uptimeLabel.text = String(instance.uptime)
  59. if let thumbnail = instance.thumbnail {
  60. thumbnailImageView.kf.setImage(with: thumbnail)
  61. }
  62. }
  63. }
  64. extension InstanceViewController: SFSafariViewControllerDelegate {
  65. }