Skip to content

Commit 849979a

Browse files
committed
Ficked Ticker position and count.
- Animation is off
1 parent 6ac43bf commit 849979a

File tree

6 files changed

+353
-213
lines changed

6 files changed

+353
-213
lines changed

PG5602_H24-4/Entities/Country+SwiftData.swift

-8
This file was deleted.

PG5602_H24-4/Launch Screen.storyboard

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13142" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12042"/>
5+
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
6+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
7+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
8+
</dependencies>
9+
<scenes>
10+
<!--View Controller-->
11+
<scene sceneID="EHf-IW-A2E">
12+
<objects>
13+
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
14+
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
15+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
16+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
17+
<subviews>
18+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="obG-Y5-kRd">
19+
<rect key="frame" x="0.0" y="626.5" width="375" height="20.5"/>
20+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
21+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
22+
<nil key="highlightedColor"/>
23+
</label>
24+
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PG5602_H24-4" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="GJd-Yh-RWb">
25+
<rect key="frame" x="0.0" y="202" width="375" height="43"/>
26+
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
27+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
28+
<nil key="highlightedColor"/>
29+
</label>
30+
</subviews>
31+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
32+
<constraints>
33+
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="obG-Y5-kRd" secondAttribute="centerX" id="5cz-MP-9tL"/>
34+
<constraint firstItem="Bcu-3y-fUS" firstAttribute="centerX" secondItem="GJd-Yh-RWb" secondAttribute="centerX" id="Q3B-4B-g5h"/>
35+
<constraint firstItem="obG-Y5-kRd" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" constant="20" symbolic="YES" id="SfN-ll-jLj"/>
36+
<constraint firstAttribute="bottom" secondItem="obG-Y5-kRd" secondAttribute="bottom" constant="20" id="Y44-ml-fuU"/>
37+
<constraint firstItem="GJd-Yh-RWb" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="bottom" multiplier="1/3" constant="1" id="moa-c2-u7t"/>
38+
<constraint firstItem="GJd-Yh-RWb" firstAttribute="leading" secondItem="Bcu-3y-fUS" secondAttribute="leading" constant="20" symbolic="YES" id="x7j-FC-K8j"/>
39+
</constraints>
40+
<viewLayoutGuide key="safeArea" id="Bcu-3y-fUS"/>
41+
</view>
42+
</viewController>
43+
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
44+
</objects>
45+
<point key="canvasLocation" x="53" y="375"/>
46+
</scene>
47+
</scenes>
48+
</document>

PG5602_H24-4/Views/ArticlesView.swift

+153-108
Original file line numberDiff line numberDiff line change
@@ -5,71 +5,111 @@
55
// Created by Karima Thingvold on 01/12/2024.
66
//
77

8-
//import SwiftUI
9-
//
8+
import SwiftUI
9+
import SwiftData
10+
1011
//struct ArticlesView: View {
11-
// var body: some View {
12-
// VStack {
13-
// // HUSK å sette på "hvis artikler, vis de, hvis ikke vis dette
14-
// Image(systemName: "square.stack.3d.up.slash")
15-
// .resizable()
16-
// .aspectRatio(contentMode: .fit)
17-
// .frame(width: 100, height: 100)
18-
// .padding()
19-
//
20-
// Text("No articles are saved.")
21-
// .font(.title3)
22-
// .foregroundColor(.secondary)
23-
// .padding(.bottom, 2)
24-
//
25-
// Text("Please go to search and fetch articles and news from the internet.")
26-
// .font(.body)
27-
// .foregroundColor(.secondary)
28-
// .multilineTextAlignment(.center)
29-
// .padding(.horizontal, 30)
12+
// @Environment(\.modelContext) var modelContext
13+
// @Query(sort: \Article.savedDate, order: .reverse) var storedArticles: [Article]
14+
// @State var selectedArticle: NewsArticle?
15+
// @State var selectedCategory = "All"
16+
// let defaultCategories = ["Technology", "Economy", "Politics", "Sports", "News"]
17+
//
18+
// @AppStorage("tickerPosition") var tickerPosition = "Top"
19+
// @AppStorage("isTickerActive") var isTickerActive = false
20+
//
21+
// var filteredArticles: [Article] {
22+
// if selectedCategory == "All" {
23+
// return storedArticles
24+
// }
25+
// return storedArticles.filter { article in
26+
// if let categoryName = article.category?.name {
27+
// return categoryName == selectedCategory
28+
// }
29+
// return false
3030
// }
31-
// .frame(maxWidth: .infinity, maxHeight: .infinity)
32-
// .background(Color(UIColor.systemBackground))
3331
// }
34-
//}
35-
36-
//#Preview {
37-
// ArticlesView()
38-
//}
39-
40-
//
41-
//import SwiftUI
42-
//import SwiftData
43-
//
44-
//struct ArticlesView: View {
45-
// @Query(sort: \StoredArticle.savedDate, order: .reverse) private var storedArticles: [StoredArticle]
46-
//
32+
//
4733
// var body: some View {
34+
//
4835
// NavigationView {
49-
// List(storedArticles) { article in
50-
// VStack(alignment: .leading) {
51-
// Text(article.title)
52-
// .font(.headline)
53-
// if let description = article.articleDescription {
54-
// Text(description)
55-
// .font(.subheadline)
56-
// .foregroundColor(.secondary)
36+
// if storedArticles.isEmpty {
37+
// VStack {
38+
// Image(systemName: "square.stack.3d.up.slash")
39+
// .resizable()
40+
// .frame(width: 70, height: 70)
41+
// .padding()
42+
//
43+
// Text("No articles are saved.")
44+
// .font(.title)
45+
// .fontWeight(.bold)
46+
// .foregroundStyle(.primary)
47+
// .padding(.bottom, 2)
48+
//
49+
// Text("Please go to search and fetch articles and news from the internet.")
50+
// .font(.body)
51+
// .foregroundStyle(.secondary)
52+
// .multilineTextAlignment(.center)
53+
// .padding(.horizontal, 30)
54+
// }
55+
// .frame(maxWidth: .infinity, maxHeight: .infinity)
56+
// .background(Color(UIColor.systemBackground))
57+
// } else {
58+
// List {
59+
// ForEach(storedArticles) { article in
60+
// NavigationLink(destination: ArticleDetailView(article: article.toNewsArticle())) {
61+
// VStack(alignment: .leading) {
62+
// Text(article.title)
63+
// .font(.headline)
64+
// if let description = article.articleDescription {
65+
// Text(description)
66+
// .font(.subheadline)
67+
// .foregroundStyle(.secondary)
68+
// }
69+
// }
70+
// }
71+
// }
72+
// .onDelete(perform: deleteArticle)
73+
// }
74+
// .navigationTitle("Your stored articles")
75+
// .toolbar {
76+
// ToolbarItem(placement: .navigationBarTrailing) {
77+
// Menu {
78+
// ForEach(defaultCategories, id: \.self) { category in
79+
// Button(action: {
80+
// selectedCategory = category
81+
// })
82+
// { Text(category)
83+
// if selectedCategory == category {
84+
// Image(systemName: "checkmark")
85+
// }
86+
// }
87+
// }
88+
// }
89+
// label: {
90+
// Image(systemName: "ellipsis.circle")
91+
// .imageScale(.large)
92+
// }
5793
// }
5894
// }
5995
// }
60-
// .navigationTitle("Lagrede Artikler")
96+
// }
97+
// }
98+
//
99+
// func deleteArticle(at offsets: IndexSet) {
100+
// for index in offsets {
101+
// let article = storedArticles[index]
102+
// article.deleteFromDatabase(context: modelContext)
61103
// }
62104
// }
63105
//}
64-
//
65106

66-
import SwiftUI
67-
import SwiftData
68107

69108
struct ArticlesView: View {
70-
@Environment(\.modelContext) private var modelContext
71-
@Query(sort: \Article.savedDate, order: .reverse)
72-
var storedArticles: [Article]
109+
@Environment(\.modelContext) var modelContext
110+
@Query(sort: \Article.savedDate, order: .reverse) var storedArticles: [Article]
111+
@AppStorage("tickerPosition") private var tickerPosition: String = "Top"
112+
@AppStorage("isNewsTickerActive") private var isNewsTickerActive: Bool = true
73113

74114
@State var selectedCategory = "All"
75115
let defaultCategories = ["Technology", "Economy", "Politics", "Sports", "News"]
@@ -85,75 +125,80 @@ struct ArticlesView: View {
85125
return false
86126
}
87127
}
88-
128+
89129
var body: some View {
90-
// VStack {
91-
// NewsTickerView()
92-
// .frame(height: 50)
93-
// .background(Color.gray.opacity(0.1))
94-
// }
95-
NavigationView {
96-
if storedArticles.isEmpty {
97-
VStack {
98-
Image(systemName: "square.stack.3d.up.slash")
99-
.resizable()
100-
.aspectRatio(contentMode: .fit)
101-
.frame(width: 70, height: 70)
102-
.padding()
103-
104-
Text("No articles are saved.")
105-
.font(.title)
106-
.fontWeight(.bold)
107-
.foregroundStyle(.primary)
108-
.padding(.bottom, 2)
109-
110-
Text("Please go to search and fetch articles and news from the internet.")
111-
.font(.body)
112-
.foregroundStyle(.secondary)
113-
.multilineTextAlignment(.center)
114-
.padding(.horizontal, 30)
115-
}
116-
.frame(maxWidth: .infinity, maxHeight: .infinity)
117-
.background(Color(UIColor.systemBackground))
118-
} else {
119-
List {
120-
ForEach(storedArticles) { article in
121-
NavigationLink(destination: ArticleDetailView(article: article.toNewsArticle())) {
122-
VStack(alignment: .leading) {
123-
Text(article.title)
124-
.font(.headline)
125-
if let description = article.articleDescription {
126-
Text(description)
127-
.font(.subheadline)
128-
.foregroundStyle(.secondary)
130+
VStack {
131+
if tickerPosition == "Top" && isNewsTickerActive {
132+
NewsTickerView()
133+
.frame(height: 50)
134+
}
135+
136+
NavigationView {
137+
if storedArticles.isEmpty {
138+
VStack {
139+
Image(systemName: "square.stack.3d.up.slash")
140+
.resizable()
141+
.frame(width: 70, height: 70)
142+
.padding()
143+
144+
Text("No articles are saved.")
145+
.font(.title)
146+
.fontWeight(.bold)
147+
.foregroundStyle(.primary)
148+
.padding(.bottom, 2)
149+
150+
Text("Please go to search and fetch articles and news from the internet.")
151+
.font(.body)
152+
.foregroundStyle(.secondary)
153+
.multilineTextAlignment(.center)
154+
.padding(.horizontal, 30)
155+
}
156+
.frame(maxWidth: .infinity, maxHeight: .infinity)
157+
.background(Color(UIColor.systemBackground))
158+
} else {
159+
List {
160+
ForEach(filteredArticles) { article in
161+
NavigationLink(destination: ArticleDetailView(article: article.toNewsArticle())) {
162+
VStack(alignment: .leading) {
163+
Text(article.title)
164+
.font(.headline)
165+
if let description = article.articleDescription {
166+
Text(description)
167+
.font(.subheadline)
168+
.foregroundStyle(.secondary)
169+
}
129170
}
130171
}
131172
}
173+
.onDelete(perform: deleteArticle)
132174
}
133-
.onDelete(perform: deleteArticle)
134-
}
135-
.navigationTitle("Lagrede Artikler")
136-
.toolbar {
137-
ToolbarItem(placement: .navigationBarTrailing) {
138-
Menu {
139-
ForEach(defaultCategories, id: \.self) { category in
140-
Button(action: {
141-
selectedCategory = category
142-
})
143-
{ Text(category)
144-
if selectedCategory == category {
145-
Image(systemName: "checkmark")
175+
.navigationTitle("Your stored articles")
176+
.toolbar {
177+
ToolbarItem(placement: .navigationBarTrailing) {
178+
Menu {
179+
ForEach(defaultCategories, id: \.self) { category in
180+
Button(action: {
181+
selectedCategory = category
182+
}) {
183+
Text(category)
184+
if selectedCategory == category {
185+
Image(systemName: "checkmark")
186+
}
146187
}
147188
}
189+
} label: {
190+
Image(systemName: "ellipsis.circle")
191+
.imageScale(.large)
148192
}
149193
}
150-
label: {
151-
Image(systemName: "ellipsis.circle")
152-
.imageScale(.large)
153-
}
154194
}
155195
}
156196
}
197+
198+
if tickerPosition == "Bottom" && isNewsTickerActive {
199+
NewsTickerView()
200+
.frame(height: 50)
201+
}
157202
}
158203
}
159204

PG5602_H24-4/Views/MainLayoutView.swift

+7
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,31 @@
55
//
66

77
import SwiftUI
8+
import SwiftData
89

910
struct MainLayoutView: View {
11+
@Environment(\.modelContext) var modelContext
12+
1013
var body: some View {
1114
TabView {
1215
Tab("My Artichles", systemImage: "doc.text") {
1316
//NewsTickerView()
1417
ArticlesView()
1518
}
19+
1620
Tab("Search", systemImage: "magnifyingglass") {
1721
SearchView()
1822
}
23+
1924
Tab("Set up", systemImage: "gearshape") {
2025
SetupView()
2126
}
2227
}
2328
}
2429
}
2530

31+
32+
2633
#Preview {
2734
MainLayoutView()
2835
}

0 commit comments

Comments
 (0)