Implemented functions for fetching and storing general information and the food menu, including UI for the food menu, TODO: resizing cells for the plan and food menu

This commit is contained in:
Deniz Duezgoeren
2019-07-13 09:48:20 +02:00
parent 92a01a83c7
commit 2f3ce29a4d
10 changed files with 520 additions and 43 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

+206 -19
View File
@@ -166,34 +166,144 @@
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Loaded by SecondViewController" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="NDk-cv-Gan">
<rect key="frame" x="99.666666666666686" y="477.66666666666669" width="215" height="17"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" misplaced="YES" text="Second View" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="zEq-FU-wV5">
<rect key="frame" x="-33" y="417" width="201.5" height="43"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="36"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="o8P-y4-8Is">
<rect key="frame" x="0.0" y="88" width="414" height="725"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="1" minimumInteritemSpacing="1" id="A6C-To-dsF">
<size key="itemSize" width="380" height="140"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" layoutMarginsFollowReadableWidth="YES" reuseIdentifier="cell" id="wDJ-H7-UTw" customClass="CollectionViewCell" customModule="AvH_Plan" customModuleProvider="target">
<rect key="frame" x="17" y="0.0" width="380" height="100"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO">
<rect key="frame" x="0.0" y="0.0" width="380" height="100"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="QWo-jL-Zoa">
<rect key="frame" x="12" y="4" width="356" height="92"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="8wB-59-rKw">
<rect key="frame" x="12" y="12" width="332" height="68"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="Tyb-ku-8cY">
<rect key="frame" x="0.0" y="0.0" width="332" height="20.333333333333332"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UpH-FU-des">
<rect key="frame" x="0.0" y="0.0" width="282.33333333333331" height="20.333333333333332"/>
<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" ambiguous="YES" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FOx-L6-Vkf">
<rect key="frame" x="290.33333333333331" y="0.0" width="41.666666666666686" height="20.333333333333332"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="eZN-T6-u2T">
<rect key="frame" x="0.0" y="28.333333333333336" width="332" height="20.333333333333336"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="I2T-ff-7vX">
<rect key="frame" x="0.0" y="0.0" width="41.666666666666664" height="20.333333333333332"/>
<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" ambiguous="YES" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="X2M-gp-JGL">
<rect key="frame" x="49.666666666666657" y="0.0" width="282.33333333333337" height="20.333333333333332"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<stackView opaque="NO" contentMode="scaleToFill" ambiguous="YES" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="Xl9-k6-4bf">
<rect key="frame" x="0.0" y="56.666666666666671" width="332" height="11.333333333333329"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0Xd-5X-OCi">
<rect key="frame" x="0.0" y="0.0" width="41.666666666666664" height="11.333333333333334"/>
<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" ambiguous="YES" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="n2h-fH-OLe">
<rect key="frame" x="49.666666666666657" y="0.0" width="282.33333333333337" height="11.333333333333334"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
</subviews>
</stackView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="8wB-59-rKw" secondAttribute="trailing" constant="12" id="5VU-QX-iX7"/>
<constraint firstAttribute="bottom" secondItem="8wB-59-rKw" secondAttribute="bottom" constant="12" id="TgW-Ta-0fg"/>
<constraint firstItem="8wB-59-rKw" firstAttribute="top" secondItem="QWo-jL-Zoa" secondAttribute="top" constant="12" id="fLq-Vs-f3Q"/>
<constraint firstItem="8wB-59-rKw" firstAttribute="leading" secondItem="QWo-jL-Zoa" secondAttribute="leading" constant="12" id="vSL-dI-fN1"/>
</constraints>
</view>
</subviews>
</view>
<constraints>
<constraint firstAttribute="bottom" secondItem="QWo-jL-Zoa" secondAttribute="bottom" constant="4" id="VeP-p7-VHS"/>
<constraint firstItem="QWo-jL-Zoa" firstAttribute="leading" secondItem="wDJ-H7-UTw" secondAttribute="leading" constant="12" id="Y66-G9-D7i"/>
<constraint firstAttribute="trailing" secondItem="QWo-jL-Zoa" secondAttribute="trailing" constant="12" id="cXg-tE-HH3"/>
<constraint firstItem="QWo-jL-Zoa" firstAttribute="top" secondItem="wDJ-H7-UTw" secondAttribute="top" constant="4" id="lGD-Ud-2wl"/>
</constraints>
<size key="customSize" width="380" height="100"/>
<connections>
<outlet property="additional" destination="0Xd-5X-OCi" id="zwQ-2f-uTT"/>
<outlet property="course" destination="I2T-ff-7vX" id="Ta3-Ju-3al"/>
<outlet property="date" destination="FOx-L6-Vkf" id="OYE-zY-5a0"/>
<outlet property="group" destination="UpH-FU-des" id="8Lz-X2-zbv"/>
<outlet property="room" destination="n2h-fH-OLe" id="ntU-iT-AHV"/>
<outlet property="time" destination="X2M-gp-JGL" id="F6J-Fe-WhS"/>
<outlet property="tintView" destination="QWo-jL-Zoa" id="gp0-x8-Cuu"/>
</connections>
</collectionViewCell>
</cells>
<connections>
<outlet property="dataSource" destination="8rJ-Kc-sve" id="uZJ-WZ-kcW"/>
<outlet property="delegate" destination="8rJ-Kc-sve" id="R8H-qW-bbB"/>
</connections>
</collectionView>
<navigationBar contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" layoutMarginsFollowReadableWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zYA-MY-Azp">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<viewLayoutGuide key="safeArea" id="Or0-Ph-ylC"/>
<items>
<navigationItem title="Personal Plan" id="8j4-CR-EDO"/>
</items>
</navigationBar>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="NDk-cv-Gan" firstAttribute="top" secondItem="zEq-FU-wV5" secondAttribute="bottom" constant="8" symbolic="YES" id="Day-4N-Vmt"/>
<constraint firstItem="NDk-cv-Gan" firstAttribute="centerX" secondItem="zEq-FU-wV5" secondAttribute="centerX" id="JgO-Fn-dHn"/>
<constraint firstAttribute="centerX" secondItem="zEq-FU-wV5" secondAttribute="centerX" id="qqM-NS-xev"/>
<constraint firstAttribute="centerY" secondItem="zEq-FU-wV5" secondAttribute="centerY" id="qzY-Ky-pLD"/>
<constraint firstItem="o8P-y4-8Is" firstAttribute="leading" secondItem="O1u-W8-tvY" secondAttribute="leading" id="6CV-3q-qko"/>
<constraint firstItem="zYA-MY-Azp" firstAttribute="trailing" secondItem="O1u-W8-tvY" secondAttribute="trailing" id="AhQ-VX-SQ8"/>
<constraint firstItem="O1u-W8-tvY" firstAttribute="bottom" secondItem="o8P-y4-8Is" secondAttribute="bottom" id="Cnb-HM-WIg"/>
<constraint firstItem="o8P-y4-8Is" firstAttribute="trailing" secondItem="O1u-W8-tvY" secondAttribute="trailing" id="PQh-Z4-g23"/>
<constraint firstItem="o8P-y4-8Is" firstAttribute="top" secondItem="zYA-MY-Azp" secondAttribute="bottom" id="Z88-qD-HMv"/>
<constraint firstItem="zYA-MY-Azp" firstAttribute="top" secondItem="O1u-W8-tvY" secondAttribute="top" id="h9U-jR-HuZ"/>
<constraint firstItem="zYA-MY-Azp" firstAttribute="leading" secondItem="O1u-W8-tvY" secondAttribute="leading" id="odb-l1-x2e"/>
</constraints>
<viewLayoutGuide key="safeArea" id="O1u-W8-tvY"/>
</view>
<tabBarItem key="tabBarItem" title="Personal" image="ic_idea" selectedImage="ic_idea" id="cPa-gy-q4n"/>
<connections>
<outlet property="collectionView" destination="o8P-y4-8Is" id="1GW-Wu-fUg"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4Nw-L8-lE0" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1491" y="-321"/>
<point key="canvasLocation" x="1489.8550724637682" y="-321.42857142857139"/>
</scene>
<!--Information-->
<scene sceneID="tt5-VM-aeV">
@@ -202,7 +312,21 @@
<view key="view" contentMode="scaleToFill" id="eFO-Bf-72I">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<navigationBar contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" layoutMarginsFollowReadableWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="n9O-m5-UQM">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<viewLayoutGuide key="safeArea" id="YA8-Ln-bdM"/>
<items>
<navigationItem title="Information" id="9lv-eD-jS6"/>
</items>
</navigationBar>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="n9O-m5-UQM" firstAttribute="leading" secondItem="eFO-Bf-72I" secondAttribute="leading" id="1Wa-Qr-Bhb"/>
<constraint firstItem="fuI-1W-d0u" firstAttribute="trailing" secondItem="n9O-m5-UQM" secondAttribute="trailing" id="Itb-7h-ird"/>
<constraint firstItem="n9O-m5-UQM" firstAttribute="top" secondItem="fuI-1W-d0u" secondAttribute="top" id="ccZ-hZ-aNP"/>
</constraints>
<viewLayoutGuide key="safeArea" id="fuI-1W-d0u"/>
</view>
<tabBarItem key="tabBarItem" title="Information" image="ic_information" selectedImage="ic_information" id="BQ7-VO-yI4"/>
@@ -218,14 +342,77 @@
<view key="view" contentMode="scaleToFill" id="nOs-f2-7qu">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<navigationBar contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" layoutMarginsFollowReadableWidth="YES" translatesAutoresizingMaskIntoConstraints="NO" id="R10-r1-giF">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<viewLayoutGuide key="safeArea" id="zEW-od-JDN"/>
<items>
<navigationItem title="Food Menu" id="mFX-6q-tAs"/>
</items>
</navigationBar>
<collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="GXo-AH-UZe">
<rect key="frame" x="0.0" y="88" width="414" height="725"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="1" minimumInteritemSpacing="1" id="7xu-lu-j4n">
<size key="itemSize" width="380" height="140"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" layoutMarginsFollowReadableWidth="YES" reuseIdentifier="cell" id="GNK-S9-s6Y" customClass="MenuViewCell" customModule="AvH_Plan" customModuleProvider="target">
<rect key="frame" x="17" y="0.0" width="380" height="100"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO">
<rect key="frame" x="0.0" y="0.0" width="380" height="100"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FiL-oG-5NS">
<rect key="frame" x="24" y="4" width="332" height="92"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</view>
<constraints>
<constraint firstAttribute="bottom" secondItem="FiL-oG-5NS" secondAttribute="bottom" constant="4" id="Luj-VM-NXr"/>
<constraint firstAttribute="trailing" secondItem="FiL-oG-5NS" secondAttribute="trailing" constant="24" id="MRl-Fb-lcN"/>
<constraint firstItem="FiL-oG-5NS" firstAttribute="top" secondItem="GNK-S9-s6Y" secondAttribute="top" constant="4" id="tSv-yf-nyx"/>
<constraint firstItem="FiL-oG-5NS" firstAttribute="leading" secondItem="GNK-S9-s6Y" secondAttribute="leading" constant="24" id="uoj-TR-t8r"/>
</constraints>
<size key="customSize" width="380" height="100"/>
<connections>
<outlet property="content" destination="FiL-oG-5NS" id="9CZ-mR-oqN"/>
</connections>
</collectionViewCell>
</cells>
<connections>
<outlet property="dataSource" destination="bBH-of-tdd" id="hWU-Ox-LbT"/>
<outlet property="delegate" destination="bBH-of-tdd" id="Goe-Im-LUU"/>
</connections>
</collectionView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="2XG-5F-awv" firstAttribute="trailing" secondItem="R10-r1-giF" secondAttribute="trailing" id="2ph-BT-xaa"/>
<constraint firstItem="GXo-AH-UZe" firstAttribute="top" secondItem="R10-r1-giF" secondAttribute="bottom" id="LJZ-CD-zAQ"/>
<constraint firstItem="R10-r1-giF" firstAttribute="top" secondItem="2XG-5F-awv" secondAttribute="top" id="MXM-m5-w5i"/>
<constraint firstItem="GXo-AH-UZe" firstAttribute="leading" secondItem="nOs-f2-7qu" secondAttribute="leading" id="MZD-gw-lhn"/>
<constraint firstItem="2XG-5F-awv" firstAttribute="trailing" secondItem="GXo-AH-UZe" secondAttribute="trailing" id="gFX-sE-QMR"/>
<constraint firstItem="R10-r1-giF" firstAttribute="leading" secondItem="nOs-f2-7qu" secondAttribute="leading" id="hI9-lC-axL"/>
<constraint firstItem="2XG-5F-awv" firstAttribute="bottom" secondItem="GXo-AH-UZe" secondAttribute="bottom" id="zs4-d5-ZjJ"/>
</constraints>
<viewLayoutGuide key="safeArea" id="2XG-5F-awv"/>
</view>
<tabBarItem key="tabBarItem" title="Menu" image="ic_tomato" selectedImage="ic_tomato" id="IfX-2p-YWq"/>
<connections>
<outlet property="collectionView" destination="GXo-AH-UZe" id="S49-xr-MOj"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="8Cd-nN-1G8" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1486" y="347"/>
<point key="canvasLocation" x="1485.5072463768117" y="346.875"/>
</scene>
<!--AvH Plan-->
<scene sceneID="yl2-sM-qoP">
+172 -9
View File
@@ -7,15 +7,19 @@
//
import UIKit
import Foundation
import Alamofire
import SwiftSoup
import SQLite
class DataFetcher {
let path = Bundle.main.path(forResource: "db", ofType: "sqlite3")
let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
let substitutions = Table("substitutions")
let personal = Table("personal")
let information = Table("information")
let foodmenu = Table("foodmenu")
let id = Expression<Int64>("id")
let group = Expression<String>("group")
let course = Expression<String>("course")
@@ -23,28 +27,46 @@ class DataFetcher {
let date = Expression<String>("date")
let time = Expression<String>("time")
let room = Expression<String>("room")
let text = Expression<String>("text")
func doAsync(completionHandler: @escaping (_ substitutions: Array<SubstModel>) -> ()) {
func doAsync(do task: String, completionHandler: @escaping (_ substitutions: Array<Any>) -> ()) {
DispatchQueue(label: "work-queue").async {
let url = "https://djd4rkn355.github.io/subst_test.html"
var url = ""
switch task {
case "menu": url = "https://djd4rkn355.github.io/food_test.html"
default: url = "https://djd4rkn355.github.io/subst_test.html"
}
Alamofire.request(url).responseString { response in
if let html = response.result.value {
completionHandler(self.parseHTML(html: html))
switch task {
case "plan": completionHandler(self.parseHTML(html: html, isPersonal: false))
case "personal": completionHandler(self.parseHTML(html: html, isPersonal: true))
case "info": completionHandler(self.parseInformation(html: html))
default: completionHandler(self.parseMenu(html: html))
}
}
}
}
}
func parseHTML(html: String) -> Array<SubstModel> {
func parseHTML(html: String, isPersonal: Bool) -> Array<SubstModel> {
var subst = Array<SubstModel>()
var personalSubst = Array<SubstModel>()
do {
let doc: Document = try SwiftSoup.parse(html)
let rows: Elements = try doc.select("tr")
let db = try Connection(path!)
// let prefs = UserDefaults.standard
// let courses = prefs.string(forKey: "courses")
// let classes = prefs.string(forKey: "classes")
let courses: String? = "GES7"
let classes: String? = "17"
try db.run(substitutions.create { t in
let db = try Connection("\(path)/db.sqlite3")
try db.run(substitutions.create(ifNotExists: true) { t in
t.column(id, primaryKey: true)
t.column(group)
t.column(course)
@@ -54,6 +76,19 @@ class DataFetcher {
t.column(room)
})
try db.run(personal.create(ifNotExists: true) { t in
t.column(id, primaryKey: true)
t.column(group)
t.column(course)
t.column(additional)
t.column(date)
t.column(time)
t.column(room)
})
try db.run(substitutions.delete())
try db.run(personal.delete())
for i in (0..<rows.size()) {
let row = rows.get(i)
let cols = try row.select("th")
@@ -70,6 +105,33 @@ class DataFetcher {
let insert = substitutions.insert(group <- mGroup, course <- mCourse, additional <- mAdditional,
date <- mDate, time <- mTime, room <- mRoom)
_ = try db.run(insert)
if courses == nil || courses == "", classes != nil && classes != "" {
if !mGroup.isEmpty && mGroup != "" {
if classes!.contains(mGroup) || mGroup.contains(classes!) {
personalSubst.append(SubstModel(group: mGroup, course: mCourse, additional: mAdditional,
date: mDate, time: mTime, room: mRoom))
let insertPersonal = personal.insert(group <- mGroup, course <- mCourse, additional <- mAdditional,
date <- mDate, time <- mTime, room <- mRoom)
_ = try db.run(insertPersonal)
}
}
} else if courses != nil && courses != "" && classes != nil && classes != "" {
if mGroup != "" && mCourse != "" {
if courses!.contains(mCourse) {
if classes!.contains(mGroup) || mGroup.contains(classes!) {
personalSubst.append(SubstModel(group: mGroup, course: mCourse, additional: mAdditional,
date: mDate, time: mTime, room: mRoom))
let insertPersonal = personal.insert(group <- mGroup, course <- mCourse, additional <- mAdditional,
date <- mDate, time <- mTime, room <- mRoom)
_ = try db.run(insertPersonal)
}
}
}
}
}
} catch Exception.Error(let type, let message) {
@@ -78,13 +140,17 @@ class DataFetcher {
} catch {
print("error")
}
return subst
if isPersonal {
return personalSubst
} else {
return subst
}
}
func getFromDatabase() -> [SubstModel] {
var substs = [SubstModel]()
do {
let db = try Connection(path!)
let db = try Connection("\(path)/db.sqlite3")
for subst in try db.prepare(substitutions) {
substs.append(SubstModel(group: subst[group], course: subst[course], additional: subst[additional], date: subst[date], time: subst[time], room: subst[room]))
}
@@ -92,6 +158,103 @@ class DataFetcher {
return substs
}
func getPersonalFromDatabase() -> [SubstModel] {
var substs = [SubstModel]()
do {
let db = try Connection("\(path)/db.sqlite3")
for subst in try db.prepare(personal) {
substs.append(SubstModel(group: subst[group], course: subst[course], additional: subst[additional], date: subst[date], time: subst[time], room: subst[room]))
}
} catch {}
return substs
}
func parseInformation(html: String) -> [String] {
var list = [String]()
do {
let doc: Document = try SwiftSoup.parse(html)
let p: Elements = try doc.select("p")
let db = try Connection("\(path)/db.sqlite3")
try db.run(information.create(ifNotExists: true) { t in
t.column(id, primaryKey: true)
t.column(text)
})
try db.run(information.delete())
for item in p {
let t = try item.text()
list.append(t)
let insert = information.insert(text <- t)
_ = try db.run(insert)
}
} catch Exception.Error(let type, let message) {
print(type)
print(message)
} catch {
print("error")
}
return list
}
func readInformation() -> [String] {
var list = [String]()
do {
let db = try Connection("\(path)/db.sqlite3")
for item in try db.prepare(information) {
list.append(item[text])
}
} catch {}
return list
}
func parseMenu(html: String) -> [String] {
var items = [String]()
do {
let doc: Document = try SwiftSoup.parse(html)
let e: Elements = try doc.select("th")
let db = try Connection("\(path)/db.sqlite3")
try db.run(foodmenu.create(ifNotExists: true) { t in
t.column(id, primaryKey: true)
t.column(text)
})
try db.run(foodmenu.delete())
for i in 0..<e.size() {
items.append(try e.get(i).text())
let insert = foodmenu.insert(text <- try e.get(i).text())
_ = try db.run(insert)
}
} catch {}
return items
}
func readMenu() -> [String] {
var menu = [String]()
do {
let db = try Connection("\(path)/db.sqlite3")
for item in try db.prepare(foodmenu) {
menu.append(item[text])
}
} catch {}
return menu
}
func getImage(from icon: String) -> UIImage? {
var imagePath = ""
let i = icon.lowercased()
+58 -2
View File
@@ -2,12 +2,68 @@
// MenuViewController.swift
// AvH Plan
//
// Created by Deniz Duezgoeren on 10.07.19.
// Created by Deniz Duezgoeren on 11.07.19.
// Copyright © 2019 Deniz Duezgoeren. All rights reserved.
//
import UIKit
class MenuViewController : UIViewController {
class MenuViewController : UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
let reuseIdentifier = "cell"
@IBOutlet weak var collectionView: UICollectionView!
var items = [String]()
private let refreshControl = UIRefreshControl()
let df = DataFetcher()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 10.0, *) {
collectionView.refreshControl = refreshControl
} else {
collectionView.addSubview(refreshControl)
}
refreshControl.addTarget(self, action: #selector(objDoAsync(_:)), for: .valueChanged)
refreshControl.tintColor = UIColor(red: 0.39, green: 0.71, blue: 0.96, alpha: 1.0)
refreshControl.attributedTitle = NSAttributedString(string: "Fetching the food menu...")
}
@objc private func objDoAsync(_ sender: Any) {
df.doAsync(do: "menu") { menuItems in
self.items = menuItems as! [String]
self.collectionView.reloadData()
self.refreshControl.endRefreshing()
}
}
override func viewDidLoad() {
super.viewDidLoad()
collectionView.backgroundColor = UIColor(red: 0.8, green: 0.8, blue: 0.8, alpha: 1.0)
self.items = self.df.readMenu()
self.collectionView.reloadData()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.items.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MenuViewCell
if self.items.count != 0 {
cell.content.text = self.items[indexPath.item]
}
cell.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("You selected cell#\(indexPath.item)!")
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.size.width, height: 64)
}
}
+78 -7
View File
@@ -1,20 +1,91 @@
//
// SecondViewController.swift
// PersonalViewController.swift
// AvH Plan
//
// Created by Deniz Duezgoeren on 25.05.19.
// Created by Deniz Duezgoeren on 11.07.19.
// Copyright © 2019 Deniz Duezgoeren. All rights reserved.
//
import UIKit
class PersonalViewController: UIViewController {
class PersonalViewController : UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
let reuseIdentifier = "cell"
@IBOutlet weak var collectionView: UICollectionView!
var substs = Array<SubstModel>()
private let refreshControl = UIRefreshControl()
let df = DataFetcher()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if #available(iOS 10.0, *) {
collectionView.refreshControl = refreshControl
} else {
collectionView.addSubview(refreshControl)
}
refreshControl.addTarget(self, action: #selector(objDoAsync(_:)), for: .valueChanged)
refreshControl.tintColor = UIColor(red: 0.39, green: 0.71, blue: 0.96, alpha: 1.0)
refreshControl.attributedTitle = NSAttributedString(string: "Fetching your plan...")
}
@objc private func objDoAsync(_ sender: Any) {
df.doAsync(do: "personal") { substitutions in
self.substs = substitutions as! [SubstModel]
self.collectionView.reloadData()
self.refreshControl.endRefreshing()
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
collectionView.backgroundColor = UIColor(red: 0.8, green: 0.8, blue: 0.8, alpha: 1.0)
self.substs = self.df.getPersonalFromDatabase()
self.collectionView.reloadData()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.substs.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! CollectionViewCell
if self.substs.count != 0 {
cell.group.text = self.substs[indexPath.item].group
cell.additional.text = self.substs[indexPath.item].additional
cell.date.text = self.substs[indexPath.item].date
cell.time.text = self.substs[indexPath.item].time
cell.room.text = self.substs[indexPath.item].room
let course = self.substs[indexPath.item].course
let image = df.getImage(from: course)
if image != nil {
let attachment: NSTextAttachment = NSTextAttachment()
attachment.bounds = CGRect(x: 0, y: 0, width: cell.course.frame.height - 6, height: cell.course.frame.height - 6)
attachment.image = image
let courseImage = NSMutableAttributedString(attachment: attachment)
let courseString = NSAttributedString(string: " " + course)
courseImage.append(courseString)
cell.course.attributedText = courseImage
} else {
cell.course.text = course
}
}
cell.backgroundColor = UIColor(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
cell.tintView.backgroundColor = cell.backgroundColor
return cell
}
// func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// print("You selected cell#\(indexPath.item)!")
// }
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.size.width, height: 108)
}
}
+2 -2
View File
@@ -29,8 +29,8 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
}
@objc private func objDoAsync(_ sender: Any) {
df.doAsync() { substitutions in
self.substs = substitutions
df.doAsync(do: "plan") { substitutions in
self.substs = substitutions as! [SubstModel]
self.collectionView.reloadData()
self.refreshControl.endRefreshing()
}