Unverified Commit 9b7b4243 authored by Zach Knox's avatar Zach Knox
Browse files

Made alerts work nicer over various screen sizes. Alignment isn't perfect, but...

Made alerts work nicer over various screen sizes. Alignment isn't perfect, but its the best I know how to do

Also TIL you can make outlets out of constraints, that's super cool
parent b2f7edbc
......@@ -13,10 +13,36 @@ class AlertCollectionViewCell: UICollectionViewCell {
@IBOutlet var imageView: UIImageView!
@IBOutlet var messageLabel: UILabel!
@IBOutlet var containingView: UIView!
@IBOutlet var containingViewWidth: NSLayoutConstraint!
var viewWidth: CGFloat!
override func awakeFromNib() {
super.awakeFromNib()
//TODO
isAccessibilityElement = true
shouldGroupAccessibilityChildren = true
setNeedsLayout()
}
override func layoutSubviews() {
super.layoutSubviews()
if(viewWidth < 640) {
containingViewWidth.constant = -30
//cell.containingView.widthAnchor.constraint(equalTo: cell.widthAnchor, multiplier: 1, constant: -10)
}
else if(viewWidth >= 640 && viewWidth < 1024) {
containingViewWidth.constant = -100
//cell.containingView.widthAnchor.constraint(equalTo: cell.widthAnchor, multiplier: 1, constant: -100)
}
else if(viewWidth >= 1024) {
containingViewWidth.constant = -300
//cell.containingView.widthAnchor.constraint(equalTo: cell.widthAnchor, multiplier: 1, constant: -150)
}
else {
containingViewWidth.constant = -10
//cell.containingView.widthAnchor.constraint(equalTo: cell.widthAnchor, multiplier: 1, constant: -10)
}
}
}
......@@ -5,6 +5,7 @@
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
......@@ -241,32 +242,46 @@
<rect key="frame" x="0.0" y="0.0" width="300" height="131"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Oab-U6-xpF">
<rect key="frame" x="8" y="33" width="64" height="64"/>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="S4r-K0-38K">
<rect key="frame" x="0.5" y="1" width="300" height="128"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Alert Text" lineBreakMode="tailTruncation" numberOfLines="5" baselineAdjustment="alignBaselines" minimumScaleFactor="0.75" adjustsFontForContentSizeCategory="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2Ns-M7-OG1">
<rect key="frame" x="72" y="8" width="228" height="112"/>
<fontDescription key="fontDescription" type="system" pointSize="19"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Oab-U6-xpF">
<rect key="frame" x="0.0" y="32" width="64" height="64"/>
<constraints>
<constraint firstAttribute="height" constant="64" id="D8k-fI-v4K"/>
<constraint firstAttribute="width" constant="64" id="FVc-XG-Cdz"/>
<constraint firstAttribute="width" secondItem="Oab-U6-xpF" secondAttribute="height" multiplier="1:1" id="oGq-If-eyX"/>
</constraints>
</imageView>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="64" id="66B-Ym-t5O"/>
<constraint firstAttribute="width" constant="64" id="u3D-mk-VoY"/>
<constraint firstItem="2Ns-M7-OG1" firstAttribute="top" secondItem="S4r-K0-38K" secondAttribute="top" constant="8" id="72c-BL-1gb"/>
<constraint firstItem="2Ns-M7-OG1" firstAttribute="leading" secondItem="Oab-U6-xpF" secondAttribute="trailing" constant="8" id="97x-ge-os6"/>
<constraint firstItem="Oab-U6-xpF" firstAttribute="leading" secondItem="S4r-K0-38K" secondAttribute="leading" id="KJK-vc-7N5"/>
<constraint firstAttribute="trailing" secondItem="2Ns-M7-OG1" secondAttribute="trailing" id="StY-Dp-GaW"/>
<constraint firstItem="Oab-U6-xpF" firstAttribute="centerY" secondItem="S4r-K0-38K" secondAttribute="centerY" id="UnJ-FG-F23"/>
<constraint firstItem="2Ns-M7-OG1" firstAttribute="bottom" secondItem="S4r-K0-38K" secondAttribute="bottom" constant="-8" id="c9J-HY-QWj"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Alert Text" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="5" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2Ns-M7-OG1">
<rect key="frame" x="76" y="9" width="217" height="113"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</view>
</subviews>
</view>
<color key="backgroundColor" white="0.21742078993055555" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="Oab-U6-xpF" firstAttribute="centerY" secondItem="RlS-h3-WtZ" secondAttribute="centerY" id="0Gm-3d-NZV"/>
<constraint firstAttribute="bottom" secondItem="2Ns-M7-OG1" secondAttribute="bottom" constant="9" id="1LV-oj-Rfc"/>
<constraint firstItem="2Ns-M7-OG1" firstAttribute="centerY" secondItem="RlS-h3-WtZ" secondAttribute="centerY" id="3e1-Vz-z7i"/>
<constraint firstItem="Oab-U6-xpF" firstAttribute="leading" secondItem="RlS-h3-WtZ" secondAttribute="leading" constant="8" id="HjX-L1-EAY"/>
<constraint firstItem="2Ns-M7-OG1" firstAttribute="leading" secondItem="Oab-U6-xpF" secondAttribute="trailing" constant="4" id="OfY-Bd-5U7"/>
<constraint firstAttribute="trailing" secondItem="2Ns-M7-OG1" secondAttribute="trailing" constant="7" id="eSX-e8-2qc"/>
<constraint firstItem="2Ns-M7-OG1" firstAttribute="top" secondItem="RlS-h3-WtZ" secondAttribute="top" constant="9" id="xBI-iS-rEV"/>
<constraint firstItem="S4r-K0-38K" firstAttribute="centerX" secondItem="RlS-h3-WtZ" secondAttribute="centerX" id="DAa-g9-pyb"/>
<constraint firstItem="S4r-K0-38K" firstAttribute="centerY" secondItem="RlS-h3-WtZ" secondAttribute="centerY" id="P2z-Aq-USK"/>
<constraint firstItem="S4r-K0-38K" firstAttribute="width" secondItem="RlS-h3-WtZ" secondAttribute="width" id="RTU-nN-RCt"/>
<constraint firstItem="S4r-K0-38K" firstAttribute="top" secondItem="RlS-h3-WtZ" secondAttribute="top" constant="1" id="fH8-Io-0p4"/>
<constraint firstAttribute="bottom" secondItem="S4r-K0-38K" secondAttribute="bottom" constant="2" id="uWj-h9-AHl"/>
</constraints>
<connections>
<outlet property="containingView" destination="S4r-K0-38K" id="iLl-66-60S"/>
<outlet property="containingViewWidth" destination="RTU-nN-RCt" id="yqn-hj-ahE"/>
<outlet property="imageView" destination="Oab-U6-xpF" id="zUI-Ac-2nk"/>
<outlet property="messageLabel" destination="2Ns-M7-OG1" id="ubW-8f-ewB"/>
</connections>
......
......@@ -16,6 +16,8 @@ class Filters {
var showClosed = true
var sortBy = SortMethod.alphabetical
var openFirst = true
var showAlerts = ["info":true, "minor":true, "major":true]
var onlyFromLocations = [String: Bool]() // Locations to show, could simply use Location objects instead if you wanted
var onlyFromCategories = [String: Bool]() //same as above, but for Categories, not Locations
......
......@@ -19,7 +19,7 @@ class FacilitiesModel: Object {
}
class FacilitiesListViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UIViewControllerPreviewingDelegate {
class FacilitiesListViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UIViewControllerPreviewingDelegate, UICollectionViewDelegateFlowLayout {
let realm = try! Realm()
......@@ -55,6 +55,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
@IBOutlet var LocationsListLayout: UICollectionViewFlowLayout!
@IBOutlet var favoritesControl: UISegmentedControl!
var showFavorites = false
......@@ -96,10 +97,12 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
}
override func viewWillLayoutSubviews() {
LocationsListLayout.itemSize.width = getCellWidth()
//LocationsListLayout.itemSize.width = getCellWidth()
LocationsListLayout.invalidateLayout()
LocationsList.reloadData()
}
/*
func getCellWidth() -> CGFloat {
let windowWidth = self.view.frame.size.width
......@@ -115,6 +118,7 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
return 0
}
*/
@IBAction func RefreshButton(_ sender: Any) {
refresh(sender, forceUpdate: true)
......@@ -561,25 +565,68 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
else {
// Do Alerts things here
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Alert Cell", for: indexPath) as! AlertCollectionViewCell
cell.viewWidth = self.view.frame.width
switch currentAlerts[indexPath.row].urgency {
case "info":
cell.imageView.image = #imageLiteral(resourceName: "info")
cell.imageView.accessibilityLabel = "Info"
case "minor":
cell.imageView.image = #imageLiteral(resourceName: "minor")
cell.imageView.accessibilityLabel = "Minor Alert"
case "major":
cell.imageView.image = #imageLiteral(resourceName: "major")
cell.imageView.accessibilityLabel = "Major Alert"
case "emergency":
cell.imageView.image = #imageLiteral(resourceName: "emergency")
cell.imageView.accessibilityLabel = "Emergency Alert"
default:
cell.imageView.image = #imageLiteral(resourceName: "major")
cell.imageView.accessibilityLabel = "Alert"
}
cell.messageLabel.text = currentAlerts[indexPath.row].message
return cell
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if(indexPath.section == 1 || alertsList.count == 0) {
let height = LocationsListLayout.itemSize.height
let width: CGFloat
let windowWidth = self.view.frame.size.width
if(windowWidth < 640) {
width = windowWidth - 20
}
else if(windowWidth >= 640 && windowWidth < 1024) {
width = (windowWidth / 2) - 15
}
else if(windowWidth >= 1024) {
width = (windowWidth / 3) - 15
}
else {
width = windowWidth - 20
}
return CGSize(width: width, height: height)
}
else {
return CGSize(width: self.view.frame.size.width, height: LocationsListLayout.itemSize.height)
}
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
var sectionInsets = LocationsListLayout.sectionInset
if(section != 1 && alertsList.count != 0) {
sectionInsets.top = 0
}
return sectionInsets
}
//unused
......
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