Commit 2f76e7c0 authored by Chris Morris's avatar Chris Morris
Browse files

Can now add items to list

Much is left to be implemented, but title and enabled fields are functional
parent 29d1b9f4
Loading
Loading
Loading
Loading
+77 −11
Original line number Diff line number Diff line
@@ -10,31 +10,99 @@
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <scenes>
        <!--View Controller-->
        <!--Add Switch View Controller-->
        <scene sceneID="CwW-Ek-h6D">
            <objects>
                <viewController storyboardIdentifier="SecondViewController" id="suB-40-Rzp" sceneMemberID="viewController">
                <viewController storyboardIdentifier="SecondViewController" id="suB-40-Rzp" customClass="AddSwitchViewController" customModule="GuardianAngelSwift" customModuleProvider="target" sceneMemberID="viewController">
                    <view key="view" contentMode="scaleToFill" id="qGh-cw-gJx">
                        <rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <subviews>
                            <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="WOp-fh-5fi">
                                <rect key="frame" x="16" y="44" width="100" height="30"/>
                                <rect key="frame" x="16" y="44" width="111" height="33"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <state key="normal" title="Back to View 1"/>
                                <connections>
                                    <segue destination="B4C-07-lOU" kind="show" animates="NO" id="vro-Fz-32w"/>
                                </connections>
                            </button>
                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Title:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="JMK-i4-JTs">
                                <rect key="frame" x="16" y="85" width="38" height="21"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <nil key="textColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Deadline:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ClX-TZ-Ugo">
                                <rect key="frame" x="16" y="167" width="72" height="21"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <nil key="textColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Enable it now?" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="NSo-dU-3EQ">
                                <rect key="frame" x="16" y="366" width="110" height="21"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <nil key="textColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Actions:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Gjl-xI-mOB">
                                <rect key="frame" x="16" y="477" width="62" height="21"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <nil key="textColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <textField opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Sample title" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="gkG-Ut-E88">
                                <rect key="frame" x="182" y="80" width="177" height="30"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <nil key="textColor"/>
                                <fontDescription key="fontDescription" type="system" pointSize="16"/>
                                <textInputTraits key="textInputTraits"/>
                            </textField>
                            <datePicker contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" datePickerMode="dateAndTime" minuteInterval="1" translatesAutoresizingMaskIntoConstraints="NO" id="VVU-cu-c0O">
                                <rect key="frame" x="0.0" y="196" width="375" height="162"/>
                                <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
                                <date key="date" timeIntervalSinceReferenceDate="546236376.03419995">
                                    <!--2018-04-24 04:19:36 +0000-->
                                </date>
                            </datePicker>
                            <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="496-iI-yQ6">
                                <rect key="frame" x="310" y="361" width="49" height="31"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                            </switch>
                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="To Be Added" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="oc2-sO-nxG">
                                <rect key="frame" x="261" y="477" width="98" height="21"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <nil key="textColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="bo5-ZK-fG9">
                                <rect key="frame" x="136" y="589" width="103" height="35"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <fontDescription key="fontDescription" type="system" pointSize="19"/>
                                <state key="normal" title="Add"/>
                                <connections>
                                    <action selector="addNewSwitchToArray:" destination="suB-40-Rzp" eventType="touchUpInside" id="jid-bh-6Mg"/>
                                </connections>
                            </button>
                        </subviews>
                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                        <viewLayoutGuide key="safeArea" id="zZX-KZ-FIN"/>
                    </view>
                    <navigationItem key="navigationItem" id="Wak-aw-9XW"/>
                    <connections>
                        <outlet property="deadline" destination="VVU-cu-c0O" id="VlM-Jt-IXa"/>
                        <outlet property="enabled" destination="496-iI-yQ6" id="QMH-Ap-cpz"/>
                        <outlet property="titleText" destination="gkG-Ut-E88" id="kct-Tg-wU3"/>
                    </connections>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="zO0-4x-Qjk" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="1298" y="117"/>
            <point key="canvasLocation" x="1296.8" y="116.74876847290641"/>
        </scene>
        <!--View Controller-->
        <scene sceneID="xj3-JM-aFc">
@@ -44,12 +112,6 @@
                        <rect key="frame" x="0.0" y="0.0" width="375" height="812"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <subviews>
                            <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="DRt-g0-gx3">
                                <rect key="frame" x="16" y="44" width="53" height="33"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                <state key="normal" title="Edit"/>
                            </button>
                            <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="MuP-GB-BNk">
                                <rect key="frame" x="306" y="44" width="53" height="33"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
@@ -103,6 +165,10 @@
                                        </connections>
                                    </tableViewCell>
                                </prototypes>
                                <connections>
                                    <outlet property="dataSource" destination="B4C-07-lOU" id="txU-bQ-mfV"/>
                                    <outlet property="delegate" destination="B4C-07-lOU" id="xHb-QV-Cqt"/>
                                </connections>
                            </tableView>
                        </subviews>
                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
@@ -114,7 +180,7 @@
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="Uua-C7-TzK" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="254" y="117"/>
            <point key="canvasLocation" x="-226" y="123"/>
        </scene>
    </scenes>
</document>
+44 −0
Original line number Diff line number Diff line
//
//  AddSwitchViewController.swift
//  GuardianAngelSwift
//
//  Created by Chris Shula on 4/24/18.
//  Copyright © 2018 Chris Morris. All rights reserved.
//

import UIKit

class AddSwitchViewController: UIViewController {
    @IBOutlet weak var titleText: UITextField!
    @IBOutlet weak var deadline: UIDatePicker!
    @IBOutlet weak var enabled: UISwitch!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.hideKeyboardWhenTappedAround()
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    @IBAction func addNewSwitchToArray(_ sender: Any) {
        var addThis = DeadManSwitch(title: titleText.text!, time:"implement this", enabled: enabled.isOn)
        var vc = ViewController()
        vc.addSwitch(add: addThis)
        vc.show(self, sender: Any?.self)
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
+106 −0
Original line number Diff line number Diff line
@@ -10,22 +10,23 @@ import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    @IBOutlet weak var DMSEntries: DMSEntryListView! //our list of switches as represented in the view
    
    var switches: [DMSEntry] = [] //our switches!
    static var switches: [DeadManSwitch] = [] //our switches!
    static var samplesLoadedAlready = false
    
    
    //below functions are to conform tu UITableView[...] standards
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return switches.count
        return ViewController.switches.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        //load ONE sample entry -- this one will be a blank when all properties are commented out
        //load all the sample entries in the array
        let cell = DMSEntries.dequeueReusableCell(withIdentifier: "DMSEntryCell") as! DMSEntry
        //cell.titleLabel.text = "Sample!"
        //cell.dateTimeLabel.text = "Sample time"
        //cell.enabledSwitch.isOn = true
        //cell.selectionStyle = .none
        
        cell.titleLabel.text = ViewController.switches[indexPath.item].title
        cell.dateTimeLabel.text = ViewController.switches[indexPath.item].time
        cell.enabledSwitch.isOn = ViewController.switches[indexPath.item].enabled
        cell.selectionStyle = .none
        return cell
 
    }
@@ -35,43 +36,70 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
        
        // Do any additional setup after loading the view, typically from a nib.
        //lets this view controller behave as a table view delegate & data source
        DMSEntries.delegate = self
        DMSEntries.dataSource = self
        DMSEntries?.delegate = self
        DMSEntries?.dataSource = self
        
        super.viewDidLoad()
        //DMSEntries.tableFooterView = UIView(frame: CGRect.zero)
    }
    
    override func viewDidAppear(_ animated: Bool) { //occurs when the first view appears
        loadSampleEntries()
        self.hideKeyboardWhenTappedAround()
    }
/* retired when UITableView[...] implemented
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        DMSEntries.reloadData()
    }
    */
    
    func OKAlert(title: String?, message: String?)
    func OKAlert(title: String?, message: String?) //this is nice becuase it lets us add an alert if necessary
    {
        let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: "Default action"), style: .default, handler: { _ in
        alert.addAction(UIAlertAction(title: NSLocalizedString("What?", comment: "Default action"), style: .default, handler: { _ in
            NSLog("The \"OK\" alert occured.")
        }))
        self.present(alert, animated: true, completion: nil)
    }
    
    private func loadSampleEntries() {
        let itemToBeAddedToList: DMSEntry = DMSEntry()
        itemToBeAddedToList.titleLabel.text = "You just added me by method!"
        itemToBeAddedToList.dateTimeLabel.text = "Wow!"
        itemToBeAddedToList.enabledSwitch.isOn = false
        switches.append(itemToBeAddedToList)
        if ViewController.samplesLoadedAlready == false
        {
            ViewController.samplesLoadedAlready = true
            var s = DeadManSwitch(title: "Sample 1", time: "now", enabled: false)
            ViewController.switches.append(s)
            s = DeadManSwitch(title: "You're doing it!", time: "wow!!!", enabled: true)
            ViewController.switches.append(s)
            
        }
    }
    
    public func addSwitch(add: DeadManSwitch)
    {
        ViewController.switches.append(add)
        //update the table data
        //DMSEntries.insertRows(at: [IndexPath(row: switches.count-1, section: 0)], with: .automatic)
        /*
         DMSEntries.beginUpdates()
        let indexPath = IndexPath(row: switches.count - 1, section: 0)
        DMSEntries.insertRows(at: [indexPath], with: .automatic)
        DMSEntries.insertRows(at: [IndexPath(row: switches.count - 1, section: 0)], with: .automatic)
        DMSEntries.endUpdates()
        */
        //end add update
        for i in 0..<ViewController.switches.count //debug output
        {
            NSLog(ViewController.switches[i].title)
        }
    }
}

//code below will handle dismissing keyboard when tapped anywhere on view: can be used on any view whatsoever
// Put this piece of code anywhere you like
extension UIViewController {
    func hideKeyboardWhenTappedAround() {
        let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard))
        tap.cancelsTouchesInView = false
        view.addGestureRecognizer(tap)
    }
    
    @objc func dismissKeyboard() {
        view.endEditing(true)
    }
}

+3 −3
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ import UIKit
class DMSEntry: UITableViewCell {
    
    //MARK: Properties
    @IBOutlet weak var titleLabel: UILabel! = UILabel()
    @IBOutlet weak var dateTimeLabel: UILabel! = UILabel()
    @IBOutlet weak var enabledSwitch: UISwitch! = UISwitch()
    @IBOutlet public weak var titleLabel: UILabel! = UILabel()
    @IBOutlet public weak var dateTimeLabel: UILabel! = UILabel()
    @IBOutlet public weak var enabledSwitch: UISwitch! = UISwitch()
}