Added PSA feature

This commit is contained in:
Deniz Duezgoeren
2019-08-07 10:16:47 +02:00
parent 35f27049b9
commit dd5458bc1b
3 changed files with 56 additions and 13 deletions
+8 -3
View File
@@ -35,7 +35,7 @@ class DataFetcher {
func doAsync(do task: String, completionHandler: @escaping (_ substitutions: [Any]) -> ()) { func doAsync(do task: String, completionHandler: @escaping (_ substitutions: [Any]) -> ()) {
DispatchQueue(label: "work-queue").async { DispatchQueue(label: "work-queue").async {
let foodUrl = "https://djd4rkn355.github.io/food.html" let foodUrl = "https://djd4rkn355.github.io/food.html"
let url = "https://djd4rkn355.github.io/subst_test.html" let url = "https://djd4rkn355.github.io/subst.html"
Alamofire.request(url).responseString { response in Alamofire.request(url).responseString { response in
if let html = response.result.value { if let html = response.result.value {
Alamofire.request(foodUrl).responseString { response in Alamofire.request(foodUrl).responseString { response in
@@ -104,8 +104,13 @@ class DataFetcher {
let insert = substitutions.insert(group <- mGroup, course <- mCourse, additional <- mAdditional, let insert = substitutions.insert(group <- mGroup, course <- mCourse, additional <- mAdditional,
date <- mDate, time <- mTime, room <- mRoom) date <- mDate, time <- mTime, room <- mRoom)
_ = try db.run(insert) _ = try db.run(insert)
if mDate.count > 2 && mDate[...mDate.index(mDate.startIndex, offsetBy: 2)] == "psa" {
if courses == nil || courses == "", classes != nil && 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.isEmpty && mGroup != "" { if !mGroup.isEmpty && mGroup != "" {
if classes!.contains(mGroup) || mGroup.contains(classes!) { if classes!.contains(mGroup) || mGroup.contains(classes!) {
personalSubst.append(SubstModel(group: mGroup, course: mCourse, additional: mAdditional, personalSubst.append(SubstModel(group: mGroup, course: mCourse, additional: mAdditional,
+11 -5
View File
@@ -23,7 +23,7 @@
<rect key="frame" x="0.0" y="0.0" width="512" height="108"/> <rect key="frame" x="0.0" y="0.0" width="512" height="108"/>
<subviews> <subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalCompressionResistancePriority="749" verticalCompressionResistancePriority="749" text="Label" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kVO-L1-w44"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalCompressionResistancePriority="749" verticalCompressionResistancePriority="749" text="Label" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kVO-L1-w44">
<rect key="frame" x="24" y="16" width="414" height="20"/> <rect key="frame" x="24" y="16" width="414" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
@@ -35,25 +35,25 @@
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vzu-WZ-FPo"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vzu-WZ-FPo">
<rect key="frame" x="24" y="44" width="42" height="21"/> <rect key="frame" x="24" y="44.5" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="z2B-fh-0m1"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="z2B-fh-0m1">
<rect key="frame" x="446" y="44" width="42" height="21"/> <rect key="frame" x="446" y="44.5" width="42" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalCompressionResistancePriority="749" verticalCompressionResistancePriority="749" ambiguous="YES" text="Label" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="F6T-RY-ZUE"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalCompressionResistancePriority="749" verticalCompressionResistancePriority="749" ambiguous="YES" text="Label" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="F6T-RY-ZUE">
<rect key="frame" x="24" y="73" width="414" height="19"/> <rect key="frame" x="24" y="73.5" width="414" height="18.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalCompressionResistancePriority="749" verticalCompressionResistancePriority="749" ambiguous="YES" text="Label" textAlignment="right" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Jed-sH-OKY"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalCompressionResistancePriority="749" verticalCompressionResistancePriority="749" ambiguous="YES" text="Label" textAlignment="right" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Jed-sH-OKY">
<rect key="frame" x="446" y="73" width="42" height="19"/> <rect key="frame" x="446" y="73.5" width="42" height="18.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
@@ -80,6 +80,7 @@
<constraint firstAttribute="bottom" secondItem="Jed-sH-OKY" secondAttribute="bottom" constant="16" id="di9-dn-Wfv"/> <constraint firstAttribute="bottom" secondItem="Jed-sH-OKY" secondAttribute="bottom" constant="16" id="di9-dn-Wfv"/>
<constraint firstItem="vzu-WZ-FPo" firstAttribute="top" secondItem="kVO-L1-w44" secondAttribute="bottom" constant="8" id="fYW-HW-mSP"/> <constraint firstItem="vzu-WZ-FPo" firstAttribute="top" secondItem="kVO-L1-w44" secondAttribute="bottom" constant="8" id="fYW-HW-mSP"/>
<constraint firstAttribute="bottom" secondItem="BNy-Bm-Hfo" secondAttribute="bottom" id="gZx-dG-A7M"/> <constraint firstAttribute="bottom" secondItem="BNy-Bm-Hfo" secondAttribute="bottom" id="gZx-dG-A7M"/>
<constraint firstItem="z2B-fh-0m1" firstAttribute="top" secondItem="47e-N3-adl" secondAttribute="bottom" constant="8" id="jFp-hu-mld"/>
<constraint firstItem="BNy-Bm-Hfo" firstAttribute="leading" secondItem="Ay1-0Z-yKh" secondAttribute="leading" id="jLw-TQ-vvC"/> <constraint firstItem="BNy-Bm-Hfo" firstAttribute="leading" secondItem="Ay1-0Z-yKh" secondAttribute="leading" id="jLw-TQ-vvC"/>
<constraint firstItem="Jed-sH-OKY" firstAttribute="top" secondItem="vzu-WZ-FPo" secondAttribute="bottom" constant="8" id="kKA-h5-ADN"/> <constraint firstItem="Jed-sH-OKY" firstAttribute="top" secondItem="vzu-WZ-FPo" secondAttribute="bottom" constant="8" id="kKA-h5-ADN"/>
<constraint firstItem="vzu-WZ-FPo" firstAttribute="top" relation="greaterThanOrEqual" secondItem="Ay1-0Z-yKh" secondAttribute="top" constant="44" id="mZr-e4-cwy"/> <constraint firstItem="vzu-WZ-FPo" firstAttribute="top" relation="greaterThanOrEqual" secondItem="Ay1-0Z-yKh" secondAttribute="top" constant="44" id="mZr-e4-cwy"/>
@@ -89,6 +90,11 @@
<constraint firstItem="kVO-L1-w44" firstAttribute="top" secondItem="Ay1-0Z-yKh" secondAttribute="top" constant="16" id="vic-2C-ffY"/> <constraint firstItem="kVO-L1-w44" firstAttribute="top" secondItem="Ay1-0Z-yKh" secondAttribute="top" constant="16" id="vic-2C-ffY"/>
<constraint firstItem="BNy-Bm-Hfo" firstAttribute="top" secondItem="F6T-RY-ZUE" secondAttribute="bottom" constant="15" id="yXT-rV-p1f"/> <constraint firstItem="BNy-Bm-Hfo" firstAttribute="top" secondItem="F6T-RY-ZUE" secondAttribute="bottom" constant="15" id="yXT-rV-p1f"/>
</constraints> </constraints>
<variation key="default">
<mask key="constraints">
<exclude reference="mZr-e4-cwy"/>
</mask>
</variation>
</view> </view>
</subviews> </subviews>
</view> </view>
+36 -4
View File
@@ -17,6 +17,8 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
let df = DataFetcher.sharedInstance let df = DataFetcher.sharedInstance
let layout = MagazineLayout() let layout = MagazineLayout()
var collectionView: UICollectionView var collectionView: UICollectionView
var url = ""
var indexOfPSA: Int? = nil
required init?(coder decoder: NSCoder) { required init?(coder decoder: NSCoder) {
collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
@@ -80,15 +82,43 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
return self.substs.count return self.substs.count
} }
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if indexOfPSA == indexPath.item {
UIApplication.shared.open(URL(string: url)!)
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath as IndexPath) as! PlanViewCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath as IndexPath) as! PlanViewCell
cell.group.text = self.substs[indexPath.item].group cell.group.text = self.substs[indexPath.item].group
cell.additional.text = self.substs[indexPath.item].additional cell.additional.text = self.substs[indexPath.item].additional
cell.time.text = self.substs[indexPath.item].time cell.time.text = self.substs[indexPath.item].time
cell.date.text = self.substs[indexPath.item].date
let course = self.substs[indexPath.item].course let course = self.substs[indexPath.item].course
let image = df.getImage(from: course) var image = df.getImage(from: course)
cell.backgroundColor = self.df.getColour(for: course)
cell.tintView.backgroundColor = cell.backgroundColor
let dateString = self.substs[indexPath.item].date
if dateString.count > 2 && dateString[dateString.startIndex...dateString.index(dateString.startIndex, offsetBy: 2)] == "psa" {
cell.date.text = ""
if dateString.count > 9 && dateString[dateString.index(dateString.startIndex, offsetBy: 3)...dateString.index(dateString.startIndex, offsetBy: 6)] == "http" {
url = "\(dateString[dateString.index(dateString.startIndex, offsetBy: 3)...])"
indexOfPSA = indexPath.item
}
image = UIImage(named: "ic_idea")
cell.backgroundColor = #colorLiteral(red: 0, green: 0.4784313725, blue: 1, alpha: 1)
cell.tintView.backgroundColor = #colorLiteral(red: 0, green: 0.4784313725, blue: 1, alpha: 1)
cell.group.textColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
cell.course.textColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
cell.additional.textColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
} else {
cell.date.text = self.substs[indexPath.item].date
cell.group.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
cell.course.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
cell.additional.textColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
}
let roomMutable = NSMutableAttributedString(string: self.substs[indexPath.item].room) let roomMutable = NSMutableAttributedString(string: self.substs[indexPath.item].room)
let room = self.substs[indexPath.item].room let room = self.substs[indexPath.item].room
@@ -100,7 +130,11 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
if image != nil { if image != nil {
let attachment: NSTextAttachment = NSTextAttachment() let attachment: NSTextAttachment = NSTextAttachment()
if indexOfPSA == indexPath.item {
attachment.bounds = CGRect(x: 0, y: 0, width: 11, height: 16)
} else {
attachment.bounds = CGRect(x: 0, y: 0, width: 16, height: 16) attachment.bounds = CGRect(x: 0, y: 0, width: 16, height: 16)
}
attachment.image = image attachment.image = image
let courseImage = NSMutableAttributedString(attachment: attachment) let courseImage = NSMutableAttributedString(attachment: attachment)
@@ -112,8 +146,6 @@ class PlanViewController : UIViewController, UICollectionViewDataSource, UIColle
cell.course.text = course cell.course.text = course
} }
cell.backgroundColor = self.df.getColour(for: course)
cell.tintView.backgroundColor = cell.backgroundColor
return cell return cell
} }