Skip to content

Commit 7a318cb

Browse files
Merge pull request #157 from cuappdev/revert-149-yana/allstops-retry-button
Revert "Allstops retry button"
2 parents 39ea74f + ebf0b2e commit 7a318cb

7 files changed

Lines changed: 186 additions & 173 deletions

TCAT.xcodeproj/project.pbxproj

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@
458458
449A7C851D80D0E80019300C /* Sources */,
459459
449A7C861D80D0E80019300C /* Frameworks */,
460460
449A7C871D80D0E80019300C /* Resources */,
461+
046C7FE1354D5CA231D4B0DB /* [CP] Embed Pods Frameworks */,
462+
46E366F31C5FDE5AE2F1856C /* [CP] Copy Pods Resources */,
461463
);
462464
buildRules = (
463465
);
@@ -477,6 +479,8 @@
477479
449A7C901D80D0E80019300C /* Sources */,
478480
449A7C911D80D0E80019300C /* Frameworks */,
479481
449A7C921D80D0E80019300C /* Resources */,
482+
D7D6F3AD37AAA12DFFBEE2FD /* [CP] Embed Pods Frameworks */,
483+
53F5B40EB43DEC59D709CAAF /* [CP] Copy Pods Resources */,
480484
);
481485
buildRules = (
482486
);
@@ -575,6 +579,21 @@
575579
/* End PBXResourcesBuildPhase section */
576580

577581
/* Begin PBXShellScriptBuildPhase section */
582+
046C7FE1354D5CA231D4B0DB /* [CP] Embed Pods Frameworks */ = {
583+
isa = PBXShellScriptBuildPhase;
584+
buildActionMask = 2147483647;
585+
files = (
586+
);
587+
inputPaths = (
588+
);
589+
name = "[CP] Embed Pods Frameworks";
590+
outputPaths = (
591+
);
592+
runOnlyForDeploymentPostprocessing = 0;
593+
shellPath = /bin/sh;
594+
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TCATTests/Pods-TCATTests-frameworks.sh\"\n";
595+
showEnvVarsInLog = 0;
596+
};
578597
0DD807D4971138217FA4C33E /* [CP] Check Pods Manifest.lock */ = {
579598
isa = PBXShellScriptBuildPhase;
580599
buildActionMask = 2147483647;
@@ -613,7 +632,7 @@
613632
files = (
614633
);
615634
inputPaths = (
616-
"${PODS_ROOT}/Target Support Files/Pods-TCAT/Pods-TCAT-resources.sh",
635+
"${SRCROOT}/Pods/Target Support Files/Pods-TCAT/Pods-TCAT-resources.sh",
617636
"${PODS_ROOT}/GoogleMaps/Maps/Frameworks/GoogleMaps.framework/Resources/GoogleMaps.bundle",
618637
"${PODS_ROOT}/GooglePlaces/Frameworks/GooglePlaces.framework/Resources/GooglePlaces.bundle",
619638
);
@@ -624,7 +643,7 @@
624643
);
625644
runOnlyForDeploymentPostprocessing = 0;
626645
shellPath = /bin/sh;
627-
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-TCAT/Pods-TCAT-resources.sh\"\n";
646+
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TCAT/Pods-TCAT-resources.sh\"\n";
628647
showEnvVarsInLog = 0;
629648
};
630649
2E3D0C0A5BDEC0DF37BFA6ED /* [CP] Check Pods Manifest.lock */ = {
@@ -645,19 +664,50 @@
645664
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
646665
showEnvVarsInLog = 0;
647666
};
667+
46E366F31C5FDE5AE2F1856C /* [CP] Copy Pods Resources */ = {
668+
isa = PBXShellScriptBuildPhase;
669+
buildActionMask = 2147483647;
670+
files = (
671+
);
672+
inputPaths = (
673+
);
674+
name = "[CP] Copy Pods Resources";
675+
outputPaths = (
676+
);
677+
runOnlyForDeploymentPostprocessing = 0;
678+
shellPath = /bin/sh;
679+
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TCATTests/Pods-TCATTests-resources.sh\"\n";
680+
showEnvVarsInLog = 0;
681+
};
682+
53F5B40EB43DEC59D709CAAF /* [CP] Copy Pods Resources */ = {
683+
isa = PBXShellScriptBuildPhase;
684+
buildActionMask = 2147483647;
685+
files = (
686+
);
687+
inputPaths = (
688+
);
689+
name = "[CP] Copy Pods Resources";
690+
outputPaths = (
691+
);
692+
runOnlyForDeploymentPostprocessing = 0;
693+
shellPath = /bin/sh;
694+
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TCATUITests/Pods-TCATUITests-resources.sh\"\n";
695+
showEnvVarsInLog = 0;
696+
};
648697
7C01627F386C89E7F1995831 /* [CP] Embed Pods Frameworks */ = {
649698
isa = PBXShellScriptBuildPhase;
650699
buildActionMask = 2147483647;
651700
files = (
652701
);
653702
inputPaths = (
654-
"${PODS_ROOT}/Target Support Files/Pods-TCAT/Pods-TCAT-frameworks.sh",
703+
"${SRCROOT}/Pods/Target Support Files/Pods-TCAT/Pods-TCAT-frameworks.sh",
655704
"${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework",
656705
"${BUILT_PRODUCTS_DIR}/DZNEmptyDataSet/DZNEmptyDataSet.framework",
657706
"${BUILT_PRODUCTS_DIR}/Fuzzywuzzy_swift/Fuzzywuzzy_swift.framework",
658707
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
659708
"${BUILT_PRODUCTS_DIR}/MarqueeLabel/MarqueeLabel.framework",
660709
"${BUILT_PRODUCTS_DIR}/NotificationBannerSwift/NotificationBannerSwift.framework",
710+
"${BUILT_PRODUCTS_DIR}/Pages/Pages.framework",
661711
"${BUILT_PRODUCTS_DIR}/Presentation/Presentation.framework",
662712
"${BUILT_PRODUCTS_DIR}/Pulley/Pulley.framework",
663713
"${BUILT_PRODUCTS_DIR}/SnapKit/SnapKit.framework",
@@ -674,6 +724,7 @@
674724
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
675725
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MarqueeLabel.framework",
676726
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/NotificationBannerSwift.framework",
727+
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Pages.framework",
677728
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Presentation.framework",
678729
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Pulley.framework",
679730
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SnapKit.framework",
@@ -684,7 +735,7 @@
684735
);
685736
runOnlyForDeploymentPostprocessing = 0;
686737
shellPath = /bin/sh;
687-
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-TCAT/Pods-TCAT-frameworks.sh\"\n";
738+
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TCAT/Pods-TCAT-frameworks.sh\"\n";
688739
showEnvVarsInLog = 0;
689740
};
690741
8F523521CC9B937AEFB99FF9 /* [CP] Check Pods Manifest.lock */ = {
@@ -705,6 +756,21 @@
705756
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
706757
showEnvVarsInLog = 0;
707758
};
759+
D7D6F3AD37AAA12DFFBEE2FD /* [CP] Embed Pods Frameworks */ = {
760+
isa = PBXShellScriptBuildPhase;
761+
buildActionMask = 2147483647;
762+
files = (
763+
);
764+
inputPaths = (
765+
);
766+
name = "[CP] Embed Pods Frameworks";
767+
outputPaths = (
768+
);
769+
runOnlyForDeploymentPostprocessing = 0;
770+
shellPath = /bin/sh;
771+
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TCATUITests/Pods-TCATUITests-frameworks.sh\"\n";
772+
showEnvVarsInLog = 0;
773+
};
708774
E3FCA3C71FAA5AFB0069BD0F /* Fabric Configuration */ = {
709775
isa = PBXShellScriptBuildPhase;
710776
buildActionMask = 12;

TCAT/AppDelegate.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,20 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
133133
Network.getAllStops().perform(withSuccess: { stops in
134134
let allBusStops = stops.allStops
135135
if allBusStops.isEmpty {
136-
self.handleGetAllStopsError()
136+
let title = "Couldn't Fetch Bus Stops"
137+
let message = "The app will continue trying on launch. You can continue to use the app as normal."
138+
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
139+
alertController.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
140+
UIApplication.shared.keyWindow?.presentInApp(alertController)
137141
} else {
138142
let data = NSKeyedArchiver.archivedData(withRootObject: allBusStops)
139143
self.userDefaults.set(data, forKey: Constants.UserDefaults.allBusStops)
140144
}
141145
}, failure: { error in
142146
print("getBusStops error:", error)
143-
self.handleGetAllStopsError()
144147
})
145148
}
146149

147-
/// Present an alert indicating bus stops weren't fetched.
148-
func handleGetAllStopsError() {
149-
let title = "Couldn't Fetch Bus Stops"
150-
let message = "The app will continue trying on launch. You can continue to use the app as normal."
151-
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
152-
alertController.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
153-
UIApplication.shared.keyWindow?.presentInApp(alertController)
154-
}
155-
156150
}
157151

158152
extension UIWindow {

TCAT/Controllers/AllStopsTableViewController.swift

Lines changed: 18 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import UIKit
1010
import DZNEmptyDataSet
1111

12-
protocol UnwindAllStopsTVCDelegate {
12+
protocol UnwindAllStopsTVCDelegate{
1313
func dismissSearchResultsVC(busStop: BusStop)
1414
}
1515

@@ -21,7 +21,6 @@ class AllStopsTableViewController: UITableViewController {
2121
var unwindAllStopsTVCDelegate: UnwindAllStopsTVCDelegate?
2222
var height: CGFloat?
2323
var currentChar: Character?
24-
var activityIndicator: UIActivityIndicatorView?
2524

2625
override func viewWillLayoutSubviews() {
2726
if let y = navigationController?.navigationBar.frame.maxY {
@@ -36,7 +35,12 @@ class AllStopsTableViewController: UITableViewController {
3635

3736
super.viewDidLoad()
3837
sectionIndexes = sectionIndexesForBusStop()
39-
sortedKeys = sortedKeysForBusStops()
38+
39+
sortedKeys = Array(sectionIndexes.keys).sorted().filter({$0 != "#"})
40+
if !allStops.isEmpty {
41+
// Adding "#" to keys for bus stops that start with a number
42+
sortedKeys.append("#")
43+
}
4044

4145
title = "All Stops"
4246
tableView.sectionIndexColor = .primaryTextColor
@@ -52,15 +56,18 @@ class AllStopsTableViewController: UITableViewController {
5256
}
5357

5458
tableView.emptyDataSetSource = self
55-
tableView.emptyDataSetDelegate = self
59+
//tableView.emptyDataSetDelegate = self
5660
tableView.tableFooterView = UIView()
5761
// Set top of table view to align with scroll view
5862
tableView.contentOffset = .zero
63+
5964
}
6065

61-
// MARK: TableView DataSource
66+
override func didReceiveMemoryWarning() {
67+
super.didReceiveMemoryWarning()
68+
// Dispose of any resources that can be recreated.
69+
}
6270

63-
/// Retrieves the section indexes for the bus stops
6471
func sectionIndexesForBusStop() -> [String: [BusStop]] {
6572

6673
var sectionIndexDictionary: [String: [BusStop]] = [:]
@@ -100,32 +107,10 @@ class AllStopsTableViewController: UITableViewController {
100107
}
101108

102109
return sectionIndexDictionary
103-
}
104-
105-
/// Retrieves the keys from the sectionIndexDictionary
106-
func sortedKeysForBusStops() -> [String] {
107-
// Don't include key '#'
108-
sortedKeys = Array(sectionIndexes.keys)
109-
.sorted()
110-
.filter { $0 != "#" }
111110

112-
if !allStops.isEmpty {
113-
// Adding "#" to keys for bus stops that start with a number
114-
sortedKeys.append("#")
115-
}
116-
117-
return sortedKeys
118111
}
119112

120-
func setUpTableOnRetry() {
121-
// Retry getting data from user defaults
122-
self.allStops = SearchTableViewManager.shared.getAllStops()
123-
// Set up table information
124-
self.sectionIndexes = self.sectionIndexesForBusStop()
125-
self.sortedKeys = self.sortedKeysForBusStops()
126-
127-
self.tableView.reloadData()
128-
}
113+
// MARK: - Table view data source
129114

130115
override func numberOfSections(in tableView: UITableView) -> Int {
131116
return sectionIndexes.count
@@ -189,66 +174,16 @@ class AllStopsTableViewController: UITableViewController {
189174
}
190175
}
191176

192-
// MARK: DZNEmptyDataSet
193-
extension AllStopsTableViewController: DZNEmptyDataSetSource, DZNEmptyDataSetDelegate {
194-
func setUpActivityIndicator() {
195-
activityIndicator = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.gray)
196-
if let activityIndicator = activityIndicator {
197-
view.addSubview(activityIndicator)
198-
activityIndicator.snp.makeConstraints { (make) in
199-
make.centerX.equalToSuperview()
200-
make.centerY.equalToSuperview()
201-
}
202-
}
203-
}
177+
// MARK: DZN EmptyDataSet Delegate
178+
extension AllStopsTableViewController: DZNEmptyDataSetSource {
204179

205180
func image(forEmptyDataSet scrollView: UIScrollView!) -> UIImage! {
206-
return activityIndicator != nil ? nil : #imageLiteral(resourceName: "emptyPin")
181+
return #imageLiteral(resourceName: "emptyPin")
207182
}
208183

209184
func description(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {
210-
if let _ = activityIndicator {
211-
return nil
212-
}
213-
let title = "Couldn't Get Stops"
185+
let title = "Couldn't get stops 😟"
214186
let attrs = [NSAttributedString.Key.foregroundColor: UIColor.mediumGrayColor]
215187
return NSAttributedString(string: title, attributes: attrs)
216188
}
217-
218-
func buttonTitle(forEmptyDataSet scrollView: UIScrollView!, for state: UIControl.State) -> NSAttributedString! {
219-
if let _ = activityIndicator {
220-
return nil
221-
}
222-
let title = "Retry"
223-
let attrs = [NSAttributedString.Key.foregroundColor: UIColor.buttonColor]
224-
return NSAttributedString(string: title, attributes: attrs)
225-
}
226-
227-
func emptyDataSet(_ scrollView: UIScrollView!, didTap didTapButton: UIButton!) {
228-
setUpActivityIndicator()
229-
if let activityIndicator = activityIndicator {
230-
tableView.reloadData()
231-
activityIndicator.startAnimating()
232-
}
233-
retryNetwork { () -> Void in
234-
self.setUpTableOnRetry()
235-
if let activityIndicator = self.activityIndicator {
236-
activityIndicator.stopAnimating()
237-
}
238-
}
239-
}
240-
241-
func retryNetwork(completion: @escaping () -> Void) {
242-
Network.getAllStops().perform(withSuccess: { stops in
243-
let allBusStops = stops.allStops
244-
if !allBusStops.isEmpty {
245-
// Only updating user defaults if retriving from network is successful
246-
let data = NSKeyedArchiver.archivedData(withRootObject: allBusStops)
247-
userDefaults.set(data, forKey: Constants.UserDefaults.allBusStops)
248-
}
249-
completion()
250-
}, failure: { error in
251-
print("AllStopsTableViewController.retryNetwork error:", error)
252-
})
253-
}
254189
}

0 commit comments

Comments
 (0)