From 5defdc59055d666fc02f0af2b647ae661377ff94 Mon Sep 17 00:00:00 2001 From: Dwayne Harris Date: Mon, 17 Sep 2018 23:43:16 -0700 Subject: [PATCH] Development --- elpha-ios.xcodeproj/project.pbxproj | 18 ++- .../Globe.imageset/Contents.json | 12 ++ .../Assets.xcassets/Globe.imageset/globe.pdf | Bin 0 -> 4256 bytes elpha-ios/Base.lproj/Main.storyboard | 148 +++++++++++++----- elpha-ios/InstanceViewController.swift | 33 +++- elpha-ios/InstancesNavigationController.swift | 4 +- elpha-ios/InstancesTableViewController.swift | 30 +++- elpha-ios/MainTabBarController.swift | 4 - elpha-ios/TimelinesNavigationController.swift | 4 +- elpha-ios/WebViewController.swift | 56 +++++++ elpha-ios/WebViewHelper.swift | 22 +++ 11 files changed, 274 insertions(+), 57 deletions(-) create mode 100644 elpha-ios/Assets.xcassets/Globe.imageset/Contents.json create mode 100644 elpha-ios/Assets.xcassets/Globe.imageset/globe.pdf create mode 100644 elpha-ios/WebViewController.swift create mode 100644 elpha-ios/WebViewHelper.swift 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 0000000000000000000000000000000000000000..d101eff8073fd35b25479da7f8df0bf22722cddb GIT binary patch literal 4256 zcmai%2UHW=7KSNNARwSpq$nd&L`o6@0hHbXDuyD`#WXquLue{hiZqcfARwSrDH@a- znn)2Y5ow|VB2A?UBAv?%sPB63eQUj0GnteB?6YU*%%8QsEo!K(D-Dx@gGE~=mnLWO zzukY;(h8OXpa22m1XflCAm{OJ_9O>Do+cRs5M4(X5}ruAyP!#UZ9JBM!vm_SU=I=z zk9Gz7&>NUoxe3D9HdiG`K{d~$)TYjex0`W59pV_s`(9Jj42_puBBh?Z<%`SF*)SQI zG_e$@J_k<-mot4lKs;;%hdjpKvb>R%gU8pkkx#p>_WMs{-csGc)=X$QnYF3ryk@U| zD{!RZh}gggEMEp`*>S}tS>|MqvNwvH%wg0v&+i14$fPnn8xFXrw$InnRLSHkxqiNS zWV}YuS5i59V5+h2P4Li5(?^%O+?eb{1d6>=m zVgl|0QR$eK#CttxI^-SG0HYNPslVF!-u;+AIQmufc#( zH#RcgozzG!z@&SKn4&b6x$8wwzd!D*=-K3VfrDx86U5ugRWjq#;&lD^@Iv~Iaa)X; zw705xbzV`@dSG{v9-1hQcSXg;_^^IgR}65!w{=tk9X=gZ@Cqek@aS>d-N3^eH`KnD zw3x!EndXWiiLuNlZVKgsbGTD-*E|=)s62v)Hm{&H$%q`Cc?0%I*A5s zEM@zf*ie0nvnPWMn&A(Q%A{j$Nu|l?<4Zww(T-NWk@ou=E9-xhO zt+VTwy*pHXcXD?q`jE|aM2p};Aey+Nv3OwD##$aQK;dVC-*PDa zmgA?>mG+__7ia}RGh~n=y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al zi3SAR@8AEb)Q5<-1498A91Q*M0U+e%;qrhT@Kb{;AZVS(?g6;{(x3=g+OGUvgUiEd z9m(G{C{&jAv;LtWptSw@ho(Tw{tpc<|G(l8v={#OwQxDbf8~QCU^D~$BMyQ1x2EuW zeIz2<(FIT3Yx_+cuhI68)&dz52sD4}dVsc(`fhdvnpu8~wP|)y#-imgia00&Cu@hn uV-=tZSS17ohm(ULWHB%V9H$EY{~ - + @@ -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") + } +}