Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Update widget with new assets
Browse files Browse the repository at this point in the history
  • Loading branch information
pg8wood committed Jan 20, 2020
1 parent 84f4ab7 commit 14de655
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
2 changes: 0 additions & 2 deletions Common/Network/OldNetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ import Foundation
import FavIcon
import PinkyPromise

@available(*, deprecated)
public enum OldNetworkError: Error {
case invalidUrl
case noResponse
case error(description: String)
}

@available(*, deprecated)
public class OldNetworkService {

public static func fetchServerStatus(url: String) -> Promise<Int> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class ServiceCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var logoImageViewWidthConstraint: NSLayoutConstraint!
@IBOutlet weak var statusImageViewWidthConstraint: NSLayoutConstraint!

enum ServiceStaus {
case online
case offline
}

override func awakeFromNib() {
super.awakeFromNib()
setupView()
Expand All @@ -40,4 +45,15 @@ class ServiceCollectionViewCell: UICollectionViewCell {
func stopLoading() {
loadingIndicator.stopAnimating()
}

func setStatusImage(_ status: ServiceStaus) {
switch status {
case .online:
statusImageView.image = UIImage(named: "check")
statusImageView.tintColor = .clear
case .offline:
statusImageView.image = UIImage(systemName: "exclamationmark.circle")
statusImageView.tintColor = .systemRed
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14810.11" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15505" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14766.13"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
<capability name="iOS 13.0 system colors" minToolsVersion="11.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="gTV-IL-0wX" customClass="ServiceCollectionViewCell" customModule="Dashboard" customModuleProvider="target">
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="gTV-IL-0wX" customClass="ServiceCollectionViewCell" customModule="DashboardWidget" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="400" height="111"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
Expand Down Expand Up @@ -43,7 +42,7 @@
<rect key="frame" x="10" y="45.5" width="20" height="20"/>
</activityIndicatorView>
</subviews>
<color key="backgroundColor" cocoaTouchSystemColor="secondarySystemGroupedBackgroundColor"/>
<color key="backgroundColor" systemColor="secondarySystemGroupedBackgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="FIt-pS-KJu" firstAttribute="centerY" secondItem="kSV-MZ-3xz" secondAttribute="centerY" id="GTe-7F-vAx"/>
<constraint firstItem="VLo-Px-XA5" firstAttribute="centerX" secondItem="kSV-MZ-3xz" secondAttribute="centerX" id="Lep-U3-4dB"/>
Expand All @@ -55,7 +54,7 @@
</view>
</subviews>
</view>
<color key="backgroundColor" cocoaTouchSystemColor="secondarySystemGroupedBackgroundColor"/>
<color key="backgroundColor" systemColor="secondarySystemGroupedBackgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="9mm-Qf-BgE" firstAttribute="centerY" secondItem="gTV-IL-0wX" secondAttribute="centerY" id="7Aj-t8-to7"/>
<constraint firstItem="tTM-DE-agA" firstAttribute="centerY" secondItem="gTV-IL-0wX" secondAttribute="centerY" id="7Qs-L1-gpl"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,17 @@ class ServiceCollectionViewController: UIViewController {
cell.stopLoading()

do {
let _ = try result.value()
let statusCode = try result.value()

database.updateLastOnlineDate(for: service, lastOnline: Date(timeIntervalSinceNow: 0))
guard statusCode == 200 else {
cell.setStatusImage(.offline)
return
}

cell.statusImageView.image = UIImage(named: "check")
database.updateLastOnlineDate(for: service, lastOnline: Date(timeIntervalSinceNow: 0))
cell.setStatusImage(.online)
} catch {
cell.statusImageView.image = UIImage(named: "server-error")
cell.setStatusImage(.offline)
}
}
}
Expand All @@ -116,8 +120,7 @@ extension ServiceCollectionViewController: UICollectionViewDelegate {

cell.logoImageView.image = service.image
cell.nameLabel.text = service.name
cell.statusImageView.image = service.wasOnlineRecently ? UIImage(named: "check") : UIImage(named: "server-error")
cell.layer.cornerRadius = 20
cell.setStatusImage(service.wasOnlineRecently ? .online : .offline)

return cell
}
Expand Down

0 comments on commit 14de655

Please sign in to comment.