Commit 825754c0 authored by Philip Brechler's avatar Philip Brechler

Add more information to Hatchery and better error handling (well any error handling to start with)

parent 9626fbf2
......@@ -332,7 +332,7 @@
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Revision: XX • Downloads: XX • Utility" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vH7-25-MOr">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Revision: XX • Downloads: XX • Utility" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="vH7-25-MOr">
<rect key="frame" x="22" y="32.5" width="384" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="yWu-nS-kan"/>
......@@ -405,14 +405,30 @@
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" translatesAutoresizingMaskIntoConstraints="NO" id="eTL-oi-7Mx">
<rect key="frame" x="0.0" y="0.0" width="414" height="808"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Revision: XX • Downloads: XX • Utility" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="z4t-oN-Q7H">
<rect key="frame" x="0.0" y="0.0" width="414" height="24"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle3"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<visualEffectView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="u4A-d0-KXe">
<rect key="frame" x="0.0" y="0.0" width="414" height="50"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="Zib-6c-UdZ">
<rect key="frame" x="0.0" y="0.0" width="414" height="50"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Revision: XX • Downloads: XX • Utility • 2123 Bytes" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="z4t-oN-Q7H">
<rect key="frame" x="4" y="0.0" width="406" height="46"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle3"/>
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="z4t-oN-Q7H" firstAttribute="leading" secondItem="Zib-6c-UdZ" secondAttribute="leading" constant="4" id="Fmy-9G-nZl"/>
<constraint firstAttribute="trailing" secondItem="z4t-oN-Q7H" secondAttribute="trailing" constant="4" id="NaK-Q5-CrO"/>
<constraint firstAttribute="bottom" secondItem="z4t-oN-Q7H" secondAttribute="bottom" constant="4" id="WWL-qi-TSB"/>
<constraint firstItem="z4t-oN-Q7H" firstAttribute="top" secondItem="Zib-6c-UdZ" secondAttribute="top" id="alx-ac-bp6"/>
</constraints>
</view>
<blurEffect style="dark"/>
</visualEffectView>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" text="This is nice" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="23s-lw-nVP">
<rect key="frame" x="0.0" y="24" width="414" height="784"/>
<rect key="frame" x="0.0" y="50" width="414" height="758"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
......
......@@ -11,6 +11,7 @@ import SWCompression
protocol HatcheryClientDelegate: class {
func didRefreshListOfEggs()
func didFailToRefreshListOfEggs(_ error: Error?)
func didDownloadEggToPath(_ path: URL)
func didFailToDownloadEgg()
}
......@@ -33,10 +34,16 @@ class HatcheryClient: NSObject, URLSessionDelegate {
let hatcheryListURL = URL(string: "basket/card10/list/json", relativeTo: hatcheryBaseURL)!
let task = session.dataTask(with: hatcheryListURL, completionHandler: { data, response, error in
guard error == nil else { return }
guard error == nil else {
DispatchQueue.main.async {
self.delegate?.didFailToRefreshListOfEggs(error)
}
return }
guard let httpResponse = response as? HTTPURLResponse,
(200...299).contains(httpResponse.statusCode) else {
//self.handleServerError(response)
DispatchQueue.main.async {
self.delegate?.didFailToRefreshListOfEggs(nil)
}
return
}
......
......@@ -27,7 +27,7 @@ class HatcheryDetailViewController: UIViewController,HatcheryClientDelegate {
override func viewWillAppear(_ animated: Bool) {
self.title = eggToShow?.name
self.descriptionTextView?.text = eggToShow?.eggDescription
self.metaDataLabel?.text = String.init(format: "Revision %@ • %d Downloads • %@", (eggToShow?.revision)!,(eggToShow?.downloadCounter)!,(eggToShow?.category)!)
self.metaDataLabel?.text = String.init(format: "Revision %@ • %d Downloads • %@ • %d Bytes", (eggToShow?.revision)!,(eggToShow?.downloadCounter)!,(eggToShow?.category)!,(eggToShow?.sizeOfContent)!)
super.viewWillAppear(animated)
}
......@@ -47,6 +47,8 @@ class HatcheryDetailViewController: UIViewController,HatcheryClientDelegate {
func didRefreshListOfEggs() {}
func didFailToRefreshListOfEggs(_ error: Error?) {}
func didDownloadEggToPath(_ path: URL) {
//TODO: Call BluetoothManager to upload? Just tell the user and they do it Control?
}
......
......@@ -82,7 +82,7 @@ class HatcheryRootTableViewController: UITableViewController,HatcheryClientDeleg
}
cell.eggNameLabel?.text = eggForCell.name
cell.metaDataLabel?.text = String.init(format: "Revision %@ • %d Downloads • %@", (eggForCell.revision)!,(eggForCell.downloadCounter)!,(eggForCell.category)!)
cell.metaDataLabel?.text = String.init(format: "Revision %@ • %d Downloads • %@ • %d Byte", (eggForCell.revision)!,(eggForCell.downloadCounter)!,(eggForCell.category)!,(eggForCell.sizeOfContent!))
return cell
}
......@@ -142,6 +142,19 @@ class HatcheryRootTableViewController: UITableViewController,HatcheryClientDeleg
func didFailToDownloadEgg() {}
func didFailToRefreshListOfEggs(_ error: Error?) {
self.refreshControl?.endRefreshing()
var errorToShow: String = "Failed to download eggs"
if (error != nil) {
errorToShow.append(contentsOf: "\n")
errorToShow.append(contentsOf: error!.localizedDescription)
}
let listError = UIAlertController.init(title: "Error", message: errorToShow, preferredStyle: .alert)
listError.view.tintColor = UIColor.init(named: "chaos_color")
listError.addAction(UIAlertAction.init(title: "OK", style: .default, handler: nil))
self.present(listError, animated: true, completion: nil)
}
//MARK: - Refresh Control
@IBAction func refreshEggs(sender:UIRefreshControl) {
......
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