Commit 52f15563 by Dima Bart

Add loading indicator when initiating login or signup actions.

parent 7e49d2c4
......@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
9A102CEE1CDAA6080026CC43 /* ActionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A102CED1CDAA6080026CC43 /* ActionCell.swift */; };
9A9C03071CD8F9AC00AE79BD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A9C03061CD8F9AC00AE79BD /* AppDelegate.swift */; };
9A9C03091CD8F9AC00AE79BD /* LoginViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A9C03081CD8F9AC00AE79BD /* LoginViewController.swift */; };
9A9C030C1CD8F9AC00AE79BD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9A9C030A1CD8F9AC00AE79BD /* Main.storyboard */; };
......@@ -64,6 +65,7 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
9A102CED1CDAA6080026CC43 /* ActionCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActionCell.swift; sourceTree = "<group>"; };
9A9C03031CD8F9AC00AE79BD /* Sample App Customers.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Sample App Customers.app"; sourceTree = BUILT_PRODUCTS_DIR; };
9A9C03061CD8F9AC00AE79BD /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
9A9C03081CD8F9AC00AE79BD /* LoginViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewController.swift; sourceTree = "<group>"; };
......@@ -89,6 +91,14 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
9A102CE81CDAA5F00026CC43 /* Cells */ = {
isa = PBXGroup;
children = (
9A102CED1CDAA6080026CC43 /* ActionCell.swift */,
);
name = Cells;
sourceTree = "<group>";
};
9A9C02FA1CD8F9AC00AE79BD = {
isa = PBXGroup;
children = (
......@@ -112,6 +122,7 @@
children = (
9A9C03061CD8F9AC00AE79BD /* AppDelegate.swift */,
9A9C03391CD920F600AE79BD /* Extensions */,
9A102CE81CDAA5F00026CC43 /* Cells */,
9A9C031A1CD8FA0C00AE79BD /* View Controllers */,
9A9C030A1CD8F9AC00AE79BD /* Main.storyboard */,
);
......@@ -271,6 +282,7 @@
9A9C03091CD8F9AC00AE79BD /* LoginViewController.swift in Sources */,
9A9C03071CD8F9AC00AE79BD /* AppDelegate.swift in Sources */,
9A9C033B1CD921D700AE79BD /* BUYClient+Extensions.swift in Sources */,
9A102CEE1CDAA6080026CC43 /* ActionCell.swift in Sources */,
9A9C031C1CD8FC6A00AE79BD /* AccountViewController.swift in Sources */,
9A9C031E1CD8FD2300AE79BD /* SignupViewController.swift in Sources */,
);
......
//
// ActionCell.swift
// Sample App Customers
//
// Created by Dima Bart on 2016-05-04.
// Copyright © 2016 Shopify Inc. All rights reserved.
//
import UIKit
class ActionCell: UITableViewCell {
@IBOutlet private weak var actionLabel: UILabel!
@IBOutlet private weak var loader: UIActivityIndicatorView!
var loading: Bool {
get {
return self.actionLabel.hidden
}
set {
self.actionLabel.hidden = newValue
self.loader.hidden = !newValue
}
}
}
......@@ -31,11 +31,21 @@ class LoginViewController: UITableViewController {
@IBOutlet private weak var emailField: UITextField!
@IBOutlet private weak var passwordField: UITextField!
@IBOutlet private weak var actionCell: ActionCell!
var email: String { return self.emailField.text ?? "" }
var password: String { return self.passwordField.text ?? "" }
// ----------------------------------
// MARK: - View Loading -
//
override func viewDidLoad() {
super.viewDidLoad()
self.actionCell.loading = false
}
// ----------------------------------
// MARK: - Actions -
//
private func loginUser() {
......@@ -44,7 +54,10 @@ class LoginViewController: UITableViewController {
BUYAccountCredentialItem(password: self.password),
])
self.actionCell.loading = true
BUYClient.sharedClient.loginCustomerWithCredentials(credentials) { (customer, token, error) in
self.actionCell.loading = false
print("Customer: \(customer), Token: \(token), Error: \(error)")
}
}
......
......@@ -34,6 +34,7 @@ class SignupViewController: UITableViewController {
@IBOutlet private weak var emailField: UITextField!
@IBOutlet private weak var passwordField: UITextField!
@IBOutlet private weak var passwordConfirmField: UITextField!
@IBOutlet private weak var actionCell: ActionCell!
var firstName: String { return self.firstNameField.text ?? "" }
var lastName: String { return self.lastNameField.text ?? "" }
......@@ -42,6 +43,15 @@ class SignupViewController: UITableViewController {
var passwordConfirm: String { return self.passwordField.text ?? "" }
// ----------------------------------
// MARK: - View Loading -
//
override func viewDidLoad() {
super.viewDidLoad()
self.actionCell.loading = false
}
// ----------------------------------
// MARK: - Actions -
//
private func createUser() {
......@@ -53,7 +63,10 @@ class SignupViewController: UITableViewController {
BUYAccountCredentialItem(passwordConfirmation: self.passwordConfirm),
])
self.actionCell.loading = true
BUYClient.sharedClient.createCustomerWithCredentials(credentials) { (customer, token, error) in
self.actionCell.loading = false
print("Customer: \(customer), Token: \(token), Error: \(error)")
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment