[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.

69 lines
2.0 KiB

//
// InstanceViewController.swift
// elpha-ios
//
// Created by Dwayne Harris on 9/17/18.
// Copyright © 2018 Elpha. All rights reserved.
//
import Foundation
import UIKit
import SafariServices
class InstanceViewController: UIViewController, SFSafariViewControllerDelegate {
@IBOutlet var thumbnailImageView: UIImageView!
@IBOutlet var instanceNameLabel: UILabel!
@IBOutlet var instanceDescriptionLabel: UILabel!
@IBOutlet var webViewButton: UIButton!
var instance: ISInstanceMO? = nil
@IBAction func webViewButtonPressed(_ sender: Any) {
guard let instance = instance, let name = instance.name else {
return
}
let safariViewController = SFSafariViewController(url: URL(string: "https://\(name)")!)
safariViewController.delegate = self
present(safariViewController, animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
webViewButton.layer.cornerRadius = 15
if let instance = instance, let name = instance.name {
navigationItem.title = name
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
guard let instance = self.instance else {
fatalError("No instance")
}
instanceNameLabel.text = instance.name
if (instance.fullDescription ?? "").isEmpty {
instanceDescriptionLabel.text = "(No description)"
} else {
instanceDescriptionLabel.text = instance.fullDescription
}
if let thumbnail = instance.thumbnail {
ImageCache.shared.getImage(forURL: thumbnail) { image, error in
guard error == nil else {
return
}
DispatchQueue.main.async {
self.thumbnailImageView.image = image
}
}
}
}
}