Skip to content

Commit

Permalink
Add loading indicators to brb
Browse files Browse the repository at this point in the history
  • Loading branch information
dantheli committed Jan 16, 2018
1 parent 8bc9673 commit b5946e4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Eatery/Controllers/BRB Feature/BRBConnectionHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class BRBConnectionHandler: WKWebView, WKNavigationDelegate {
getHTML { (html: NSString) in
let tableHTMLRegex = "(<tr class=\\\"(?:even|odd|odd first-child)\\\"><td class=\\\"first-child account_name\\\">(.*?)<\\/td><td class=\\\"date_(and_|)time\\\"><span class=\\\"date\\\">(.*?)<\\/span><\\/td><td class=\\\"activity_details\\\">(.*?)<\\/td><td class=\\\"last-child amount_points (credit|debit)\\\" title=\\\"(credit|debit)\\\">(.*?)<\\/td><\\/tr>)"

let regex = try? NSRegularExpression(pattern: tableHTMLRegex as String, options: .useUnicodeWordBoundaries)
let regex = try? NSRegularExpression(pattern: tableHTMLRegex, options: .useUnicodeWordBoundaries)
if let matches = regex?.matches(in: html as String, options: NSRegularExpression.MatchingOptions.withTransparentBounds , range: NSMakeRange(0, html.length))
{
for match in matches
Expand Down
6 changes: 3 additions & 3 deletions Eatery/Controllers/BRB Feature/BRBLoginView.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import UIKit
import NVActivityIndicatorView

protocol BRBLoginViewDelegate {
func brbLoginViewClickedLogin(brbLoginView: BRBLoginView, netid: String, password: String)
Expand All @@ -18,7 +19,7 @@ class BRBLoginView: UIView, UITextFieldDelegate {
let privacyStatementButton = UIButton()
let privacyStatementTextView = UITextView()

var activityIndicator = UIActivityIndicatorView()
var activityIndicator: NVActivityIndicatorView!

override init(frame: CGRect) {
super.init(frame: frame)
Expand Down Expand Up @@ -160,8 +161,7 @@ class BRBLoginView: UIView, UITextFieldDelegate {
make.height.equalTo(55)
}

activityIndicator = UIActivityIndicatorView()
activityIndicator.color = .white
activityIndicator = NVActivityIndicatorView(frame: CGRect(x: 0.0, y: 0.0, width: 22.0, height: 22.0), type: .circleStrokeSpin, color: .white, padding: nil)
addSubview(activityIndicator)
activityIndicator.snp.makeConstraints { make in
make.center.equalTo(loginButton)
Expand Down
25 changes: 9 additions & 16 deletions Eatery/Controllers/BRB Feature/BRBViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import UIKit
import WebKit
import SafariServices
import Crashlytics
import NVActivityIndicatorView

class BRBViewController: UIViewController, BRBConnectionDelegate, BRBLoginViewDelegate, BRBAccountSettingsDelegate, UITableViewDelegate, UITableViewDataSource {

Expand All @@ -11,8 +12,7 @@ class BRBViewController: UIViewController, BRBConnectionDelegate, BRBLoginViewDe
var timer: Timer!

var tableView: UITableView!
let activityIndicatorView = UIActivityIndicatorView()
let activityIndicatorDescriptionLabel = UILabel()
var activityIndicatorView: NVActivityIndicatorView!
let timeout = 30.0 // seconds
var time = 0.0 // time of request
var historyHeader : EateriesCollectionViewHeaderView?
Expand All @@ -35,12 +35,6 @@ class BRBViewController: UIViewController, BRBConnectionDelegate, BRBLoginViewDe
}

connectionHandler.delegate = self

activityIndicatorView.color = .black
activityIndicatorView.hidesWhenStopped = true
activityIndicatorDescriptionLabel.text = "Logging in, this may take a minute"
activityIndicatorDescriptionLabel.textAlignment = .center
activityIndicatorDescriptionLabel.font = UIFont.systemFont(ofSize: 12)

navigationItem.rightBarButtonItem?.isEnabled = false

Expand Down Expand Up @@ -117,13 +111,8 @@ class BRBViewController: UIViewController, BRBConnectionDelegate, BRBLoginViewDe
}

func setupAccountPage() {

diningHistory = connectionHandler.diningHistory

if diningHistory.count == 0 {
activityIndicatorView.startAnimating()
}

navigationItem.rightBarButtonItem?.isEnabled = true

tableView = UITableView(frame: .zero, style: .grouped)
Expand All @@ -139,6 +128,10 @@ class BRBViewController: UIViewController, BRBConnectionDelegate, BRBLoginViewDe
tableView.snp.makeConstraints { make in
make.top.edges.equalToSuperview()
}

activityIndicatorView = NVActivityIndicatorView(frame: CGRect(x: 16.0, y: 8.0, width: 36.0, height: 36.0), type: .circleStrokeSpin, color: .gray)
activityIndicatorView.startAnimating()
tableView.tableFooterView = activityIndicatorView
}

/// MARK: Table view delegate/data source
Expand Down Expand Up @@ -240,6 +233,9 @@ class BRBViewController: UIViewController, BRBConnectionDelegate, BRBLoginViewDe

let indexPaths = (0..<entries.count).map { IndexPath(row: $0, section: 1) }
self.tableView.insertRows(at: indexPaths, with: .automatic)

tableView.tableFooterView = nil
activityIndicatorView.removeFromSuperview()
}

func showSafariVC() {
Expand All @@ -264,9 +260,6 @@ class BRBViewController: UIViewController, BRBConnectionDelegate, BRBLoginViewDe
keychainItemWrapper["netid"] = loginView?.netidTextField.text! as AnyObject?
keychainItemWrapper["password"] = loginView?.passwordTextField.text! as AnyObject?
}

activityIndicatorView.stopAnimating()
activityIndicatorDescriptionLabel.removeFromSuperview()

if loginView != nil {
loginView?.superview?.removeFromSuperview()
Expand Down
2 changes: 1 addition & 1 deletion Eatery/Controllers/EateriesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class EateriesViewController: UIViewController, MenuButtonsDelegate, CLLocationM
}, completion: nil)
}

UIView.animate(withDuration: 0.55) {
UIView.animate(withDuration: 0.35) {
self.activityIndicator.alpha = 0.0
}
}
Expand Down

0 comments on commit b5946e4

Please sign in to comment.