diff --git a/elpha-ios.xcodeproj/project.pbxproj b/elpha-ios.xcodeproj/project.pbxproj index dac5462..7a14391 100644 --- a/elpha-ios.xcodeproj/project.pbxproj +++ b/elpha-ios.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 157405A82150588A00EEAAEB /* InstanceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 157405A72150588A00EEAAEB /* InstanceViewController.swift */; }; + 157405AA2150804200EEAAEB /* WebViewHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 157405A92150804200EEAAEB /* WebViewHelper.swift */; }; + 157405AC215080D400EEAAEB /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 157405AB215080D400EEAAEB /* WebViewController.swift */; }; 15830D93214F6F6F0037C342 /* ImageCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15830D92214F6F6F0037C342 /* ImageCache.swift */; }; 159048AF214F5015004F4014 /* InstancesTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 159048AE214F5015004F4014 /* InstancesTableViewCell.swift */; }; 15960E5B213145E100C38CE9 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15960E5A213145E100C38CE9 /* AppDelegate.swift */; }; @@ -31,6 +33,8 @@ /* Begin PBXFileReference section */ 157405A72150588A00EEAAEB /* InstanceViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstanceViewController.swift; sourceTree = ""; }; + 157405A92150804200EEAAEB /* WebViewHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewHelper.swift; sourceTree = ""; }; + 157405AB215080D400EEAAEB /* WebViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebViewController.swift; sourceTree = ""; }; 15830D92214F6F6F0037C342 /* ImageCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCache.swift; sourceTree = ""; }; 159048AE214F5015004F4014 /* InstancesTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstancesTableViewCell.swift; sourceTree = ""; }; 15960E57213145E100C38CE9 /* elpha-ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "elpha-ios.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -89,6 +93,7 @@ 15960E7B213272CD00C38CE9 /* AuthenticationManager.swift */, 15960E7621322C6F00C38CE9 /* Configuration.swift */, 15830D92214F6F6F0037C342 /* ImageCache.swift */, + 157405A92150804200EEAAEB /* WebViewHelper.swift */, 15960E63213145E200C38CE9 /* Assets.xcassets */, 15960E6E21321FA500C38CE9 /* Elpha.xcdatamodeld */, 15960E7121322B9F00C38CE9 /* Keychain Helper */, @@ -111,16 +116,17 @@ 15960E782132383600C38CE9 /* View Controllers */ = { isa = PBXGroup; children = ( - 15960E5E213145E100C38CE9 /* SecondViewController.swift */, - 15960E792132387A00C38CE9 /* MainTabBarController.swift */, 15960E7D21329FED00C38CE9 /* AuthenticateViewController.swift */, - 15960E7F21353DCF00C38CE9 /* TimelineViewController.swift */, - 15960E812136668500C38CE9 /* TimelinesNavigationController.swift */, - 15960E83213774FC00C38CE9 /* InstancesTableViewController.swift */, 15960E852137775D00C38CE9 /* InstancesNavigationController.swift */, 15960E87213902A400C38CE9 /* InstancesTableView.swift */, 159048AE214F5015004F4014 /* InstancesTableViewCell.swift */, + 15960E83213774FC00C38CE9 /* InstancesTableViewController.swift */, 157405A72150588A00EEAAEB /* InstanceViewController.swift */, + 15960E792132387A00C38CE9 /* MainTabBarController.swift */, + 15960E5E213145E100C38CE9 /* SecondViewController.swift */, + 15960E812136668500C38CE9 /* TimelinesNavigationController.swift */, + 15960E7F21353DCF00C38CE9 /* TimelineViewController.swift */, + 157405AB215080D400EEAAEB /* WebViewController.swift */, ); name = "View Controllers"; sourceTree = ""; @@ -197,6 +203,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 157405AC215080D400EEAAEB /* WebViewController.swift in Sources */, 15960E88213902A400C38CE9 /* InstancesTableView.swift in Sources */, 159048AF214F5015004F4014 /* InstancesTableViewCell.swift in Sources */, 15830D93214F6F6F0037C342 /* ImageCache.swift in Sources */, @@ -204,6 +211,7 @@ 15960E7021321FA500C38CE9 /* Elpha.xcdatamodeld in Sources */, 15960E5F213145E100C38CE9 /* SecondViewController.swift in Sources */, 15960E8021353DCF00C38CE9 /* TimelineViewController.swift in Sources */, + 157405AA2150804200EEAAEB /* WebViewHelper.swift in Sources */, 15960E7A2132387A00C38CE9 /* MainTabBarController.swift in Sources */, 15960E7C213272CD00C38CE9 /* AuthenticationManager.swift in Sources */, 15960E7E21329FED00C38CE9 /* AuthenticateViewController.swift in Sources */, diff --git a/elpha-ios/Assets.xcassets/Globe.imageset/Contents.json b/elpha-ios/Assets.xcassets/Globe.imageset/Contents.json new file mode 100644 index 0000000..aa4ae54 --- /dev/null +++ b/elpha-ios/Assets.xcassets/Globe.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "globe.pdf" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/elpha-ios/Assets.xcassets/Globe.imageset/globe.pdf b/elpha-ios/Assets.xcassets/Globe.imageset/globe.pdf new file mode 100644 index 0000000..d101eff Binary files /dev/null and b/elpha-ios/Assets.xcassets/Globe.imageset/globe.pdf differ diff --git a/elpha-ios/Base.lproj/Main.storyboard b/elpha-ios/Base.lproj/Main.storyboard index 81279d5..2c52f5c 100644 --- a/elpha-ios/Base.lproj/Main.storyboard +++ b/elpha-ios/Base.lproj/Main.storyboard @@ -1,6 +1,6 @@ - + @@ -14,7 +14,7 @@ - + @@ -30,17 +30,17 @@ - + - + @@ -50,7 +50,7 @@ - + + + + - + + + @@ -314,31 +385,33 @@ + + - + - + + diff --git a/elpha-ios/InstanceViewController.swift b/elpha-ios/InstanceViewController.swift index 9061d85..3640fa0 100644 --- a/elpha-ios/InstanceViewController.swift +++ b/elpha-ios/InstanceViewController.swift @@ -12,9 +12,31 @@ import UIKit class InstanceViewController: UIViewController { @IBOutlet var thumbnailImageView: UIImageView! @IBOutlet var instanceNameLabel: UILabel! + @IBOutlet var instanceDescriptionLabel: UILabel! + @IBOutlet var webViewButton: UIButton! var instance: Instance? = nil + @IBAction func webViewButtonPressed(_ sender: Any) { + guard let instance = instance, let name = instance.name else { + return + } + + if let webViewController = WebViewHelper.getWebViewController(url: URL(string: "https://\(name)")!) { + navigationController?.pushViewController(webViewController, 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) @@ -22,10 +44,13 @@ class InstanceViewController: UIViewController { fatalError("No instance") } - print(instanceNameLabel) - print(thumbnailImageView) + instanceNameLabel.text = instance.name - instanceNameLabel?.text = instance.name + if (instance.fullDescription ?? "").isEmpty { + instanceDescriptionLabel.text = "(No description)" + } else { + instanceDescriptionLabel.text = instance.fullDescription + } if let thumbnailURL = instance.thumbnail { ImageCache.shared.getImage(forURL: URL(string: thumbnailURL)!) { image, error in @@ -34,7 +59,7 @@ class InstanceViewController: UIViewController { } DispatchQueue.main.async { - self.thumbnailImageView?.image = image + self.thumbnailImageView.image = image } } } diff --git a/elpha-ios/InstancesNavigationController.swift b/elpha-ios/InstancesNavigationController.swift index 3a4b781..bd21a16 100644 --- a/elpha-ios/InstancesNavigationController.swift +++ b/elpha-ios/InstancesNavigationController.swift @@ -9,7 +9,5 @@ import UIKit class InstancesNavigationController: UINavigationController { - override func viewDidLoad() { - super.viewDidLoad() - } + } diff --git a/elpha-ios/InstancesTableViewController.swift b/elpha-ios/InstancesTableViewController.swift index 699c0d1..6daae8e 100644 --- a/elpha-ios/InstancesTableViewController.swift +++ b/elpha-ios/InstancesTableViewController.swift @@ -42,18 +42,31 @@ class InstancesTableViewController: UITableViewController, UIViewControllerPrevi let instanceRequestCount = 20 var instances: [Instance] = [] var nextID: String? = nil - var loading: Bool = false var finished: Bool = false + var loading: Bool = false { + didSet { + DispatchQueue.main.async { + if self.loading { + UIApplication.shared.isNetworkActivityIndicatorVisible = true + self.refreshControl?.beginRefreshing() + } else { + UIApplication.shared.isNetworkActivityIndicatorVisible = false + self.refreshControl?.endRefreshing() + } + } + } + } + override func viewDidLoad() { super.viewDidLoad() - UINavigationBar.appearance().barTintColor = UIColor.red - UINavigationBar.appearance().tintColor = UIColor.white + UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] mainNavigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(done)) registerForPreviewing(with: self, sourceView: tableView) + refreshControl?.addTarget(self, action: #selector(self.reloadInstances), for: .valueChanged) loadInstances() } @@ -62,6 +75,13 @@ class InstancesTableViewController: UITableViewController, UIViewControllerPrevi dismiss(animated: true, completion: nil) } + @objc func reloadInstances() { + self.nextID = nil + self.finished = false + + loadInstances() + } + func loadInstances() { loading = true @@ -77,6 +97,10 @@ class InstancesTableViewController: UITableViewController, UIViewControllerPrevi params.append("min_id=\(nextID)") } else { instances = [] + + DispatchQueue.main.async { + self.tableView.reloadData() + } } let requestURL = "\(Config.instancesServiceUrl)\(Config.instancesServiceEndpoint)?\(params.joined(separator: "&"))" diff --git a/elpha-ios/MainTabBarController.swift b/elpha-ios/MainTabBarController.swift index ad70946..267173f 100644 --- a/elpha-ios/MainTabBarController.swift +++ b/elpha-ios/MainTabBarController.swift @@ -9,10 +9,6 @@ import UIKit class MainTabBarController: UITabBarController { - override func viewDidLoad() { - super.viewDidLoad() - } - override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) diff --git a/elpha-ios/TimelinesNavigationController.swift b/elpha-ios/TimelinesNavigationController.swift index 3ad65ef..7ed8e53 100644 --- a/elpha-ios/TimelinesNavigationController.swift +++ b/elpha-ios/TimelinesNavigationController.swift @@ -9,7 +9,5 @@ import UIKit class TimelinesNavigationController: UINavigationController { - override func viewDidLoad() { - super.viewDidLoad() - } + } diff --git a/elpha-ios/WebViewController.swift b/elpha-ios/WebViewController.swift new file mode 100644 index 0000000..707e29b --- /dev/null +++ b/elpha-ios/WebViewController.swift @@ -0,0 +1,56 @@ +// +// WebViewController.swift +// elpha-ios +// +// Created by Dwayne Harris on 9/17/18. +// Copyright © 2018 Elpha. All rights reserved. +// + +import Foundation +import UIKit +import WebKit + +class WebViewController: UIViewController, WKNavigationDelegate { + @IBOutlet var mainWebView: WKWebView! + @IBOutlet var mainProgressView: UIProgressView! + + var url: URL? = nil + + override func viewDidLoad() { + super.viewDidLoad() + + UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] + + mainWebView.navigationDelegate = self + mainWebView.addObserver(self, forKeyPath: #keyPath(WKWebView.title), options: .new, context: nil) + mainWebView.addObserver(self, forKeyPath: #keyPath(WKWebView.estimatedProgress), options: .new, context: nil) + + if let url = url { + mainWebView.load(URLRequest(url: url)) + } + } + + @objc func done() { + dismiss(animated: true, completion: nil) + } + + override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { + if keyPath == #keyPath(WKWebView.title) { + if let title = mainWebView.title { + navigationItem.title = title + } + } + + if keyPath == #keyPath(WKWebView.estimatedProgress) { + mainProgressView.progress = Float(mainWebView.estimatedProgress) + } + } + + func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { + mainProgressView.alpha = 1.0 + } + + func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { + mainProgressView.alpha = 0.0 + } +} diff --git a/elpha-ios/WebViewHelper.swift b/elpha-ios/WebViewHelper.swift new file mode 100644 index 0000000..5a8f2f8 --- /dev/null +++ b/elpha-ios/WebViewHelper.swift @@ -0,0 +1,22 @@ +// +// WebViewHelper.swift +// elpha-ios +// +// Created by Dwayne Harris on 9/17/18. +// Copyright © 2018 Elpha. All rights reserved. +// + +import Foundation +import UIKit + +class WebViewHelper { + static func getWebViewController(url: URL) -> WebViewController? { + let storyboard = UIStoryboard(name: "Main", bundle: nil) + if let webViewController = storyboard.instantiateViewController(withIdentifier: "WebViewController") as? WebViewController { + webViewController.url = url + return webViewController + } + + fatalError("Could not instantiate WebViewController") + } +}