forked from firka/firka
Compare commits
4 Commits
dev
...
ios-restor
| Author | SHA1 | Date | |
|---|---|---|---|
| c6b0aebd38 | |||
| 729eee1c02 | |||
| 5acc5d95f6 | |||
| 0c77b0bfe3 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -94,7 +94,11 @@ firka/debug-info/
|
|||||||
**/ios/Flutter/flutter_export_environment.sh
|
**/ios/Flutter/flutter_export_environment.sh
|
||||||
**/ios/ServiceDefinitions.json
|
**/ios/ServiceDefinitions.json
|
||||||
**/ios/Runner/GeneratedPluginRegistrant.*
|
**/ios/Runner/GeneratedPluginRegistrant.*
|
||||||
**/ios/Flutter/
|
**/ios/Flutter/*
|
||||||
|
!**/ios/Flutter/Debug.xcconfig
|
||||||
|
!**/ios/Flutter/Release.xcconfig
|
||||||
|
!**/ios/Flutter/WidgetExtension.xcconfig
|
||||||
|
!**/ios/Flutter/AppFrameworkInfo.plist
|
||||||
|
|
||||||
# dart
|
# dart
|
||||||
**/.env*
|
**/.env*
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ Balkezes mód is van, mert úgy tűnik, van, aki nem volt szerencsés az életbe
|
|||||||
|
|
||||||
## Mit támogattok?
|
## Mit támogattok?
|
||||||
|
|
||||||
Jelenleg **Androidot** támogatunk (Wear OS-es okosóra-kísérőalkalmazással).
|
Jelenleg **Androidot** és **iOS-t** támogatunk.
|
||||||
<br />
|
<br />
|
||||||
Tervezzük a böngészős támogatást is!
|
Tervezzük a böngészős támogatást is!
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ Der Einstellungsbildschirm bietet Optionen, von denen du nicht wusstest, dass du
|
|||||||
|
|
||||||
## Was wird unterstützt?
|
## Was wird unterstützt?
|
||||||
|
|
||||||
Derzeit unterstützen wir **Android** (mit einer Wear OS Smartwatch-Begleit-App).
|
Derzeit unterstützen wir **Android** und **iOS**.
|
||||||
<br />
|
<br />
|
||||||
Wir planen, auch deinen Browser zu unterstützen!
|
Wir planen, auch deinen Browser zu unterstützen!
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ The settings screen has options you didn't know you needed. Adjust the bell offs
|
|||||||
|
|
||||||
## What do you support?
|
## What do you support?
|
||||||
|
|
||||||
Currently, we support **Android** (with a Wear OS smartwatch companion app).
|
Currently, we support **Android** and **iOS**.
|
||||||
<br />
|
<br />
|
||||||
We're planning on supporting your browser also!
|
We're planning on supporting your browser also!
|
||||||
|
|
||||||
|
|||||||
@@ -3,3 +3,6 @@
|
|||||||
# Production: https://your-domain.com/api/v1
|
# Production: https://your-domain.com/api/v1
|
||||||
BACKEND_BASE_URL=http://192.168.X.YYY:3000/api/v1
|
BACKEND_BASE_URL=http://192.168.X.YYY:3000/api/v1
|
||||||
BACKEND_API_KEY=development_api_key_12345
|
BACKEND_API_KEY=development_api_key_12345
|
||||||
|
|
||||||
|
# Live Activity push server (refilc-live-server)
|
||||||
|
LIVE_SERVER_URL=https://live.devbeni.lol
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
icons:
|
icons:
|
||||||
"flutter_launcher_icons.yaml": "993c1cd3a99db70747299601e556d19ec959b0a16fd9ff2dbf2386cb6f2a640d"
|
"flutter_launcher_icons.yaml": "c600507ca0df7cebd0f708124842512a14ed3d597b779176200d6ba25b1335b1"
|
||||||
"pubspec.yaml": "97e478fd72968c34de0c0ad4421daa9b2e2531d60bb28a893d7d3b5a9a90116c"
|
"pubspec.yaml": "2dc106a9058067fe175f3ebd53fff68ee7e78261133ac5983af4f8ac88cf97aa"
|
||||||
"assets/images/logos/colored_logo.webp": "4b4fa99d144fe6694aa4487ba1b26aeecafae41e3c877836cd7da28d61a77983"
|
"assets/images/logos/colored_logo.webp": "4b4fa99d144fe6694aa4487ba1b26aeecafae41e3c877836cd7da28d61a77983"
|
||||||
"assets/images/logos/monochrome_logo.png": "c269a5e689622484d800a4fda5927591a0bf99d34790a4f146b93cf6edabd455"
|
"assets/images/logos/monochrome_logo.png": "c269a5e689622484d800a4fda5927591a0bf99d34790a4f146b93cf6edabd455"
|
||||||
"assets/images/logos/colored_logo_without_mustache.png": "d11cff9f38985885873bfdd2d84e61f8fab03803eada94d4caac1545ef3685f3"
|
"assets/images/logos/colored_logo_without_mustache.png": "d11cff9f38985885873bfdd2d84e61f8fab03803eada94d4caac1545ef3685f3"
|
||||||
"assets/images/logos/colored_logo_only_mustache.png": "bad6220c11bdfb1dfe04e5173bd2ebedd3999689d4b3a68fc63dc520c96dd33b"
|
"assets/images/logos/colored_logo_only_mustache.png": "bad6220c11bdfb1dfe04e5173bd2ebedd3999689d4b3a68fc63dc520c96dd33b"
|
||||||
splash:
|
splash:
|
||||||
"flutter_native_splash.yaml": "f1bddb74798b1539c4e9213ca9ae305d625ebb0ac5bcbe079b523437e0abc2c4"
|
"flutter_native_splash.yaml": "64d1847d02072fbd66f90c772ec59c33b4bc304d73a81d6934204a456841ef0c"
|
||||||
"assets/images/logos/splash.png": "88fbebc3d686cb9095bcce362029b69978b1b14270e465e91d962b1425db1152"
|
"assets/images/logos/splash.png": "88fbebc3d686cb9095bcce362029b69978b1b14270e465e91d962b1425db1152"
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
flutter_launcher_icons:
|
flutter_launcher_icons:
|
||||||
generate: true
|
generate: true
|
||||||
android: "launcher_icon"
|
android: "launcher_icon"
|
||||||
ios: false
|
|
||||||
image_path: "assets/images/logos/colored_logo.webp"
|
image_path: "assets/images/logos/colored_logo.webp"
|
||||||
adaptive_icon_monochrome: "assets/images/logos/monochrome_logo.png"
|
adaptive_icon_monochrome: "assets/images/logos/monochrome_logo.png"
|
||||||
adaptive_icon_background: "assets/images/logos/colored_logo_without_mustache.png"
|
adaptive_icon_background: "assets/images/logos/colored_logo_without_mustache.png"
|
||||||
adaptive_icon_foreground: "assets/images/logos/colored_logo_only_mustache.png"
|
adaptive_icon_foreground: "assets/images/logos/colored_logo_only_mustache.png"
|
||||||
adaptive_icon_foreground_inset: 0
|
adaptive_icon_foreground_inset: 0
|
||||||
min_sdk_android: 21
|
min_sdk_android: 21
|
||||||
|
ios: true
|
||||||
|
remove_alpha_channel_ios: true
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ flutter_native_splash:
|
|||||||
icon_background_color_dark: "#7ca120"
|
icon_background_color_dark: "#7ca120"
|
||||||
|
|
||||||
android: true
|
android: true
|
||||||
ios: false
|
ios: true
|
||||||
web: false
|
web: false
|
||||||
|
|||||||
39
firka/ios/.gitignore
vendored
Normal file
39
firka/ios/.gitignore
vendored
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
**/dgph
|
||||||
|
*.mode1v3
|
||||||
|
*.mode2v3
|
||||||
|
*.moved-aside
|
||||||
|
*.pbxuser
|
||||||
|
*.perspectivev3
|
||||||
|
**/*sync/
|
||||||
|
.sconsign.dblite
|
||||||
|
.tags*
|
||||||
|
**/.vagrant/
|
||||||
|
**/DerivedData/
|
||||||
|
Icon?
|
||||||
|
**/Pods/
|
||||||
|
**/.symlinks/
|
||||||
|
profile
|
||||||
|
xcuserdata
|
||||||
|
**/.generated/
|
||||||
|
Flutter/App.framework
|
||||||
|
Flutter/Flutter.framework
|
||||||
|
Flutter/Flutter.podspec
|
||||||
|
Flutter/Generated.xcconfig
|
||||||
|
Flutter/ephemeral/
|
||||||
|
Flutter/app.flx
|
||||||
|
Flutter/app.zip
|
||||||
|
Flutter/flutter_assets/
|
||||||
|
Flutter/flutter_export_environment.sh
|
||||||
|
ServiceDefinitions.json
|
||||||
|
Runner/GeneratedPluginRegistrant.*
|
||||||
|
|
||||||
|
# Exceptions to above rules.
|
||||||
|
!default.mode1v3
|
||||||
|
!default.mode2v3
|
||||||
|
!default.pbxuser
|
||||||
|
!default.perspectivev3
|
||||||
|
|
||||||
|
/.DerivedData
|
||||||
|
|
||||||
|
# Developer-specific configuration
|
||||||
|
.dev_config
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"colors" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"filename" : "Icon-1024.png",
|
||||||
|
"idiom" : "universal",
|
||||||
|
"platform" : "watchos",
|
||||||
|
"size" : "1024x1024"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 147 KiB |
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct CountdownRing: View {
|
||||||
|
let totalMinutes: Int
|
||||||
|
let remainingMinutes: Int
|
||||||
|
let label: String
|
||||||
|
var size: CGFloat = 80
|
||||||
|
var lineWidth: CGFloat = 8
|
||||||
|
var displayOffset: Int = 0 // Add to displayed minutes (e.g., +1)
|
||||||
|
|
||||||
|
private var clampedRemainingMinutes: Int {
|
||||||
|
guard totalMinutes > 0 else { return 0 }
|
||||||
|
return max(0, min(remainingMinutes, totalMinutes))
|
||||||
|
}
|
||||||
|
|
||||||
|
var progress: Double {
|
||||||
|
guard totalMinutes > 0 else { return 0 }
|
||||||
|
return Double(totalMinutes - clampedRemainingMinutes) / Double(totalMinutes)
|
||||||
|
}
|
||||||
|
|
||||||
|
var displayedMinutes: Int {
|
||||||
|
max(0, remainingMinutes + displayOffset)
|
||||||
|
}
|
||||||
|
|
||||||
|
var ringColor: Color {
|
||||||
|
if clampedRemainingMinutes < 5 { return .red }
|
||||||
|
if clampedRemainingMinutes < 10 { return .yellow }
|
||||||
|
return .green
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
Circle()
|
||||||
|
.stroke(Color(white: 0.2), lineWidth: lineWidth)
|
||||||
|
|
||||||
|
Circle()
|
||||||
|
.trim(from: 0, to: progress)
|
||||||
|
.stroke(ringColor, style: StrokeStyle(lineWidth: lineWidth, lineCap: .round))
|
||||||
|
.rotationEffect(.degrees(-90))
|
||||||
|
.animation(.easeInOut, value: progress)
|
||||||
|
|
||||||
|
VStack(spacing: 1) {
|
||||||
|
Text("\(displayedMinutes)")
|
||||||
|
.font(size > 60 ? .title2 : .headline)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
Text(label)
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(width: size, height: size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
VStack(spacing: 20) {
|
||||||
|
CountdownRing(totalMinutes: 45, remainingMinutes: 30, label: "min")
|
||||||
|
|
||||||
|
CountdownRing(totalMinutes: 45, remainingMinutes: 8, label: "min")
|
||||||
|
|
||||||
|
CountdownRing(totalMinutes: 45, remainingMinutes: 3, label: "min")
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
42
firka/ios/FirkaWatch Watch App/Components/FirkaCard.swift
Normal file
42
firka/ios/FirkaWatch Watch App/Components/FirkaCard.swift
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct FirkaCard<Content: View>: View {
|
||||||
|
let content: Content
|
||||||
|
var isHighlighted: Bool = false
|
||||||
|
var backgroundColor: Color? = nil
|
||||||
|
|
||||||
|
init(
|
||||||
|
isHighlighted: Bool = false,
|
||||||
|
backgroundColor: Color? = nil,
|
||||||
|
@ViewBuilder content: () -> Content
|
||||||
|
) {
|
||||||
|
self.isHighlighted = isHighlighted
|
||||||
|
self.backgroundColor = backgroundColor
|
||||||
|
self.content = content()
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
content
|
||||||
|
.padding(12)
|
||||||
|
.background(
|
||||||
|
backgroundColor ??
|
||||||
|
(isHighlighted ? Color.green.opacity(0.2) : Color(white: 0.12))
|
||||||
|
)
|
||||||
|
.cornerRadius(12)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
FirkaCard {
|
||||||
|
Text("Normal Card")
|
||||||
|
.foregroundColor(.primary)
|
||||||
|
}
|
||||||
|
|
||||||
|
FirkaCard(isHighlighted: true) {
|
||||||
|
Text("Highlighted Card")
|
||||||
|
.foregroundColor(.primary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
39
firka/ios/FirkaWatch Watch App/Components/GradeBadge.swift
Normal file
39
firka/ios/FirkaWatch Watch App/Components/GradeBadge.swift
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct GradeBadge: View {
|
||||||
|
let grade: Int
|
||||||
|
var size: CGFloat = 24
|
||||||
|
|
||||||
|
var color: Color {
|
||||||
|
switch grade {
|
||||||
|
case 5: return .green
|
||||||
|
case 4: return .blue
|
||||||
|
case 3: return .yellow
|
||||||
|
case 2: return .orange
|
||||||
|
default: return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
Circle()
|
||||||
|
.fill(color)
|
||||||
|
.frame(width: size, height: size)
|
||||||
|
|
||||||
|
Text("\(grade)")
|
||||||
|
.font(.system(size: size * 0.5, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
HStack(spacing: 12) {
|
||||||
|
GradeBadge(grade: 5)
|
||||||
|
GradeBadge(grade: 4)
|
||||||
|
GradeBadge(grade: 3)
|
||||||
|
GradeBadge(grade: 2)
|
||||||
|
GradeBadge(grade: 1)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
46
firka/ios/FirkaWatch Watch App/Components/GradeRow.swift
Normal file
46
firka/ios/FirkaWatch Watch App/Components/GradeRow.swift
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct GradeRow: View {
|
||||||
|
let grade: WidgetGrade
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack(alignment: .center, spacing: 8) {
|
||||||
|
Text(grade.displayValue)
|
||||||
|
.font(.caption)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.frame(width: 24, height: 24)
|
||||||
|
.background(
|
||||||
|
Circle()
|
||||||
|
.fill(grade.gradeColor)
|
||||||
|
)
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
if let topic = grade.topic {
|
||||||
|
Text(topic)
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.primary)
|
||||||
|
.lineLimit(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(grade.type.name)
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
|
||||||
|
if let weight = grade.weightPercentage, weight != 100 {
|
||||||
|
Text("(\(weight)%)")
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 8)
|
||||||
|
.padding(.vertical, 6)
|
||||||
|
.background(Color(white: 0.15))
|
||||||
|
.cornerRadius(6)
|
||||||
|
}
|
||||||
|
}
|
||||||
146
firka/ios/FirkaWatch Watch App/Components/LessonCard.swift
Normal file
146
firka/ios/FirkaWatch Watch App/Components/LessonCard.swift
Normal file
@@ -0,0 +1,146 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct LessonCard: View {
|
||||||
|
let lesson: WidgetLesson
|
||||||
|
let isActive: Bool
|
||||||
|
let colors: WidgetColors?
|
||||||
|
|
||||||
|
var backgroundColor: Color {
|
||||||
|
if let colors = colors {
|
||||||
|
return colors.cardColor
|
||||||
|
}
|
||||||
|
return Color(white: 0.15)
|
||||||
|
}
|
||||||
|
|
||||||
|
var textPrimaryColor: Color {
|
||||||
|
if let colors = colors {
|
||||||
|
return colors.textPrimaryColor
|
||||||
|
}
|
||||||
|
return .primary
|
||||||
|
}
|
||||||
|
|
||||||
|
var textSecondaryColor: Color {
|
||||||
|
if let colors = colors {
|
||||||
|
return colors.textSecondaryColor
|
||||||
|
}
|
||||||
|
return .secondary
|
||||||
|
}
|
||||||
|
|
||||||
|
var textTertiaryColor: Color {
|
||||||
|
if let colors = colors {
|
||||||
|
return colors.textTertiaryColor
|
||||||
|
}
|
||||||
|
return .secondary.opacity(0.7)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
|
HStack(alignment: .top, spacing: 8) {
|
||||||
|
if let number = lesson.lessonNumber {
|
||||||
|
Text("\(number)")
|
||||||
|
.font(.headline)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.foregroundColor(isActive ? .white : textPrimaryColor)
|
||||||
|
.frame(width: 28, height: 28)
|
||||||
|
.background(
|
||||||
|
Circle()
|
||||||
|
.fill(isActive ? Color.green : Color.clear)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text(lesson.displayName)
|
||||||
|
.font(.headline)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.foregroundColor(lesson.isCancelled ? .red :
|
||||||
|
lesson.isSubstitution ? .orange : textPrimaryColor)
|
||||||
|
.strikethrough(lesson.isCancelled, color: .red)
|
||||||
|
.lineLimit(1)
|
||||||
|
|
||||||
|
Text(lesson.timeString)
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(lesson.isCancelled ? .red.opacity(0.8) :
|
||||||
|
lesson.isSubstitution ? .orange.opacity(0.8) : textSecondaryColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
|
||||||
|
if let room = lesson.roomName {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Image(systemName: "door.right.hand.closed")
|
||||||
|
.font(.caption2)
|
||||||
|
Text(room)
|
||||||
|
.font(.caption2)
|
||||||
|
}
|
||||||
|
.foregroundColor(lesson.isCancelled ? .red.opacity(0.7) :
|
||||||
|
lesson.isSubstitution ? .orange.opacity(0.7) : textSecondaryColor)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let teacher = lesson.teacher {
|
||||||
|
Text(teacher)
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(lesson.isCancelled ? .red.opacity(0.7) :
|
||||||
|
lesson.isSubstitution ? .orange.opacity(0.7) : textTertiaryColor)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(10)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
.background(backgroundColor)
|
||||||
|
.cornerRadius(10)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: 10)
|
||||||
|
.stroke(
|
||||||
|
isActive ? Color.green : Color.clear,
|
||||||
|
lineWidth: isActive ? 2 : 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
LessonCard(
|
||||||
|
lesson: WidgetLesson(
|
||||||
|
uid: "1",
|
||||||
|
date: "2026-02-01",
|
||||||
|
start: Date(),
|
||||||
|
end: Date().addingTimeInterval(3600),
|
||||||
|
name: "Matematika",
|
||||||
|
lessonNumber: 3,
|
||||||
|
teacher: "Nagy János",
|
||||||
|
substituteTeacher: nil,
|
||||||
|
subject: WidgetSubject(uid: "math", name: "Matematika", category: nil, sortIndex: 1, teacherName: "Nagy János"),
|
||||||
|
theme: nil,
|
||||||
|
roomName: "201",
|
||||||
|
isCancelled: false,
|
||||||
|
isSubstitution: false
|
||||||
|
),
|
||||||
|
isActive: true,
|
||||||
|
colors: nil
|
||||||
|
)
|
||||||
|
|
||||||
|
LessonCard(
|
||||||
|
lesson: WidgetLesson(
|
||||||
|
uid: "2",
|
||||||
|
date: "2026-02-01",
|
||||||
|
start: Date().addingTimeInterval(7200),
|
||||||
|
end: Date().addingTimeInterval(10800),
|
||||||
|
name: "Angol",
|
||||||
|
lessonNumber: 4,
|
||||||
|
teacher: "Kovács Éva",
|
||||||
|
substituteTeacher: nil,
|
||||||
|
subject: WidgetSubject(uid: "eng", name: "Angol", category: nil, sortIndex: 2, teacherName: "Kovács Éva"),
|
||||||
|
theme: nil,
|
||||||
|
roomName: "105",
|
||||||
|
isCancelled: false,
|
||||||
|
isSubstitution: false
|
||||||
|
),
|
||||||
|
isActive: false,
|
||||||
|
colors: nil
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
68
firka/ios/FirkaWatch Watch App/Components/ProgressBar.swift
Normal file
68
firka/ios/FirkaWatch Watch App/Components/ProgressBar.swift
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct AverageProgressBar: View {
|
||||||
|
let average: Double
|
||||||
|
|
||||||
|
var progress: Double {
|
||||||
|
(average - 1) / 4
|
||||||
|
}
|
||||||
|
|
||||||
|
var color: Color {
|
||||||
|
switch average {
|
||||||
|
case 4.5...: return .green
|
||||||
|
case 3.5..<4.5: return .blue
|
||||||
|
case 2.5..<3.5: return .yellow
|
||||||
|
case 1.5..<2.5: return .orange
|
||||||
|
default: return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
GeometryReader { geo in
|
||||||
|
ZStack(alignment: .leading) {
|
||||||
|
RoundedRectangle(cornerRadius: 2)
|
||||||
|
.fill(Color(white: 0.3))
|
||||||
|
|
||||||
|
RoundedRectangle(cornerRadius: 2)
|
||||||
|
.fill(color)
|
||||||
|
.frame(width: geo.size.width * progress)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(height: 4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
VStack(spacing: 16) {
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Text("5.0 - Excellent")
|
||||||
|
.font(.caption)
|
||||||
|
AverageProgressBar(average: 5.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Text("4.2 - Good")
|
||||||
|
.font(.caption)
|
||||||
|
AverageProgressBar(average: 4.2)
|
||||||
|
}
|
||||||
|
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Text("3.0 - Average")
|
||||||
|
.font(.caption)
|
||||||
|
AverageProgressBar(average: 3.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Text("2.0 - Below Average")
|
||||||
|
.font(.caption)
|
||||||
|
AverageProgressBar(average: 2.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Text("1.2 - Poor")
|
||||||
|
.font(.caption)
|
||||||
|
AverageProgressBar(average: 1.2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
43
firka/ios/FirkaWatch Watch App/Components/SubjectRow.swift
Normal file
43
firka/ios/FirkaWatch Watch App/Components/SubjectRow.swift
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct SubjectRow: View {
|
||||||
|
let name: String
|
||||||
|
let average: Double?
|
||||||
|
let gradeCount: Int
|
||||||
|
|
||||||
|
var averageColor: Color {
|
||||||
|
guard let avg = average else { return .gray }
|
||||||
|
switch avg {
|
||||||
|
case 4.5...: return .green
|
||||||
|
case 3.5...: return .blue
|
||||||
|
case 2.5...: return .yellow
|
||||||
|
case 1.5...: return .orange
|
||||||
|
default: return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack(alignment: .center, spacing: 8) {
|
||||||
|
Text(name)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.primary)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
if let avg = average {
|
||||||
|
Text(String(format: "%.2f", avg))
|
||||||
|
.font(.caption)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.foregroundColor(averageColor)
|
||||||
|
} else {
|
||||||
|
Text("\(gradeCount)")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 8)
|
||||||
|
.padding(.vertical, 6)
|
||||||
|
.background(Color(white: 0.15))
|
||||||
|
.cornerRadius(6)
|
||||||
|
}
|
||||||
|
}
|
||||||
189
firka/ios/FirkaWatch Watch App/ContentView.swift
Normal file
189
firka/ios/FirkaWatch Watch App/ContentView.swift
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import WatchConnectivity
|
||||||
|
internal import Combine
|
||||||
|
|
||||||
|
struct ContentView: View {
|
||||||
|
var dataStore = DataStore.shared
|
||||||
|
@State private var selectedTab = 0
|
||||||
|
@State private var isRequestingToken = false
|
||||||
|
@Environment(\.scenePhase) private var scenePhase
|
||||||
|
|
||||||
|
private let staleCheckTimer = Timer.publish(every: 30, on: .main, in: .common).autoconnect()
|
||||||
|
|
||||||
|
private let autoRefreshThreshold: TimeInterval = 10 * 60
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Group {
|
||||||
|
if dataStore.isRecoveringToken {
|
||||||
|
VStack(spacing: 16) {
|
||||||
|
ProgressView()
|
||||||
|
.scaleEffect(1.2)
|
||||||
|
Text("recovering_token".localized)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
else if dataStore.needsReauth && dataStore.hasToken {
|
||||||
|
ReauthRequiredView(onTokenReceived: {
|
||||||
|
dataStore.resetRecoveryState()
|
||||||
|
dataStore.checkTokenState()
|
||||||
|
Task {
|
||||||
|
await dataStore.refreshAllWithRecovery()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if !dataStore.hasToken && dataStore.data == nil {
|
||||||
|
if isRequestingToken {
|
||||||
|
ProgressView("connecting".localized)
|
||||||
|
} else {
|
||||||
|
PairingView(onRequestToken: requestToken)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mainContent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.task {
|
||||||
|
dataStore.reconcileSharedSessionState()
|
||||||
|
WatchL10n.shared.reconcileFromSharedState()
|
||||||
|
dataStore.checkTokenState()
|
||||||
|
dataStore.loadFromCache()
|
||||||
|
if dataStore.hasToken {
|
||||||
|
await dataStore.refreshAllWithRecovery()
|
||||||
|
} else {
|
||||||
|
requestToken()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onChange(of: scenePhase) { oldPhase, newPhase in
|
||||||
|
if newPhase == .active && oldPhase != .active {
|
||||||
|
dataStore.reconcileSharedSessionState()
|
||||||
|
WatchL10n.shared.reconcileFromSharedState()
|
||||||
|
if shouldAutoRefresh {
|
||||||
|
print("[Watch] App came to foreground, data is stale (>10 min), refreshing...")
|
||||||
|
Task {
|
||||||
|
await dataStore.refreshAllWithRecovery()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("[Watch] App came to foreground, data is fresh (<10 min), skipping refresh")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onReceive(staleCheckTimer) { _ in
|
||||||
|
guard scenePhase == .active else { return }
|
||||||
|
dataStore.reconcileSharedSessionState()
|
||||||
|
WatchL10n.shared.reconcileFromSharedState()
|
||||||
|
|
||||||
|
if !dataStore.hasToken {
|
||||||
|
dataStore.checkTokenState()
|
||||||
|
if dataStore.hasToken {
|
||||||
|
print("[Watch] Token appeared (iCloud Keychain sync?), refreshing...")
|
||||||
|
Task {
|
||||||
|
await dataStore.refreshAllWithRecovery()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if shouldAutoRefresh && !dataStore.isLoading {
|
||||||
|
print("[Watch] Data became stale (>10 min), auto-refreshing...")
|
||||||
|
Task {
|
||||||
|
await dataStore.refreshAllWithRecovery()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var shouldAutoRefresh: Bool {
|
||||||
|
guard dataStore.hasToken else { return false }
|
||||||
|
guard let lastUpdated = dataStore.lastUpdated else { return true }
|
||||||
|
let elapsed = Date().timeIntervalSince(lastUpdated)
|
||||||
|
return elapsed >= autoRefreshThreshold
|
||||||
|
}
|
||||||
|
|
||||||
|
private func requestToken() {
|
||||||
|
guard !isRequestingToken else { return }
|
||||||
|
guard WCSession.default.activationState == .activated else {
|
||||||
|
print("[Watch] Cannot request token: session not activated")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard WCSession.default.isReachable else {
|
||||||
|
print("[Watch] Cannot request token: iPhone not reachable")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
print("[Watch] Requesting token from iPhone...")
|
||||||
|
isRequestingToken = true
|
||||||
|
WatchConnectivityManager.shared.requestTokenFromPhone()
|
||||||
|
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
|
||||||
|
self.isRequestingToken = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var mainContent: some View {
|
||||||
|
TabView(selection: $selectedTab) {
|
||||||
|
HomeView(dataStore: dataStore)
|
||||||
|
.tag(0)
|
||||||
|
|
||||||
|
TimetableView(dataStore: dataStore)
|
||||||
|
.tag(1)
|
||||||
|
|
||||||
|
GradesView(dataStore: dataStore)
|
||||||
|
.tag(2)
|
||||||
|
|
||||||
|
NavigationStack {
|
||||||
|
SettingsView()
|
||||||
|
}
|
||||||
|
.tag(3)
|
||||||
|
}
|
||||||
|
.tabViewStyle(.verticalPage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PairingView: View {
|
||||||
|
var onRequestToken: (() -> Void)?
|
||||||
|
|
||||||
|
private var isWatchSystemPaired: Bool {
|
||||||
|
guard WCSession.isSupported() else { return false }
|
||||||
|
return WCSession.default.isCompanionAppInstalled
|
||||||
|
}
|
||||||
|
|
||||||
|
private var titleKey: String {
|
||||||
|
isWatchSystemPaired ? "login_on_iphone" : "pair_with_iphone"
|
||||||
|
}
|
||||||
|
|
||||||
|
private var descriptionKey: String {
|
||||||
|
isWatchSystemPaired ? "open_and_login_on_iphone" : "open_firka_on_iphone"
|
||||||
|
}
|
||||||
|
|
||||||
|
private var iconName: String {
|
||||||
|
isWatchSystemPaired
|
||||||
|
? "person.crop.circle.badge.exclamationmark"
|
||||||
|
: "iphone.and.arrow.right.inward"
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(spacing: 10) {
|
||||||
|
Image(systemName: iconName)
|
||||||
|
.font(.system(size: 36))
|
||||||
|
.foregroundColor(.blue)
|
||||||
|
|
||||||
|
Text(titleKey.localized)
|
||||||
|
.font(.headline)
|
||||||
|
|
||||||
|
Text(descriptionKey.localized)
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.padding(.horizontal)
|
||||||
|
|
||||||
|
if isWatchSystemPaired {
|
||||||
|
Button("sync_button".localized) {
|
||||||
|
onRequestToken?()
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderedProminent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
|
||||||
|
<string>$(TeamIdentifierPrefix)app.firkaa.legacy</string>
|
||||||
|
<key>com.apple.security.application-groups</key>
|
||||||
|
<array>
|
||||||
|
<string>group.app.firkaa.legacy</string>
|
||||||
|
</array>
|
||||||
|
<key>keychain-access-groups</key>
|
||||||
|
<array>
|
||||||
|
<string>$(AppIdentifierPrefix)app.firka.shared</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
35
firka/ios/FirkaWatch Watch App/FirkaWatchApp.swift
Normal file
35
firka/ios/FirkaWatch Watch App/FirkaWatchApp.swift
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import WatchKit
|
||||||
|
|
||||||
|
@main
|
||||||
|
struct FirkaWatchApp: App {
|
||||||
|
@WKApplicationDelegateAdaptor(WatchAppDelegate.self) var delegate
|
||||||
|
|
||||||
|
var body: some Scene {
|
||||||
|
WindowGroup {
|
||||||
|
ContentView()
|
||||||
|
.preferredColorScheme(.dark)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class WatchAppDelegate: NSObject, WKApplicationDelegate {
|
||||||
|
func applicationDidFinishLaunching() {
|
||||||
|
print("[Watch] applicationDidFinishLaunching called")
|
||||||
|
WatchConnectivityManager.shared.activate()
|
||||||
|
}
|
||||||
|
|
||||||
|
func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {
|
||||||
|
for task in backgroundTasks {
|
||||||
|
switch task {
|
||||||
|
case let refreshTask as WKApplicationRefreshBackgroundTask:
|
||||||
|
Task {
|
||||||
|
await BackgroundRefreshManager.shared.handleBackgroundRefresh()
|
||||||
|
refreshTask.setTaskCompletedWithSnapshot(false)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
task.setTaskCompletedWithSnapshot(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
464
firka/ios/FirkaWatch Watch App/Localization/WatchL10n.swift
Normal file
464
firka/ios/FirkaWatch Watch App/Localization/WatchL10n.swift
Normal file
@@ -0,0 +1,464 @@
|
|||||||
|
import Foundation
|
||||||
|
import SwiftUI
|
||||||
|
import WidgetKit
|
||||||
|
|
||||||
|
enum WatchLanguage: String, CaseIterable, Codable {
|
||||||
|
case hungarian = "hu"
|
||||||
|
case english = "en"
|
||||||
|
case german = "de"
|
||||||
|
|
||||||
|
var displayName: String {
|
||||||
|
switch self {
|
||||||
|
case .hungarian: return "Magyar"
|
||||||
|
case .english: return "English"
|
||||||
|
case .german: return "Deutsch"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var flag: String {
|
||||||
|
switch self {
|
||||||
|
case .hungarian: return "🇭🇺"
|
||||||
|
case .english: return "🇬🇧"
|
||||||
|
case .german: return "🇩🇪"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Observable
|
||||||
|
class WatchL10n {
|
||||||
|
static let shared = WatchL10n()
|
||||||
|
|
||||||
|
private let languageKey = "watch_language"
|
||||||
|
private let syncWithiPhoneKey = "watch_sync_language_with_iphone"
|
||||||
|
private let lastAppliedSharedLanguageVersionKey = "watch_last_applied_shared_language_version"
|
||||||
|
private static let appGroupID = "group.app.firkaa.legacy"
|
||||||
|
private var appGroupDefaults: UserDefaults? {
|
||||||
|
UserDefaults(suiteName: Self.appGroupID)
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentLanguage: WatchLanguage {
|
||||||
|
didSet {
|
||||||
|
UserDefaults.standard.set(currentLanguage.rawValue, forKey: languageKey)
|
||||||
|
appGroupDefaults?.set(currentLanguage.rawValue, forKey: languageKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var syncWithiPhone: Bool {
|
||||||
|
didSet {
|
||||||
|
UserDefaults.standard.set(syncWithiPhone, forKey: syncWithiPhoneKey)
|
||||||
|
appGroupDefaults?.set(syncWithiPhone, forKey: syncWithiPhoneKey)
|
||||||
|
if syncWithiPhone {
|
||||||
|
refreshFromiPhoneAndSharedState()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var strings: [String: String] = [:]
|
||||||
|
|
||||||
|
private init() {
|
||||||
|
let savedLanguage = UserDefaults.standard.string(forKey: languageKey) ?? "hu"
|
||||||
|
self.currentLanguage = WatchLanguage(rawValue: savedLanguage) ?? .hungarian
|
||||||
|
if let storedSyncPref = UserDefaults.standard.object(forKey: syncWithiPhoneKey) as? Bool {
|
||||||
|
self.syncWithiPhone = storedSyncPref
|
||||||
|
} else {
|
||||||
|
self.syncWithiPhone = true
|
||||||
|
UserDefaults.standard.set(true, forKey: syncWithiPhoneKey)
|
||||||
|
appGroupDefaults?.set(true, forKey: syncWithiPhoneKey)
|
||||||
|
}
|
||||||
|
appGroupDefaults?.set(currentLanguage.rawValue, forKey: languageKey)
|
||||||
|
loadStrings()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func loadStrings() {
|
||||||
|
strings = Self.stringsForLanguage(currentLanguage)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setLanguage(_ language: WatchLanguage) {
|
||||||
|
if Thread.isMainThread {
|
||||||
|
currentLanguage = language
|
||||||
|
loadStrings()
|
||||||
|
WidgetCenter.shared.reloadAllTimelines()
|
||||||
|
} else {
|
||||||
|
DispatchQueue.main.async { [self] in
|
||||||
|
currentLanguage = language
|
||||||
|
loadStrings()
|
||||||
|
WidgetCenter.shared.reloadAllTimelines()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateFromiPhone(languageCode: String, sharedStateVersion: Int64? = nil) {
|
||||||
|
guard syncWithiPhone else { return }
|
||||||
|
let lastAppliedVersion = lastAppliedSharedLanguageVersion()
|
||||||
|
if let sharedStateVersion,
|
||||||
|
sharedStateVersion > 0,
|
||||||
|
sharedStateVersion < lastAppliedVersion {
|
||||||
|
print("[WatchL10n] Ignoring stale WC language update (version: \(sharedStateVersion), lastApplied: \(lastAppliedVersion))")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if let language = WatchLanguage(rawValue: languageCode) {
|
||||||
|
if language != currentLanguage {
|
||||||
|
setLanguage(language)
|
||||||
|
}
|
||||||
|
if let sharedStateVersion, sharedStateVersion > 0 {
|
||||||
|
setLastAppliedSharedLanguageVersion(max(lastAppliedVersion, sharedStateVersion))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func parseInt64(_ value: Any?) -> Int64? {
|
||||||
|
if let value = value as? Int64 { return value }
|
||||||
|
if let value = value as? Int { return Int64(value) }
|
||||||
|
if let value = value as? Double { return Int64(value) }
|
||||||
|
if let value = value as? String, let parsed = Int64(value) { return parsed }
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func lastAppliedSharedLanguageVersion() -> Int64 {
|
||||||
|
parseInt64(UserDefaults.standard.object(forKey: lastAppliedSharedLanguageVersionKey)) ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setLastAppliedSharedLanguageVersion(_ value: Int64) {
|
||||||
|
UserDefaults.standard.set(value, forKey: lastAppliedSharedLanguageVersionKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func resetLanguageVersionTracking() {
|
||||||
|
setLastAppliedSharedLanguageVersion(0)
|
||||||
|
print("[WatchL10n] Language version tracking reset for account switch")
|
||||||
|
}
|
||||||
|
|
||||||
|
func reconcileFromSharedState() {
|
||||||
|
guard syncWithiPhone else { return }
|
||||||
|
guard let sharedState = SharedLanguageStateManager.shared.loadState() else { return }
|
||||||
|
let lastAppliedVersion = lastAppliedSharedLanguageVersion()
|
||||||
|
guard sharedState.stateVersion > lastAppliedVersion else { return }
|
||||||
|
|
||||||
|
if let language = WatchLanguage(rawValue: sharedState.languageCode) {
|
||||||
|
if language != currentLanguage {
|
||||||
|
setLanguage(language)
|
||||||
|
}
|
||||||
|
setLastAppliedSharedLanguageVersion(sharedState.stateVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func refreshFromiPhoneAndSharedState() {
|
||||||
|
guard syncWithiPhone else { return }
|
||||||
|
requestLanguageFromiPhone()
|
||||||
|
reconcileFromSharedState()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func requestLanguageFromiPhone() {
|
||||||
|
WatchConnectivityManager.shared.requestLanguageFromPhone()
|
||||||
|
}
|
||||||
|
|
||||||
|
func string(_ key: String) -> String {
|
||||||
|
return strings[key] ?? key
|
||||||
|
}
|
||||||
|
|
||||||
|
func string(_ key: String, _ args: CVarArg...) -> String {
|
||||||
|
let format = strings[key] ?? key
|
||||||
|
return String(format: format, arguments: args)
|
||||||
|
}
|
||||||
|
|
||||||
|
static func stringsForLanguage(_ language: WatchLanguage) -> [String: String] {
|
||||||
|
switch language {
|
||||||
|
case .hungarian:
|
||||||
|
return hungarianStrings
|
||||||
|
case .english:
|
||||||
|
return englishStrings
|
||||||
|
case .german:
|
||||||
|
return germanStrings
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static let hungarianStrings: [String: String] = [
|
||||||
|
// Home View
|
||||||
|
"current_lesson": "Jelenlegi óra",
|
||||||
|
"next": "Következő",
|
||||||
|
"break": "Szünet",
|
||||||
|
"next_lesson": "Következő: %@",
|
||||||
|
"first_lesson": "Első órád",
|
||||||
|
"today_lessons_count": "Ma %d órád van",
|
||||||
|
"no_more_lessons": "Ma nincs több órád",
|
||||||
|
"pair_with_iphone": "Párosítsd az iPhone-oddal",
|
||||||
|
"open_firka_on_iphone": "Nyisd meg a Firka appot az iPhone-odon",
|
||||||
|
"login_on_iphone": "Jelentkezz be iPhone-on",
|
||||||
|
"open_and_login_on_iphone": "Nyisd meg a Firka appot iPhone-on, és lépj be egy fiókba",
|
||||||
|
"updated": "Frissítve: %@",
|
||||||
|
"minutes": "perc",
|
||||||
|
"time_now": "most",
|
||||||
|
"time_hours_minutes": "%d ó %d p",
|
||||||
|
"time_hours": "%d óra",
|
||||||
|
"time_minutes_only": "%d perc",
|
||||||
|
"time_since_minutes_one": "1 perce",
|
||||||
|
"time_since_minutes_many": "%d perce",
|
||||||
|
"time_since_hours_one": "1 órája",
|
||||||
|
"time_since_hours_many": "%d órája",
|
||||||
|
"time_since_days_one": "1 napja",
|
||||||
|
"time_since_days_many": "%d napja",
|
||||||
|
|
||||||
|
// Timetable View
|
||||||
|
"free_day": "Szabad nap",
|
||||||
|
"lesson_number": "%d. óra",
|
||||||
|
"day_mon": "H",
|
||||||
|
"day_tue": "K",
|
||||||
|
"day_wed": "Sz",
|
||||||
|
"day_thu": "Cs",
|
||||||
|
"day_fri": "P",
|
||||||
|
|
||||||
|
// Grades View
|
||||||
|
"grades_count": "%d jegy",
|
||||||
|
"total_average": "Teljes átlag",
|
||||||
|
"average": "Átlag:",
|
||||||
|
"no_data": "Nincs adat",
|
||||||
|
"no_grades": "Nincsenek jegyek",
|
||||||
|
|
||||||
|
// Lesson Detail
|
||||||
|
"lesson_details": "Óra részletei",
|
||||||
|
"cancelled": "Elmarad",
|
||||||
|
"substitution": "Helyettesítés",
|
||||||
|
"teacher": "Tanár",
|
||||||
|
"room": "Terem",
|
||||||
|
"topic": "Téma",
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
"settings": "Beállítások",
|
||||||
|
"refresh_interval": "Frissítési időköz",
|
||||||
|
"auto": "Automatikus",
|
||||||
|
"15_minutes": "15 perc",
|
||||||
|
"30_minutes": "30 perc",
|
||||||
|
"1_hour": "1 óra",
|
||||||
|
"version": "Verzió",
|
||||||
|
"language": "Nyelv",
|
||||||
|
"sync_with_iphone": "iPhone nyelvével",
|
||||||
|
"clear_cache": "Cache törlése",
|
||||||
|
"logout": "Kijelentkezés",
|
||||||
|
|
||||||
|
// Refresh
|
||||||
|
"refresh": "Frissítés",
|
||||||
|
"refreshing": "Frissítés...",
|
||||||
|
"refresh_success": "Sikeres!",
|
||||||
|
"refresh_failed": "Sikertelen",
|
||||||
|
"error_api": "Kréta API hiba",
|
||||||
|
"error_network": "Hálózati hiba",
|
||||||
|
|
||||||
|
// Date labels
|
||||||
|
"tomorrow_first_lesson": "Holnap első órád",
|
||||||
|
"day_first_lesson": "%@ első órád",
|
||||||
|
"next_school_day": "Következő iskolai nap",
|
||||||
|
|
||||||
|
// Navigation
|
||||||
|
"home": "Kezdőlap",
|
||||||
|
"timetable": "Órarend",
|
||||||
|
"grades": "Jegyek",
|
||||||
|
|
||||||
|
// Reauth
|
||||||
|
"reauth_required": "Újrabelépés szükséges",
|
||||||
|
"reauth_description": "A munkamenet lejárt. Lépj be újra az iPhone appban.",
|
||||||
|
"sync_button": "Szinkronizálás",
|
||||||
|
"syncing": "Szinkronizálás...",
|
||||||
|
"sync_success": "Sikeres!",
|
||||||
|
"sync_failed": "Sikertelen",
|
||||||
|
"phone_not_reachable": "iPhone nem elérhető",
|
||||||
|
"connecting": "Kapcsolódás...",
|
||||||
|
"recovering_token": "Token helyreállítása...",
|
||||||
|
]
|
||||||
|
|
||||||
|
private static let englishStrings: [String: String] = [
|
||||||
|
// Home View
|
||||||
|
"current_lesson": "Current Lesson",
|
||||||
|
"next": "Next",
|
||||||
|
"break": "Break",
|
||||||
|
"next_lesson": "Next: %@",
|
||||||
|
"first_lesson": "First Lesson",
|
||||||
|
"today_lessons_count": "You have %d lessons today",
|
||||||
|
"no_more_lessons": "No more lessons today",
|
||||||
|
"pair_with_iphone": "Pair with iPhone",
|
||||||
|
"open_firka_on_iphone": "Open Firka app on your iPhone",
|
||||||
|
"login_on_iphone": "Sign in on iPhone",
|
||||||
|
"open_and_login_on_iphone": "Open Firka on your iPhone and sign in to an account",
|
||||||
|
"updated": "Updated: %@",
|
||||||
|
"minutes": "min",
|
||||||
|
"time_now": "now",
|
||||||
|
"time_hours_minutes": "%dh %dm",
|
||||||
|
"time_hours": "%d hours",
|
||||||
|
"time_minutes_only": "%d min",
|
||||||
|
"time_since_minutes_one": "1 min ago",
|
||||||
|
"time_since_minutes_many": "%d mins ago",
|
||||||
|
"time_since_hours_one": "1 hour ago",
|
||||||
|
"time_since_hours_many": "%d hours ago",
|
||||||
|
"time_since_days_one": "1 day ago",
|
||||||
|
"time_since_days_many": "%d days ago",
|
||||||
|
|
||||||
|
// Timetable View
|
||||||
|
"free_day": "Free Day",
|
||||||
|
"lesson_number": "Lesson %d",
|
||||||
|
"day_mon": "Mon",
|
||||||
|
"day_tue": "Tue",
|
||||||
|
"day_wed": "Wed",
|
||||||
|
"day_thu": "Thu",
|
||||||
|
"day_fri": "Fri",
|
||||||
|
|
||||||
|
// Grades View
|
||||||
|
"grades_count": "%d grades",
|
||||||
|
"total_average": "Total Average",
|
||||||
|
"average": "Average:",
|
||||||
|
"no_data": "No data",
|
||||||
|
"no_grades": "No grades",
|
||||||
|
|
||||||
|
// Lesson Detail
|
||||||
|
"lesson_details": "Lesson Details",
|
||||||
|
"cancelled": "Cancelled",
|
||||||
|
"substitution": "Substitution",
|
||||||
|
"teacher": "Teacher",
|
||||||
|
"room": "Room",
|
||||||
|
"topic": "Topic",
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
"settings": "Settings",
|
||||||
|
"refresh_interval": "Refresh Interval",
|
||||||
|
"auto": "Auto",
|
||||||
|
"15_minutes": "15 minutes",
|
||||||
|
"30_minutes": "30 minutes",
|
||||||
|
"1_hour": "1 hour",
|
||||||
|
"version": "Version",
|
||||||
|
"language": "Language",
|
||||||
|
"sync_with_iphone": "Sync with iPhone",
|
||||||
|
"clear_cache": "Clear Cache",
|
||||||
|
"logout": "Log Out",
|
||||||
|
|
||||||
|
// Refresh
|
||||||
|
"refresh": "Refresh",
|
||||||
|
"refreshing": "Refreshing...",
|
||||||
|
"refresh_success": "Success!",
|
||||||
|
"refresh_failed": "Failed",
|
||||||
|
"error_api": "Kréta API Error",
|
||||||
|
"error_network": "Network Error",
|
||||||
|
|
||||||
|
// Date labels
|
||||||
|
"tomorrow_first_lesson": "Tomorrow's first lesson",
|
||||||
|
"day_first_lesson": "%@'s first lesson",
|
||||||
|
"next_school_day": "Next school day",
|
||||||
|
|
||||||
|
// Navigation
|
||||||
|
"home": "Home",
|
||||||
|
"timetable": "Timetable",
|
||||||
|
"grades": "Grades",
|
||||||
|
|
||||||
|
// Reauth
|
||||||
|
"reauth_required": "Re-login Required",
|
||||||
|
"reauth_description": "Your session has expired. Please log in again on your iPhone.",
|
||||||
|
"sync_button": "Sync",
|
||||||
|
"syncing": "Syncing...",
|
||||||
|
"sync_success": "Success!",
|
||||||
|
"sync_failed": "Failed",
|
||||||
|
"phone_not_reachable": "iPhone not reachable",
|
||||||
|
"connecting": "Connecting...",
|
||||||
|
"recovering_token": "Recovering session...",
|
||||||
|
]
|
||||||
|
|
||||||
|
private static let germanStrings: [String: String] = [
|
||||||
|
// Home View
|
||||||
|
"current_lesson": "Aktuelle Stunde",
|
||||||
|
"next": "Nächste",
|
||||||
|
"break": "Pause",
|
||||||
|
"next_lesson": "Nächste: %@",
|
||||||
|
"first_lesson": "Erste Stunde",
|
||||||
|
"today_lessons_count": "Du hast heute %d Stunden",
|
||||||
|
"no_more_lessons": "Keine Stunden mehr heute",
|
||||||
|
"pair_with_iphone": "Mit iPhone koppeln",
|
||||||
|
"open_firka_on_iphone": "Öffne Firka auf deinem iPhone",
|
||||||
|
"login_on_iphone": "Auf iPhone anmelden",
|
||||||
|
"open_and_login_on_iphone": "Öffne Firka auf deinem iPhone und melde dich mit einem Konto an",
|
||||||
|
"updated": "Aktualisiert: %@",
|
||||||
|
"minutes": "Min",
|
||||||
|
"time_now": "jetzt",
|
||||||
|
"time_hours_minutes": "%d Std %d Min",
|
||||||
|
"time_hours": "%d Stunden",
|
||||||
|
"time_minutes_only": "%d Min",
|
||||||
|
"time_since_minutes_one": "vor 1 Min",
|
||||||
|
"time_since_minutes_many": "vor %d Min",
|
||||||
|
"time_since_hours_one": "vor 1 Std",
|
||||||
|
"time_since_hours_many": "vor %d Std",
|
||||||
|
"time_since_days_one": "vor 1 Tag",
|
||||||
|
"time_since_days_many": "vor %d Tagen",
|
||||||
|
|
||||||
|
// Timetable View
|
||||||
|
"free_day": "Freier Tag",
|
||||||
|
"lesson_number": "%d. Stunde",
|
||||||
|
"day_mon": "Mo",
|
||||||
|
"day_tue": "Di",
|
||||||
|
"day_wed": "Mi",
|
||||||
|
"day_thu": "Do",
|
||||||
|
"day_fri": "Fr",
|
||||||
|
|
||||||
|
// Grades View
|
||||||
|
"grades_count": "%d Noten",
|
||||||
|
"total_average": "Gesamtdurchschnitt",
|
||||||
|
"average": "Durchschnitt:",
|
||||||
|
"no_data": "Keine Daten",
|
||||||
|
"no_grades": "Keine Noten",
|
||||||
|
|
||||||
|
// Lesson Detail
|
||||||
|
"lesson_details": "Stundendetails",
|
||||||
|
"cancelled": "Entfällt",
|
||||||
|
"substitution": "Vertretung",
|
||||||
|
"teacher": "Lehrer",
|
||||||
|
"room": "Raum",
|
||||||
|
"topic": "Thema",
|
||||||
|
|
||||||
|
// Settings
|
||||||
|
"settings": "Einstellungen",
|
||||||
|
"refresh_interval": "Aktualisierungsintervall",
|
||||||
|
"auto": "Automatisch",
|
||||||
|
"15_minutes": "15 Minuten",
|
||||||
|
"30_minutes": "30 Minuten",
|
||||||
|
"1_hour": "1 Stunde",
|
||||||
|
"version": "Version",
|
||||||
|
"language": "Sprache",
|
||||||
|
"sync_with_iphone": "Mit iPhone synchronisieren",
|
||||||
|
"clear_cache": "Cache löschen",
|
||||||
|
"logout": "Abmelden",
|
||||||
|
|
||||||
|
// Refresh
|
||||||
|
"refresh": "Aktualisieren",
|
||||||
|
"refreshing": "Wird aktualisiert...",
|
||||||
|
"refresh_success": "Erfolgreich!",
|
||||||
|
"refresh_failed": "Fehlgeschlagen",
|
||||||
|
"error_api": "Kréta API Fehler",
|
||||||
|
"error_network": "Netzwerkfehler",
|
||||||
|
|
||||||
|
// Date labels
|
||||||
|
"tomorrow_first_lesson": "Morgen erste Stunde",
|
||||||
|
"day_first_lesson": "%@ erste Stunde",
|
||||||
|
"next_school_day": "Nächster Schultag",
|
||||||
|
|
||||||
|
// Navigation
|
||||||
|
"home": "Startseite",
|
||||||
|
"timetable": "Stundenplan",
|
||||||
|
"grades": "Noten",
|
||||||
|
|
||||||
|
// Reauth
|
||||||
|
"reauth_required": "Erneute Anmeldung erforderlich",
|
||||||
|
"reauth_description": "Ihre Sitzung ist abgelaufen. Bitte melden Sie sich erneut auf dem iPhone an.",
|
||||||
|
"sync_button": "Synchronisieren",
|
||||||
|
"syncing": "Synchronisierung...",
|
||||||
|
"sync_success": "Erfolgreich!",
|
||||||
|
"sync_failed": "Fehlgeschlagen",
|
||||||
|
"phone_not_reachable": "iPhone nicht erreichbar",
|
||||||
|
"connecting": "Verbindung...",
|
||||||
|
"recovering_token": "Sitzung wiederherstellen...",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
extension String {
|
||||||
|
var localized: String {
|
||||||
|
WatchL10n.shared.string(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
func localized(_ args: CVarArg...) -> String {
|
||||||
|
let format = WatchL10n.shared.string(self)
|
||||||
|
return String(format: format, arguments: args)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
import Foundation
|
||||||
|
import WatchKit
|
||||||
|
import WidgetKit
|
||||||
|
|
||||||
|
class BackgroundRefreshManager {
|
||||||
|
static let shared = BackgroundRefreshManager()
|
||||||
|
|
||||||
|
private init() {}
|
||||||
|
|
||||||
|
func scheduleNextRefresh() {
|
||||||
|
let interval = calculateOptimalRefreshInterval()
|
||||||
|
|
||||||
|
let preferredDate = Date().addingTimeInterval(interval)
|
||||||
|
WKApplication.shared().scheduleBackgroundRefresh(
|
||||||
|
withPreferredDate: preferredDate,
|
||||||
|
userInfo: nil
|
||||||
|
) { error in
|
||||||
|
if let error = error {
|
||||||
|
print("[BackgroundRefresh] Schedule error: \(error)")
|
||||||
|
} else {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "HH:mm"
|
||||||
|
print("[BackgroundRefresh] Next refresh scheduled at: \(formatter.string(from: preferredDate)) (\(Int(interval/60)) min)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func calculateOptimalRefreshInterval() -> TimeInterval {
|
||||||
|
let userRefreshMinutes = UserDefaults.standard.integer(forKey: "refreshInterval")
|
||||||
|
let now = Date()
|
||||||
|
let calendar = Calendar.current
|
||||||
|
|
||||||
|
let todayLessons = getTodayLessons()
|
||||||
|
|
||||||
|
guard !todayLessons.isEmpty else {
|
||||||
|
return getDefaultInterval(userSetting: userRefreshMinutes, now: now, calendar: calendar)
|
||||||
|
}
|
||||||
|
|
||||||
|
let sortedLessons = todayLessons.sorted { $0.start < $1.start }
|
||||||
|
|
||||||
|
guard let firstLesson = sortedLessons.first,
|
||||||
|
let lastLesson = sortedLessons.last else {
|
||||||
|
return getDefaultInterval(userSetting: userRefreshMinutes, now: now, calendar: calendar)
|
||||||
|
}
|
||||||
|
|
||||||
|
let firstStart = firstLesson.start
|
||||||
|
let lastEnd = lastLesson.end
|
||||||
|
|
||||||
|
let schoolStartBuffer = firstStart.addingTimeInterval(-30 * 60)
|
||||||
|
|
||||||
|
if now < schoolStartBuffer {
|
||||||
|
let intervalUntilWakeUp = schoolStartBuffer.timeIntervalSince(now)
|
||||||
|
let interval = max(intervalUntilWakeUp, 15 * 60)
|
||||||
|
print("[BackgroundRefresh] Before school - next refresh in \(Int(interval/60)) min (30 min before first lesson)")
|
||||||
|
return min(interval, 60 * 60) // Max 1 hour
|
||||||
|
}
|
||||||
|
|
||||||
|
if now >= schoolStartBuffer && now <= lastEnd {
|
||||||
|
let interval = TimeInterval((userRefreshMinutes > 0 ? userRefreshMinutes : 15) * 60)
|
||||||
|
print("[BackgroundRefresh] During school - using \(Int(interval/60)) min interval")
|
||||||
|
return interval
|
||||||
|
}
|
||||||
|
|
||||||
|
let tomorrowLessons = getTomorrowLessons()
|
||||||
|
if !tomorrowLessons.isEmpty,
|
||||||
|
let tomorrowFirst = tomorrowLessons.sorted(by: { $0.start < $1.start }).first {
|
||||||
|
|
||||||
|
let tomorrowStartBuffer = tomorrowFirst.start.addingTimeInterval(-30 * 60)
|
||||||
|
let timeUntilTomorrowWakeUp = tomorrowStartBuffer.timeIntervalSince(now)
|
||||||
|
|
||||||
|
if timeUntilTomorrowWakeUp > 2 * 60 * 60 {
|
||||||
|
print("[BackgroundRefresh] After school - 1 hour interval (tomorrow's first lesson in \(Int(timeUntilTomorrowWakeUp/60)) min)")
|
||||||
|
return 60 * 60
|
||||||
|
} else {
|
||||||
|
print("[BackgroundRefresh] After school, tomorrow soon - 30 min interval")
|
||||||
|
return 30 * 60
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print("[BackgroundRefresh] After school, no tomorrow lessons - 1 hour interval")
|
||||||
|
return 60 * 60
|
||||||
|
}
|
||||||
|
|
||||||
|
private func getDefaultInterval(userSetting: Int, now: Date, calendar: Calendar) -> TimeInterval {
|
||||||
|
if userSetting > 0 {
|
||||||
|
print("[BackgroundRefresh] No timetable - using user setting: \(userSetting) min")
|
||||||
|
return TimeInterval(userSetting * 60)
|
||||||
|
}
|
||||||
|
|
||||||
|
let hour = calendar.component(.hour, from: now)
|
||||||
|
let weekday = calendar.component(.weekday, from: now)
|
||||||
|
let isWeekday = weekday >= 2 && weekday <= 6
|
||||||
|
|
||||||
|
if isWeekday && hour >= 6 && hour <= 16 {
|
||||||
|
print("[BackgroundRefresh] No timetable - weekday school hours: 15 min")
|
||||||
|
return 15 * 60
|
||||||
|
} else {
|
||||||
|
print("[BackgroundRefresh] No timetable - off hours: 1 hour")
|
||||||
|
return 60 * 60
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func getTodayLessons() -> [WidgetLesson] {
|
||||||
|
guard let data = DataStore.shared.data else { return [] }
|
||||||
|
return data.timetable.today
|
||||||
|
}
|
||||||
|
|
||||||
|
private func getTomorrowLessons() -> [WidgetLesson] {
|
||||||
|
guard let data = DataStore.shared.data else { return [] }
|
||||||
|
return data.timetable.tomorrow
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleBackgroundRefresh() async {
|
||||||
|
await DataStore.shared.refreshAllWithRecovery()
|
||||||
|
|
||||||
|
WidgetCenter.shared.reloadAllTimelines()
|
||||||
|
|
||||||
|
scheduleNextRefresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
551
firka/ios/FirkaWatch Watch App/Services/DataStore.swift
Normal file
551
firka/ios/FirkaWatch Watch App/Services/DataStore.swift
Normal file
@@ -0,0 +1,551 @@
|
|||||||
|
import Foundation
|
||||||
|
import Observation
|
||||||
|
import WidgetKit
|
||||||
|
|
||||||
|
// MARK: - Cache Wrapper
|
||||||
|
|
||||||
|
struct CachedWatchData: Codable {
|
||||||
|
let widgetData: WidgetData
|
||||||
|
let lastUpdated: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - DataStore
|
||||||
|
|
||||||
|
@Observable
|
||||||
|
class DataStore {
|
||||||
|
static let shared = DataStore()
|
||||||
|
|
||||||
|
var data: WidgetData?
|
||||||
|
var lastUpdated: Date?
|
||||||
|
var isLoading: Bool = false
|
||||||
|
var error: String?
|
||||||
|
|
||||||
|
var isRecoveringToken: Bool = false
|
||||||
|
|
||||||
|
private(set) var recoveryAttempted: Bool = false
|
||||||
|
|
||||||
|
private(set) var hasToken: Bool = false
|
||||||
|
|
||||||
|
var needsReauth: Bool {
|
||||||
|
(error == "token_expired" || error == "no_token") && recoveryAttempted && !isRecoveringToken
|
||||||
|
}
|
||||||
|
|
||||||
|
private let appGroupID = "group.app.firkaa.legacy"
|
||||||
|
private let cacheFileName = "watch_data.json"
|
||||||
|
private let lastHandledSessionStateVersionKey = "firka.watch.last_handled_session_state_version"
|
||||||
|
private let lastHandledSessionActiveStudentIdNormKey = "firka.watch.last_handled_session_active_student_id_norm"
|
||||||
|
|
||||||
|
private init() {
|
||||||
|
checkTokenState()
|
||||||
|
loadFromCache()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var hasValidToken: Bool {
|
||||||
|
TokenManager.shared.loadToken() != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkTokenState() {
|
||||||
|
hasToken = TokenManager.shared.loadToken() != nil
|
||||||
|
print("[Watch] Token state updated: hasToken = \(hasToken)")
|
||||||
|
}
|
||||||
|
|
||||||
|
private func parseInt64(_ value: Any?) -> Int64? {
|
||||||
|
if let value = value as? Int64 { return value }
|
||||||
|
if let value = value as? Int { return Int64(value) }
|
||||||
|
if let value = value as? Double { return Int64(value) }
|
||||||
|
if let value = value as? String, let parsed = Int64(value) { return parsed }
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func lastHandledSessionStateVersion() -> Int64 {
|
||||||
|
parseInt64(UserDefaults.standard.object(forKey: lastHandledSessionStateVersionKey)) ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setLastHandledSessionStateVersion(_ value: Int64) {
|
||||||
|
UserDefaults.standard.set(value, forKey: lastHandledSessionStateVersionKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func lastHandledSessionActiveStudentIdNorm() -> Int64? {
|
||||||
|
parseInt64(UserDefaults.standard.object(forKey: lastHandledSessionActiveStudentIdNormKey))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setLastHandledSessionActiveStudentIdNorm(_ value: Int64?) {
|
||||||
|
if let value {
|
||||||
|
UserDefaults.standard.set(value, forKey: lastHandledSessionActiveStudentIdNormKey)
|
||||||
|
} else {
|
||||||
|
UserDefaults.standard.removeObject(forKey: lastHandledSessionActiveStudentIdNormKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func reconcileSharedSessionState() {
|
||||||
|
guard let state = SharedSessionStateManager.shared.loadState() else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let lastVersion = lastHandledSessionStateVersion()
|
||||||
|
guard state.stateVersion > lastVersion else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if !state.hasAnyAccount {
|
||||||
|
print("[Watch] Shared session state: no active iPhone account, clearing watch state")
|
||||||
|
clearAll()
|
||||||
|
resetRecoveryState()
|
||||||
|
setLastHandledSessionStateVersion(state.stateVersion)
|
||||||
|
setLastHandledSessionActiveStudentIdNorm(nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if let activeStudentIdNorm = state.activeStudentIdNorm {
|
||||||
|
let lastHandledActiveStudentIdNorm = lastHandledSessionActiveStudentIdNorm()
|
||||||
|
if lastHandledActiveStudentIdNorm != activeStudentIdNorm {
|
||||||
|
print("[Watch] Shared session switched active account to \(activeStudentIdNorm), clearing stale cache")
|
||||||
|
clearCache()
|
||||||
|
data = nil
|
||||||
|
lastUpdated = nil
|
||||||
|
error = nil
|
||||||
|
recoveryAttempted = false
|
||||||
|
WatchL10n.shared.resetLanguageVersionTracking()
|
||||||
|
}
|
||||||
|
setLastHandledSessionActiveStudentIdNorm(activeStudentIdNorm)
|
||||||
|
} else {
|
||||||
|
setLastHandledSessionActiveStudentIdNorm(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
setLastHandledSessionStateVersion(state.stateVersion)
|
||||||
|
checkTokenState()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Cache Loading
|
||||||
|
|
||||||
|
func loadFromCache() {
|
||||||
|
if let widgetData = WidgetData.load() {
|
||||||
|
self.data = widgetData
|
||||||
|
self.lastUpdated = widgetData.lastUpdated
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let cachedData = loadWatchCache() else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.data = cachedData.widgetData
|
||||||
|
self.lastUpdated = cachedData.lastUpdated
|
||||||
|
}
|
||||||
|
|
||||||
|
private func loadWatchCache() -> CachedWatchData? {
|
||||||
|
guard let containerURL = FileManager.default.containerURL(
|
||||||
|
forSecurityApplicationGroupIdentifier: appGroupID
|
||||||
|
) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let fileURL = containerURL.appendingPathComponent(cacheFileName)
|
||||||
|
|
||||||
|
guard let cacheData = try? Data(contentsOf: fileURL) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let decoder = JSONDecoder()
|
||||||
|
decoder.dateDecodingStrategy = .iso8601
|
||||||
|
|
||||||
|
return try? decoder.decode(CachedWatchData.self, from: cacheData)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func saveToCache(_ data: WidgetData) {
|
||||||
|
guard let containerURL = FileManager.default.containerURL(
|
||||||
|
forSecurityApplicationGroupIdentifier: appGroupID
|
||||||
|
) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let fileURL = containerURL.appendingPathComponent(cacheFileName)
|
||||||
|
let cached = CachedWatchData(widgetData: data, lastUpdated: Date())
|
||||||
|
|
||||||
|
let encoder = JSONEncoder()
|
||||||
|
encoder.dateEncodingStrategy = .iso8601
|
||||||
|
|
||||||
|
do {
|
||||||
|
let encodedData = try encoder.encode(cached)
|
||||||
|
try encodedData.write(to: fileURL)
|
||||||
|
} catch {
|
||||||
|
self.error = "Failed to save cache"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Cache Management
|
||||||
|
|
||||||
|
func clearCache() {
|
||||||
|
guard let containerURL = FileManager.default.containerURL(
|
||||||
|
forSecurityApplicationGroupIdentifier: appGroupID
|
||||||
|
) else { return }
|
||||||
|
|
||||||
|
let fileURL = containerURL.appendingPathComponent(cacheFileName)
|
||||||
|
try? FileManager.default.removeItem(at: fileURL)
|
||||||
|
|
||||||
|
data = nil
|
||||||
|
lastUpdated = nil
|
||||||
|
|
||||||
|
print("[Watch] Cache cleared")
|
||||||
|
}
|
||||||
|
|
||||||
|
func clearAll() {
|
||||||
|
clearCache()
|
||||||
|
error = nil
|
||||||
|
isLoading = false
|
||||||
|
checkTokenState()
|
||||||
|
|
||||||
|
print("[Watch] All data cleared")
|
||||||
|
}
|
||||||
|
|
||||||
|
func clearError() {
|
||||||
|
error = nil
|
||||||
|
print("[Watch] Error cleared")
|
||||||
|
}
|
||||||
|
|
||||||
|
func setReauthRequired() {
|
||||||
|
error = "token_expired"
|
||||||
|
print("[Watch] Reauth required state set")
|
||||||
|
}
|
||||||
|
|
||||||
|
func resetRecoveryState() {
|
||||||
|
recoveryAttempted = false
|
||||||
|
error = nil
|
||||||
|
print("[Watch] Recovery state reset")
|
||||||
|
}
|
||||||
|
|
||||||
|
func attemptTokenRecovery() async -> Bool {
|
||||||
|
guard !isRecoveringToken else {
|
||||||
|
print("[Watch] Token recovery already in progress")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
isRecoveringToken = true
|
||||||
|
recoveryAttempted = false
|
||||||
|
error = nil
|
||||||
|
print("[Watch] Starting token recovery via central method...")
|
||||||
|
|
||||||
|
defer {
|
||||||
|
isRecoveringToken = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if let token = TokenManager.shared.loadToken(), !TokenManager.shared.isTokenExpired() {
|
||||||
|
print("[Watch] Recovery: Token is already valid")
|
||||||
|
checkTokenState()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if let _ = await TokenManager.shared.recoverToken() {
|
||||||
|
print("[Watch] Recovery: Central recovery succeeded")
|
||||||
|
checkTokenState()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
print("[Watch] Recovery: All attempts failed")
|
||||||
|
recoveryAttempted = true
|
||||||
|
self.error = "token_expired"
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
private func refreshComplications() {
|
||||||
|
WidgetCenter.shared.reloadAllTimelines()
|
||||||
|
print("[Watch] Complications refreshed")
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Proactive Token Refresh
|
||||||
|
|
||||||
|
func refreshTokenProactively() async {
|
||||||
|
guard hasValidToken else { return }
|
||||||
|
await TokenManager.shared.refreshTokenProactively()
|
||||||
|
checkTokenState()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Data Refresh
|
||||||
|
|
||||||
|
func refreshAll() async {
|
||||||
|
guard !isLoading else {
|
||||||
|
print("[Watch] DataStore.refreshAll() already in progress, skipping duplicate call")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
print("[Watch] DataStore.refreshAll() called")
|
||||||
|
isLoading = true
|
||||||
|
error = nil
|
||||||
|
|
||||||
|
defer { isLoading = false }
|
||||||
|
|
||||||
|
await TokenManager.shared.refreshTokenProactively()
|
||||||
|
|
||||||
|
guard hasValidToken else {
|
||||||
|
print("[Watch] No valid token, setting error = no_token")
|
||||||
|
error = "no_token"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
let (startOfWeek, endOfWeek) = getCurrentWeekDateRange()
|
||||||
|
|
||||||
|
async let timetableTask = KretaAPIClient.shared.fetchTimetable(
|
||||||
|
from: startOfWeek,
|
||||||
|
to: endOfWeek
|
||||||
|
)
|
||||||
|
async let gradesTask = KretaAPIClient.shared.fetchGrades()
|
||||||
|
|
||||||
|
let (lessons, grades) = try await (timetableTask, gradesTask)
|
||||||
|
|
||||||
|
let timetableData = buildTimetableData(from: lessons)
|
||||||
|
let averagesData = buildAveragesData(from: grades)
|
||||||
|
|
||||||
|
let widgetData = WidgetData(
|
||||||
|
lastUpdated: Date(),
|
||||||
|
locale: Locale.current.language.languageCode?.identifier ?? "hu",
|
||||||
|
theme: "dark",
|
||||||
|
timetable: timetableData,
|
||||||
|
grades: grades,
|
||||||
|
averages: averagesData
|
||||||
|
)
|
||||||
|
|
||||||
|
self.data = widgetData
|
||||||
|
self.lastUpdated = Date()
|
||||||
|
|
||||||
|
saveToCache(widgetData)
|
||||||
|
|
||||||
|
refreshComplications()
|
||||||
|
|
||||||
|
print("[Watch] refreshAll() completed successfully")
|
||||||
|
|
||||||
|
} catch let error as APIError {
|
||||||
|
handleAPIError(error)
|
||||||
|
} catch {
|
||||||
|
print("[Watch] refreshAll() network error: \(error)")
|
||||||
|
self.error = "network"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var isRecoveryInProgress: Bool = false
|
||||||
|
|
||||||
|
func refreshAllWithRecovery() async {
|
||||||
|
guard !isRecoveryInProgress && !isLoading else {
|
||||||
|
print("[Watch] refreshAllWithRecovery() already in progress or refreshAll() running, skipping duplicate call")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
isRecoveryInProgress = true
|
||||||
|
defer { isRecoveryInProgress = false }
|
||||||
|
|
||||||
|
reconcileSharedSessionState()
|
||||||
|
WatchL10n.shared.refreshFromiPhoneAndSharedState()
|
||||||
|
|
||||||
|
let sharedActiveStudentIdNorm = SharedSessionStateManager.shared.loadState()?.activeStudentIdNorm
|
||||||
|
let localStudentIdNorm = TokenManager.shared.loadToken()?.studentIdNorm
|
||||||
|
let shouldRequestTokenFromPhone =
|
||||||
|
!hasValidToken ||
|
||||||
|
(sharedActiveStudentIdNorm != nil && localStudentIdNorm != sharedActiveStudentIdNorm)
|
||||||
|
|
||||||
|
if shouldRequestTokenFromPhone {
|
||||||
|
WatchConnectivityManager.shared.requestTokenFromPhone()
|
||||||
|
try? await Task.sleep(nanoseconds: 2_000_000_000)
|
||||||
|
checkTokenState()
|
||||||
|
}
|
||||||
|
|
||||||
|
await refreshAll()
|
||||||
|
|
||||||
|
guard error == "token_expired" || error == "no_token" else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
print("[Watch] Token issue after refreshAll(), starting auto-recovery flow...")
|
||||||
|
let recovered = await attemptTokenRecovery()
|
||||||
|
if recovered {
|
||||||
|
await refreshAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Handles API errors and maps them to user-friendly messages
|
||||||
|
private func handleAPIError(_ error: APIError) {
|
||||||
|
print("[Watch] handleAPIError: \(error)")
|
||||||
|
switch error {
|
||||||
|
case .tokenError(let tokenError):
|
||||||
|
switch tokenError {
|
||||||
|
case .noToken:
|
||||||
|
print("[Watch] Setting error = no_token")
|
||||||
|
self.error = "no_token"
|
||||||
|
case .refreshExpired, .invalidGrant:
|
||||||
|
print("[Watch] Setting error = token_expired")
|
||||||
|
self.error = "token_expired"
|
||||||
|
case .invalidResponse, .networkError:
|
||||||
|
print("[Watch] Setting error = network (token error)")
|
||||||
|
self.error = "network"
|
||||||
|
}
|
||||||
|
case .unauthorized:
|
||||||
|
print("[Watch] Setting error = token_expired (unauthorized)")
|
||||||
|
self.error = "token_expired"
|
||||||
|
case .requestFailed(let statusCode):
|
||||||
|
if statusCode >= 500 {
|
||||||
|
print("[Watch] Setting error = api_error (server error \(statusCode))")
|
||||||
|
self.error = "api_error"
|
||||||
|
} else {
|
||||||
|
print("[Watch] Setting error = network (request failed \(statusCode))")
|
||||||
|
self.error = "network"
|
||||||
|
}
|
||||||
|
case .decodingFailed, .invalidURL:
|
||||||
|
print("[Watch] Setting error = network")
|
||||||
|
self.error = "network"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Data Processing
|
||||||
|
|
||||||
|
private func buildTimetableData(from lessons: [WidgetLesson]) -> TimetableData {
|
||||||
|
let today = Date()
|
||||||
|
let todayString = formatDateForComparison(today)
|
||||||
|
let tomorrowString = formatDateForComparison(today.addingTimeInterval(86400))
|
||||||
|
|
||||||
|
let todayLessons = lessons.filter { $0.date == todayString }.sorted { $0.start < $1.start }
|
||||||
|
let tomorrowLessons = lessons.filter { $0.date == tomorrowString }.sorted { $0.start < $1.start }
|
||||||
|
|
||||||
|
var nextSchoolDayLessons: [WidgetLesson]? = nil
|
||||||
|
var nextSchoolDayDateString: String? = nil
|
||||||
|
|
||||||
|
for daysOffset in 2...14 {
|
||||||
|
let checkDate = today.addingTimeInterval(TimeInterval(daysOffset * 86400))
|
||||||
|
let checkDateString = formatDateForComparison(checkDate)
|
||||||
|
let checkLessons = lessons.filter { $0.date == checkDateString }
|
||||||
|
|
||||||
|
if !checkLessons.isEmpty {
|
||||||
|
nextSchoolDayLessons = checkLessons.sorted { $0.start < $1.start }
|
||||||
|
nextSchoolDayDateString = checkDateString
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentBreak: BreakInfo? = nil
|
||||||
|
|
||||||
|
return TimetableData(
|
||||||
|
today: todayLessons,
|
||||||
|
tomorrow: tomorrowLessons,
|
||||||
|
nextSchoolDay: nextSchoolDayLessons,
|
||||||
|
nextSchoolDayDate: nextSchoolDayDateString,
|
||||||
|
currentBreak: currentBreak,
|
||||||
|
allLessons: lessons
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builds AveragesData from grades (matching Flutter's calculation)
|
||||||
|
private func buildAveragesData(from grades: [WidgetGrade]) -> AveragesData {
|
||||||
|
guard !grades.isEmpty else {
|
||||||
|
return AveragesData(overall: nil, subjects: [])
|
||||||
|
}
|
||||||
|
|
||||||
|
var subjectGradesMap: [String: [(value: Int, weight: Double)]] = [:]
|
||||||
|
|
||||||
|
for grade in grades {
|
||||||
|
if let numeric = grade.normalizedNumericValue {
|
||||||
|
let key = grade.subject.uid
|
||||||
|
let weight = Double(grade.weightPercentage ?? 100) / 100.0
|
||||||
|
subjectGradesMap[key, default: []].append((value: numeric, weight: weight))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var subjectAverages: [SubjectAverage] = []
|
||||||
|
|
||||||
|
for (uid, gradeValues) in subjectGradesMap {
|
||||||
|
if let firstGrade = grades.first(where: { $0.subject.uid == uid }) {
|
||||||
|
var weightedSum = 0.0
|
||||||
|
var totalWeight = 0.0
|
||||||
|
|
||||||
|
for (value, weight) in gradeValues {
|
||||||
|
weightedSum += Double(value) * weight
|
||||||
|
totalWeight += weight
|
||||||
|
}
|
||||||
|
|
||||||
|
let average = totalWeight > 0 ? weightedSum / totalWeight : Double.nan
|
||||||
|
|
||||||
|
if !average.isNaN {
|
||||||
|
subjectAverages.append(
|
||||||
|
SubjectAverage(
|
||||||
|
uid: uid,
|
||||||
|
name: firstGrade.subject.name,
|
||||||
|
average: average,
|
||||||
|
gradeCount: gradeValues.count
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let overall: Double?
|
||||||
|
if !subjectAverages.isEmpty {
|
||||||
|
let sumOfAverages = subjectAverages.reduce(0.0) { $0 + $1.average }
|
||||||
|
overall = sumOfAverages / Double(subjectAverages.count)
|
||||||
|
} else {
|
||||||
|
overall = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return AveragesData(overall: overall, subjects: subjectAverages)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func getCurrentWeekDateRange() -> (start: Date, end: Date) {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let today = Date()
|
||||||
|
|
||||||
|
let weekday = calendar.component(.weekday, from: today)
|
||||||
|
let daysToMonday = weekday == 1 ? -6 : (2 - weekday)
|
||||||
|
let monday = calendar.date(byAdding: .day, value: daysToMonday, to: today)!
|
||||||
|
|
||||||
|
let nextSunday = calendar.date(byAdding: .day, value: 13, to: monday)!
|
||||||
|
|
||||||
|
return (monday, nextSunday)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func formatDateForComparison(_ date: Date) -> String {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let components = calendar.dateComponents([.year, .month, .day], from: date)
|
||||||
|
return String(format: "%04d-%02d-%02d",
|
||||||
|
components.year ?? 0,
|
||||||
|
components.month ?? 0,
|
||||||
|
components.day ?? 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Computed Helpers
|
||||||
|
|
||||||
|
var timeSinceUpdate: String? {
|
||||||
|
guard let lastUpdated = lastUpdated else { return nil }
|
||||||
|
|
||||||
|
let elapsed = Date().timeIntervalSince(lastUpdated)
|
||||||
|
|
||||||
|
if elapsed < 60 {
|
||||||
|
return "time_now".localized
|
||||||
|
}
|
||||||
|
|
||||||
|
// Minutes
|
||||||
|
let minutes = Int(elapsed / 60)
|
||||||
|
if minutes < 60 {
|
||||||
|
return minutes == 1
|
||||||
|
? "time_since_minutes_one".localized
|
||||||
|
: "time_since_minutes_many".localized(minutes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hours
|
||||||
|
let hours = Int(elapsed / 3600)
|
||||||
|
if hours < 24 {
|
||||||
|
return hours == 1
|
||||||
|
? "time_since_hours_one".localized
|
||||||
|
: "time_since_hours_many".localized(hours)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Days
|
||||||
|
let days = Int(elapsed / 86400)
|
||||||
|
return days == 1
|
||||||
|
? "time_since_days_one".localized
|
||||||
|
: "time_since_days_many".localized(days)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if data is stale (> 1 hour old or never updated)
|
||||||
|
var isStale: Bool {
|
||||||
|
guard let lastUpdated = lastUpdated else { return true }
|
||||||
|
|
||||||
|
let elapsed = Date().timeIntervalSince(lastUpdated)
|
||||||
|
return elapsed > 3600 // 1 hour
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,456 @@
|
|||||||
|
import Foundation
|
||||||
|
import WatchConnectivity
|
||||||
|
|
||||||
|
class WatchConnectivityManager: NSObject, WCSessionDelegate {
|
||||||
|
static let shared = WatchConnectivityManager()
|
||||||
|
private let lastAppliedTokenUpdateKey = "watch_last_applied_token_update_ms"
|
||||||
|
private let minPhoneTokenRequestInterval: TimeInterval = 5
|
||||||
|
private var lastPhoneTokenRequestAt: Date?
|
||||||
|
|
||||||
|
private override init() {
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
private var lastAppliedTokenUpdateMs: Int64 {
|
||||||
|
get {
|
||||||
|
Int64(UserDefaults.standard.double(forKey: lastAppliedTokenUpdateKey))
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
UserDefaults.standard.set(Double(newValue), forKey: lastAppliedTokenUpdateKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func extractSentAtMs(from authDict: [String: Any]) -> Int64? {
|
||||||
|
if let value = authDict["sentAtMs"] as? Int64 {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
if let value = authDict["sentAtMs"] as? Int {
|
||||||
|
return Int64(value)
|
||||||
|
}
|
||||||
|
if let value = authDict["sentAtMs"] as? Double {
|
||||||
|
return Int64(value)
|
||||||
|
}
|
||||||
|
if let value = authDict["sentAtMs"] as? String,
|
||||||
|
let parsed = Int64(value) {
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func parseInt64(_ value: Any?) -> Int64? {
|
||||||
|
if let value = value as? Int64 {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
if let value = value as? Int {
|
||||||
|
return Int64(value)
|
||||||
|
}
|
||||||
|
if let value = value as? Double {
|
||||||
|
return Int64(value)
|
||||||
|
}
|
||||||
|
if let value = value as? String, let parsed = Int64(value) {
|
||||||
|
return parsed
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func activate() {
|
||||||
|
print("[Watch] WatchConnectivityManager.activate() called")
|
||||||
|
if WCSession.isSupported() {
|
||||||
|
print("[Watch] WCSession is supported, activating...")
|
||||||
|
WCSession.default.delegate = self
|
||||||
|
WCSession.default.activate()
|
||||||
|
} else {
|
||||||
|
print("[Watch] WCSession is NOT supported!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func session(
|
||||||
|
_ session: WCSession,
|
||||||
|
activationDidCompleteWith activationState: WCSessionActivationState,
|
||||||
|
error: Error?
|
||||||
|
) {
|
||||||
|
print("[Watch] Session activation completed with state: \(activationState.rawValue)")
|
||||||
|
if let error = error {
|
||||||
|
print("[Watch] Activation error: \(error.localizedDescription)")
|
||||||
|
}
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if activationState == .activated {
|
||||||
|
let context = session.receivedApplicationContext
|
||||||
|
if !context.isEmpty {
|
||||||
|
self.processApplicationContext(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func session(
|
||||||
|
_ session: WCSession,
|
||||||
|
didReceiveApplicationContext applicationContext: [String: Any]
|
||||||
|
) {
|
||||||
|
print("[Watch] didReceiveApplicationContext called")
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.processApplicationContext(applicationContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func session(
|
||||||
|
_ session: WCSession,
|
||||||
|
didReceiveUserInfo userInfo: [String: Any] = [:]
|
||||||
|
) {
|
||||||
|
print("[Watch] didReceiveUserInfo called")
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.processUserInfo(userInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func session(
|
||||||
|
_ session: WCSession,
|
||||||
|
didReceiveMessage message: [String: Any],
|
||||||
|
replyHandler: @escaping ([String: Any]) -> Void
|
||||||
|
) {
|
||||||
|
print("[Watch] didReceiveMessage called: \(message)")
|
||||||
|
|
||||||
|
if let messageId = message["id"] as? String, messageId == "token_update" {
|
||||||
|
if let authDict = message["auth"] as? [String: Any] {
|
||||||
|
print("[Watch] Received immediate token_update via sendMessage")
|
||||||
|
processAuthData(authDict)
|
||||||
|
replyHandler(["success": true])
|
||||||
|
} else {
|
||||||
|
replyHandler(["error": "no_auth"])
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let action = message["action"] as? String else {
|
||||||
|
replyHandler(["error": "no_action"])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch action {
|
||||||
|
case "getToken":
|
||||||
|
handleGetTokenRequest(replyHandler: replyHandler)
|
||||||
|
default:
|
||||||
|
replyHandler(["error": "unknown_action"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleGetTokenRequest(replyHandler: @escaping ([String: Any]) -> Void) {
|
||||||
|
guard TokenManager.shared.loadToken() != nil else {
|
||||||
|
print("[Watch] No token to send to iPhone")
|
||||||
|
replyHandler(["error": "no_token"])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if TokenManager.shared.isTokenExpired() {
|
||||||
|
print("[Watch] Token expired, attempting refresh before sending to iPhone...")
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
let freshToken = try await KretaAPIClient.shared.getValidToken()
|
||||||
|
print("[Watch] Token refresh succeeded, sending fresh token to iPhone")
|
||||||
|
|
||||||
|
var tokenData: [String: Any] = [
|
||||||
|
"studentId": freshToken.studentId,
|
||||||
|
"studentIdNorm": freshToken.studentIdNorm,
|
||||||
|
"iss": freshToken.iss,
|
||||||
|
"idToken": freshToken.idToken,
|
||||||
|
"accessToken": freshToken.accessToken,
|
||||||
|
"refreshToken": freshToken.refreshToken,
|
||||||
|
"expiryDate": Int64(freshToken.expiryDate.timeIntervalSince1970 * 1000)
|
||||||
|
]
|
||||||
|
if let tokenVersion = freshToken.effectiveTokenVersion {
|
||||||
|
tokenData["tokenVersion"] = tokenVersion
|
||||||
|
}
|
||||||
|
tokenData["updatedAtMs"] = freshToken.effectiveUpdatedAtMs ?? Int64(Date().timeIntervalSince1970 * 1000)
|
||||||
|
|
||||||
|
replyHandler(["token": tokenData])
|
||||||
|
} catch {
|
||||||
|
print("[Watch] Token refresh failed after all retries: \(error)")
|
||||||
|
replyHandler(["error": "refresh_failed"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let token = TokenManager.shared.loadToken() else {
|
||||||
|
replyHandler(["error": "no_token"])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var tokenData: [String: Any] = [
|
||||||
|
"studentId": token.studentId,
|
||||||
|
"studentIdNorm": token.studentIdNorm,
|
||||||
|
"iss": token.iss,
|
||||||
|
"idToken": token.idToken,
|
||||||
|
"accessToken": token.accessToken,
|
||||||
|
"refreshToken": token.refreshToken,
|
||||||
|
"expiryDate": Int64(token.expiryDate.timeIntervalSince1970 * 1000)
|
||||||
|
]
|
||||||
|
if let tokenVersion = token.effectiveTokenVersion {
|
||||||
|
tokenData["tokenVersion"] = tokenVersion
|
||||||
|
}
|
||||||
|
tokenData["updatedAtMs"] = token.effectiveUpdatedAtMs ?? Int64(Date().timeIntervalSince1970 * 1000)
|
||||||
|
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "HH:mm:ss"
|
||||||
|
formatter.timeZone = TimeZone.current
|
||||||
|
print("[Watch] Sending token to iPhone, expiry: \(formatter.string(from: token.expiryDate))")
|
||||||
|
replyHandler(["token": tokenData])
|
||||||
|
}
|
||||||
|
|
||||||
|
func requestTokenFromPhone() {
|
||||||
|
guard WCSession.default.activationState == .activated else {
|
||||||
|
print("[Watch] Cannot request token: session not activated")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard WCSession.default.isReachable else {
|
||||||
|
print("[Watch] Cannot request token: iPhone not reachable")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let now = Date()
|
||||||
|
if let lastPhoneTokenRequestAt,
|
||||||
|
now.timeIntervalSince(lastPhoneTokenRequestAt) < minPhoneTokenRequestInterval {
|
||||||
|
print("[Watch] Skipping token request due to cooldown")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lastPhoneTokenRequestAt = now
|
||||||
|
|
||||||
|
print("[Watch] Requesting token from iPhone...")
|
||||||
|
|
||||||
|
WCSession.default.sendMessage(
|
||||||
|
["action": "requestToken"],
|
||||||
|
replyHandler: { response in
|
||||||
|
print("[Watch] Received response from iPhone")
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if let authDict = response["auth"] as? [String: Any] {
|
||||||
|
print("[Watch] Token received from iPhone")
|
||||||
|
self.processAuthData(authDict)
|
||||||
|
} else if let error = response["error"] as? String {
|
||||||
|
print("[Watch] Token request error: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
errorHandler: { error in
|
||||||
|
print("[Watch] Token request failed: \(error.localizedDescription)")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func processApplicationContext(_ context: [String: Any]) {
|
||||||
|
if (context["force_logout"] as? Bool) == true {
|
||||||
|
print("[Watch] Received force_logout via applicationContext")
|
||||||
|
handleForceLogoutFromPhone()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if let authDict = context["auth"] as? [String: Any] {
|
||||||
|
print("[Watch] Received auth from iPhone")
|
||||||
|
processAuthData(authDict)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let language = context["language"] as? String {
|
||||||
|
let sharedStateVersion =
|
||||||
|
parseInt64(context["language_state_version"]) ??
|
||||||
|
parseInt64(context["languageStateVersion"])
|
||||||
|
print("[Watch] Received language from iPhone: \(language)")
|
||||||
|
WatchL10n.shared.updateFromiPhone(
|
||||||
|
languageCode: language,
|
||||||
|
sharedStateVersion: sharedStateVersion
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func processUserInfo(_ userInfo: [String: Any]) {
|
||||||
|
if let messageId = userInfo["id"] as? String {
|
||||||
|
switch messageId {
|
||||||
|
case "token_update":
|
||||||
|
if let authDict = userInfo["auth"] as? [String: Any] {
|
||||||
|
print("[Watch] Received token_update via userInfo")
|
||||||
|
processAuthData(authDict)
|
||||||
|
}
|
||||||
|
case "language_update":
|
||||||
|
if let language = userInfo["language"] as? String {
|
||||||
|
let sharedStateVersion =
|
||||||
|
parseInt64(userInfo["language_state_version"]) ??
|
||||||
|
parseInt64(userInfo["languageStateVersion"])
|
||||||
|
print("[Watch] Received language_update via userInfo: \(language)")
|
||||||
|
WatchL10n.shared.updateFromiPhone(
|
||||||
|
languageCode: language,
|
||||||
|
sharedStateVersion: sharedStateVersion
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case "reauth_required":
|
||||||
|
print("[Watch] Received reauth_required notification from iPhone")
|
||||||
|
DataStore.shared.setReauthRequired()
|
||||||
|
case "force_logout":
|
||||||
|
print("[Watch] Received force_logout notification from iPhone")
|
||||||
|
handleForceLogoutFromPhone()
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleForceLogoutFromPhone() {
|
||||||
|
TokenManager.shared.deleteToken()
|
||||||
|
_ = SharedSessionStateManager.shared.publishState(
|
||||||
|
hasAnyAccount: false,
|
||||||
|
activeStudentIdNorm: nil
|
||||||
|
)
|
||||||
|
DataStore.shared.clearAll()
|
||||||
|
DataStore.shared.resetRecoveryState()
|
||||||
|
DataStore.shared.checkTokenState()
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendTokenToiPhoneInBackground() {
|
||||||
|
guard WCSession.default.activationState == .activated else {
|
||||||
|
print("[Watch] Cannot send token: session not activated")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let token = TokenManager.shared.loadToken() else {
|
||||||
|
print("[Watch] No token to send to iPhone")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var tokenData: [String: Any] = [
|
||||||
|
"studentId": token.studentId,
|
||||||
|
"studentIdNorm": token.studentIdNorm,
|
||||||
|
"iss": token.iss,
|
||||||
|
"idToken": token.idToken,
|
||||||
|
"accessToken": token.accessToken,
|
||||||
|
"refreshToken": token.refreshToken,
|
||||||
|
"expiryDate": Int64(token.expiryDate.timeIntervalSince1970 * 1000)
|
||||||
|
]
|
||||||
|
if let tokenVersion = token.effectiveTokenVersion {
|
||||||
|
tokenData["tokenVersion"] = tokenVersion
|
||||||
|
}
|
||||||
|
tokenData["updatedAtMs"] = token.effectiveUpdatedAtMs ?? Int64(Date().timeIntervalSince1970 * 1000)
|
||||||
|
|
||||||
|
do {
|
||||||
|
try WCSession.default.updateApplicationContext(["auth": tokenData])
|
||||||
|
print("[Watch] Token sent via applicationContext")
|
||||||
|
} catch {
|
||||||
|
print("[Watch] Failed to update applicationContext: \(error)")
|
||||||
|
}
|
||||||
|
|
||||||
|
WCSession.default.transferUserInfo([
|
||||||
|
"id": "token_update_from_watch",
|
||||||
|
"auth": tokenData
|
||||||
|
])
|
||||||
|
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "HH:mm:ss"
|
||||||
|
formatter.timeZone = TimeZone.current
|
||||||
|
print("[Watch] Token sent to iPhone (background), expiry: \(formatter.string(from: token.expiryDate))")
|
||||||
|
}
|
||||||
|
|
||||||
|
func requestLanguageFromPhone() {
|
||||||
|
guard WCSession.default.activationState == .activated else {
|
||||||
|
print("[Watch] Cannot request language: session not activated")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard WCSession.default.isReachable else {
|
||||||
|
print("[Watch] Cannot request language: iPhone not reachable")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
print("[Watch] Requesting language from iPhone...")
|
||||||
|
|
||||||
|
WCSession.default.sendMessage(
|
||||||
|
["action": "requestLanguage"],
|
||||||
|
replyHandler: { response in
|
||||||
|
print("[Watch] Received language response from iPhone")
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if let language = response["language"] as? String {
|
||||||
|
let sharedStateVersion =
|
||||||
|
self.parseInt64(response["language_state_version"]) ??
|
||||||
|
self.parseInt64(response["languageStateVersion"])
|
||||||
|
print("[Watch] Language received from iPhone: \(language)")
|
||||||
|
WatchL10n.shared.updateFromiPhone(
|
||||||
|
languageCode: language,
|
||||||
|
sharedStateVersion: sharedStateVersion
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
errorHandler: { error in
|
||||||
|
print("[Watch] Language request failed: \(error.localizedDescription)")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func processAuthData(_ authDict: [String: Any]) {
|
||||||
|
print("[Watch] processAuthData called")
|
||||||
|
do {
|
||||||
|
let incomingSentAtMs = extractSentAtMs(from: authDict) ?? 0
|
||||||
|
let previousSentAtMs = lastAppliedTokenUpdateMs
|
||||||
|
|
||||||
|
if incomingSentAtMs > 0 && incomingSentAtMs < previousSentAtMs {
|
||||||
|
print("[Watch] Ignoring stale token_update (sentAtMs: \(incomingSentAtMs), lastApplied: \(previousSentAtMs))")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let jsonData = try JSONSerialization.data(withJSONObject: authDict)
|
||||||
|
|
||||||
|
let decoder = JSONDecoder()
|
||||||
|
decoder.dateDecodingStrategy = .custom { decoder in
|
||||||
|
let container = try decoder.singleValueContainer()
|
||||||
|
let timestamp = try container.decode(Int64.self)
|
||||||
|
return Date(timeIntervalSince1970: Double(timestamp) / 1000.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
let token = try decoder.decode(WatchToken.self, from: jsonData)
|
||||||
|
let currentToken = TokenManager.shared.loadToken()
|
||||||
|
|
||||||
|
let isAccountSwitch = currentToken != nil && !token.isSameAccount(as: currentToken!)
|
||||||
|
let shouldForceAccountSwitch: Bool
|
||||||
|
if isAccountSwitch {
|
||||||
|
if incomingSentAtMs > 0 {
|
||||||
|
shouldForceAccountSwitch = true
|
||||||
|
} else {
|
||||||
|
shouldForceAccountSwitch = token.isNewer(than: currentToken!)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
shouldForceAccountSwitch = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if incomingSentAtMs <= 0,
|
||||||
|
let currentToken,
|
||||||
|
!isAccountSwitch,
|
||||||
|
!token.isNewer(than: currentToken) {
|
||||||
|
print("[Watch] Ignoring stale token_update without sentAtMs (same account, not newer)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
print("[Watch] Token decoded, saving... (sentAtMs: \(incomingSentAtMs), forceSwitch: \(shouldForceAccountSwitch))")
|
||||||
|
|
||||||
|
try TokenManager.shared.saveToken(
|
||||||
|
token,
|
||||||
|
syncToSharedKeychain: false,
|
||||||
|
forceAccountSwitch: shouldForceAccountSwitch
|
||||||
|
)
|
||||||
|
print("[Watch] Token saved successfully")
|
||||||
|
_ = SharedSessionStateManager.shared.publishState(
|
||||||
|
hasAnyAccount: true,
|
||||||
|
activeStudentIdNorm: token.studentIdNorm
|
||||||
|
)
|
||||||
|
if incomingSentAtMs > 0 {
|
||||||
|
lastAppliedTokenUpdateMs = max(previousSentAtMs, incomingSentAtMs)
|
||||||
|
}
|
||||||
|
|
||||||
|
DataStore.shared.clearError()
|
||||||
|
DataStore.shared.resetRecoveryState()
|
||||||
|
DataStore.shared.checkTokenState()
|
||||||
|
|
||||||
|
Task {
|
||||||
|
await DataStore.shared.refreshAllWithRecovery()
|
||||||
|
print("[Watch] Data refresh completed")
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
print("[Watch] Failed to process auth data: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
119
firka/ios/FirkaWatch Watch App/Views/GradeSubjectView.swift
Normal file
119
firka/ios/FirkaWatch Watch App/Views/GradeSubjectView.swift
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct GradeSubjectView: View {
|
||||||
|
let subjectName: String
|
||||||
|
let grades: [WidgetGrade]
|
||||||
|
let average: Double
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ScrollView {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
FirkaCard {
|
||||||
|
HStack {
|
||||||
|
Text("average".localized)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
Text(String(format: "%.2f", average))
|
||||||
|
.font(.headline)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.foregroundColor(averageColor(average))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ForEach(groupedGrades, id: \.date) { group in
|
||||||
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
|
Text(formatDate(group.date))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
|
||||||
|
ForEach(group.grades) { grade in
|
||||||
|
gradeRow(grade)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
.navigationTitle(subjectName)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var groupedGrades: [(date: Date, grades: [WidgetGrade])] {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let grouped = Dictionary(grouping: grades) { grade in
|
||||||
|
calendar.startOfDay(for: grade.recordDate)
|
||||||
|
}
|
||||||
|
return grouped
|
||||||
|
.map { (date: $0.key, grades: $0.value) }
|
||||||
|
.sorted { $0.date > $1.date }
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func gradeRow(_ grade: WidgetGrade) -> some View {
|
||||||
|
FirkaCard {
|
||||||
|
HStack(alignment: .top, spacing: 10) {
|
||||||
|
if let normalizedValue = grade.normalizedNumericValue {
|
||||||
|
if grade.isPercentageGrade, let rawValue = grade.numericValue {
|
||||||
|
ZStack {
|
||||||
|
Circle()
|
||||||
|
.fill(gradeColor(normalizedValue))
|
||||||
|
.frame(width: 32, height: 32)
|
||||||
|
Text("\(rawValue)%")
|
||||||
|
.font(.system(size: 10, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
GradeBadge(grade: normalizedValue)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Text(grade.displayValue)
|
||||||
|
.font(.caption)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.padding(6)
|
||||||
|
.background(Color.gray)
|
||||||
|
.cornerRadius(12)
|
||||||
|
}
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text(grade.displayTypeWithWeight)
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(.medium)
|
||||||
|
|
||||||
|
if let topic = grade.topic, !topic.isEmpty {
|
||||||
|
Text(topic)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.lineLimit(2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func gradeColor(_ value: Int) -> Color {
|
||||||
|
switch value {
|
||||||
|
case 5: return .green
|
||||||
|
case 4: return .blue
|
||||||
|
case 3: return .yellow
|
||||||
|
case 2: return .orange
|
||||||
|
default: return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func formatDate(_ date: Date) -> String {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "yyyy. MM. dd."
|
||||||
|
return formatter.string(from: date)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func averageColor(_ avg: Double) -> Color {
|
||||||
|
switch avg {
|
||||||
|
case 4.5...: return .green
|
||||||
|
case 3.5..<4.5: return .blue
|
||||||
|
case 2.5..<3.5: return .yellow
|
||||||
|
case 1.5..<2.5: return .orange
|
||||||
|
default: return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
108
firka/ios/FirkaWatch Watch App/Views/GradesView.swift
Normal file
108
firka/ios/FirkaWatch Watch App/Views/GradesView.swift
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct GradesView: View {
|
||||||
|
let dataStore: DataStore
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
NavigationStack {
|
||||||
|
if dataStore.data == nil {
|
||||||
|
ContentUnavailableView("no_data".localized, systemImage: "graduationcap")
|
||||||
|
} else if subjects.isEmpty {
|
||||||
|
ContentUnavailableView("no_grades".localized, systemImage: "graduationcap")
|
||||||
|
} else {
|
||||||
|
ScrollView {
|
||||||
|
VStack(spacing: 8) {
|
||||||
|
ForEach(subjects, id: \.uid) { subject in
|
||||||
|
NavigationLink {
|
||||||
|
GradeSubjectView(
|
||||||
|
subjectName: subject.name,
|
||||||
|
grades: gradesFor(subject.uid),
|
||||||
|
average: subject.average
|
||||||
|
)
|
||||||
|
} label: {
|
||||||
|
subjectRow(subject)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let overall = dataStore.data?.averages.overall {
|
||||||
|
overallAverageCard(overall)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var subjects: [SubjectAverage] {
|
||||||
|
(dataStore.data?.averages.subjects ?? []).sorted { $0.name < $1.name }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func gradesFor(_ uid: String) -> [WidgetGrade] {
|
||||||
|
dataStore.data?.grades.filter { $0.subject.uid == uid } ?? []
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func subjectRow(_ subject: SubjectAverage) -> some View {
|
||||||
|
FirkaCard {
|
||||||
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
|
HStack {
|
||||||
|
Text(subject.name)
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(.medium)
|
||||||
|
.lineLimit(1)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Text(String(format: "%.2f", subject.average))
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.foregroundColor(averageColor(subject.average))
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack(spacing: 8) {
|
||||||
|
AverageProgressBar(average: subject.average)
|
||||||
|
|
||||||
|
Text("grades_count".localized(subject.gradeCount))
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func overallAverageCard(_ average: Double) -> some View {
|
||||||
|
FirkaCard {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text("total_average".localized)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Text(String(format: "%.2f", average))
|
||||||
|
.font(.title3)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.foregroundColor(averageColor(average))
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
AverageProgressBar(average: average)
|
||||||
|
.frame(width: 60)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.top, 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func averageColor(_ avg: Double) -> Color {
|
||||||
|
switch avg {
|
||||||
|
case 4.5...: return .green
|
||||||
|
case 3.5..<4.5: return .blue
|
||||||
|
case 2.5..<3.5: return .yellow
|
||||||
|
case 1.5..<2.5: return .orange
|
||||||
|
default: return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
598
firka/ios/FirkaWatch Watch App/Views/HomeView.swift
Normal file
598
firka/ios/FirkaWatch Watch App/Views/HomeView.swift
Normal file
@@ -0,0 +1,598 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import WatchConnectivity
|
||||||
|
internal import Combine
|
||||||
|
|
||||||
|
struct HomeView: View {
|
||||||
|
let dataStore: DataStore
|
||||||
|
@State private var currentTime = Date()
|
||||||
|
|
||||||
|
private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ScrollView {
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
if let breakInfo = dataStore.data?.timetable.currentBreak {
|
||||||
|
breakView(breakInfo)
|
||||||
|
} else if !dataStore.hasToken && dataStore.data == nil {
|
||||||
|
noTokenView
|
||||||
|
} else if let current = currentLesson {
|
||||||
|
currentLessonView(current)
|
||||||
|
} else if let next = nextLesson {
|
||||||
|
if isBreakBetweenLessons {
|
||||||
|
breakBetweenView(next)
|
||||||
|
} else {
|
||||||
|
beforeSchoolView(next)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
noMoreLessonsView
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshButton
|
||||||
|
|
||||||
|
if dataStore.lastUpdated != nil {
|
||||||
|
lastUpdatedView
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
.onReceive(timer) { _ in
|
||||||
|
currentTime = Date()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Refresh Button
|
||||||
|
|
||||||
|
@State private var refreshStatus: RefreshStatus = .idle
|
||||||
|
@State private var wasLoadingFromBackground: Bool = false
|
||||||
|
@State private var lastUpdateTime: Date? = nil
|
||||||
|
|
||||||
|
enum RefreshStatus {
|
||||||
|
case idle, loading, success, failure
|
||||||
|
}
|
||||||
|
|
||||||
|
private var refreshButton: some View {
|
||||||
|
Button(action: {
|
||||||
|
guard !dataStore.isLoading else { return }
|
||||||
|
Task {
|
||||||
|
refreshStatus = .loading
|
||||||
|
await dataStore.refreshAllWithRecovery()
|
||||||
|
if dataStore.error == nil && dataStore.data != nil {
|
||||||
|
refreshStatus = .success
|
||||||
|
} else {
|
||||||
|
refreshStatus = .failure
|
||||||
|
}
|
||||||
|
try? await Task.sleep(nanoseconds: 2_000_000_000)
|
||||||
|
refreshStatus = .idle
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
HStack(spacing: 6) {
|
||||||
|
if dataStore.isLoading && refreshStatus != .loading {
|
||||||
|
ProgressView()
|
||||||
|
.scaleEffect(0.8)
|
||||||
|
} else {
|
||||||
|
switch refreshStatus {
|
||||||
|
case .idle:
|
||||||
|
Image(systemName: "arrow.clockwise")
|
||||||
|
case .loading:
|
||||||
|
ProgressView()
|
||||||
|
.scaleEffect(0.8)
|
||||||
|
case .success:
|
||||||
|
Image(systemName: "checkmark.circle.fill")
|
||||||
|
.foregroundColor(.green)
|
||||||
|
case .failure:
|
||||||
|
Image(systemName: "xmark.circle.fill")
|
||||||
|
.foregroundColor(.red)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Text(refreshStatusText)
|
||||||
|
}
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.blue)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.disabled(dataStore.isLoading || refreshStatus == .loading)
|
||||||
|
.padding(.top, 8)
|
||||||
|
.onChange(of: dataStore.isLoading) { oldValue, newValue in
|
||||||
|
if newValue && refreshStatus != .loading {
|
||||||
|
wasLoadingFromBackground = true
|
||||||
|
}
|
||||||
|
if !newValue && wasLoadingFromBackground && refreshStatus != .loading {
|
||||||
|
wasLoadingFromBackground = false
|
||||||
|
if dataStore.error == nil && dataStore.data != nil {
|
||||||
|
refreshStatus = .success
|
||||||
|
} else if dataStore.error != nil {
|
||||||
|
refreshStatus = .failure
|
||||||
|
}
|
||||||
|
Task {
|
||||||
|
try? await Task.sleep(nanoseconds: 2_000_000_000)
|
||||||
|
if refreshStatus == .success || refreshStatus == .failure {
|
||||||
|
refreshStatus = .idle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onChange(of: dataStore.lastUpdated) { oldValue, newValue in
|
||||||
|
guard let oldValue, let newValue else { return }
|
||||||
|
guard newValue > oldValue else { return }
|
||||||
|
guard dataStore.error == nil else { return }
|
||||||
|
guard refreshStatus != .loading else { return }
|
||||||
|
|
||||||
|
refreshStatus = .success
|
||||||
|
Task {
|
||||||
|
try? await Task.sleep(nanoseconds: 2_000_000_000)
|
||||||
|
if refreshStatus == .success {
|
||||||
|
refreshStatus = .idle
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var refreshStatusText: String {
|
||||||
|
if dataStore.isLoading && refreshStatus != .loading {
|
||||||
|
return "refreshing".localized
|
||||||
|
}
|
||||||
|
|
||||||
|
switch refreshStatus {
|
||||||
|
case .idle: return "refresh".localized
|
||||||
|
case .loading: return "refreshing".localized
|
||||||
|
case .success: return "refresh_success".localized
|
||||||
|
case .failure:
|
||||||
|
if let error = dataStore.error {
|
||||||
|
switch error {
|
||||||
|
case "api_error": return "error_api".localized
|
||||||
|
case "network": return "error_network".localized
|
||||||
|
case "token_expired", "no_token": return "reauth_required".localized
|
||||||
|
default: return "refresh_failed".localized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "refresh_failed".localized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Computed Properties
|
||||||
|
|
||||||
|
private var now: Date { currentTime }
|
||||||
|
|
||||||
|
private var todayLessons: [WidgetLesson] {
|
||||||
|
let todayStr = formatDateForHomeView(currentTime)
|
||||||
|
|
||||||
|
if let allLessons = dataStore.data?.timetable.allLessons, !allLessons.isEmpty {
|
||||||
|
return allLessons
|
||||||
|
.filter { $0.date == todayStr }
|
||||||
|
.sorted { $0.start < $1.start }
|
||||||
|
}
|
||||||
|
|
||||||
|
return dataStore.data?.timetable.today ?? []
|
||||||
|
}
|
||||||
|
|
||||||
|
private var currentLesson: WidgetLesson? {
|
||||||
|
todayLessons.first { currentTime >= $0.start && currentTime <= $0.end }
|
||||||
|
}
|
||||||
|
|
||||||
|
private var nextLesson: WidgetLesson? {
|
||||||
|
todayLessons
|
||||||
|
.filter { $0.start > currentTime }
|
||||||
|
.sorted { $0.start < $1.start }
|
||||||
|
.first
|
||||||
|
}
|
||||||
|
|
||||||
|
private var previousLesson: WidgetLesson? {
|
||||||
|
todayLessons
|
||||||
|
.filter { $0.end < currentTime }
|
||||||
|
.sorted { $0.end > $1.end }
|
||||||
|
.first
|
||||||
|
}
|
||||||
|
|
||||||
|
private var isBreakBetweenLessons: Bool {
|
||||||
|
guard let prev = previousLesson, let next = nextLesson else { return false }
|
||||||
|
return currentTime > prev.end && currentTime < next.start
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Current Lesson View (with CountdownRing)
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func currentLessonView(_ lesson: WidgetLesson) -> some View {
|
||||||
|
VStack(spacing: 10) {
|
||||||
|
Text("current_lesson".localized)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
|
||||||
|
let totalMinutes = Int(lesson.end.timeIntervalSince(lesson.start) / 60)
|
||||||
|
let remaining = max(0, Int(lesson.end.timeIntervalSince(now) / 60))
|
||||||
|
|
||||||
|
HStack(spacing: 10) {
|
||||||
|
CountdownRing(
|
||||||
|
totalMinutes: totalMinutes,
|
||||||
|
remainingMinutes: remaining,
|
||||||
|
label: "minutes".localized,
|
||||||
|
size: 56,
|
||||||
|
lineWidth: 6,
|
||||||
|
displayOffset: 1
|
||||||
|
)
|
||||||
|
.id("lesson-\(lesson.start.timeIntervalSince1970)")
|
||||||
|
FirkaCard(
|
||||||
|
isHighlighted: true,
|
||||||
|
backgroundColor: lessonCardBackgroundColor(
|
||||||
|
for: lesson,
|
||||||
|
isHighlighted: true
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
lessonTitleWithStatus(
|
||||||
|
lesson,
|
||||||
|
font: .subheadline,
|
||||||
|
weight: .semibold,
|
||||||
|
lineLimit: 2
|
||||||
|
)
|
||||||
|
|
||||||
|
HStack(spacing: 6) {
|
||||||
|
if let room = lesson.roomName {
|
||||||
|
Label(room, systemImage: "door.right.hand.closed")
|
||||||
|
}
|
||||||
|
Text(lesson.timeString)
|
||||||
|
}
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next lesson preview
|
||||||
|
if let next = nextLesson {
|
||||||
|
Text("next".localized)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
|
||||||
|
FirkaCard(backgroundColor: lessonCardBackgroundColor(for: next)) {
|
||||||
|
HStack {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
lessonTitleWithStatus(
|
||||||
|
next,
|
||||||
|
font: .subheadline,
|
||||||
|
weight: .regular,
|
||||||
|
lineLimit: 2
|
||||||
|
)
|
||||||
|
if let room = next.roomName {
|
||||||
|
Text(room)
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
Text(next.start, style: .time)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Break Between Lessons (with CountdownRing)
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func breakBetweenView(_ next: WidgetLesson) -> some View {
|
||||||
|
VStack(spacing: 10) {
|
||||||
|
Text("break".localized)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
|
||||||
|
let remaining = max(0, Int(ceil(next.start.timeIntervalSince(now) / 60)))
|
||||||
|
let totalBreakMinutes: Int = {
|
||||||
|
guard let previous = previousLesson else { return max(remaining, 1) }
|
||||||
|
let breakSeconds = max(60, next.start.timeIntervalSince(previous.end))
|
||||||
|
return max(1, Int(ceil(breakSeconds / 60)))
|
||||||
|
}()
|
||||||
|
|
||||||
|
HStack(spacing: 10) {
|
||||||
|
CountdownRing(
|
||||||
|
totalMinutes: totalBreakMinutes,
|
||||||
|
remainingMinutes: remaining,
|
||||||
|
label: "minutes".localized,
|
||||||
|
size: 56,
|
||||||
|
lineWidth: 6,
|
||||||
|
displayOffset: 1
|
||||||
|
)
|
||||||
|
.id("break-\(next.start.timeIntervalSince1970)")
|
||||||
|
|
||||||
|
FirkaCard(backgroundColor: lessonCardBackgroundColor(for: next)) {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text("next_lesson".localized(next.displayName))
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.lineLimit(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack(spacing: 6) {
|
||||||
|
if let room = next.roomName {
|
||||||
|
Label(room, systemImage: "door.right.hand.closed")
|
||||||
|
}
|
||||||
|
Text(next.start, style: .time)
|
||||||
|
}
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Before School View
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func beforeSchoolView(_ first: WidgetLesson) -> some View {
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
Text("first_lesson".localized)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
|
||||||
|
FirkaCard(backgroundColor: lessonCardBackgroundColor(for: first)) {
|
||||||
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
|
lessonTitleWithStatus(
|
||||||
|
first,
|
||||||
|
font: .headline,
|
||||||
|
weight: .regular,
|
||||||
|
lineLimit: 2
|
||||||
|
)
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
if let room = first.roomName {
|
||||||
|
Label(room, systemImage: "door.right.hand.closed")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Text(relativeTimeString(to: first.start))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.blue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !todayLessons.isEmpty {
|
||||||
|
Text("today_lessons_count".localized(todayLessons.count))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - No More Lessons View
|
||||||
|
|
||||||
|
private var noMoreLessonsView: some View {
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
Image(systemName: "checkmark.circle.fill")
|
||||||
|
.font(.system(size: 44))
|
||||||
|
.foregroundColor(.green)
|
||||||
|
|
||||||
|
Text("no_more_lessons".localized)
|
||||||
|
.font(.headline)
|
||||||
|
|
||||||
|
if let (nextLesson, dayLabel) = nextSchoolDayFirstLesson {
|
||||||
|
Text(dayLabel)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.padding(.top, 8)
|
||||||
|
|
||||||
|
FirkaCard(backgroundColor: lessonCardBackgroundColor(for: nextLesson)) {
|
||||||
|
HStack {
|
||||||
|
lessonTitleWithStatus(
|
||||||
|
nextLesson,
|
||||||
|
font: .subheadline,
|
||||||
|
weight: .regular,
|
||||||
|
lineLimit: 2
|
||||||
|
)
|
||||||
|
Spacer()
|
||||||
|
Text(nextLesson.start, style: .time)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var nextSchoolDayFirstLesson: (lesson: WidgetLesson, label: String)? {
|
||||||
|
guard let allLessons = dataStore.data?.timetable.allLessons, !allLessons.isEmpty else {
|
||||||
|
if let tomorrow = dataStore.data?.timetable.tomorrow.first {
|
||||||
|
return (tomorrow, "tomorrow_first_lesson".localized)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let now = currentTime
|
||||||
|
let todayStr = formatDateForHomeView(now)
|
||||||
|
|
||||||
|
let futureLessons = allLessons.filter { $0.date > todayStr }
|
||||||
|
.sorted { $0.date < $1.date || ($0.date == $1.date && $0.start < $1.start) }
|
||||||
|
|
||||||
|
guard let firstFuture = futureLessons.first else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let label = labelForDate(firstFuture.date, relativeTo: now)
|
||||||
|
|
||||||
|
return (firstFuture, label)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func formatDateForHomeView(_ date: Date) -> String {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let components = calendar.dateComponents([.year, .month, .day], from: date)
|
||||||
|
return String(format: "%04d-%02d-%02d",
|
||||||
|
components.year ?? 0,
|
||||||
|
components.month ?? 0,
|
||||||
|
components.day ?? 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func labelForDate(_ dateStr: String, relativeTo: Date) -> String {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "yyyy-MM-dd"
|
||||||
|
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||||
|
formatter.timeZone = TimeZone.current
|
||||||
|
|
||||||
|
guard let targetDate = formatter.date(from: dateStr) else {
|
||||||
|
return "next_school_day".localized
|
||||||
|
}
|
||||||
|
|
||||||
|
let today = calendar.startOfDay(for: relativeTo)
|
||||||
|
let target = calendar.startOfDay(for: targetDate)
|
||||||
|
|
||||||
|
let daysDiff = calendar.dateComponents([.day], from: today, to: target).day ?? 0
|
||||||
|
|
||||||
|
switch daysDiff {
|
||||||
|
case 1:
|
||||||
|
return "tomorrow_first_lesson".localized
|
||||||
|
case 2...6:
|
||||||
|
let dayFormatter = DateFormatter()
|
||||||
|
let langCode = WatchL10n.shared.currentLanguage.rawValue
|
||||||
|
dayFormatter.locale = Locale(identifier: langCode)
|
||||||
|
dayFormatter.dateFormat = "EEEE"
|
||||||
|
let dayName = dayFormatter.string(from: targetDate).capitalized
|
||||||
|
return "day_first_lesson".localized(dayName)
|
||||||
|
default:
|
||||||
|
return "next_school_day".localized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func lessonTitleWithStatus(
|
||||||
|
_ lesson: WidgetLesson,
|
||||||
|
font: Font,
|
||||||
|
weight: Font.Weight = .regular,
|
||||||
|
lineLimit: Int = 2
|
||||||
|
) -> some View {
|
||||||
|
Text(lesson.displayName)
|
||||||
|
.font(font)
|
||||||
|
.fontWeight(weight)
|
||||||
|
.lineLimit(lineLimit)
|
||||||
|
.foregroundColor(lessonPrimaryTextColor(for: lesson))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func lessonPrimaryTextColor(for lesson: WidgetLesson) -> Color {
|
||||||
|
if lesson.isCancelled {
|
||||||
|
return .red
|
||||||
|
}
|
||||||
|
if lesson.isSubstitution {
|
||||||
|
return .yellow
|
||||||
|
}
|
||||||
|
return .primary
|
||||||
|
}
|
||||||
|
|
||||||
|
private func lessonCardBackgroundColor(
|
||||||
|
for lesson: WidgetLesson,
|
||||||
|
isHighlighted: Bool = false
|
||||||
|
) -> Color {
|
||||||
|
if lesson.isCancelled {
|
||||||
|
return Color.red.opacity(0.16)
|
||||||
|
}
|
||||||
|
if lesson.isSubstitution {
|
||||||
|
return Color.yellow.opacity(0.16)
|
||||||
|
}
|
||||||
|
if isHighlighted {
|
||||||
|
return Color.green.opacity(0.2)
|
||||||
|
}
|
||||||
|
return Color(white: 0.12)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Break/Vacation View
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func breakView(_ breakInfo: BreakInfo) -> some View {
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
let icon = SeasonalIconHelper.iconName(for: breakInfo.nameKey, season: nil)
|
||||||
|
let color = SeasonalIconHelper.iconColor(for: breakInfo.nameKey, season: nil)
|
||||||
|
|
||||||
|
Image(systemName: icon)
|
||||||
|
.font(.system(size: 44))
|
||||||
|
.foregroundColor(color)
|
||||||
|
|
||||||
|
Text(breakInfo.name)
|
||||||
|
.font(.headline)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - No Token View
|
||||||
|
|
||||||
|
private var isWatchSystemPaired: Bool {
|
||||||
|
guard WCSession.isSupported() else { return false }
|
||||||
|
return WCSession.default.isCompanionAppInstalled
|
||||||
|
}
|
||||||
|
|
||||||
|
private var noTokenTitleKey: String {
|
||||||
|
isWatchSystemPaired ? "login_on_iphone" : "pair_with_iphone"
|
||||||
|
}
|
||||||
|
|
||||||
|
private var noTokenDescriptionKey: String {
|
||||||
|
isWatchSystemPaired ? "open_and_login_on_iphone" : "open_firka_on_iphone"
|
||||||
|
}
|
||||||
|
|
||||||
|
private var noTokenIconName: String {
|
||||||
|
isWatchSystemPaired
|
||||||
|
? "person.crop.circle.badge.exclamationmark"
|
||||||
|
: "iphone.and.arrow.right.inward"
|
||||||
|
}
|
||||||
|
|
||||||
|
private var noTokenView: some View {
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
Image(systemName: noTokenIconName)
|
||||||
|
.font(.system(size: 44))
|
||||||
|
.foregroundColor(.blue)
|
||||||
|
|
||||||
|
Text(noTokenTitleKey.localized)
|
||||||
|
.font(.headline)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
|
||||||
|
Text(noTokenDescriptionKey.localized)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Last Updated View
|
||||||
|
|
||||||
|
private var lastUpdatedView: some View {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
if dataStore.isStale {
|
||||||
|
Image(systemName: "exclamationmark.triangle.fill")
|
||||||
|
.foregroundColor(.yellow)
|
||||||
|
}
|
||||||
|
if let text = dataStore.timeSinceUpdate {
|
||||||
|
Text("updated".localized(text))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.padding(.top, 8)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Relative Time Helper
|
||||||
|
|
||||||
|
private func relativeTimeString(to date: Date) -> String {
|
||||||
|
let now = currentTime
|
||||||
|
let interval = date.timeIntervalSince(now)
|
||||||
|
|
||||||
|
guard interval > 0 else {
|
||||||
|
return "time_now".localized
|
||||||
|
}
|
||||||
|
|
||||||
|
let totalMinutes = Int(interval / 60)
|
||||||
|
let hours = totalMinutes / 60
|
||||||
|
let minutes = totalMinutes % 60
|
||||||
|
|
||||||
|
if hours > 0 && minutes > 0 {
|
||||||
|
return "time_hours_minutes".localized(hours, minutes)
|
||||||
|
} else if hours > 0 {
|
||||||
|
return "time_hours".localized(hours)
|
||||||
|
} else {
|
||||||
|
return "time_minutes_only".localized(minutes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
109
firka/ios/FirkaWatch Watch App/Views/LessonDetailView.swift
Normal file
109
firka/ios/FirkaWatch Watch App/Views/LessonDetailView.swift
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct LessonDetailView: View {
|
||||||
|
let lesson: WidgetLesson
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ScrollView {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
HStack {
|
||||||
|
if let number = lesson.lessonNumber {
|
||||||
|
Text("lesson_number".localized(number))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.blue)
|
||||||
|
.padding(.horizontal, 8)
|
||||||
|
.padding(.vertical, 4)
|
||||||
|
.background(Color.blue.opacity(0.2))
|
||||||
|
.cornerRadius(8)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Text("\(formatTime(lesson.start)) - \(formatTime(lesson.end))")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(lesson.displayName)
|
||||||
|
.font(.headline)
|
||||||
|
.lineLimit(3)
|
||||||
|
|
||||||
|
if lesson.isCancelled || lesson.isSubstitution {
|
||||||
|
HStack(spacing: 8) {
|
||||||
|
if lesson.isCancelled {
|
||||||
|
Label("cancelled".localized, systemImage: "xmark.circle.fill")
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.red)
|
||||||
|
}
|
||||||
|
if lesson.isSubstitution {
|
||||||
|
Label("substitution".localized, systemImage: "person.2.fill")
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.orange)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 10) {
|
||||||
|
if lesson.isSubstitution, let substitute = lesson.substituteTeacher {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Label("teacher".localized, systemImage: "person.fill")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
|
||||||
|
if let original = lesson.teacher {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(original)
|
||||||
|
.strikethrough()
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
Text("→")
|
||||||
|
.foregroundColor(.orange)
|
||||||
|
Text(substitute)
|
||||||
|
.foregroundColor(.orange)
|
||||||
|
}
|
||||||
|
.font(.subheadline)
|
||||||
|
} else {
|
||||||
|
Text(substitute)
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundColor(.orange)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if let teacher = lesson.teacher {
|
||||||
|
detailRow(icon: "person.fill", label: "teacher".localized, value: teacher)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let room = lesson.roomName {
|
||||||
|
detailRow(icon: "door.right.hand.closed", label: "room".localized, value: room)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let theme = lesson.theme, !theme.isEmpty {
|
||||||
|
detailRow(icon: "doc.text.fill", label: "topic".localized, value: theme)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
.navigationTitle("lesson_details".localized)
|
||||||
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func detailRow(icon: String, label: String, value: String) -> some View {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Label(label, systemImage: icon)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
|
||||||
|
Text(value)
|
||||||
|
.font(.subheadline)
|
||||||
|
.lineLimit(5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func formatTime(_ date: Date) -> String {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "HH:mm"
|
||||||
|
return formatter.string(from: date)
|
||||||
|
}
|
||||||
|
}
|
||||||
308
firka/ios/FirkaWatch Watch App/Views/ReauthRequiredView.swift
Normal file
308
firka/ios/FirkaWatch Watch App/Views/ReauthRequiredView.swift
Normal file
@@ -0,0 +1,308 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import WatchConnectivity
|
||||||
|
|
||||||
|
struct ReauthRequiredView: View {
|
||||||
|
@State private var isSyncing = false
|
||||||
|
@State private var syncStatus: SyncStatus = .idle
|
||||||
|
var onTokenReceived: (() -> Void)?
|
||||||
|
|
||||||
|
enum SyncStatus {
|
||||||
|
case idle
|
||||||
|
case syncing
|
||||||
|
case success
|
||||||
|
case failed
|
||||||
|
case phoneNotReachable
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ScrollView {
|
||||||
|
VStack(spacing: 16) {
|
||||||
|
Image(systemName: statusIcon)
|
||||||
|
.font(.system(size: 44))
|
||||||
|
.foregroundColor(statusColor)
|
||||||
|
.symbolEffect(.pulse, isActive: syncStatus == .syncing)
|
||||||
|
|
||||||
|
Text("reauth_required".localized)
|
||||||
|
.font(.headline)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
|
||||||
|
Text("reauth_description".localized)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.padding(.horizontal, 8)
|
||||||
|
|
||||||
|
if let statusMessage = statusMessage {
|
||||||
|
Text(statusMessage)
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(statusMessageColor)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
}
|
||||||
|
|
||||||
|
Button(action: syncWithiPhone) {
|
||||||
|
HStack {
|
||||||
|
if syncStatus == .syncing {
|
||||||
|
ProgressView()
|
||||||
|
.scaleEffect(0.8)
|
||||||
|
} else {
|
||||||
|
Image(systemName: "arrow.triangle.2.circlepath")
|
||||||
|
}
|
||||||
|
Text("sync_button".localized)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderedProminent)
|
||||||
|
.tint(syncStatus == .success ? .green : .blue)
|
||||||
|
.disabled(syncStatus == .syncing)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var statusIcon: String {
|
||||||
|
switch syncStatus {
|
||||||
|
case .idle:
|
||||||
|
return "exclamationmark.arrow.circlepath"
|
||||||
|
case .syncing:
|
||||||
|
return "arrow.triangle.2.circlepath"
|
||||||
|
case .success:
|
||||||
|
return "checkmark.circle.fill"
|
||||||
|
case .failed:
|
||||||
|
return "xmark.circle.fill"
|
||||||
|
case .phoneNotReachable:
|
||||||
|
return "iphone.slash"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var statusColor: Color {
|
||||||
|
switch syncStatus {
|
||||||
|
case .idle:
|
||||||
|
return .orange
|
||||||
|
case .syncing:
|
||||||
|
return .blue
|
||||||
|
case .success:
|
||||||
|
return .green
|
||||||
|
case .failed:
|
||||||
|
return .red
|
||||||
|
case .phoneNotReachable:
|
||||||
|
return .gray
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var statusMessage: String? {
|
||||||
|
switch syncStatus {
|
||||||
|
case .idle:
|
||||||
|
return nil
|
||||||
|
case .syncing:
|
||||||
|
return "syncing".localized
|
||||||
|
case .success:
|
||||||
|
return "sync_success".localized
|
||||||
|
case .failed:
|
||||||
|
return "sync_failed".localized
|
||||||
|
case .phoneNotReachable:
|
||||||
|
return "phone_not_reachable".localized
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var statusMessageColor: Color {
|
||||||
|
switch syncStatus {
|
||||||
|
case .success:
|
||||||
|
return .green
|
||||||
|
case .failed, .phoneNotReachable:
|
||||||
|
return .red
|
||||||
|
default:
|
||||||
|
return .secondary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func syncWithiPhone() {
|
||||||
|
guard WCSession.default.activationState == .activated else {
|
||||||
|
syncStatus = .failed
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard WCSession.default.isReachable else {
|
||||||
|
syncStatus = .phoneNotReachable
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
syncStatus = .syncing
|
||||||
|
|
||||||
|
WCSession.default.sendMessage(
|
||||||
|
["action": "requestToken"],
|
||||||
|
replyHandler: { response in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if let authDict = response["auth"] as? [String: Any] {
|
||||||
|
print("[Watch] Token received from iPhone via reauth sync")
|
||||||
|
self.processAuthData(authDict)
|
||||||
|
|
||||||
|
if !TokenManager.shared.isTokenExpired() {
|
||||||
|
self.syncStatus = .success
|
||||||
|
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||||
|
self.onTokenReceived?()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("[Watch] Received token is already expired - iPhone needs reauth")
|
||||||
|
self.syncStatus = .failed
|
||||||
|
}
|
||||||
|
} else if let error = response["error"] as? String {
|
||||||
|
print("[Watch] iPhone returned error: \(error)")
|
||||||
|
|
||||||
|
if error == "needsReauth" || error == "no_token" {
|
||||||
|
self.sendWatchTokenToiPhone()
|
||||||
|
} else {
|
||||||
|
self.syncStatus = .failed
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
print("[Watch] No token in response - iPhone may need reauth")
|
||||||
|
self.syncStatus = .failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
errorHandler: { error in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
print("[Watch] Reauth sync failed: \(error.localizedDescription)")
|
||||||
|
self.syncStatus = .failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 15) {
|
||||||
|
if self.syncStatus == .syncing {
|
||||||
|
self.syncStatus = .failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func sendWatchTokenToiPhone() {
|
||||||
|
guard TokenManager.shared.loadToken() != nil else {
|
||||||
|
print("[Watch] No token to send to iPhone")
|
||||||
|
syncStatus = .failed
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if TokenManager.shared.isTokenExpired() {
|
||||||
|
print("[Watch] Watch token is expired - attempting to refresh with retries...")
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
_ = try await KretaAPIClient.shared.getValidToken()
|
||||||
|
print("[Watch] Token refresh succeeded! Now sending to iPhone...")
|
||||||
|
await MainActor.run {
|
||||||
|
self.sendRefreshedTokenToiPhone()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
print("[Watch] Token refresh failed after all retries: \(error)")
|
||||||
|
await MainActor.run {
|
||||||
|
self.syncStatus = .failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
sendRefreshedTokenToiPhone()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func sendRefreshedTokenToiPhone() {
|
||||||
|
guard let token = TokenManager.shared.loadToken() else {
|
||||||
|
print("[Watch] No token after refresh")
|
||||||
|
syncStatus = .failed
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
print("[Watch] Sending Watch token to iPhone...")
|
||||||
|
|
||||||
|
var tokenData: [String: Any] = [
|
||||||
|
"studentId": token.studentId,
|
||||||
|
"studentIdNorm": token.studentIdNorm,
|
||||||
|
"iss": token.iss,
|
||||||
|
"idToken": token.idToken,
|
||||||
|
"accessToken": token.accessToken,
|
||||||
|
"refreshToken": token.refreshToken,
|
||||||
|
"expiryDate": Int64(token.expiryDate.timeIntervalSince1970 * 1000)
|
||||||
|
]
|
||||||
|
if let tokenVersion = token.effectiveTokenVersion {
|
||||||
|
tokenData["tokenVersion"] = tokenVersion
|
||||||
|
}
|
||||||
|
tokenData["updatedAtMs"] = token.effectiveUpdatedAtMs ?? Int64(Date().timeIntervalSince1970 * 1000)
|
||||||
|
|
||||||
|
WCSession.default.sendMessage(
|
||||||
|
["action": "receiveTokenFromWatch", "token": tokenData],
|
||||||
|
replyHandler: { response in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if let success = response["success"] as? Bool, success {
|
||||||
|
print("[Watch] iPhone accepted our token!")
|
||||||
|
self.syncStatus = .success
|
||||||
|
|
||||||
|
DataStore.shared.clearError()
|
||||||
|
|
||||||
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||||
|
self.onTokenReceived?()
|
||||||
|
}
|
||||||
|
} else if let error = response["error"] as? String {
|
||||||
|
print("[Watch] iPhone rejected our token: \(error)")
|
||||||
|
self.syncStatus = .failed
|
||||||
|
} else {
|
||||||
|
self.syncStatus = .failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
errorHandler: { error in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
print("[Watch] Failed to send token to iPhone: \(error)")
|
||||||
|
self.syncStatus = .failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func processAuthData(_ authDict: [String: Any]) {
|
||||||
|
do {
|
||||||
|
func parseInt64(_ value: Any?) -> Int64? {
|
||||||
|
if let value = value as? Int64 { return value }
|
||||||
|
if let value = value as? Int { return Int64(value) }
|
||||||
|
if let value = value as? Double { return Int64(value) }
|
||||||
|
if let value = value as? String, let parsed = Int64(value) { return parsed }
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let incomingSentAtMs = parseInt64(authDict["sentAtMs"]) ?? 0
|
||||||
|
let jsonData = try JSONSerialization.data(withJSONObject: authDict)
|
||||||
|
|
||||||
|
let decoder = JSONDecoder()
|
||||||
|
decoder.dateDecodingStrategy = .custom { decoder in
|
||||||
|
let container = try decoder.singleValueContainer()
|
||||||
|
let timestamp = try container.decode(Int64.self)
|
||||||
|
return Date(timeIntervalSince1970: Double(timestamp) / 1000.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
let token = try decoder.decode(WatchToken.self, from: jsonData)
|
||||||
|
let currentToken = TokenManager.shared.loadToken()
|
||||||
|
let shouldForceAccountSwitch: Bool
|
||||||
|
if incomingSentAtMs > 0,
|
||||||
|
let currentToken,
|
||||||
|
!token.isSameAccount(as: currentToken) {
|
||||||
|
shouldForceAccountSwitch = true
|
||||||
|
} else {
|
||||||
|
shouldForceAccountSwitch = false
|
||||||
|
}
|
||||||
|
|
||||||
|
try TokenManager.shared.saveToken(
|
||||||
|
token,
|
||||||
|
syncToSharedKeychain: false,
|
||||||
|
forceAccountSwitch: shouldForceAccountSwitch
|
||||||
|
)
|
||||||
|
|
||||||
|
DataStore.shared.checkTokenState()
|
||||||
|
DataStore.shared.clearError()
|
||||||
|
|
||||||
|
print("[Watch] Token saved via reauth sync")
|
||||||
|
} catch {
|
||||||
|
print("[Watch] Failed to process auth data: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
ReauthRequiredView()
|
||||||
|
}
|
||||||
78
firka/ios/FirkaWatch Watch App/Views/SettingsView.swift
Normal file
78
firka/ios/FirkaWatch Watch App/Views/SettingsView.swift
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct SettingsView: View {
|
||||||
|
@AppStorage("refreshInterval") private var refreshInterval: Int = 0
|
||||||
|
@State private var l10n = WatchL10n.shared
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
List {
|
||||||
|
Section("language".localized) {
|
||||||
|
Toggle("sync_with_iphone".localized, isOn: Binding(
|
||||||
|
get: { l10n.syncWithiPhone },
|
||||||
|
set: { l10n.syncWithiPhone = $0 }
|
||||||
|
))
|
||||||
|
|
||||||
|
if !l10n.syncWithiPhone {
|
||||||
|
Picker("language".localized, selection: Binding(
|
||||||
|
get: { l10n.currentLanguage },
|
||||||
|
set: { l10n.setLanguage($0) }
|
||||||
|
)) {
|
||||||
|
ForEach(WatchLanguage.allCases, id: \.self) { lang in
|
||||||
|
HStack {
|
||||||
|
Text(lang.flag)
|
||||||
|
Text(lang.displayName)
|
||||||
|
}
|
||||||
|
.tag(lang)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Section("refresh".localized) {
|
||||||
|
Picker("refresh_interval".localized, selection: $refreshInterval) {
|
||||||
|
Text("auto".localized).tag(0)
|
||||||
|
Text("15_minutes".localized).tag(15)
|
||||||
|
Text("30_minutes".localized).tag(30)
|
||||||
|
Text("1_hour".localized).tag(60)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Section {
|
||||||
|
Button("clear_cache".localized) {
|
||||||
|
clearCache()
|
||||||
|
}
|
||||||
|
|
||||||
|
Button("logout".localized, role: .destructive) {
|
||||||
|
logout()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Section {
|
||||||
|
HStack {
|
||||||
|
Text("version".localized)
|
||||||
|
Spacer()
|
||||||
|
Text(appVersion)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.navigationTitle("settings".localized)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var appVersion: String {
|
||||||
|
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
private func clearCache() {
|
||||||
|
DataStore.shared.clearCache()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func logout() {
|
||||||
|
TokenManager.shared.deleteToken()
|
||||||
|
_ = SharedSessionStateManager.shared.publishState(
|
||||||
|
hasAnyAccount: false,
|
||||||
|
activeStudentIdNorm: nil
|
||||||
|
)
|
||||||
|
DataStore.shared.clearAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
369
firka/ios/FirkaWatch Watch App/Views/TimetableView.swift
Normal file
369
firka/ios/FirkaWatch Watch App/Views/TimetableView.swift
Normal file
@@ -0,0 +1,369 @@
|
|||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct TimetableView: View {
|
||||||
|
let dataStore: DataStore
|
||||||
|
|
||||||
|
@State private var selectedDay: Int = 0
|
||||||
|
@State private var weekOffset: Int = 0
|
||||||
|
|
||||||
|
private var dayLabels: [String] {
|
||||||
|
[
|
||||||
|
"day_mon".localized,
|
||||||
|
"day_tue".localized,
|
||||||
|
"day_wed".localized,
|
||||||
|
"day_thu".localized,
|
||||||
|
"day_fri".localized
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
NavigationStack {
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
daySelector
|
||||||
|
|
||||||
|
Divider()
|
||||||
|
.padding(.vertical, 4)
|
||||||
|
|
||||||
|
lessonsContent
|
||||||
|
}
|
||||||
|
.onAppear {
|
||||||
|
updateWeekAndDay()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateWeekAndDay() {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let now = Date()
|
||||||
|
|
||||||
|
if shouldShowNextWeek() {
|
||||||
|
weekOffset = 1
|
||||||
|
selectedDay = findFirstSchoolDay(weekOffset: 1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
weekOffset = 0
|
||||||
|
let weekday = calendar.component(.weekday, from: now)
|
||||||
|
let todayIndex = weekday - 2
|
||||||
|
|
||||||
|
if todayIndex < 0 || todayIndex > 4 {
|
||||||
|
selectedDay = findFirstSchoolDay(weekOffset: 0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if areTodayLessonsDone(dayIndex: todayIndex) {
|
||||||
|
if let nextDay = findNextSchoolDay(after: todayIndex) {
|
||||||
|
selectedDay = nextDay
|
||||||
|
} else {
|
||||||
|
selectedDay = todayIndex
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
selectedDay = todayIndex
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func areTodayLessonsDone(dayIndex: Int) -> Bool {
|
||||||
|
let todayLessons = lessonsForDay(dayIndex)
|
||||||
|
guard !todayLessons.isEmpty else { return true }
|
||||||
|
|
||||||
|
let now = Date()
|
||||||
|
let lastLesson = todayLessons.sorted { $0.end > $1.end }.first
|
||||||
|
return lastLesson.map { now > $0.end } ?? true
|
||||||
|
}
|
||||||
|
|
||||||
|
private func findNextSchoolDay(after dayIndex: Int) -> Int? {
|
||||||
|
for day in (dayIndex + 1)...4 {
|
||||||
|
if !lessonsForDay(day).isEmpty {
|
||||||
|
return day
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func findFirstSchoolDay(weekOffset: Int) -> Int {
|
||||||
|
let oldOffset = self.weekOffset
|
||||||
|
for day in 0...4 {
|
||||||
|
let lessons = lessonsForDayWithOffset(day, weekOffset: weekOffset)
|
||||||
|
if !lessons.isEmpty {
|
||||||
|
return day
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
private func lessonsForDayWithOffset(_ day: Int, weekOffset: Int) -> [WidgetLesson] {
|
||||||
|
guard let data = dataStore.data else { return [] }
|
||||||
|
|
||||||
|
let allLessons: [WidgetLesson]
|
||||||
|
if let all = data.timetable.allLessons, !all.isEmpty {
|
||||||
|
allLessons = all
|
||||||
|
} else {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
let targetDateStr = getDateStringForDayWithOffset(day, weekOffset: weekOffset)
|
||||||
|
return allLessons.filter { $0.date == targetDateStr }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func getDateStringForDayWithOffset(_ day: Int, weekOffset: Int) -> String {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let now = Date()
|
||||||
|
|
||||||
|
let weekday = calendar.component(.weekday, from: now)
|
||||||
|
let daysFromMonday = (weekday == 1) ? -6 : (2 - weekday)
|
||||||
|
|
||||||
|
guard let monday = calendar.date(byAdding: .day, value: daysFromMonday, to: now) else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
let totalDaysToAdd = day + (weekOffset * 7)
|
||||||
|
guard let targetDate = calendar.date(byAdding: .day, value: totalDaysToAdd, to: monday) else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatDate(targetDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func shouldShowNextWeek() -> Bool {
|
||||||
|
guard let allLessons = dataStore.data?.timetable.allLessons, !allLessons.isEmpty else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
let now = Date()
|
||||||
|
let calendar = Calendar.current
|
||||||
|
|
||||||
|
let weekday = calendar.component(.weekday, from: now)
|
||||||
|
let daysFromMonday = (weekday == 1) ? -6 : (2 - weekday)
|
||||||
|
guard let monday = calendar.date(byAdding: .day, value: daysFromMonday, to: now),
|
||||||
|
let friday = calendar.date(byAdding: .day, value: 4, to: monday) else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
let fridayString = formatDate(friday)
|
||||||
|
let mondayString = formatDate(monday)
|
||||||
|
|
||||||
|
let currentWeekLessons = allLessons.filter { lesson in
|
||||||
|
lesson.date >= mondayString && lesson.date <= fridayString
|
||||||
|
}
|
||||||
|
|
||||||
|
guard !currentWeekLessons.isEmpty else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
let lastLesson = currentWeekLessons
|
||||||
|
.sorted { $0.date > $1.date || ($0.date == $1.date && $0.end > $1.end) }
|
||||||
|
.first
|
||||||
|
|
||||||
|
guard let last = lastLesson else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return now > last.end
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Day Selector
|
||||||
|
|
||||||
|
private var daySelector: some View {
|
||||||
|
HStack(spacing: 6) {
|
||||||
|
ForEach(0..<5, id: \.self) { day in
|
||||||
|
Button(action: { selectedDay = day }) {
|
||||||
|
Text(dayLabels[day])
|
||||||
|
.font(.system(size: 14, weight: .semibold))
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.frame(height: 32)
|
||||||
|
.foregroundColor(selectedDay == day ? .white : .primary)
|
||||||
|
.background(selectedDay == day ? Color.blue : Color.clear)
|
||||||
|
.cornerRadius(8)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: 8)
|
||||||
|
.stroke(isToday(day) && selectedDay != day ? Color.blue : Color.clear, lineWidth: 2)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 8)
|
||||||
|
.padding(.vertical, 6)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func isToday(_ day: Int) -> Bool {
|
||||||
|
guard weekOffset == 0 else { return false }
|
||||||
|
let weekday = Calendar.current.component(.weekday, from: Date())
|
||||||
|
return day == weekday - 2
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Lessons Content
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private var lessonsContent: some View {
|
||||||
|
let lessons = lessonsForDay(selectedDay)
|
||||||
|
|
||||||
|
if lessons.isEmpty {
|
||||||
|
freeDayView
|
||||||
|
} else {
|
||||||
|
ScrollView {
|
||||||
|
VStack(spacing: 6) {
|
||||||
|
ForEach(lessons) { lesson in
|
||||||
|
NavigationLink {
|
||||||
|
LessonDetailView(lesson: lesson)
|
||||||
|
} label: {
|
||||||
|
lessonRow(lesson)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 8)
|
||||||
|
.padding(.vertical, 6)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func lessonsForDay(_ day: Int) -> [WidgetLesson] {
|
||||||
|
guard let data = dataStore.data else { return [] }
|
||||||
|
|
||||||
|
let allLessons: [WidgetLesson]
|
||||||
|
if let all = data.timetable.allLessons, !all.isEmpty {
|
||||||
|
allLessons = all
|
||||||
|
} else {
|
||||||
|
var combined: [WidgetLesson] = []
|
||||||
|
combined.append(contentsOf: data.timetable.today)
|
||||||
|
combined.append(contentsOf: data.timetable.tomorrow)
|
||||||
|
if let nextSchoolDay = data.timetable.nextSchoolDay {
|
||||||
|
combined.append(contentsOf: nextSchoolDay)
|
||||||
|
}
|
||||||
|
allLessons = combined
|
||||||
|
}
|
||||||
|
|
||||||
|
let targetDateStr = getDateStringForDay(day)
|
||||||
|
|
||||||
|
let uniqueDates = Set(allLessons.map { $0.date }).sorted()
|
||||||
|
print("[Watch] lessonsForDay: day=\(day), weekOffset=\(weekOffset), targetDate=\(targetDateStr), lessons=\(allLessons.count)")
|
||||||
|
print("[Watch] Unique dates in lessons: \(uniqueDates)")
|
||||||
|
|
||||||
|
if let first = allLessons.first {
|
||||||
|
let cal = Calendar.current
|
||||||
|
let comp = cal.dateComponents([.year, .month, .day, .hour, .minute], from: first.start)
|
||||||
|
print("[Watch] First lesson: date=\(first.date), start=\(comp.year!)-\(comp.month!)-\(comp.day!) \(comp.hour!):\(comp.minute!)")
|
||||||
|
}
|
||||||
|
|
||||||
|
let filtered = allLessons.filter { $0.date == targetDateStr }
|
||||||
|
print("[Watch] Filtered lessons: \(filtered.count) for \(targetDateStr)")
|
||||||
|
|
||||||
|
return filtered.sorted { ($0.lessonNumber ?? 0) < ($1.lessonNumber ?? 0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func getDateStringForDay(_ day: Int) -> String {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let now = Date()
|
||||||
|
|
||||||
|
let weekday = calendar.component(.weekday, from: now)
|
||||||
|
let daysFromMonday = (weekday == 1) ? -6 : (2 - weekday)
|
||||||
|
|
||||||
|
guard let monday = calendar.date(byAdding: .day, value: daysFromMonday, to: now) else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
let totalDaysToAdd = day + (weekOffset * 7)
|
||||||
|
guard let targetDate = calendar.date(byAdding: .day, value: totalDaysToAdd, to: monday) else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return formatDate(targetDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func formatDate(_ date: Date) -> String {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let components = calendar.dateComponents([.year, .month, .day], from: date)
|
||||||
|
return String(format: "%04d-%02d-%02d",
|
||||||
|
components.year ?? 0,
|
||||||
|
components.month ?? 0,
|
||||||
|
components.day ?? 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var freeDayView: some View {
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
Image(systemName: "sun.max.fill")
|
||||||
|
.font(.system(size: 40))
|
||||||
|
.foregroundColor(.yellow)
|
||||||
|
|
||||||
|
Text("free_day".localized)
|
||||||
|
.font(.headline)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Lesson Row
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func lessonRow(_ lesson: WidgetLesson) -> some View {
|
||||||
|
FirkaCard(isHighlighted: lesson.isCurrentlyActive) {
|
||||||
|
HStack(alignment: .top, spacing: 8) {
|
||||||
|
if let number = lesson.lessonNumber {
|
||||||
|
Text("\(number).")
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.foregroundColor(.blue)
|
||||||
|
.frame(width: 24, alignment: .leading)
|
||||||
|
}
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
HStack {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(lesson.displayName)
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(.medium)
|
||||||
|
.lineLimit(1)
|
||||||
|
|
||||||
|
if let statusIcon = lessonStatusIconName(for: lesson) {
|
||||||
|
Image(systemName: statusIcon)
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(lessonStatusColor(for: lesson))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Text(lesson.start, style: .time)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
if let teacher = lesson.teacher {
|
||||||
|
Text(teacher)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
if let room = lesson.roomName {
|
||||||
|
Text("•")
|
||||||
|
Text(room)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func lessonStatusIconName(for lesson: WidgetLesson) -> String? {
|
||||||
|
if lesson.isCancelled {
|
||||||
|
return "xmark.circle.fill"
|
||||||
|
}
|
||||||
|
if lesson.isSubstitution {
|
||||||
|
return "exclamationmark.circle.fill"
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func lessonStatusColor(for lesson: WidgetLesson) -> Color {
|
||||||
|
lesson.isCancelled ? .red : .yellow
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
struct TimetableView_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
TimetableView(dataStore: DataStore.shared)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"colors" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"platform" : "watchos",
|
||||||
|
"size" : "1024x1024"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"colors" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
369
firka/ios/FirkaWatchComplications/FirkaComplications.swift
Normal file
369
firka/ios/FirkaWatchComplications/FirkaComplications.swift
Normal file
@@ -0,0 +1,369 @@
|
|||||||
|
#if os(watchOS)
|
||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
// MARK: - Complication Localization Helper
|
||||||
|
|
||||||
|
private struct ComplicationL10n {
|
||||||
|
private static let appGroupID = "group.app.firkaa.legacy"
|
||||||
|
|
||||||
|
enum Language: String {
|
||||||
|
case hungarian = "hu"
|
||||||
|
case english = "en"
|
||||||
|
case german = "de"
|
||||||
|
}
|
||||||
|
|
||||||
|
static var currentLanguage: Language {
|
||||||
|
guard let defaults = UserDefaults(suiteName: appGroupID) else {
|
||||||
|
return .hungarian
|
||||||
|
}
|
||||||
|
let code = defaults.string(forKey: "watch_language") ?? "hu"
|
||||||
|
return Language(rawValue: code) ?? .hungarian
|
||||||
|
}
|
||||||
|
|
||||||
|
static func string(_ key: String) -> String {
|
||||||
|
switch currentLanguage {
|
||||||
|
case .hungarian: return hungarianStrings[key] ?? key
|
||||||
|
case .english: return englishStrings[key] ?? key
|
||||||
|
case .german: return germanStrings[key] ?? key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static let hungarianStrings: [String: String] = [
|
||||||
|
"current_lesson": "Jelenlegi óra",
|
||||||
|
"next": "Következő",
|
||||||
|
"no_more_lessons": "Nincs több óra",
|
||||||
|
"average_abbrev": "Átl",
|
||||||
|
"next_lesson_title": "Következő óra",
|
||||||
|
"average_title": "Átlag",
|
||||||
|
"lesson_inline": "Óra (inline)"
|
||||||
|
]
|
||||||
|
|
||||||
|
private static let englishStrings: [String: String] = [
|
||||||
|
"current_lesson": "Current Lesson",
|
||||||
|
"next": "Next",
|
||||||
|
"no_more_lessons": "No more lessons",
|
||||||
|
"average_abbrev": "Avg",
|
||||||
|
"next_lesson_title": "Next Lesson",
|
||||||
|
"average_title": "Average",
|
||||||
|
"lesson_inline": "Lesson (inline)"
|
||||||
|
]
|
||||||
|
|
||||||
|
private static let germanStrings: [String: String] = [
|
||||||
|
"current_lesson": "Aktuelle Stunde",
|
||||||
|
"next": "Nächste",
|
||||||
|
"no_more_lessons": "Keine Stunden mehr",
|
||||||
|
"average_abbrev": "Ø",
|
||||||
|
"next_lesson_title": "Nächste Stunde",
|
||||||
|
"average_title": "Durchschnitt",
|
||||||
|
"lesson_inline": "Stunde (inline)"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Watch Cache Loader
|
||||||
|
|
||||||
|
private struct WatchCacheLoader {
|
||||||
|
private static let appGroupID = "group.app.firkaa.legacy"
|
||||||
|
private static let cacheFileName = "watch_data.json"
|
||||||
|
|
||||||
|
static func loadWidgetData() -> WidgetData? {
|
||||||
|
guard let containerURL = FileManager.default.containerURL(
|
||||||
|
forSecurityApplicationGroupIdentifier: appGroupID
|
||||||
|
) else {
|
||||||
|
print("[WatchComplication] No App Group container")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let fileURL = containerURL.appendingPathComponent(cacheFileName)
|
||||||
|
|
||||||
|
guard FileManager.default.fileExists(atPath: fileURL.path) else {
|
||||||
|
print("[WatchComplication] Cache file not found: \(fileURL.path)")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let data = try? Data(contentsOf: fileURL) else {
|
||||||
|
print("[WatchComplication] Could not read cache file")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let decoder = JSONDecoder()
|
||||||
|
decoder.dateDecodingStrategy = .iso8601
|
||||||
|
|
||||||
|
struct CachedWatchData: Codable {
|
||||||
|
let widgetData: WidgetData
|
||||||
|
let lastUpdated: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
let cached = try decoder.decode(CachedWatchData.self, from: data)
|
||||||
|
print("[WatchComplication] Loaded cache from \(cached.lastUpdated)")
|
||||||
|
return cached.widgetData
|
||||||
|
} catch {
|
||||||
|
print("[WatchComplication] Failed to decode: \(error)")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Timeline Entry
|
||||||
|
|
||||||
|
struct FirkaTimelineEntry: TimelineEntry {
|
||||||
|
let date: Date
|
||||||
|
let data: WidgetData?
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Timeline Provider
|
||||||
|
|
||||||
|
struct FirkaTimelineProvider: TimelineProvider {
|
||||||
|
func placeholder(in context: Context) -> FirkaTimelineEntry {
|
||||||
|
FirkaTimelineEntry(date: Date(), data: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSnapshot(in context: Context, completion: @escaping (FirkaTimelineEntry) -> Void) {
|
||||||
|
let data = WatchCacheLoader.loadWidgetData()
|
||||||
|
completion(FirkaTimelineEntry(date: Date(), data: data))
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTimeline(in context: Context, completion: @escaping (Timeline<FirkaTimelineEntry>) -> Void) {
|
||||||
|
let data = WatchCacheLoader.loadWidgetData()
|
||||||
|
let entry = FirkaTimelineEntry(date: Date(), data: data)
|
||||||
|
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let now = Date()
|
||||||
|
let hour = calendar.component(.hour, from: now)
|
||||||
|
let weekday = calendar.component(.weekday, from: now)
|
||||||
|
let isSchoolHours = (weekday >= 2 && weekday <= 6) && (hour >= 6 && hour <= 16)
|
||||||
|
|
||||||
|
let refreshInterval: TimeInterval = isSchoolHours ? 15 * 60 : 60 * 60
|
||||||
|
let nextRefresh = now.addingTimeInterval(refreshInterval)
|
||||||
|
|
||||||
|
let timeline = Timeline(entries: [entry], policy: .after(nextRefresh))
|
||||||
|
completion(timeline)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Next Lesson Complication (accessoryRectangular)
|
||||||
|
|
||||||
|
struct NextLessonComplication: Widget {
|
||||||
|
let kind = "NextLessonComplication"
|
||||||
|
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
StaticConfiguration(kind: kind, provider: FirkaTimelineProvider()) { entry in
|
||||||
|
NextLessonView(entry: entry)
|
||||||
|
.containerBackground(.fill.tertiary, for: .widget)
|
||||||
|
}
|
||||||
|
.configurationDisplayName(ComplicationL10n.string("next_lesson_title"))
|
||||||
|
.description("Shows the current or next lesson.")
|
||||||
|
.supportedFamilies([.accessoryRectangular])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct NextLessonView: View {
|
||||||
|
let entry: FirkaTimelineEntry
|
||||||
|
|
||||||
|
private var now: Date { Date() }
|
||||||
|
|
||||||
|
private var todayLessons: [WidgetLesson] {
|
||||||
|
(entry.data?.timetable.today ?? []).sorted { $0.start < $1.start }
|
||||||
|
}
|
||||||
|
|
||||||
|
private var currentLesson: WidgetLesson? {
|
||||||
|
todayLessons.first { now >= $0.start && now <= $0.end }
|
||||||
|
}
|
||||||
|
|
||||||
|
private var nextLesson: WidgetLesson? {
|
||||||
|
todayLessons.first { $0.start > now }
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if let breakInfo = entry.data?.timetable.currentBreak {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Image(systemName: SeasonalIconHelper.iconName(for: breakInfo.nameKey, season: nil))
|
||||||
|
.font(.caption)
|
||||||
|
Text(breakInfo.name)
|
||||||
|
.font(.headline)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else if let lesson = currentLesson {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text(ComplicationL10n.string("current_lesson"))
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
Text(lesson.displayName)
|
||||||
|
.font(.headline)
|
||||||
|
.lineLimit(1)
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
if let room = lesson.roomName {
|
||||||
|
Image(systemName: "door.right.hand.closed")
|
||||||
|
.font(.caption2)
|
||||||
|
Text(room)
|
||||||
|
.font(.caption2)
|
||||||
|
}
|
||||||
|
Text("→ \(lesson.end, formatter: Self.timeFormatter)")
|
||||||
|
.font(.caption2)
|
||||||
|
}
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else if let lesson = nextLesson {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text(ComplicationL10n.string("next"))
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
Text(lesson.displayName)
|
||||||
|
.font(.headline)
|
||||||
|
.lineLimit(1)
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
if let room = lesson.roomName {
|
||||||
|
Image(systemName: "door.right.hand.closed")
|
||||||
|
.font(.caption2)
|
||||||
|
Text(room)
|
||||||
|
.font(.caption2)
|
||||||
|
}
|
||||||
|
Text(lesson.start, formatter: Self.timeFormatter)
|
||||||
|
.font(.caption2)
|
||||||
|
}
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else if entry.data != nil {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Image(systemName: "checkmark.circle.fill")
|
||||||
|
.font(.title3)
|
||||||
|
.foregroundStyle(.green)
|
||||||
|
Text(ComplicationL10n.string("no_more_lessons"))
|
||||||
|
.font(.headline)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Image(systemName: "book.fill")
|
||||||
|
.font(.title3)
|
||||||
|
Text("Firka")
|
||||||
|
.font(.headline)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static let timeFormatter: DateFormatter = {
|
||||||
|
let f = DateFormatter()
|
||||||
|
f.dateFormat = "HH:mm"
|
||||||
|
return f
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Average Complication (accessoryCircular)
|
||||||
|
|
||||||
|
struct AverageComplication: Widget {
|
||||||
|
let kind = "AverageComplication"
|
||||||
|
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
StaticConfiguration(kind: kind, provider: FirkaTimelineProvider()) { entry in
|
||||||
|
AverageView(entry: entry)
|
||||||
|
.containerBackground(.fill.tertiary, for: .widget)
|
||||||
|
}
|
||||||
|
.configurationDisplayName(ComplicationL10n.string("average_title"))
|
||||||
|
.description("Shows the overall grade average.")
|
||||||
|
.supportedFamilies([.accessoryCircular])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct AverageView: View {
|
||||||
|
let entry: FirkaTimelineEntry
|
||||||
|
|
||||||
|
private var averageColor: Color {
|
||||||
|
guard let avg = entry.data?.averages.overall else { return .gray }
|
||||||
|
switch avg {
|
||||||
|
case 4.5...: return .green
|
||||||
|
case 3.5..<4.5: return .blue
|
||||||
|
case 2.5..<3.5: return .yellow
|
||||||
|
case 1.5..<2.5: return .orange
|
||||||
|
default: return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if let average = entry.data?.averages.overall {
|
||||||
|
Gauge(value: average, in: 1...5) {
|
||||||
|
Text(ComplicationL10n.string("average_abbrev"))
|
||||||
|
} currentValueLabel: {
|
||||||
|
Text(String(format: "%.1f", average))
|
||||||
|
.font(.system(.body, design: .rounded, weight: .bold))
|
||||||
|
}
|
||||||
|
.gaugeStyle(.accessoryCircular)
|
||||||
|
.tint(averageColor)
|
||||||
|
} else {
|
||||||
|
ZStack {
|
||||||
|
AccessoryWidgetBackground()
|
||||||
|
Text("—")
|
||||||
|
.font(.title3)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Inline Complication (accessoryInline)
|
||||||
|
|
||||||
|
struct InlineComplication: Widget {
|
||||||
|
let kind = "InlineComplication"
|
||||||
|
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
StaticConfiguration(kind: kind, provider: FirkaTimelineProvider()) { entry in
|
||||||
|
InlineView(entry: entry)
|
||||||
|
.containerBackground(.fill.tertiary, for: .widget)
|
||||||
|
}
|
||||||
|
.configurationDisplayName(ComplicationL10n.string("lesson_inline"))
|
||||||
|
.description("One-line summary of the next lesson.")
|
||||||
|
.supportedFamilies([.accessoryInline])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private struct InlineView: View {
|
||||||
|
let entry: FirkaTimelineEntry
|
||||||
|
|
||||||
|
private var now: Date { Date() }
|
||||||
|
|
||||||
|
private var todayLessons: [WidgetLesson] {
|
||||||
|
(entry.data?.timetable.today ?? []).sorted { $0.start < $1.start }
|
||||||
|
}
|
||||||
|
|
||||||
|
private var currentOrNextLesson: WidgetLesson? {
|
||||||
|
todayLessons.first { now >= $0.start && now <= $0.end }
|
||||||
|
?? todayLessons.first { $0.start > now }
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if let breakInfo = entry.data?.timetable.currentBreak {
|
||||||
|
Text(breakInfo.name)
|
||||||
|
} else if let lesson = currentOrNextLesson {
|
||||||
|
Text("\(lesson.displayName) \(lesson.start, formatter: Self.timeFormatter)")
|
||||||
|
} else if entry.data != nil {
|
||||||
|
Text(ComplicationL10n.string("no_more_lessons"))
|
||||||
|
} else {
|
||||||
|
Text("Firka")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static let timeFormatter: DateFormatter = {
|
||||||
|
let f = DateFormatter()
|
||||||
|
f.dateFormat = "HH:mm"
|
||||||
|
return f
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Widget Bundle
|
||||||
|
|
||||||
|
@main
|
||||||
|
struct FirkaWatchWidgets: WidgetBundle {
|
||||||
|
var body: some Widget {
|
||||||
|
NextLessonComplication()
|
||||||
|
AverageComplication()
|
||||||
|
InlineComplication()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
11
firka/ios/FirkaWatchComplications/Info.plist
Normal file
11
firka/ios/FirkaWatchComplications/Info.plist
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>NSExtension</key>
|
||||||
|
<dict>
|
||||||
|
<key>NSExtensionPointIdentifier</key>
|
||||||
|
<string>com.apple.widgetkit-extension</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
12
firka/ios/FirkaWatchComplicationsExtension.entitlements
Normal file
12
firka/ios/FirkaWatchComplicationsExtension.entitlements
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
|
||||||
|
<string>$(TeamIdentifierPrefix)app.firkaa.legacy</string>
|
||||||
|
<key>com.apple.security.application-groups</key>
|
||||||
|
<array>
|
||||||
|
<string>group.app.firkaa.legacy</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
24
firka/ios/Flutter/AppFrameworkInfo.plist
Normal file
24
firka/ios/Flutter/AppFrameworkInfo.plist
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
|
<string>en</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>App</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>io.flutter.flutter.app</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>App</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>FMWK</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
<key>CFBundleSignature</key>
|
||||||
|
<string>????</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
2
firka/ios/Flutter/Debug.xcconfig
Normal file
2
firka/ios/Flutter/Debug.xcconfig
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
|
||||||
|
#include "Generated.xcconfig"
|
||||||
2
firka/ios/Flutter/Release.xcconfig
Normal file
2
firka/ios/Flutter/Release.xcconfig
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
|
||||||
|
#include "Generated.xcconfig"
|
||||||
2
firka/ios/Flutter/WidgetExtension.xcconfig
Normal file
2
firka/ios/Flutter/WidgetExtension.xcconfig
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// Extensions take the version from Flutter so it matches the app.
|
||||||
|
#include "Generated.xcconfig"
|
||||||
12
firka/ios/HomeWidgetsExtension.entitlements
Normal file
12
firka/ios/HomeWidgetsExtension.entitlements
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
|
||||||
|
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>
|
||||||
|
<key>com.apple.security.application-groups</key>
|
||||||
|
<array>
|
||||||
|
<string>group.app.firkaa.legacy</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"colors" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"platform" : "ios",
|
||||||
|
"size" : "1024x1024"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"appearances" : [
|
||||||
|
{
|
||||||
|
"appearance" : "luminosity",
|
||||||
|
"value" : "dark"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"idiom" : "universal",
|
||||||
|
"platform" : "ios",
|
||||||
|
"size" : "1024x1024"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"appearances" : [
|
||||||
|
{
|
||||||
|
"appearance" : "luminosity",
|
||||||
|
"value" : "tinted"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"idiom" : "universal",
|
||||||
|
"platform" : "ios",
|
||||||
|
"size" : "1024x1024"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"colors" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
45
firka/ios/HomeWidgetsExtension/AveragesWidget.swift
Normal file
45
firka/ios/HomeWidgetsExtension/AveragesWidget.swift
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct AveragesWidget: Widget {
|
||||||
|
let kind: String = "AveragesWidget"
|
||||||
|
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
AppIntentConfiguration(
|
||||||
|
kind: kind,
|
||||||
|
intent: AveragesWidgetIntent.self,
|
||||||
|
provider: AveragesProvider()
|
||||||
|
) { entry in
|
||||||
|
AveragesWidgetView(entry: entry)
|
||||||
|
.containerBackground(.clear, for: .widget)
|
||||||
|
}
|
||||||
|
.configurationDisplayName(LocalizedStringResource("widget_averages_title", defaultValue: "Averages"))
|
||||||
|
.description(LocalizedStringResource("widget_averages_description", defaultValue: "Shows subject averages"))
|
||||||
|
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AveragesWidgetView: View {
|
||||||
|
@Environment(\.widgetFamily) var family
|
||||||
|
let entry: AveragesEntry
|
||||||
|
|
||||||
|
var localization: WidgetLocalization {
|
||||||
|
WidgetLocalization(locale: entry.locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Group {
|
||||||
|
switch family {
|
||||||
|
case .systemSmall:
|
||||||
|
AveragesSmallView(entry: entry, localization: localization)
|
||||||
|
case .systemMedium:
|
||||||
|
AveragesMediumView(entry: entry, localization: localization)
|
||||||
|
case .systemLarge:
|
||||||
|
AveragesLargeView(entry: entry, localization: localization)
|
||||||
|
default:
|
||||||
|
AveragesMediumView(entry: entry, localization: localization)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.widgetURL(URL(string: "firka://widget/grades"))
|
||||||
|
}
|
||||||
|
}
|
||||||
94
firka/ios/HomeWidgetsExtension/Controls/AppControls.swift
Normal file
94
firka/ios/HomeWidgetsExtension/Controls/AppControls.swift
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
import AppIntents
|
||||||
|
|
||||||
|
private let appGroup = "group.app.firkaa.legacy"
|
||||||
|
|
||||||
|
// MARK: - Navigation Intents (iOS 16+, used by Controls and Shortcuts)
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct OpenHomeIntent: AppIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("control_home_title", defaultValue: "Firka Home")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("control_home_description", defaultValue: "Open Firka home screen"))
|
||||||
|
static var openAppWhenRun: Bool = true
|
||||||
|
|
||||||
|
func perform() async throws -> some IntentResult {
|
||||||
|
UserDefaults(suiteName: appGroup)?.set("home", forKey: "controlNavigation")
|
||||||
|
return .result()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct OpenGradesIntent: AppIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("control_grades_title", defaultValue: "Firka Grades")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("control_grades_description", defaultValue: "Open Firka grades"))
|
||||||
|
static var openAppWhenRun: Bool = true
|
||||||
|
|
||||||
|
func perform() async throws -> some IntentResult {
|
||||||
|
UserDefaults(suiteName: appGroup)?.set("grades", forKey: "controlNavigation")
|
||||||
|
return .result()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct OpenTimetableIntent: AppIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("control_timetable_title", defaultValue: "Firka Timetable")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("control_timetable_description", defaultValue: "Open Firka timetable"))
|
||||||
|
static var openAppWhenRun: Bool = true
|
||||||
|
|
||||||
|
func perform() async throws -> some IntentResult {
|
||||||
|
UserDefaults(suiteName: appGroup)?.set("timetable", forKey: "controlNavigation")
|
||||||
|
return .result()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Home Control (iOS 18+)
|
||||||
|
|
||||||
|
@available(iOS 18.0, *)
|
||||||
|
struct HomeControl: ControlWidget {
|
||||||
|
static let kind = "app.firkaa.legacy.control.home"
|
||||||
|
|
||||||
|
var body: some ControlWidgetConfiguration {
|
||||||
|
StaticControlConfiguration(kind: Self.kind) {
|
||||||
|
ControlWidgetButton(action: OpenHomeIntent()) {
|
||||||
|
Label(LocalizedStringResource("control_home_label", defaultValue: "Home"), systemImage: "house.fill")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.displayName(LocalizedStringResource("control_home_display", defaultValue: "Firka - Home"))
|
||||||
|
.description(LocalizedStringResource("control_home_description", defaultValue: "Open Firka home screen"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Grades Control (iOS 18+)
|
||||||
|
|
||||||
|
@available(iOS 18.0, *)
|
||||||
|
struct GradesControl: ControlWidget {
|
||||||
|
static let kind = "app.firkaa.legacy.control.grades"
|
||||||
|
|
||||||
|
var body: some ControlWidgetConfiguration {
|
||||||
|
StaticControlConfiguration(kind: Self.kind) {
|
||||||
|
ControlWidgetButton(action: OpenGradesIntent()) {
|
||||||
|
Label(LocalizedStringResource("control_grades_label", defaultValue: "Grades"), systemImage: "star.fill")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.displayName(LocalizedStringResource("control_grades_display", defaultValue: "Firka - Grades"))
|
||||||
|
.description(LocalizedStringResource("control_grades_description", defaultValue: "Open Firka grades"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Timetable Control (iOS 18+)
|
||||||
|
|
||||||
|
@available(iOS 18.0, *)
|
||||||
|
struct TimetableControl: ControlWidget {
|
||||||
|
static let kind = "app.firkaa.legacy.control.timetable"
|
||||||
|
|
||||||
|
var body: some ControlWidgetConfiguration {
|
||||||
|
StaticControlConfiguration(kind: Self.kind) {
|
||||||
|
ControlWidgetButton(action: OpenTimetableIntent()) {
|
||||||
|
Label(LocalizedStringResource("control_timetable_label", defaultValue: "Timetable"), systemImage: "calendar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.displayName(LocalizedStringResource("control_timetable_display", defaultValue: "Firka - Timetable"))
|
||||||
|
.description(LocalizedStringResource("control_timetable_description", defaultValue: "Open Firka timetable"))
|
||||||
|
}
|
||||||
|
}
|
||||||
45
firka/ios/HomeWidgetsExtension/GradesWidget.swift
Normal file
45
firka/ios/HomeWidgetsExtension/GradesWidget.swift
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct GradesWidget: Widget {
|
||||||
|
let kind: String = "GradesWidget"
|
||||||
|
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
AppIntentConfiguration(
|
||||||
|
kind: kind,
|
||||||
|
intent: GradesWidgetIntent.self,
|
||||||
|
provider: GradesProvider()
|
||||||
|
) { entry in
|
||||||
|
GradesWidgetView(entry: entry)
|
||||||
|
.containerBackground(.clear, for: .widget)
|
||||||
|
}
|
||||||
|
.configurationDisplayName(LocalizedStringResource("widget_grades_title", defaultValue: "Recent Grades"))
|
||||||
|
.description(LocalizedStringResource("widget_grades_description", defaultValue: "Shows your recent grades"))
|
||||||
|
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GradesWidgetView: View {
|
||||||
|
@Environment(\.widgetFamily) var family
|
||||||
|
let entry: GradesEntry
|
||||||
|
|
||||||
|
var localization: WidgetLocalization {
|
||||||
|
WidgetLocalization(locale: entry.locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Group {
|
||||||
|
switch family {
|
||||||
|
case .systemSmall:
|
||||||
|
GradesSmallView(entry: entry, localization: localization)
|
||||||
|
case .systemMedium:
|
||||||
|
GradesMediumView(entry: entry, localization: localization)
|
||||||
|
case .systemLarge:
|
||||||
|
GradesLargeView(entry: entry, localization: localization)
|
||||||
|
default:
|
||||||
|
GradesMediumView(entry: entry, localization: localization)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.widgetURL(URL(string: "firka://widget/grades"))
|
||||||
|
}
|
||||||
|
}
|
||||||
273
firka/ios/HomeWidgetsExtension/Helpers/Localization.swift
Normal file
273
firka/ios/HomeWidgetsExtension/Helpers/Localization.swift
Normal file
@@ -0,0 +1,273 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct WidgetLocalization {
|
||||||
|
let locale: String
|
||||||
|
|
||||||
|
init(locale: String = "hu") {
|
||||||
|
self.locale = locale
|
||||||
|
}
|
||||||
|
|
||||||
|
private var translations: [String: [String: String]] {
|
||||||
|
[
|
||||||
|
"today_timetable": [
|
||||||
|
"hu": "Mai órarend",
|
||||||
|
"en": "Today's timetable",
|
||||||
|
"de": "Stundenplan heute"
|
||||||
|
],
|
||||||
|
"tomorrow_timetable": [
|
||||||
|
"hu": "Holnapi órarend",
|
||||||
|
"en": "Tomorrow's timetable",
|
||||||
|
"de": "Stundenplan morgen"
|
||||||
|
],
|
||||||
|
"next_school_day_timetable": [
|
||||||
|
"hu": "Következő órarend (%@)",
|
||||||
|
"en": "Next timetable (%@)",
|
||||||
|
"de": "Nächster Stundenplan (%@)"
|
||||||
|
],
|
||||||
|
"no_lessons_ahead": [
|
||||||
|
"hu": "Nincs óra a héten",
|
||||||
|
"en": "No lessons this week",
|
||||||
|
"de": "Kein Unterricht diese Woche"
|
||||||
|
],
|
||||||
|
"current_lesson": [
|
||||||
|
"hu": "Jelenlegi óra",
|
||||||
|
"en": "Current lesson",
|
||||||
|
"de": "Aktuelle Stunde"
|
||||||
|
],
|
||||||
|
"next_lesson": [
|
||||||
|
"hu": "Következő óra",
|
||||||
|
"en": "Next lesson",
|
||||||
|
"de": "Nächste Stunde"
|
||||||
|
],
|
||||||
|
"recent_grades": [
|
||||||
|
"hu": "Legutóbbi jegyek",
|
||||||
|
"en": "Recent grades",
|
||||||
|
"de": "Letzte Noten"
|
||||||
|
],
|
||||||
|
"subject_averages": [
|
||||||
|
"hu": "Tantárgyi átlagok",
|
||||||
|
"en": "Subject averages",
|
||||||
|
"de": "Fachdurchschnitte"
|
||||||
|
],
|
||||||
|
"overall_average": [
|
||||||
|
"hu": "Tanulmányi átlag",
|
||||||
|
"en": "Overall average",
|
||||||
|
"de": "Gesamtdurchschnitt"
|
||||||
|
],
|
||||||
|
"no_lessons": [
|
||||||
|
"hu": "Nincs több óra ma",
|
||||||
|
"en": "No more lessons today",
|
||||||
|
"de": "Keine Stunden mehr heute"
|
||||||
|
],
|
||||||
|
"no_grades": [
|
||||||
|
"hu": "Még nincsenek jegyeid",
|
||||||
|
"en": "No grades yet",
|
||||||
|
"de": "Noch keine Noten"
|
||||||
|
],
|
||||||
|
"no_averages": [
|
||||||
|
"hu": "Még nincsenek átlagok",
|
||||||
|
"en": "No averages yet",
|
||||||
|
"de": "Noch keine Durchschnitte"
|
||||||
|
],
|
||||||
|
"login_required": [
|
||||||
|
"hu": "Jelentkezz be újra",
|
||||||
|
"en": "Please log in again",
|
||||||
|
"de": "Bitte erneut anmelden"
|
||||||
|
],
|
||||||
|
"timetable_unavailable": [
|
||||||
|
"hu": "Az órarend még nem elérhető",
|
||||||
|
"en": "Timetable not available yet",
|
||||||
|
"de": "Stundenplan noch nicht verfügbar"
|
||||||
|
],
|
||||||
|
"happy_break": [
|
||||||
|
"hu": "Kellemes %@ szünetet!",
|
||||||
|
"en": "Happy %@ break!",
|
||||||
|
"de": "Schöne %@ Ferien!"
|
||||||
|
],
|
||||||
|
"days_remaining": [
|
||||||
|
"hu": "Még %d nap",
|
||||||
|
"en": "%d days left",
|
||||||
|
"de": "Noch %d Tage"
|
||||||
|
],
|
||||||
|
"break_autumn": [
|
||||||
|
"hu": "őszi",
|
||||||
|
"en": "autumn",
|
||||||
|
"de": "Herbst"
|
||||||
|
],
|
||||||
|
"break_winter": [
|
||||||
|
"hu": "téli",
|
||||||
|
"en": "winter",
|
||||||
|
"de": "Winter"
|
||||||
|
],
|
||||||
|
"break_spring": [
|
||||||
|
"hu": "tavaszi",
|
||||||
|
"en": "spring",
|
||||||
|
"de": "Frühlings"
|
||||||
|
],
|
||||||
|
"break_summer": [
|
||||||
|
"hu": "nyári",
|
||||||
|
"en": "summer",
|
||||||
|
"de": "Sommer"
|
||||||
|
],
|
||||||
|
"room": [
|
||||||
|
"hu": "Terem",
|
||||||
|
"en": "Room",
|
||||||
|
"de": "Raum"
|
||||||
|
],
|
||||||
|
"until": [
|
||||||
|
"hu": "eddig:",
|
||||||
|
"en": "until",
|
||||||
|
"de": "bis"
|
||||||
|
],
|
||||||
|
"no_more_lessons_today": [
|
||||||
|
"hu": "Ma már nincs több óra",
|
||||||
|
"en": "No more lessons today",
|
||||||
|
"de": "Keine Stunden mehr heute"
|
||||||
|
],
|
||||||
|
"tomorrow": [
|
||||||
|
"hu": "Holnap",
|
||||||
|
"en": "Tomorrow",
|
||||||
|
"de": "Morgen"
|
||||||
|
],
|
||||||
|
"tomorrow_short": [
|
||||||
|
"hu": "holnap",
|
||||||
|
"en": "tmrw",
|
||||||
|
"de": "morgen"
|
||||||
|
],
|
||||||
|
"next": [
|
||||||
|
"hu": "Következő",
|
||||||
|
"en": "Next",
|
||||||
|
"de": "Nächste"
|
||||||
|
],
|
||||||
|
"minutes_short": [
|
||||||
|
"hu": "perc",
|
||||||
|
"en": "min",
|
||||||
|
"de": "Min"
|
||||||
|
],
|
||||||
|
"lesson_short": [
|
||||||
|
"hu": "óra",
|
||||||
|
"en": "lesson",
|
||||||
|
"de": "Std"
|
||||||
|
],
|
||||||
|
"break_between": [
|
||||||
|
"hu": "Szünet",
|
||||||
|
"en": "Break",
|
||||||
|
"de": "Pause"
|
||||||
|
],
|
||||||
|
"in_minutes": [
|
||||||
|
"hu": "%d perc múlva",
|
||||||
|
"en": "in %d min",
|
||||||
|
"de": "in %d Min"
|
||||||
|
],
|
||||||
|
"today_new_grades": [
|
||||||
|
"hu": "Ma: %d új jegy",
|
||||||
|
"en": "Today: %d new",
|
||||||
|
"de": "Heute: %d neue"
|
||||||
|
],
|
||||||
|
"latest": [
|
||||||
|
"hu": "Legutóbbi",
|
||||||
|
"en": "Latest",
|
||||||
|
"de": "Letzte"
|
||||||
|
],
|
||||||
|
"today_grades": [
|
||||||
|
"hu": "Mai jegyek",
|
||||||
|
"en": "Today's grades",
|
||||||
|
"de": "Heutige Noten"
|
||||||
|
],
|
||||||
|
"pieces": [
|
||||||
|
"hu": "%d db",
|
||||||
|
"en": "%d pcs",
|
||||||
|
"de": "%d Stk"
|
||||||
|
],
|
||||||
|
"latest_grade": [
|
||||||
|
"hu": "Legutóbbi jegy",
|
||||||
|
"en": "Latest grade",
|
||||||
|
"de": "Letzte Note"
|
||||||
|
],
|
||||||
|
"average_short": [
|
||||||
|
"hu": "Átlag",
|
||||||
|
"en": "Avg",
|
||||||
|
"de": "Durchschn."
|
||||||
|
],
|
||||||
|
"overall_average_title": [
|
||||||
|
"hu": "Összesített átlag",
|
||||||
|
"en": "Overall average",
|
||||||
|
"de": "Gesamtdurchschnitt"
|
||||||
|
],
|
||||||
|
"subjects_count": [
|
||||||
|
"hu": "%d tárgy",
|
||||||
|
"en": "%d subjects",
|
||||||
|
"de": "%d Fächer"
|
||||||
|
],
|
||||||
|
"subject_averages_title": [
|
||||||
|
"hu": "Tantárgy átlagok",
|
||||||
|
"en": "Subject averages",
|
||||||
|
"de": "Fachdurchschnitte"
|
||||||
|
],
|
||||||
|
"subject_short": [
|
||||||
|
"hu": "tárgy",
|
||||||
|
"en": "subj",
|
||||||
|
"de": "Fächer"
|
||||||
|
],
|
||||||
|
"minutes_abbrev": [
|
||||||
|
"hu": "p",
|
||||||
|
"en": "min",
|
||||||
|
"de": "Min"
|
||||||
|
],
|
||||||
|
"hours_abbrev": [
|
||||||
|
"hu": "óra",
|
||||||
|
"en": "h",
|
||||||
|
"de": "Std"
|
||||||
|
],
|
||||||
|
"in_hours": [
|
||||||
|
"hu": "%d óra múlva",
|
||||||
|
"en": "in %d h",
|
||||||
|
"de": "in %d Std"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
func string(_ key: String) -> String {
|
||||||
|
translations[key]?[locale] ?? translations[key]?["hu"] ?? key
|
||||||
|
}
|
||||||
|
|
||||||
|
func string(_ key: String, _ arg: String) -> String {
|
||||||
|
let template = string(key)
|
||||||
|
return template.replacingOccurrences(of: "%@", with: arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func string(_ key: String, _ arg: Int) -> String {
|
||||||
|
let template = string(key)
|
||||||
|
return template.replacingOccurrences(of: "%d", with: "\(arg)")
|
||||||
|
}
|
||||||
|
|
||||||
|
static func formatShortDate(_ isoString: String?, locale: String = "hu") -> String {
|
||||||
|
guard let isoString = isoString else { return "" }
|
||||||
|
|
||||||
|
let isoFormatter = ISO8601DateFormatter()
|
||||||
|
isoFormatter.formatOptions = [.withInternetDateTime]
|
||||||
|
|
||||||
|
let shortFormatter = DateFormatter()
|
||||||
|
shortFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
|
||||||
|
shortFormatter.locale = Locale(identifier: "en_US_POSIX")
|
||||||
|
|
||||||
|
let date: Date?
|
||||||
|
if let d = isoFormatter.date(from: isoString) {
|
||||||
|
date = d
|
||||||
|
} else if let d = shortFormatter.date(from: isoString) {
|
||||||
|
date = d
|
||||||
|
} else {
|
||||||
|
let simple = DateFormatter()
|
||||||
|
simple.dateFormat = "yyyy-MM-dd"
|
||||||
|
simple.locale = Locale(identifier: "en_US_POSIX")
|
||||||
|
date = simple.date(from: String(isoString.prefix(10)))
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let date = date else { return "" }
|
||||||
|
|
||||||
|
let displayFormatter = DateFormatter()
|
||||||
|
displayFormatter.locale = Locale(identifier: locale == "de" ? "de_DE" : locale == "en" ? "en_US" : "hu_HU")
|
||||||
|
displayFormatter.dateFormat = locale == "hu" ? "MMM d." : "MMM d"
|
||||||
|
return displayFormatter.string(from: date)
|
||||||
|
}
|
||||||
|
}
|
||||||
29
firka/ios/HomeWidgetsExtension/HomeWidgetsBundle.swift
Normal file
29
firka/ios/HomeWidgetsExtension/HomeWidgetsBundle.swift
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
@main
|
||||||
|
struct HomeWidgetsBundle: WidgetBundle {
|
||||||
|
var body: some Widget {
|
||||||
|
// Home Screen Widgets
|
||||||
|
TimetableWidget()
|
||||||
|
GradesWidget()
|
||||||
|
AveragesWidget()
|
||||||
|
|
||||||
|
// Lock Screen Widgets (circular & rectangular)
|
||||||
|
TimetableLockScreenWidget()
|
||||||
|
GradesLockScreenWidget()
|
||||||
|
AveragesLockScreenWidget()
|
||||||
|
|
||||||
|
// Inline Widgets (above the clock)
|
||||||
|
TimetableInlineWidget()
|
||||||
|
GradesInlineWidget()
|
||||||
|
AveragesInlineWidget()
|
||||||
|
|
||||||
|
// Control Widgets (iOS 18+ Control Center & Lock Screen buttons)
|
||||||
|
if #available(iOS 18.0, *) {
|
||||||
|
HomeControl()
|
||||||
|
GradesControl()
|
||||||
|
TimetableControl()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
firka/ios/HomeWidgetsExtension/Info.plist
Normal file
11
firka/ios/HomeWidgetsExtension/Info.plist
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>NSExtension</key>
|
||||||
|
<dict>
|
||||||
|
<key>NSExtensionPointIdentifier</key>
|
||||||
|
<string>com.apple.widgetkit-extension</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
13
firka/ios/HomeWidgetsExtension/Intents/AveragesIntent.swift
Normal file
13
firka/ios/HomeWidgetsExtension/Intents/AveragesIntent.swift
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import AppIntents
|
||||||
|
import WidgetKit
|
||||||
|
|
||||||
|
struct AveragesWidgetIntent: WidgetConfigurationIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("widget_averages_title", defaultValue: "Averages")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("widget_averages_description", defaultValue: "Shows subject averages"))
|
||||||
|
|
||||||
|
@Parameter(title: LocalizedStringResource("param_style", defaultValue: "Style"), default: .liquidGlass)
|
||||||
|
var style: WidgetStyle?
|
||||||
|
|
||||||
|
@Parameter(title: LocalizedStringResource("param_subjects", defaultValue: "Subjects"))
|
||||||
|
var selectedSubjects: [SubjectEntity]?
|
||||||
|
}
|
||||||
10
firka/ios/HomeWidgetsExtension/Intents/GradesIntent.swift
Normal file
10
firka/ios/HomeWidgetsExtension/Intents/GradesIntent.swift
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import AppIntents
|
||||||
|
import WidgetKit
|
||||||
|
|
||||||
|
struct GradesWidgetIntent: WidgetConfigurationIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("widget_grades_title", defaultValue: "Recent Grades")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("widget_grades_description", defaultValue: "Shows your recent grades"))
|
||||||
|
|
||||||
|
@Parameter(title: LocalizedStringResource("param_style", defaultValue: "Style"), default: .liquidGlass)
|
||||||
|
var style: WidgetStyle?
|
||||||
|
}
|
||||||
45
firka/ios/HomeWidgetsExtension/Intents/TimetableIntent.swift
Normal file
45
firka/ios/HomeWidgetsExtension/Intents/TimetableIntent.swift
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import AppIntents
|
||||||
|
import WidgetKit
|
||||||
|
|
||||||
|
enum TimetableDisplayMode: String, AppEnum {
|
||||||
|
case current = "current"
|
||||||
|
case next = "next"
|
||||||
|
|
||||||
|
static var typeDisplayRepresentation: TypeDisplayRepresentation {
|
||||||
|
TypeDisplayRepresentation(name: LocalizedStringResource("display_mode_type", defaultValue: "Display Mode"))
|
||||||
|
}
|
||||||
|
|
||||||
|
static var caseDisplayRepresentations: [TimetableDisplayMode: DisplayRepresentation] {
|
||||||
|
[
|
||||||
|
.current: DisplayRepresentation(title: LocalizedStringResource("display_mode_current", defaultValue: "Current Lesson")),
|
||||||
|
.next: DisplayRepresentation(title: LocalizedStringResource("display_mode_next", defaultValue: "Next Lesson"))
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum WidgetStyle: String, AppEnum {
|
||||||
|
case liquidGlass = "liquid_glass"
|
||||||
|
case appTheme = "app_theme"
|
||||||
|
|
||||||
|
static var typeDisplayRepresentation: TypeDisplayRepresentation {
|
||||||
|
TypeDisplayRepresentation(name: LocalizedStringResource("style_type", defaultValue: "Style"))
|
||||||
|
}
|
||||||
|
|
||||||
|
static var caseDisplayRepresentations: [WidgetStyle: DisplayRepresentation] {
|
||||||
|
[
|
||||||
|
.liquidGlass: DisplayRepresentation(title: LocalizedStringResource("style_liquid_glass", defaultValue: "Liquid Glass")),
|
||||||
|
.appTheme: DisplayRepresentation(title: LocalizedStringResource("style_app_theme", defaultValue: "App Theme"))
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TimetableWidgetIntent: WidgetConfigurationIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("widget_timetable_title", defaultValue: "Timetable")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("widget_timetable_description", defaultValue: "Shows your daily timetable"))
|
||||||
|
|
||||||
|
@Parameter(title: LocalizedStringResource("param_style", defaultValue: "Style"), default: .liquidGlass)
|
||||||
|
var style: WidgetStyle?
|
||||||
|
|
||||||
|
@Parameter(title: LocalizedStringResource("param_display_mode_small", defaultValue: "Small Widget Display"), default: .current)
|
||||||
|
var displayMode: TimetableDisplayMode?
|
||||||
|
}
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
// MARK: - Lock Screen Averages Widget
|
||||||
|
|
||||||
|
struct AveragesLockScreenWidget: Widget {
|
||||||
|
let kind: String = "AveragesLockScreenWidget"
|
||||||
|
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
AppIntentConfiguration(
|
||||||
|
kind: kind,
|
||||||
|
intent: AveragesWidgetIntent.self,
|
||||||
|
provider: AveragesProvider()
|
||||||
|
) { entry in
|
||||||
|
AveragesLockScreenView(entry: entry)
|
||||||
|
}
|
||||||
|
.configurationDisplayName(LocalizedStringResource("widget_averages_title", defaultValue: "Averages"))
|
||||||
|
.description(LocalizedStringResource("widget_averages_lockscreen_description", defaultValue: "Shows your averages on lock screen"))
|
||||||
|
.supportedFamilies([.accessoryCircular, .accessoryRectangular])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Lock Screen View
|
||||||
|
|
||||||
|
struct AveragesLockScreenView: View {
|
||||||
|
@Environment(\.widgetFamily) var family
|
||||||
|
let entry: AveragesEntry
|
||||||
|
|
||||||
|
var localization: WidgetLocalization {
|
||||||
|
WidgetLocalization(locale: entry.locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Group {
|
||||||
|
switch family {
|
||||||
|
case .accessoryInline:
|
||||||
|
AveragesInlineView(entry: entry, localization: localization)
|
||||||
|
case .accessoryCircular:
|
||||||
|
AveragesCircularView(entry: entry, localization: localization)
|
||||||
|
case .accessoryRectangular:
|
||||||
|
AveragesRectangularView(entry: entry, localization: localization)
|
||||||
|
default:
|
||||||
|
Text("--")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.containerBackground(.clear, for: .widget)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Inline View
|
||||||
|
|
||||||
|
struct AveragesInlineView: View {
|
||||||
|
let entry: AveragesEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if let overall = entry.overallAverage {
|
||||||
|
Text("\(localization.string("average_short")): \(String(format: "%.2f", overall))")
|
||||||
|
} else if let first = entry.subjectAverages.first {
|
||||||
|
Text("\(first.name): \(String(format: "%.2f", first.average))")
|
||||||
|
} else {
|
||||||
|
Text(localization.string("no_averages"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Circular View
|
||||||
|
|
||||||
|
struct AveragesCircularView: View {
|
||||||
|
let entry: AveragesEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if let overall = entry.overallAverage {
|
||||||
|
Gauge(value: overall, in: 1...5) {
|
||||||
|
Text("")
|
||||||
|
} currentValueLabel: {
|
||||||
|
Text(String(format: "%.1f", overall))
|
||||||
|
.font(.system(.title2, design: .rounded, weight: .bold))
|
||||||
|
.foregroundStyle(averageColor(overall))
|
||||||
|
}
|
||||||
|
.gaugeStyle(.accessoryCircularCapacity)
|
||||||
|
.tint(averageColor(overall))
|
||||||
|
} else if let first = entry.subjectAverages.first {
|
||||||
|
ZStack {
|
||||||
|
AccessoryWidgetBackground()
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
Text(String(format: "%.1f", first.average))
|
||||||
|
.font(.system(.title2, design: .rounded, weight: .bold))
|
||||||
|
.foregroundStyle(averageColor(first.average))
|
||||||
|
Text(String(first.name.prefix(4)))
|
||||||
|
.font(.system(.caption2))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ZStack {
|
||||||
|
AccessoryWidgetBackground()
|
||||||
|
Image(systemName: "chart.bar")
|
||||||
|
.font(.title2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func averageColor(_ value: Double) -> Color {
|
||||||
|
switch value {
|
||||||
|
case 4.5...: return .green
|
||||||
|
case 3.5..<4.5: return .blue
|
||||||
|
case 2.5..<3.5: return .yellow
|
||||||
|
case 1.5..<2.5: return .orange
|
||||||
|
default: return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Rectangular View
|
||||||
|
|
||||||
|
struct AveragesRectangularView: View {
|
||||||
|
let entry: AveragesEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if let overall = entry.overallAverage {
|
||||||
|
HStack(spacing: 8) {
|
||||||
|
Text(String(format: "%.2f", overall))
|
||||||
|
.font(.system(.title, design: .rounded, weight: .bold))
|
||||||
|
.foregroundStyle(averageColor(overall))
|
||||||
|
.fixedSize()
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 0) {
|
||||||
|
Text(localization.string("average_short"))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
Text(localization.string("subjects_count", entry.subjectAverages.count))
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else if !entry.subjectAverages.isEmpty {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text(localization.string("subject_averages_title"))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
HStack(spacing: 8) {
|
||||||
|
ForEach(entry.subjectAverages.prefix(3), id: \.uid) { subject in
|
||||||
|
VStack(alignment: .leading, spacing: 0) {
|
||||||
|
Text(String(format: "%.1f", subject.average))
|
||||||
|
.font(.system(.subheadline, design: .rounded, weight: .bold))
|
||||||
|
.foregroundStyle(averageColor(subject.average))
|
||||||
|
Text(String(subject.name.prefix(5)))
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else {
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Label(localization.string("no_averages"), systemImage: "chart.bar")
|
||||||
|
.font(.headline)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func averageColor(_ value: Double) -> Color {
|
||||||
|
switch value {
|
||||||
|
case 4.5...: return .green
|
||||||
|
case 3.5..<4.5: return .blue
|
||||||
|
case 2.5..<3.5: return .yellow
|
||||||
|
case 1.5..<2.5: return .orange
|
||||||
|
default: return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,232 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
// MARK: - Lock Screen Grades Widget
|
||||||
|
|
||||||
|
struct GradesLockScreenWidget: Widget {
|
||||||
|
let kind: String = "GradesLockScreenWidget"
|
||||||
|
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
AppIntentConfiguration(
|
||||||
|
kind: kind,
|
||||||
|
intent: GradesWidgetIntent.self,
|
||||||
|
provider: GradesProvider()
|
||||||
|
) { entry in
|
||||||
|
GradesLockScreenView(entry: entry)
|
||||||
|
}
|
||||||
|
.configurationDisplayName(LocalizedStringResource("widget_grades_title", defaultValue: "Recent Grades"))
|
||||||
|
.description(LocalizedStringResource("widget_grades_lockscreen_description", defaultValue: "Shows recent grades on lock screen"))
|
||||||
|
.supportedFamilies([.accessoryCircular, .accessoryRectangular])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Lock Screen View
|
||||||
|
|
||||||
|
struct GradesLockScreenView: View {
|
||||||
|
@Environment(\.widgetFamily) var family
|
||||||
|
let entry: GradesEntry
|
||||||
|
|
||||||
|
var localization: WidgetLocalization {
|
||||||
|
WidgetLocalization(locale: entry.locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Group {
|
||||||
|
switch family {
|
||||||
|
case .accessoryInline:
|
||||||
|
GradesInlineView(entry: entry, localization: localization)
|
||||||
|
case .accessoryCircular:
|
||||||
|
GradesCircularView(entry: entry, localization: localization)
|
||||||
|
case .accessoryRectangular:
|
||||||
|
GradesRectangularView(entry: entry, localization: localization)
|
||||||
|
default:
|
||||||
|
Text("--")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.containerBackground(.clear, for: .widget)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Inline View
|
||||||
|
|
||||||
|
struct GradesInlineView: View {
|
||||||
|
let entry: GradesEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var todayGrades: [WidgetGrade] {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let today = calendar.startOfDay(for: Date())
|
||||||
|
return entry.grades.filter { calendar.startOfDay(for: $0.recordDate) == today }
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if let latest = entry.grades.first {
|
||||||
|
if todayGrades.count > 0 {
|
||||||
|
Text(localization.string("today_new_grades", todayGrades.count))
|
||||||
|
} else {
|
||||||
|
Text("\(localization.string("latest")): \(latest.displayValue) \(latest.subject.name)")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Text(localization.string("no_grades"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Circular View
|
||||||
|
|
||||||
|
struct GradesCircularView: View {
|
||||||
|
let entry: GradesEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var todayGradesCount: Int {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let today = calendar.startOfDay(for: Date())
|
||||||
|
return entry.grades.filter { calendar.startOfDay(for: $0.recordDate) == today }.count
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if let latest = entry.grades.first {
|
||||||
|
ZStack {
|
||||||
|
AccessoryWidgetBackground()
|
||||||
|
Text(latest.displayValue)
|
||||||
|
.font(.system(.title, design: .rounded, weight: .bold))
|
||||||
|
.foregroundStyle(gradeColor(latest.numericValue))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ZStack {
|
||||||
|
AccessoryWidgetBackground()
|
||||||
|
Image(systemName: "graduationcap")
|
||||||
|
.font(.title2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func gradeColor(_ value: Int?) -> Color {
|
||||||
|
guard let value = value else { return .primary }
|
||||||
|
switch value {
|
||||||
|
case 5: return .green
|
||||||
|
case 4: return .blue
|
||||||
|
case 3: return .yellow
|
||||||
|
case 2: return .orange
|
||||||
|
case 1: return .red
|
||||||
|
default: return .primary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Rectangular View
|
||||||
|
|
||||||
|
struct GradesRectangularView: View {
|
||||||
|
let entry: GradesEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var todayGrades: [WidgetGrade] {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let today = calendar.startOfDay(for: Date())
|
||||||
|
return entry.grades.filter { calendar.startOfDay(for: $0.recordDate) == today }
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if !entry.grades.isEmpty {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
if todayGrades.count > 0 {
|
||||||
|
HStack {
|
||||||
|
Text(localization.string("today_grades"))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
Spacer()
|
||||||
|
Text(localization.string("pieces", todayGrades.count))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
ForEach(todayGrades.prefix(5), id: \.uid) { grade in
|
||||||
|
GradeBadge(grade: grade)
|
||||||
|
}
|
||||||
|
if todayGrades.count > 5 {
|
||||||
|
Text("+\(todayGrades.count - 5)")
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
} else if let latest = entry.grades.first {
|
||||||
|
HStack {
|
||||||
|
Text(localization.string("latest_grade"))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
Spacer()
|
||||||
|
Text(formatDate(latest.recordDate))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
HStack {
|
||||||
|
Text(latest.displayValue)
|
||||||
|
.font(.title2)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.foregroundStyle(gradeColor(latest.numericValue))
|
||||||
|
Text(latest.subject.name)
|
||||||
|
.font(.subheadline)
|
||||||
|
.lineLimit(1)
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else {
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Label(localization.string("no_grades"), systemImage: "graduationcap")
|
||||||
|
.font(.headline)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func formatDate(_ date: Date) -> String {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "MMM d."
|
||||||
|
return formatter.string(from: date)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func gradeColor(_ value: Int?) -> Color {
|
||||||
|
guard let value = value else { return .primary }
|
||||||
|
switch value {
|
||||||
|
case 5: return .green
|
||||||
|
case 4: return .blue
|
||||||
|
case 3: return .yellow
|
||||||
|
case 2: return .orange
|
||||||
|
case 1: return .red
|
||||||
|
default: return .primary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Grade Badge
|
||||||
|
|
||||||
|
struct GradeBadge: View {
|
||||||
|
let grade: WidgetGrade
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Text(grade.displayValue)
|
||||||
|
.font(.system(.caption, design: .rounded, weight: .bold))
|
||||||
|
.foregroundStyle(gradeColor(grade.numericValue))
|
||||||
|
.padding(.horizontal, 6)
|
||||||
|
.padding(.vertical, 2)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 4)
|
||||||
|
.fill(gradeColor(grade.numericValue).opacity(0.2))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func gradeColor(_ value: Int?) -> Color {
|
||||||
|
guard let value = value else { return .primary }
|
||||||
|
switch value {
|
||||||
|
case 5: return .green
|
||||||
|
case 4: return .blue
|
||||||
|
case 3: return .yellow
|
||||||
|
case 2: return .orange
|
||||||
|
case 1: return .red
|
||||||
|
default: return .primary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
154
firka/ios/HomeWidgetsExtension/LockScreen/InlineWidgets.swift
Normal file
154
firka/ios/HomeWidgetsExtension/LockScreen/InlineWidgets.swift
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
// MARK: - Timetable Inline Widget
|
||||||
|
|
||||||
|
struct TimetableInlineWidget: Widget {
|
||||||
|
let kind: String = "TimetableInlineWidget"
|
||||||
|
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
AppIntentConfiguration(
|
||||||
|
kind: kind,
|
||||||
|
intent: TimetableWidgetIntent.self,
|
||||||
|
provider: TimetableProvider()
|
||||||
|
) { entry in
|
||||||
|
TimetableInlineWidgetView(entry: entry)
|
||||||
|
.containerBackground(.clear, for: .widget)
|
||||||
|
}
|
||||||
|
.configurationDisplayName(LocalizedStringResource("widget_timetable_title", defaultValue: "Timetable"))
|
||||||
|
.description(LocalizedStringResource("widget_timetable_inline_description", defaultValue: "Shows next lesson above the clock"))
|
||||||
|
.supportedFamilies([.accessoryInline])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TimetableInlineWidgetView: View {
|
||||||
|
let entry: TimetableEntry
|
||||||
|
|
||||||
|
var localization: WidgetLocalization {
|
||||||
|
WidgetLocalization(locale: entry.data?.locale ?? "hu")
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if entry.state == .onBreak, let breakInfo = entry.breakInfo {
|
||||||
|
Text(localization.string(breakInfo.nameKey))
|
||||||
|
} else if let current = entry.currentLesson {
|
||||||
|
let remaining = minutesRemaining(until: current.end)
|
||||||
|
Text("\(current.subject.name) · \(remaining) \(localization.string("minutes_abbrev"))")
|
||||||
|
} else if entry.isNextSchoolDay {
|
||||||
|
if let first = entry.lessons.first {
|
||||||
|
let dateStr = WidgetLocalization.formatShortDate(entry.nextSchoolDayDateString, locale: localization.locale)
|
||||||
|
let lessonNum = first.lessonNumber ?? 1
|
||||||
|
Text("\(dateStr): \(lessonNum). \(first.subject.name)")
|
||||||
|
} else {
|
||||||
|
Text(localization.string("no_lessons_ahead"))
|
||||||
|
}
|
||||||
|
} else if entry.isNextDay {
|
||||||
|
if let first = entry.lessons.first {
|
||||||
|
let lessonNum = first.lessonNumber ?? 1
|
||||||
|
Text("\(localization.string("tomorrow")): \(lessonNum). \(first.subject.name)")
|
||||||
|
} else {
|
||||||
|
Text(localization.string("no_lessons_ahead"))
|
||||||
|
}
|
||||||
|
} else if let next = entry.nextLesson {
|
||||||
|
let until = minutesRemaining(until: next.start)
|
||||||
|
if until <= 0 {
|
||||||
|
Text("→ \(next.subject.name)")
|
||||||
|
} else if until > 60 {
|
||||||
|
let hours = until / 60
|
||||||
|
Text("→ \(next.subject.name) · \(hours) \(localization.string("hours_abbrev"))")
|
||||||
|
} else {
|
||||||
|
Text("→ \(next.subject.name) · \(until) \(localization.string("minutes_abbrev"))")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Text(localization.string("no_lessons_ahead"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func minutesRemaining(until date: Date) -> Int {
|
||||||
|
let diff = date.timeIntervalSince(entry.date)
|
||||||
|
return max(0, Int(ceil(diff / 60)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Grades Inline Widget
|
||||||
|
|
||||||
|
struct GradesInlineWidget: Widget {
|
||||||
|
let kind: String = "GradesInlineWidget"
|
||||||
|
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
AppIntentConfiguration(
|
||||||
|
kind: kind,
|
||||||
|
intent: GradesWidgetIntent.self,
|
||||||
|
provider: GradesProvider()
|
||||||
|
) { entry in
|
||||||
|
GradesInlineWidgetView(entry: entry)
|
||||||
|
.containerBackground(.clear, for: .widget)
|
||||||
|
}
|
||||||
|
.configurationDisplayName(LocalizedStringResource("widget_grades_title", defaultValue: "Grades"))
|
||||||
|
.description(LocalizedStringResource("widget_grades_inline_description", defaultValue: "Shows recent grades above the clock"))
|
||||||
|
.supportedFamilies([.accessoryInline])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GradesInlineWidgetView: View {
|
||||||
|
let entry: GradesEntry
|
||||||
|
|
||||||
|
var localization: WidgetLocalization {
|
||||||
|
WidgetLocalization(locale: entry.locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
var todayGrades: [WidgetGrade] {
|
||||||
|
let calendar = Calendar.current
|
||||||
|
let today = calendar.startOfDay(for: Date())
|
||||||
|
return entry.grades.filter { calendar.startOfDay(for: $0.recordDate) == today }
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if todayGrades.count > 0 {
|
||||||
|
Text("📝 \(localization.string("today_new_grades", todayGrades.count))")
|
||||||
|
} else if let latest = entry.grades.first {
|
||||||
|
// No grades today - show latest
|
||||||
|
Text("\(localization.string("latest")): \(latest.displayValue) \(latest.subject.name)")
|
||||||
|
} else {
|
||||||
|
Text(localization.string("no_grades"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Averages Inline Widget
|
||||||
|
|
||||||
|
struct AveragesInlineWidget: Widget {
|
||||||
|
let kind: String = "AveragesInlineWidget"
|
||||||
|
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
AppIntentConfiguration(
|
||||||
|
kind: kind,
|
||||||
|
intent: AveragesWidgetIntent.self,
|
||||||
|
provider: AveragesProvider()
|
||||||
|
) { entry in
|
||||||
|
AveragesInlineWidgetView(entry: entry)
|
||||||
|
.containerBackground(.clear, for: .widget)
|
||||||
|
}
|
||||||
|
.configurationDisplayName(LocalizedStringResource("widget_averages_title", defaultValue: "Averages"))
|
||||||
|
.description(LocalizedStringResource("widget_averages_inline_description", defaultValue: "Shows your average above the clock"))
|
||||||
|
.supportedFamilies([.accessoryInline])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AveragesInlineWidgetView: View {
|
||||||
|
let entry: AveragesEntry
|
||||||
|
|
||||||
|
var localization: WidgetLocalization {
|
||||||
|
WidgetLocalization(locale: entry.locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if let overall = entry.overallAverage {
|
||||||
|
Text("\(localization.string("average_short")): \(String(format: "%.2f", overall)) · \(entry.subjectAverages.count) \(localization.string("subject_short"))")
|
||||||
|
} else if let first = entry.subjectAverages.first {
|
||||||
|
Text("\(first.name): \(String(format: "%.2f", first.average))")
|
||||||
|
} else {
|
||||||
|
Text(localization.string("no_averages"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,301 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
// MARK: - Lock Screen Timetable Widget
|
||||||
|
|
||||||
|
struct TimetableLockScreenWidget: Widget {
|
||||||
|
let kind: String = "TimetableLockScreenWidget"
|
||||||
|
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
AppIntentConfiguration(
|
||||||
|
kind: kind,
|
||||||
|
intent: TimetableWidgetIntent.self,
|
||||||
|
provider: TimetableProvider()
|
||||||
|
) { entry in
|
||||||
|
TimetableLockScreenView(entry: entry)
|
||||||
|
}
|
||||||
|
.configurationDisplayName(LocalizedStringResource("widget_timetable_title", defaultValue: "Timetable"))
|
||||||
|
.description(LocalizedStringResource("widget_timetable_lockscreen_description", defaultValue: "Shows current lesson on lock screen"))
|
||||||
|
.supportedFamilies([.accessoryCircular, .accessoryRectangular])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Lock Screen View
|
||||||
|
|
||||||
|
struct TimetableLockScreenView: View {
|
||||||
|
@Environment(\.widgetFamily) var family
|
||||||
|
let entry: TimetableEntry
|
||||||
|
|
||||||
|
var localization: WidgetLocalization {
|
||||||
|
WidgetLocalization(locale: entry.data?.locale ?? "hu")
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Group {
|
||||||
|
switch family {
|
||||||
|
case .accessoryInline:
|
||||||
|
TimetableInlineView(entry: entry, localization: localization)
|
||||||
|
case .accessoryCircular:
|
||||||
|
TimetableCircularView(entry: entry, localization: localization)
|
||||||
|
case .accessoryRectangular:
|
||||||
|
TimetableRectangularView(entry: entry, localization: localization)
|
||||||
|
default:
|
||||||
|
Text("--")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.containerBackground(.clear, for: .widget)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Inline View (single line next to date)
|
||||||
|
|
||||||
|
struct TimetableInlineView: View {
|
||||||
|
let entry: TimetableEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if entry.state == .onBreak, let breakInfo = entry.breakInfo {
|
||||||
|
Text("🏖️ \(localization.string(breakInfo.nameKey))")
|
||||||
|
} else if let current = entry.currentLesson {
|
||||||
|
let remaining = minutesRemaining(until: current.end)
|
||||||
|
Text("\(current.subject.name) - \(remaining) \(localization.string("minutes_short"))")
|
||||||
|
} else if entry.isNextSchoolDay {
|
||||||
|
if let first = entry.lessons.first {
|
||||||
|
let dateStr = WidgetLocalization.formatShortDate(entry.nextSchoolDayDateString, locale: localization.locale)
|
||||||
|
let lessonNum = first.lessonNumber ?? 1
|
||||||
|
Text("\(dateStr): \(lessonNum). \(first.subject.name)")
|
||||||
|
} else {
|
||||||
|
Text(localization.string("no_lessons_ahead"))
|
||||||
|
}
|
||||||
|
} else if entry.isNextDay {
|
||||||
|
if let first = entry.lessons.first {
|
||||||
|
let lessonNum = first.lessonNumber ?? 1
|
||||||
|
Text("\(localization.string("tomorrow")): \(lessonNum). \(first.subject.name)")
|
||||||
|
} else {
|
||||||
|
Text(localization.string("no_lessons_ahead"))
|
||||||
|
}
|
||||||
|
} else if let next = entry.nextLesson {
|
||||||
|
let until = minutesRemaining(until: next.start)
|
||||||
|
if until <= 0 {
|
||||||
|
Text("\(localization.string("next")): \(next.subject.name)")
|
||||||
|
} else if until > 60 {
|
||||||
|
let hours = until / 60
|
||||||
|
Text("\(next.subject.name) \(localization.string("in_hours", hours))")
|
||||||
|
} else {
|
||||||
|
Text("\(next.subject.name) \(localization.string("in_minutes", until))")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Text(localization.string("no_lessons_ahead"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func minutesRemaining(until date: Date) -> Int {
|
||||||
|
let diff = date.timeIntervalSince(entry.date)
|
||||||
|
return max(0, Int(ceil(diff / 60)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Circular View (small circle)
|
||||||
|
|
||||||
|
struct TimetableCircularView: View {
|
||||||
|
let entry: TimetableEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if entry.state == .onBreak {
|
||||||
|
ZStack {
|
||||||
|
AccessoryWidgetBackground()
|
||||||
|
Image(systemName: "sun.max.fill")
|
||||||
|
.font(.title2)
|
||||||
|
}
|
||||||
|
} else if let current = entry.currentLesson {
|
||||||
|
let remaining = minutesRemaining(until: current.end)
|
||||||
|
Gauge(value: Double(remaining), in: 0...45) {
|
||||||
|
Text("")
|
||||||
|
} currentValueLabel: {
|
||||||
|
Text("\(remaining)")
|
||||||
|
.font(.system(.title2, design: .rounded, weight: .bold))
|
||||||
|
}
|
||||||
|
.gaugeStyle(.accessoryCircularCapacity)
|
||||||
|
} else if entry.isNextSchoolDay || entry.isNextDay {
|
||||||
|
let lessonCount = entry.lessons.count
|
||||||
|
if lessonCount > 0 {
|
||||||
|
ZStack {
|
||||||
|
AccessoryWidgetBackground()
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
Text("\(lessonCount)")
|
||||||
|
.font(.system(.title2, design: .rounded, weight: .bold))
|
||||||
|
Text(localization.string("lesson_short"))
|
||||||
|
.font(.system(.caption2))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ZStack {
|
||||||
|
AccessoryWidgetBackground()
|
||||||
|
Image(systemName: "calendar.badge.checkmark")
|
||||||
|
.font(.title2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if let next = entry.nextLesson {
|
||||||
|
let until = minutesRemaining(until: next.start)
|
||||||
|
ZStack {
|
||||||
|
AccessoryWidgetBackground()
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
if until > 60 {
|
||||||
|
let hours = until / 60
|
||||||
|
Text("\(hours)")
|
||||||
|
.font(.system(.title2, design: .rounded, weight: .bold))
|
||||||
|
Text(localization.string("hours_abbrev"))
|
||||||
|
.font(.system(.caption2))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
} else {
|
||||||
|
Text("\(until)")
|
||||||
|
.font(.system(.title2, design: .rounded, weight: .bold))
|
||||||
|
Text(localization.string("minutes_abbrev"))
|
||||||
|
.font(.system(.caption2))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if let lesson = entry.lessons.first, let lessonNum = lesson.lessonNumber {
|
||||||
|
ZStack {
|
||||||
|
AccessoryWidgetBackground()
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
Text("\(lessonNum).")
|
||||||
|
.font(.system(.title2, design: .rounded, weight: .bold))
|
||||||
|
Text(localization.string("lesson_short"))
|
||||||
|
.font(.system(.caption2))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ZStack {
|
||||||
|
AccessoryWidgetBackground()
|
||||||
|
Image(systemName: "calendar.badge.checkmark")
|
||||||
|
.font(.title2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func minutesRemaining(until date: Date) -> Int {
|
||||||
|
let diff = date.timeIntervalSince(entry.date)
|
||||||
|
return max(0, Int(ceil(diff / 60)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Rectangular View (medium rectangle)
|
||||||
|
|
||||||
|
struct TimetableRectangularView: View {
|
||||||
|
let entry: TimetableEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if entry.state == .onBreak, let breakInfo = entry.breakInfo {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Label(localization.string(breakInfo.nameKey), systemImage: "sun.max.fill")
|
||||||
|
.font(.headline)
|
||||||
|
Text(localization.string("until") + " " + formatDate(breakInfo.endDate))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else if let current = entry.currentLesson {
|
||||||
|
let remaining = minutesRemaining(until: current.end)
|
||||||
|
let lessonNum = current.lessonNumber ?? 0
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
HStack {
|
||||||
|
Text("\(lessonNum). \(current.subject.name)")
|
||||||
|
.font(.headline)
|
||||||
|
.lineLimit(1)
|
||||||
|
Spacer()
|
||||||
|
Text("\(remaining)'")
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
HStack {
|
||||||
|
if let room = current.roomName {
|
||||||
|
Label(room, systemImage: "mappin")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
Text(formatTimeRange(current.start, current.end))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else if let next = entry.nextLesson {
|
||||||
|
let until = minutesRemaining(until: next.start)
|
||||||
|
let isFutureDay = entry.isNextDay || entry.isNextSchoolDay
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
HStack {
|
||||||
|
if entry.isNextSchoolDay {
|
||||||
|
let dateStr = WidgetLocalization.formatShortDate(entry.nextSchoolDayDateString, locale: localization.locale)
|
||||||
|
Text(dateStr)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
} else {
|
||||||
|
Text(entry.isNextDay ? localization.string("tomorrow") : localization.string("next"))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
if until > 0 && !isFutureDay {
|
||||||
|
if until > 60 {
|
||||||
|
Text(localization.string("in_hours", until / 60))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
} else {
|
||||||
|
Text(localization.string("in_minutes", until))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Text("\(next.lessonNumber ?? 0). \(next.subject.name)")
|
||||||
|
.font(.headline)
|
||||||
|
.lineLimit(1)
|
||||||
|
HStack {
|
||||||
|
if let room = next.roomName {
|
||||||
|
Label(room, systemImage: "mappin")
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
Text(formatTimeRange(next.start, next.end))
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else {
|
||||||
|
VStack(alignment: .leading) {
|
||||||
|
Label(localization.string("no_lessons"), systemImage: "checkmark.circle")
|
||||||
|
.font(.headline)
|
||||||
|
Text(localization.string("no_more_lessons_today"))
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func minutesRemaining(until date: Date) -> Int {
|
||||||
|
let diff = date.timeIntervalSince(entry.date)
|
||||||
|
return max(0, Int(ceil(diff / 60)))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func formatTimeRange(_ start: Date, _ end: Date) -> String {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "HH:mm"
|
||||||
|
return "\(formatter.string(from: start)) - \(formatter.string(from: end))"
|
||||||
|
}
|
||||||
|
|
||||||
|
private func formatDate(_ date: Date) -> String {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "MMM d."
|
||||||
|
return formatter.string(from: date)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct AveragesEntry: TimelineEntry {
|
||||||
|
let date: Date
|
||||||
|
let configuration: AveragesWidgetIntent
|
||||||
|
let overallAverage: Double?
|
||||||
|
let subjectAverages: [SubjectAverage]
|
||||||
|
let locale: String
|
||||||
|
let isFiltered: Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AveragesProvider: AppIntentTimelineProvider {
|
||||||
|
typealias Entry = AveragesEntry
|
||||||
|
typealias Intent = AveragesWidgetIntent
|
||||||
|
|
||||||
|
func placeholder(in context: Context) -> AveragesEntry {
|
||||||
|
AveragesEntry(
|
||||||
|
date: Date(),
|
||||||
|
configuration: AveragesWidgetIntent(),
|
||||||
|
overallAverage: nil,
|
||||||
|
subjectAverages: [],
|
||||||
|
locale: "hu",
|
||||||
|
isFiltered: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func snapshot(for configuration: AveragesWidgetIntent, in context: Context) async -> AveragesEntry {
|
||||||
|
createEntry(for: configuration)
|
||||||
|
}
|
||||||
|
|
||||||
|
func timeline(for configuration: AveragesWidgetIntent, in context: Context) async -> Timeline<AveragesEntry> {
|
||||||
|
let entry = createEntry(for: configuration)
|
||||||
|
|
||||||
|
// Refresh every 30 minutes
|
||||||
|
let refreshDate = Date().addingTimeInterval(30 * 60)
|
||||||
|
return Timeline(entries: [entry], policy: .after(refreshDate))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func createEntry(for configuration: AveragesWidgetIntent) -> AveragesEntry {
|
||||||
|
let data = WidgetData.load()
|
||||||
|
|
||||||
|
var subjectAverages = data?.averages.subjects ?? []
|
||||||
|
let isFiltered = configuration.selectedSubjects?.isEmpty == false
|
||||||
|
|
||||||
|
if isFiltered {
|
||||||
|
let selectedIds = Set(configuration.selectedSubjects!.map { $0.id })
|
||||||
|
subjectAverages = subjectAverages.filter { selectedIds.contains($0.uid) }
|
||||||
|
}
|
||||||
|
|
||||||
|
return AveragesEntry(
|
||||||
|
date: Date(),
|
||||||
|
configuration: configuration,
|
||||||
|
overallAverage: data?.averages.overall,
|
||||||
|
subjectAverages: subjectAverages,
|
||||||
|
locale: data?.locale ?? "hu",
|
||||||
|
isFiltered: isFiltered
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct GradesEntry: TimelineEntry {
|
||||||
|
let date: Date
|
||||||
|
let configuration: GradesWidgetIntent
|
||||||
|
let grades: [WidgetGrade]
|
||||||
|
let locale: String
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GradesProvider: AppIntentTimelineProvider {
|
||||||
|
typealias Entry = GradesEntry
|
||||||
|
typealias Intent = GradesWidgetIntent
|
||||||
|
|
||||||
|
func placeholder(in context: Context) -> GradesEntry {
|
||||||
|
GradesEntry(date: Date(), configuration: GradesWidgetIntent(), grades: [], locale: "hu")
|
||||||
|
}
|
||||||
|
|
||||||
|
func snapshot(for configuration: GradesWidgetIntent, in context: Context) async -> GradesEntry {
|
||||||
|
let data = WidgetData.load()
|
||||||
|
return GradesEntry(
|
||||||
|
date: Date(),
|
||||||
|
configuration: configuration,
|
||||||
|
grades: data?.grades ?? [],
|
||||||
|
locale: data?.locale ?? "hu"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func timeline(for configuration: GradesWidgetIntent, in context: Context) async -> Timeline<GradesEntry> {
|
||||||
|
let data = WidgetData.load()
|
||||||
|
let entry = GradesEntry(
|
||||||
|
date: Date(),
|
||||||
|
configuration: configuration,
|
||||||
|
grades: data?.grades ?? [],
|
||||||
|
locale: data?.locale ?? "hu"
|
||||||
|
)
|
||||||
|
|
||||||
|
let refreshDate = Date().addingTimeInterval(30 * 60)
|
||||||
|
return Timeline(entries: [entry], policy: .after(refreshDate))
|
||||||
|
}
|
||||||
|
}
|
||||||
384
firka/ios/HomeWidgetsExtension/Providers/TimetableProvider.swift
Normal file
384
firka/ios/HomeWidgetsExtension/Providers/TimetableProvider.swift
Normal file
@@ -0,0 +1,384 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct TimetableEntry: TimelineEntry {
|
||||||
|
let date: Date
|
||||||
|
let configuration: TimetableWidgetIntent
|
||||||
|
let data: WidgetData?
|
||||||
|
let lessons: [WidgetLesson]
|
||||||
|
let currentLesson: WidgetLesson?
|
||||||
|
let nextLesson: WidgetLesson?
|
||||||
|
let isNextDay: Bool
|
||||||
|
let isNextSchoolDay: Bool
|
||||||
|
let nextSchoolDayDateString: String?
|
||||||
|
let breakInfo: BreakInfo?
|
||||||
|
let state: TimetableState
|
||||||
|
let debugInfo: String
|
||||||
|
}
|
||||||
|
|
||||||
|
enum TimetableState {
|
||||||
|
case normal
|
||||||
|
case noMoreLessons
|
||||||
|
case onBreak
|
||||||
|
case loginRequired
|
||||||
|
case unavailable
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TimetableProvider: AppIntentTimelineProvider {
|
||||||
|
typealias Entry = TimetableEntry
|
||||||
|
typealias Intent = TimetableWidgetIntent
|
||||||
|
|
||||||
|
private struct LessonCandidate {
|
||||||
|
let lessons: [WidgetLesson]
|
||||||
|
let day: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
private static let dateFormatter: DateFormatter = {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "yyyy-MM-dd"
|
||||||
|
formatter.locale = Locale(identifier: "en_US_POSIX")
|
||||||
|
formatter.timeZone = TimeZone.current
|
||||||
|
return formatter
|
||||||
|
}()
|
||||||
|
|
||||||
|
private static let isoFormatterWithFractional: ISO8601DateFormatter = {
|
||||||
|
let formatter = ISO8601DateFormatter()
|
||||||
|
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
||||||
|
return formatter
|
||||||
|
}()
|
||||||
|
|
||||||
|
private static let isoFormatter: ISO8601DateFormatter = {
|
||||||
|
let formatter = ISO8601DateFormatter()
|
||||||
|
formatter.formatOptions = [.withInternetDateTime]
|
||||||
|
return formatter
|
||||||
|
}()
|
||||||
|
|
||||||
|
private func parseNextSchoolDayDate(_ dateString: String?) -> Date? {
|
||||||
|
guard let dateString = dateString else { return nil }
|
||||||
|
if let date = Self.isoFormatterWithFractional.date(from: dateString) {
|
||||||
|
return date
|
||||||
|
}
|
||||||
|
if let date = Self.isoFormatter.date(from: dateString) {
|
||||||
|
return date
|
||||||
|
}
|
||||||
|
if let date = Self.dateFormatter.date(from: dateString) {
|
||||||
|
return date
|
||||||
|
}
|
||||||
|
|
||||||
|
let trimmed = String(dateString.prefix(10))
|
||||||
|
return Self.dateFormatter.date(from: trimmed)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func startOfDay(for lessons: [WidgetLesson], calendar: Calendar) -> Date? {
|
||||||
|
guard let first = lessons.first else { return nil }
|
||||||
|
return calendar.startOfDay(for: first.start)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func nextSchoolDay(from data: WidgetData, calendar: Calendar) -> Date? {
|
||||||
|
if let firstNextLesson = data.timetable.nextSchoolDay?.first {
|
||||||
|
return calendar.startOfDay(for: firstNextLesson.start)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let parsedDate = parseNextSchoolDayDate(data.timetable.nextSchoolDayDate) {
|
||||||
|
return calendar.startOfDay(for: parsedDate)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func placeholder(in context: Context) -> TimetableEntry {
|
||||||
|
TimetableEntry(
|
||||||
|
date: Date(),
|
||||||
|
configuration: TimetableWidgetIntent(),
|
||||||
|
data: nil,
|
||||||
|
lessons: [],
|
||||||
|
currentLesson: nil,
|
||||||
|
nextLesson: nil,
|
||||||
|
isNextDay: false,
|
||||||
|
isNextSchoolDay: false,
|
||||||
|
nextSchoolDayDateString: nil,
|
||||||
|
breakInfo: nil,
|
||||||
|
state: .normal,
|
||||||
|
debugInfo: "placeholder"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func snapshot(for configuration: TimetableWidgetIntent, in context: Context) async -> TimetableEntry {
|
||||||
|
createEntry(for: configuration, date: Date())
|
||||||
|
}
|
||||||
|
|
||||||
|
func timeline(for configuration: TimetableWidgetIntent, in context: Context) async -> Timeline<TimetableEntry> {
|
||||||
|
var entries: [TimetableEntry] = []
|
||||||
|
let now = Date()
|
||||||
|
let calendar = Calendar.current
|
||||||
|
|
||||||
|
let data = WidgetData.load()
|
||||||
|
|
||||||
|
// If on break, create single entry
|
||||||
|
if let breakInfo = data?.timetable.currentBreak {
|
||||||
|
let entry = TimetableEntry(
|
||||||
|
date: now,
|
||||||
|
configuration: configuration,
|
||||||
|
data: data,
|
||||||
|
lessons: [],
|
||||||
|
currentLesson: nil,
|
||||||
|
nextLesson: nil,
|
||||||
|
isNextDay: false,
|
||||||
|
isNextSchoolDay: false,
|
||||||
|
nextSchoolDayDateString: nil,
|
||||||
|
breakInfo: breakInfo,
|
||||||
|
state: .onBreak,
|
||||||
|
debugInfo: WidgetData.lastError
|
||||||
|
)
|
||||||
|
entries.append(entry)
|
||||||
|
return Timeline(entries: entries, policy: .after(calendar.startOfDay(for: now.addingTimeInterval(86400))))
|
||||||
|
}
|
||||||
|
|
||||||
|
let todayLessons = data?.timetable.today ?? []
|
||||||
|
|
||||||
|
entries.append(createEntry(for: configuration, date: now))
|
||||||
|
|
||||||
|
let currentLesson = todayLessons.first { now >= $0.start && now <= $0.end }
|
||||||
|
let nextLesson = todayLessons.first { $0.start > now }
|
||||||
|
|
||||||
|
let isLockScreenWidget = context.family == .accessoryInline ||
|
||||||
|
context.family == .accessoryCircular ||
|
||||||
|
context.family == .accessoryRectangular
|
||||||
|
|
||||||
|
if isLockScreenWidget {
|
||||||
|
var minuteEntries: [Date] = []
|
||||||
|
|
||||||
|
if let current = currentLesson {
|
||||||
|
var time = now.addingTimeInterval(60)
|
||||||
|
while time <= current.end && minuteEntries.count < 60 {
|
||||||
|
minuteEntries.append(time)
|
||||||
|
time = time.addingTimeInterval(60)
|
||||||
|
}
|
||||||
|
minuteEntries.append(current.end.addingTimeInterval(1))
|
||||||
|
}
|
||||||
|
|
||||||
|
if let next = nextLesson {
|
||||||
|
let minutesUntilNext = next.start.timeIntervalSince(now) / 60
|
||||||
|
|
||||||
|
if minutesUntilNext <= 60 {
|
||||||
|
var time = currentLesson?.end.addingTimeInterval(60) ?? now.addingTimeInterval(60)
|
||||||
|
while time < next.start && minuteEntries.count < 120 {
|
||||||
|
minuteEntries.append(time)
|
||||||
|
time = time.addingTimeInterval(60)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let sixtyMinutesBefore = next.start.addingTimeInterval(-60 * 60)
|
||||||
|
if sixtyMinutesBefore > now {
|
||||||
|
minuteEntries.append(sixtyMinutesBefore)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
minuteEntries.append(next.start)
|
||||||
|
|
||||||
|
var nextLessonTime = next.start.addingTimeInterval(60)
|
||||||
|
while nextLessonTime <= next.end && minuteEntries.count < 180 {
|
||||||
|
minuteEntries.append(nextLessonTime)
|
||||||
|
nextLessonTime = nextLessonTime.addingTimeInterval(60)
|
||||||
|
}
|
||||||
|
minuteEntries.append(next.end.addingTimeInterval(1))
|
||||||
|
}
|
||||||
|
|
||||||
|
for time in minuteEntries {
|
||||||
|
if time > now {
|
||||||
|
entries.append(createEntry(for: configuration, date: time))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for lesson in todayLessons {
|
||||||
|
if lesson.start > now {
|
||||||
|
entries.append(createEntry(for: configuration, date: lesson.start))
|
||||||
|
}
|
||||||
|
if lesson.end > now {
|
||||||
|
entries.append(createEntry(for: configuration, date: lesson.end.addingTimeInterval(1)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let tomorrowLessons = data?.timetable.tomorrow ?? []
|
||||||
|
for lesson in tomorrowLessons {
|
||||||
|
if lesson.start > now {
|
||||||
|
entries.append(createEntry(for: configuration, date: lesson.start))
|
||||||
|
}
|
||||||
|
if lesson.end > now {
|
||||||
|
entries.append(createEntry(for: configuration, date: lesson.end.addingTimeInterval(1)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let nextSchoolDayLessons = data?.timetable.nextSchoolDay ?? []
|
||||||
|
for lesson in nextSchoolDayLessons {
|
||||||
|
if lesson.start > now {
|
||||||
|
entries.append(createEntry(for: configuration, date: lesson.start))
|
||||||
|
}
|
||||||
|
if lesson.end > now {
|
||||||
|
entries.append(createEntry(for: configuration, date: lesson.end.addingTimeInterval(1)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let midnight = calendar.startOfDay(for: now.addingTimeInterval(86400))
|
||||||
|
entries.append(createEntry(for: configuration, date: midnight))
|
||||||
|
|
||||||
|
if let data = data,
|
||||||
|
let nextSchoolDay = nextSchoolDay(from: data, calendar: calendar) {
|
||||||
|
let dayBeforeNextSchoolDay = calendar.date(byAdding: .day, value: -1, to: nextSchoolDay)!
|
||||||
|
|
||||||
|
if dayBeforeNextSchoolDay > now {
|
||||||
|
entries.append(createEntry(for: configuration, date: dayBeforeNextSchoolDay))
|
||||||
|
}
|
||||||
|
|
||||||
|
if nextSchoolDay > now {
|
||||||
|
entries.append(createEntry(for: configuration, date: nextSchoolDay))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let uniqueDates = Set(entries.map { $0.date })
|
||||||
|
entries = uniqueDates.map { date in
|
||||||
|
entries.first { $0.date == date }!
|
||||||
|
}
|
||||||
|
entries.sort { $0.date < $1.date }
|
||||||
|
|
||||||
|
if isLockScreenWidget {
|
||||||
|
var refreshDate: Date
|
||||||
|
if let current = currentLesson {
|
||||||
|
refreshDate = current.end.addingTimeInterval(1)
|
||||||
|
} else if let next = nextLesson {
|
||||||
|
refreshDate = next.end.addingTimeInterval(1)
|
||||||
|
} else {
|
||||||
|
refreshDate = midnight
|
||||||
|
}
|
||||||
|
return Timeline(entries: entries, policy: .after(refreshDate))
|
||||||
|
}
|
||||||
|
|
||||||
|
return Timeline(entries: entries, policy: .atEnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func createEntry(for configuration: TimetableWidgetIntent, date: Date) -> TimetableEntry {
|
||||||
|
let data = WidgetData.load()
|
||||||
|
let calendar = Calendar.current
|
||||||
|
|
||||||
|
guard let data = data else {
|
||||||
|
return TimetableEntry(
|
||||||
|
date: date,
|
||||||
|
configuration: configuration,
|
||||||
|
data: nil,
|
||||||
|
lessons: [],
|
||||||
|
currentLesson: nil,
|
||||||
|
nextLesson: nil,
|
||||||
|
isNextDay: false,
|
||||||
|
isNextSchoolDay: false,
|
||||||
|
nextSchoolDayDateString: nil,
|
||||||
|
breakInfo: nil,
|
||||||
|
state: .loginRequired,
|
||||||
|
debugInfo: WidgetData.lastError
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let breakInfo = data.timetable.currentBreak {
|
||||||
|
return TimetableEntry(
|
||||||
|
date: date,
|
||||||
|
configuration: configuration,
|
||||||
|
data: data,
|
||||||
|
lessons: [],
|
||||||
|
currentLesson: nil,
|
||||||
|
nextLesson: nil,
|
||||||
|
isNextDay: false,
|
||||||
|
isNextSchoolDay: false,
|
||||||
|
nextSchoolDayDateString: nil,
|
||||||
|
breakInfo: breakInfo,
|
||||||
|
state: .onBreak,
|
||||||
|
debugInfo: WidgetData.lastError
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let entryDay = calendar.startOfDay(for: date)
|
||||||
|
let tomorrowOfEntryDay = calendar.date(byAdding: .day, value: 1, to: entryDay)!
|
||||||
|
|
||||||
|
let todayLessons = data.timetable.today
|
||||||
|
let tomorrowLessons = data.timetable.tomorrow
|
||||||
|
let nextSchoolDayLessons = data.timetable.nextSchoolDay ?? []
|
||||||
|
|
||||||
|
var candidates: [LessonCandidate] = []
|
||||||
|
|
||||||
|
if let todayDay = startOfDay(for: todayLessons, calendar: calendar), !todayLessons.isEmpty {
|
||||||
|
candidates.append(LessonCandidate(lessons: todayLessons, day: todayDay))
|
||||||
|
}
|
||||||
|
|
||||||
|
if let tomorrowDay = startOfDay(for: tomorrowLessons, calendar: calendar), !tomorrowLessons.isEmpty {
|
||||||
|
candidates.append(LessonCandidate(lessons: tomorrowLessons, day: tomorrowDay))
|
||||||
|
}
|
||||||
|
|
||||||
|
if !nextSchoolDayLessons.isEmpty,
|
||||||
|
let resolvedNextSchoolDay = nextSchoolDay(from: data, calendar: calendar)
|
||||||
|
?? startOfDay(for: nextSchoolDayLessons, calendar: calendar) {
|
||||||
|
candidates.append(LessonCandidate(lessons: nextSchoolDayLessons, day: resolvedNextSchoolDay))
|
||||||
|
}
|
||||||
|
|
||||||
|
candidates.sort { $0.day < $1.day }
|
||||||
|
|
||||||
|
// Pick the closest candidate that still has lessons ahead relative to this entry date.
|
||||||
|
let selectedCandidate = candidates.first { candidate in
|
||||||
|
if candidate.day > entryDay {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if candidate.day == entryDay, let lastLesson = candidate.lessons.last {
|
||||||
|
return date <= lastLesson.end
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let selectedCandidate = selectedCandidate else {
|
||||||
|
let hadLessonsTodayButFinished = candidates.contains { candidate in
|
||||||
|
guard candidate.day == entryDay, let lastLesson = candidate.lessons.last else { return false }
|
||||||
|
return date > lastLesson.end
|
||||||
|
}
|
||||||
|
|
||||||
|
return TimetableEntry(
|
||||||
|
date: date,
|
||||||
|
configuration: configuration,
|
||||||
|
data: data,
|
||||||
|
lessons: [],
|
||||||
|
currentLesson: nil,
|
||||||
|
nextLesson: nil,
|
||||||
|
isNextDay: false,
|
||||||
|
isNextSchoolDay: false,
|
||||||
|
nextSchoolDayDateString: nil,
|
||||||
|
breakInfo: nil,
|
||||||
|
state: hadLessonsTodayButFinished ? .noMoreLessons : .unavailable,
|
||||||
|
debugInfo: WidgetData.lastError
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let lessons = selectedCandidate.lessons
|
||||||
|
let isToday = selectedCandidate.day == entryDay
|
||||||
|
let isNextDay = selectedCandidate.day == tomorrowOfEntryDay
|
||||||
|
let isNextSchoolDay = !isToday && !isNextDay
|
||||||
|
let nextSchoolDayDateString = isNextSchoolDay
|
||||||
|
? (data.timetable.nextSchoolDayDate ?? Self.dateFormatter.string(from: selectedCandidate.day))
|
||||||
|
: nil
|
||||||
|
|
||||||
|
let currentLesson = lessons.first { lesson in
|
||||||
|
return date >= lesson.start && date <= lesson.end
|
||||||
|
}
|
||||||
|
let nextLesson = lessons.first { $0.start > date }
|
||||||
|
|
||||||
|
return TimetableEntry(
|
||||||
|
date: date,
|
||||||
|
configuration: configuration,
|
||||||
|
data: data,
|
||||||
|
lessons: lessons,
|
||||||
|
currentLesson: currentLesson,
|
||||||
|
nextLesson: nextLesson,
|
||||||
|
isNextDay: isNextDay,
|
||||||
|
isNextSchoolDay: isNextSchoolDay,
|
||||||
|
nextSchoolDayDateString: nextSchoolDayDateString,
|
||||||
|
breakInfo: nil,
|
||||||
|
state: .normal,
|
||||||
|
debugInfo: WidgetData.lastError
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import AppIntents
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct AverageEntity: AppEntity {
|
||||||
|
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: LocalizedStringResource("entity_average", defaultValue: "Average"))
|
||||||
|
static var defaultQuery = AverageEntityQuery()
|
||||||
|
|
||||||
|
var id: String
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_subject", defaultValue: "Subject"))
|
||||||
|
var subjectName: String
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_average", defaultValue: "Average"))
|
||||||
|
var average: Double
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_grade_count", defaultValue: "Grade count"))
|
||||||
|
var gradeCount: Int
|
||||||
|
|
||||||
|
var displayRepresentation: DisplayRepresentation {
|
||||||
|
DisplayRepresentation(
|
||||||
|
title: "\(subjectName)",
|
||||||
|
subtitle: "\(String(format: "%.2f", average)) (\(gradeCount))"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
init(from avg: SubjectAverage) {
|
||||||
|
self.id = avg.uid
|
||||||
|
self.subjectName = avg.name
|
||||||
|
self.average = avg.average
|
||||||
|
self.gradeCount = avg.gradeCount
|
||||||
|
}
|
||||||
|
|
||||||
|
init(id: String, subjectName: String, average: Double, gradeCount: Int) {
|
||||||
|
self.id = id
|
||||||
|
self.subjectName = subjectName
|
||||||
|
self.average = average
|
||||||
|
self.gradeCount = gradeCount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct AverageEntityQuery: EntityQuery {
|
||||||
|
func entities(for identifiers: [String]) async throws -> [AverageEntity] {
|
||||||
|
guard let data = WidgetData.load() else { return [] }
|
||||||
|
return data.averages.subjects
|
||||||
|
.filter { identifiers.contains($0.uid) }
|
||||||
|
.map { AverageEntity(from: $0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
func suggestedEntities() async throws -> [AverageEntity] {
|
||||||
|
guard let data = WidgetData.load() else { return [] }
|
||||||
|
return data.averages.subjects.map { AverageEntity(from: $0) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
import AppIntents
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct GradeEntity: AppEntity {
|
||||||
|
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: LocalizedStringResource("entity_grade", defaultValue: "Grade"))
|
||||||
|
static var defaultQuery = GradeEntityQuery()
|
||||||
|
|
||||||
|
var id: String
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_subject", defaultValue: "Subject"))
|
||||||
|
var subject: String
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_value", defaultValue: "Value"))
|
||||||
|
var numericValue: Int
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_grade", defaultValue: "Grade"))
|
||||||
|
var strValue: String
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_topic", defaultValue: "Topic"))
|
||||||
|
var topic: String
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_type", defaultValue: "Type"))
|
||||||
|
var type: String
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_teacher", defaultValue: "Teacher"))
|
||||||
|
var teacher: String
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_date", defaultValue: "Date"))
|
||||||
|
var date: Date
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_weight", defaultValue: "Weight"))
|
||||||
|
var weight: Int
|
||||||
|
|
||||||
|
var displayRepresentation: DisplayRepresentation {
|
||||||
|
DisplayRepresentation(
|
||||||
|
title: "\(subject): \(strValue)",
|
||||||
|
subtitle: "\(topic)"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
init(from grade: WidgetGrade) {
|
||||||
|
self.id = grade.uid
|
||||||
|
self.subject = grade.subject.name
|
||||||
|
self.numericValue = grade.numericValue ?? 0
|
||||||
|
self.strValue = grade.displayValue
|
||||||
|
self.topic = grade.topic ?? ""
|
||||||
|
self.type = grade.type.name
|
||||||
|
self.teacher = grade.subject.teacherName ?? ""
|
||||||
|
self.date = grade.recordDate
|
||||||
|
self.weight = grade.weightPercentage ?? 100
|
||||||
|
}
|
||||||
|
|
||||||
|
init(id: String, subject: String, numericValue: Int, strValue: String, topic: String, type: String, teacher: String, date: Date, weight: Int) {
|
||||||
|
self.id = id
|
||||||
|
self.subject = subject
|
||||||
|
self.numericValue = numericValue
|
||||||
|
self.strValue = strValue
|
||||||
|
self.topic = topic
|
||||||
|
self.type = type
|
||||||
|
self.teacher = teacher
|
||||||
|
self.date = date
|
||||||
|
self.weight = weight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct GradeEntityQuery: EntityQuery {
|
||||||
|
func entities(for identifiers: [String]) async throws -> [GradeEntity] {
|
||||||
|
guard let data = WidgetData.load() else { return [] }
|
||||||
|
return data.grades
|
||||||
|
.filter { identifiers.contains($0.uid) }
|
||||||
|
.map { GradeEntity(from: $0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
func suggestedEntities() async throws -> [GradeEntity] {
|
||||||
|
guard let data = WidgetData.load() else { return [] }
|
||||||
|
return data.grades.prefix(10).map { GradeEntity(from: $0) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
import AppIntents
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct LessonEntity: AppEntity {
|
||||||
|
static var typeDisplayRepresentation = TypeDisplayRepresentation(name: LocalizedStringResource("entity_lesson", defaultValue: "Lesson"))
|
||||||
|
static var defaultQuery = LessonEntityQuery()
|
||||||
|
|
||||||
|
var id: String
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_name", defaultValue: "Name"))
|
||||||
|
var name: String
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_teacher", defaultValue: "Teacher"))
|
||||||
|
var teacher: String
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_room", defaultValue: "Room"))
|
||||||
|
var room: String
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_start_time", defaultValue: "Start time"))
|
||||||
|
var startTime: Date
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_end_time", defaultValue: "End time"))
|
||||||
|
var endTime: Date
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_lesson_number", defaultValue: "Lesson number"))
|
||||||
|
var lessonNumber: Int
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_cancelled", defaultValue: "Cancelled"))
|
||||||
|
var isCancelled: Bool
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_substitution", defaultValue: "Substitution"))
|
||||||
|
var isSubstitution: Bool
|
||||||
|
|
||||||
|
@Property(title: LocalizedStringResource("entity_prop_theme", defaultValue: "Theme"))
|
||||||
|
var theme: String
|
||||||
|
|
||||||
|
var displayRepresentation: DisplayRepresentation {
|
||||||
|
DisplayRepresentation(
|
||||||
|
title: "\(name)",
|
||||||
|
subtitle: "\(lessonNumber). \(room) - \(teacher)"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
init(from lesson: WidgetLesson) {
|
||||||
|
self.id = lesson.uid
|
||||||
|
self.name = lesson.subject.name
|
||||||
|
self.teacher = lesson.teacher ?? ""
|
||||||
|
self.room = lesson.roomName ?? ""
|
||||||
|
self.startTime = lesson.start
|
||||||
|
self.endTime = lesson.end
|
||||||
|
self.lessonNumber = lesson.lessonNumber ?? 0
|
||||||
|
self.isCancelled = lesson.isCancelled
|
||||||
|
self.isSubstitution = lesson.isSubstitution
|
||||||
|
self.theme = lesson.theme ?? ""
|
||||||
|
}
|
||||||
|
|
||||||
|
init(id: String, name: String, teacher: String, room: String, startTime: Date, endTime: Date, lessonNumber: Int, isCancelled: Bool, isSubstitution: Bool, theme: String) {
|
||||||
|
self.id = id
|
||||||
|
self.name = name
|
||||||
|
self.teacher = teacher
|
||||||
|
self.room = room
|
||||||
|
self.startTime = startTime
|
||||||
|
self.endTime = endTime
|
||||||
|
self.lessonNumber = lessonNumber
|
||||||
|
self.isCancelled = isCancelled
|
||||||
|
self.isSubstitution = isSubstitution
|
||||||
|
self.theme = theme
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct LessonEntityQuery: EntityQuery {
|
||||||
|
func entities(for identifiers: [String]) async throws -> [LessonEntity] {
|
||||||
|
guard let data = WidgetData.load() else { return [] }
|
||||||
|
let allLessons = data.timetable.today + data.timetable.tomorrow + (data.timetable.nextSchoolDay ?? [])
|
||||||
|
return allLessons
|
||||||
|
.filter { identifiers.contains($0.uid) }
|
||||||
|
.map { LessonEntity(from: $0) }
|
||||||
|
}
|
||||||
|
|
||||||
|
func suggestedEntities() async throws -> [LessonEntity] {
|
||||||
|
guard let data = WidgetData.load() else { return [] }
|
||||||
|
return data.timetable.today.map { LessonEntity(from: $0) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import AppIntents
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct SubjectEntity: AppEntity {
|
||||||
|
let id: String
|
||||||
|
let name: String
|
||||||
|
|
||||||
|
static var typeDisplayRepresentation: TypeDisplayRepresentation {
|
||||||
|
TypeDisplayRepresentation(name: LocalizedStringResource("subjects_type", defaultValue: "Subjects"))
|
||||||
|
}
|
||||||
|
|
||||||
|
static var defaultQuery = SubjectQuery()
|
||||||
|
|
||||||
|
var displayRepresentation: DisplayRepresentation {
|
||||||
|
DisplayRepresentation(title: "\(name)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct SubjectQuery: EntityQuery {
|
||||||
|
func entities(for identifiers: [String]) async throws -> [SubjectEntity] {
|
||||||
|
let data = WidgetData.load()
|
||||||
|
return data?.averages.subjects
|
||||||
|
.filter { identifiers.contains($0.uid) }
|
||||||
|
.map { SubjectEntity(id: $0.uid, name: $0.name) } ?? []
|
||||||
|
}
|
||||||
|
|
||||||
|
func suggestedEntities() async throws -> [SubjectEntity] {
|
||||||
|
let data = WidgetData.load()
|
||||||
|
return data?.averages.subjects
|
||||||
|
.map { SubjectEntity(id: $0.uid, name: $0.name) } ?? []
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultResult() async -> SubjectEntity? {
|
||||||
|
try? await suggestedEntities().first
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import AppIntents
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct FirkaShortcuts: AppShortcutsProvider {
|
||||||
|
static var appShortcuts: [AppShortcut] {
|
||||||
|
AppShortcut(
|
||||||
|
intent: GetNextLessonIntent(),
|
||||||
|
phrases: [
|
||||||
|
"Next lesson \(.applicationName)",
|
||||||
|
"What is my next lesson \(.applicationName)"
|
||||||
|
],
|
||||||
|
shortTitle: LocalizedStringResource("shortcut_short_next_lesson", defaultValue: "Next lesson"),
|
||||||
|
systemImageName: "calendar"
|
||||||
|
)
|
||||||
|
AppShortcut(
|
||||||
|
intent: GetClosestLessonIntent(),
|
||||||
|
phrases: [
|
||||||
|
"Closest lesson \(.applicationName)",
|
||||||
|
"When is my next lesson \(.applicationName)"
|
||||||
|
],
|
||||||
|
shortTitle: LocalizedStringResource("shortcut_short_closest_lesson", defaultValue: "Closest lesson"),
|
||||||
|
systemImageName: "forward"
|
||||||
|
)
|
||||||
|
AppShortcut(
|
||||||
|
intent: GetTodayTimetableIntent(),
|
||||||
|
phrases: [
|
||||||
|
"Today's timetable \(.applicationName)",
|
||||||
|
"What lessons do I have today \(.applicationName)"
|
||||||
|
],
|
||||||
|
shortTitle: LocalizedStringResource("shortcut_short_today_timetable", defaultValue: "Today's timetable"),
|
||||||
|
systemImageName: "clock"
|
||||||
|
)
|
||||||
|
AppShortcut(
|
||||||
|
intent: GetClosestTimetableIntent(),
|
||||||
|
phrases: [
|
||||||
|
"Closest timetable \(.applicationName)",
|
||||||
|
"When are my next lessons \(.applicationName)"
|
||||||
|
],
|
||||||
|
shortTitle: LocalizedStringResource("shortcut_short_closest_timetable", defaultValue: "Closest timetable"),
|
||||||
|
systemImageName: "forward.fill"
|
||||||
|
)
|
||||||
|
AppShortcut(
|
||||||
|
intent: GetOverallAverageIntent(),
|
||||||
|
phrases: [
|
||||||
|
"My average \(.applicationName)",
|
||||||
|
"What is my average \(.applicationName)"
|
||||||
|
],
|
||||||
|
shortTitle: LocalizedStringResource("shortcut_short_overall_average", defaultValue: "My average"),
|
||||||
|
systemImageName: "chart.bar"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import AppIntents
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct GetClosestLessonIntent: AppIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("shortcut_closest_lesson_title", defaultValue: "Closest lesson")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("shortcut_closest_lesson_description", defaultValue: "Get the closest lesson (today, tomorrow, or next school day)"))
|
||||||
|
|
||||||
|
func perform() async throws -> some ReturnsValue<LessonEntity> & ProvidesDialog {
|
||||||
|
guard let data = WidgetData.load() else {
|
||||||
|
throw ShortcutError.noData
|
||||||
|
}
|
||||||
|
let now = Date()
|
||||||
|
|
||||||
|
if let lesson = data.timetable.today.first(where: { $0.start > now })
|
||||||
|
?? data.timetable.today.first(where: { $0.end > now }) {
|
||||||
|
let entity = LessonEntity(from: lesson)
|
||||||
|
return .result(value: entity, dialog: "\(entity.name) - \(entity.room)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if let lesson = data.timetable.tomorrow.first {
|
||||||
|
let entity = LessonEntity(from: lesson)
|
||||||
|
return .result(value: entity, dialog: "\(entity.name) - \(entity.room)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if let lesson = data.timetable.nextSchoolDay?.first {
|
||||||
|
let entity = LessonEntity(from: lesson)
|
||||||
|
return .result(value: entity, dialog: "\(entity.name) - \(entity.room)")
|
||||||
|
}
|
||||||
|
|
||||||
|
throw ShortcutError.noUpcomingLesson
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import AppIntents
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct GetClosestTimetableIntent: AppIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("shortcut_closest_timetable_title", defaultValue: "Closest timetable")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("shortcut_closest_timetable_description", defaultValue: "Get the closest school day's timetable (today, tomorrow, or next school day)"))
|
||||||
|
|
||||||
|
func perform() async throws -> some ReturnsValue<[LessonEntity]> & ProvidesDialog {
|
||||||
|
guard let data = WidgetData.load() else {
|
||||||
|
throw ShortcutError.noData
|
||||||
|
}
|
||||||
|
let now = Date()
|
||||||
|
|
||||||
|
let remaining = data.timetable.today.filter { $0.end > now }
|
||||||
|
if !remaining.isEmpty {
|
||||||
|
let entities = remaining.map { LessonEntity(from: $0) }
|
||||||
|
let summary = entities.map { "\($0.lessonNumber). \($0.name)" }.joined(separator: ", ")
|
||||||
|
return .result(value: entities, dialog: "\(summary)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !data.timetable.tomorrow.isEmpty {
|
||||||
|
let entities = data.timetable.tomorrow.map { LessonEntity(from: $0) }
|
||||||
|
let summary = entities.map { "\($0.lessonNumber). \($0.name)" }.joined(separator: ", ")
|
||||||
|
return .result(value: entities, dialog: "\(summary)")
|
||||||
|
}
|
||||||
|
|
||||||
|
if let nextDay = data.timetable.nextSchoolDay, !nextDay.isEmpty {
|
||||||
|
let entities = nextDay.map { LessonEntity(from: $0) }
|
||||||
|
let summary = entities.map { "\($0.lessonNumber). \($0.name)" }.joined(separator: ", ")
|
||||||
|
return .result(value: entities, dialog: "\(summary)")
|
||||||
|
}
|
||||||
|
|
||||||
|
throw ShortcutError.noUpcomingLesson
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import AppIntents
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct GetNextLessonIntent: AppIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("shortcut_next_lesson_title", defaultValue: "Next lesson")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("shortcut_next_lesson_description", defaultValue: "Get the next lesson details"))
|
||||||
|
|
||||||
|
func perform() async throws -> some ReturnsValue<LessonEntity> & ProvidesDialog {
|
||||||
|
guard let data = WidgetData.load() else {
|
||||||
|
throw ShortcutError.noData
|
||||||
|
}
|
||||||
|
let now = Date()
|
||||||
|
let upcoming = data.timetable.today.first { $0.start > now }
|
||||||
|
?? data.timetable.today.first { $0.end > now }
|
||||||
|
guard let lesson = upcoming else {
|
||||||
|
throw ShortcutError.noUpcomingLesson
|
||||||
|
}
|
||||||
|
let entity = LessonEntity(from: lesson)
|
||||||
|
return .result(value: entity, dialog: "\(entity.name) - \(entity.room)")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import AppIntents
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct GetOverallAverageIntent: AppIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("shortcut_overall_average_title", defaultValue: "Overall average")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("shortcut_overall_average_description", defaultValue: "Get the overall academic average"))
|
||||||
|
|
||||||
|
func perform() async throws -> some ReturnsValue<Double> & ProvidesDialog {
|
||||||
|
guard let data = WidgetData.load() else {
|
||||||
|
throw ShortcutError.noData
|
||||||
|
}
|
||||||
|
guard let overall = data.averages.overall else {
|
||||||
|
throw ShortcutError.noData
|
||||||
|
}
|
||||||
|
let rounded = (overall * 100).rounded() / 100
|
||||||
|
return .result(value: rounded, dialog: "\(String(format: "%.2f", rounded))")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import AppIntents
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct GetRecentGradesIntent: AppIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("shortcut_recent_grades_title", defaultValue: "Recent grades")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("shortcut_recent_grades_description", defaultValue: "Get the most recent grades"))
|
||||||
|
|
||||||
|
@Parameter(title: LocalizedStringResource("shortcut_param_count", defaultValue: "Count"), default: 5)
|
||||||
|
var count: Int
|
||||||
|
|
||||||
|
func perform() async throws -> some ReturnsValue<[GradeEntity]> & ProvidesDialog {
|
||||||
|
guard let data = WidgetData.load() else {
|
||||||
|
throw ShortcutError.noData
|
||||||
|
}
|
||||||
|
let grades = Array(data.grades.prefix(count))
|
||||||
|
let entities = grades.map { GradeEntity(from: $0) }
|
||||||
|
let summary = entities.map { "\($0.subject): \($0.strValue)" }.joined(separator: ", ")
|
||||||
|
return .result(value: entities, dialog: "\(summary)")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import AppIntents
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct GetSubjectAverageIntent: AppIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("shortcut_subject_average_title", defaultValue: "Subject average")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("shortcut_subject_average_description", defaultValue: "Get the average for a subject"))
|
||||||
|
|
||||||
|
@Parameter(title: LocalizedStringResource("shortcut_param_subject", defaultValue: "Subject"))
|
||||||
|
var subject: SubjectEntity
|
||||||
|
|
||||||
|
func perform() async throws -> some ReturnsValue<AverageEntity> & ProvidesDialog {
|
||||||
|
guard let data = WidgetData.load() else {
|
||||||
|
throw ShortcutError.noData
|
||||||
|
}
|
||||||
|
guard let avg = data.averages.subjects.first(where: { $0.uid == subject.id }) else {
|
||||||
|
throw ShortcutError.subjectNotFound
|
||||||
|
}
|
||||||
|
let entity = AverageEntity(from: avg)
|
||||||
|
return .result(value: entity, dialog: "\(entity.subjectName): \(String(format: "%.2f", entity.average))")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import AppIntents
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct GetTodayTimetableIntent: AppIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("shortcut_today_timetable_title", defaultValue: "Today's timetable")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("shortcut_today_timetable_description", defaultValue: "Get today's full timetable"))
|
||||||
|
|
||||||
|
func perform() async throws -> some ReturnsValue<[LessonEntity]> & ProvidesDialog {
|
||||||
|
guard let data = WidgetData.load() else {
|
||||||
|
throw ShortcutError.noData
|
||||||
|
}
|
||||||
|
guard !data.timetable.today.isEmpty else {
|
||||||
|
throw ShortcutError.noLessonsToday
|
||||||
|
}
|
||||||
|
let entities = data.timetable.today.map { LessonEntity(from: $0) }
|
||||||
|
let summary = entities.map { "\($0.lessonNumber). \($0.name)" }.joined(separator: ", ")
|
||||||
|
return .result(value: entities, dialog: "\(summary)")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import AppIntents
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
struct GetTomorrowTimetableIntent: AppIntent {
|
||||||
|
static var title: LocalizedStringResource = LocalizedStringResource("shortcut_tomorrow_timetable_title", defaultValue: "Tomorrow's timetable")
|
||||||
|
static var description: IntentDescription = IntentDescription(LocalizedStringResource("shortcut_tomorrow_timetable_description", defaultValue: "Get tomorrow's timetable"))
|
||||||
|
|
||||||
|
func perform() async throws -> some ReturnsValue<[LessonEntity]> & ProvidesDialog {
|
||||||
|
guard let data = WidgetData.load() else {
|
||||||
|
throw ShortcutError.noData
|
||||||
|
}
|
||||||
|
guard !data.timetable.tomorrow.isEmpty else {
|
||||||
|
throw ShortcutError.noLessonsTomorrow
|
||||||
|
}
|
||||||
|
let entities = data.timetable.tomorrow.map { LessonEntity(from: $0) }
|
||||||
|
let summary = entities.map { "\($0.lessonNumber). \($0.name)" }.joined(separator: ", ")
|
||||||
|
return .result(value: entities, dialog: "\(summary)")
|
||||||
|
}
|
||||||
|
}
|
||||||
25
firka/ios/HomeWidgetsExtension/Shortcuts/ShortcutError.swift
Normal file
25
firka/ios/HomeWidgetsExtension/Shortcuts/ShortcutError.swift
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import Foundation
|
||||||
|
|
||||||
|
@available(iOS 16.0, *)
|
||||||
|
enum ShortcutError: Error, CustomLocalizedStringResourceConvertible {
|
||||||
|
case noData
|
||||||
|
case noUpcomingLesson
|
||||||
|
case noLessonsToday
|
||||||
|
case noLessonsTomorrow
|
||||||
|
case subjectNotFound
|
||||||
|
|
||||||
|
var localizedStringResource: LocalizedStringResource {
|
||||||
|
switch self {
|
||||||
|
case .noData:
|
||||||
|
return LocalizedStringResource("shortcut_error_no_data", defaultValue: "No data available. Open the Firka app to refresh.")
|
||||||
|
case .noUpcomingLesson:
|
||||||
|
return LocalizedStringResource("shortcut_error_no_upcoming_lesson", defaultValue: "No more lessons today.")
|
||||||
|
case .noLessonsToday:
|
||||||
|
return LocalizedStringResource("shortcut_error_no_lessons_today", defaultValue: "No lessons today.")
|
||||||
|
case .noLessonsTomorrow:
|
||||||
|
return LocalizedStringResource("shortcut_error_no_lessons_tomorrow", defaultValue: "No lessons tomorrow.")
|
||||||
|
case .subjectNotFound:
|
||||||
|
return LocalizedStringResource("shortcut_error_subject_not_found", defaultValue: "Subject not found.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
60
firka/ios/HomeWidgetsExtension/TimetableWidget.swift
Normal file
60
firka/ios/HomeWidgetsExtension/TimetableWidget.swift
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct TimetableWidget: Widget {
|
||||||
|
let kind: String = "TimetableWidget"
|
||||||
|
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
AppIntentConfiguration(
|
||||||
|
kind: kind,
|
||||||
|
intent: TimetableWidgetIntent.self,
|
||||||
|
provider: TimetableProvider()
|
||||||
|
) { entry in
|
||||||
|
TimetableWidgetView(entry: entry)
|
||||||
|
.containerBackground(.clear, for: .widget)
|
||||||
|
}
|
||||||
|
.configurationDisplayName(LocalizedStringResource("widget_timetable_title", defaultValue: "Timetable"))
|
||||||
|
.description(LocalizedStringResource("widget_timetable_description", defaultValue: "Shows your daily timetable"))
|
||||||
|
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TimetableWidgetView: View {
|
||||||
|
@Environment(\.widgetFamily) var family
|
||||||
|
let entry: TimetableEntry
|
||||||
|
|
||||||
|
var localization: WidgetLocalization {
|
||||||
|
WidgetLocalization(locale: entry.data?.locale ?? "hu")
|
||||||
|
}
|
||||||
|
|
||||||
|
var style: WidgetStyleType {
|
||||||
|
(entry.configuration.style ?? .appTheme) == .liquidGlass ? .liquidGlass : .appTheme
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Group {
|
||||||
|
switch entry.state {
|
||||||
|
case .onBreak:
|
||||||
|
if let breakInfo = entry.breakInfo {
|
||||||
|
BreakView(breakInfo: breakInfo, localization: localization, style: style)
|
||||||
|
}
|
||||||
|
case .loginRequired:
|
||||||
|
EmptyStateView(message: localization.string("login_required"), style: style)
|
||||||
|
case .unavailable:
|
||||||
|
EmptyStateView(message: localization.string("timetable_unavailable"), style: style)
|
||||||
|
case .noMoreLessons, .normal:
|
||||||
|
switch family {
|
||||||
|
case .systemSmall:
|
||||||
|
TimetableSmallView(entry: entry, localization: localization)
|
||||||
|
case .systemMedium:
|
||||||
|
TimetableMediumView(entry: entry, localization: localization)
|
||||||
|
case .systemLarge:
|
||||||
|
TimetableLargeView(entry: entry, localization: localization)
|
||||||
|
default:
|
||||||
|
TimetableMediumView(entry: entry, localization: localization)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.widgetURL(URL(string: "firka://widget/timetable"))
|
||||||
|
}
|
||||||
|
}
|
||||||
234
firka/ios/HomeWidgetsExtension/Views/AveragesViews.swift
Normal file
234
firka/ios/HomeWidgetsExtension/Views/AveragesViews.swift
Normal file
@@ -0,0 +1,234 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import WidgetKit
|
||||||
|
|
||||||
|
struct AveragesSmallView: View {
|
||||||
|
let entry: AveragesEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var style: WidgetStyleType {
|
||||||
|
(entry.configuration.style ?? .appTheme) == .liquidGlass ? .liquidGlass : .appTheme
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
WidgetBackground(style: style, colors: nil)
|
||||||
|
|
||||||
|
VStack(spacing: 8) {
|
||||||
|
Text(localization.string("overall_average"))
|
||||||
|
.font(.caption)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
|
||||||
|
if let average = entry.overallAverage {
|
||||||
|
Text(String(format: "%.2f", average))
|
||||||
|
.font(.system(size: 36, weight: .bold))
|
||||||
|
.minimumScaleFactor(0.5)
|
||||||
|
.foregroundStyle(averageColor(for: average))
|
||||||
|
} else {
|
||||||
|
Text("-")
|
||||||
|
.font(.system(size: 36, weight: .bold))
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func averageColor(for value: Double) -> Color {
|
||||||
|
switch value {
|
||||||
|
case 4.5...: return .green
|
||||||
|
case 3.5..<4.5: return .blue
|
||||||
|
case 2.5..<3.5: return .yellow
|
||||||
|
case 1.5..<2.5: return .orange
|
||||||
|
default: return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AveragesMediumView: View {
|
||||||
|
let entry: AveragesEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
private let maxVisible = 4
|
||||||
|
|
||||||
|
var style: WidgetStyleType {
|
||||||
|
(entry.configuration.style ?? .appTheme) == .liquidGlass ? .liquidGlass : .appTheme
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalCount: Int {
|
||||||
|
entry.subjectAverages.count
|
||||||
|
}
|
||||||
|
|
||||||
|
var showingCount: Int {
|
||||||
|
min(totalCount, maxVisible)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
WidgetBackground(style: style, colors: nil)
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
|
HStack {
|
||||||
|
Text(localization.string("subject_averages"))
|
||||||
|
.font(.caption)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
if entry.isFiltered && totalCount > maxVisible {
|
||||||
|
Text("\(showingCount)/\(totalCount)")
|
||||||
|
.font(.caption2)
|
||||||
|
.fontWeight(.medium)
|
||||||
|
.padding(.horizontal, 6)
|
||||||
|
.padding(.vertical, 2)
|
||||||
|
.background(
|
||||||
|
Capsule()
|
||||||
|
.fill(Color.secondary.opacity(0.2))
|
||||||
|
)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let overall = entry.overallAverage {
|
||||||
|
Text(String(format: "%.2f", overall))
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.foregroundStyle(averageColor(for: overall))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if entry.subjectAverages.isEmpty {
|
||||||
|
Spacer()
|
||||||
|
Text(localization.string("no_averages"))
|
||||||
|
.font(.subheadline)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
Spacer()
|
||||||
|
} else {
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
ForEach(entry.subjectAverages.prefix(maxVisible)) { subject in
|
||||||
|
AverageRow(subject: subject, style: style, compact: true)
|
||||||
|
}
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func averageColor(for value: Double) -> Color {
|
||||||
|
switch value {
|
||||||
|
case 4.5...: return .green
|
||||||
|
case 3.5..<4.5: return .blue
|
||||||
|
case 2.5..<3.5: return .yellow
|
||||||
|
case 1.5..<2.5: return .orange
|
||||||
|
default: return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AveragesLargeView: View {
|
||||||
|
let entry: AveragesEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
private let maxVisible = 9
|
||||||
|
|
||||||
|
var style: WidgetStyleType {
|
||||||
|
(entry.configuration.style ?? .appTheme) == .liquidGlass ? .liquidGlass : .appTheme
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalCount: Int {
|
||||||
|
entry.subjectAverages.count
|
||||||
|
}
|
||||||
|
|
||||||
|
var showingCount: Int {
|
||||||
|
min(totalCount, maxVisible)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
WidgetBackground(style: style, colors: nil)
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
HStack {
|
||||||
|
Text(localization.string("subject_averages"))
|
||||||
|
.font(.headline)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.widgetTextStyle(style, colors: nil)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
if entry.isFiltered && totalCount > maxVisible {
|
||||||
|
Text("\(showingCount)/\(totalCount)")
|
||||||
|
.font(.caption)
|
||||||
|
.fontWeight(.medium)
|
||||||
|
.padding(.horizontal, 6)
|
||||||
|
.padding(.vertical, 2)
|
||||||
|
.background(
|
||||||
|
Capsule()
|
||||||
|
.fill(Color.secondary.opacity(0.2))
|
||||||
|
)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let overall = entry.overallAverage {
|
||||||
|
Text(String(format: "%.2f", overall))
|
||||||
|
.font(.headline)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.foregroundStyle(averageColor(for: overall))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if entry.subjectAverages.isEmpty {
|
||||||
|
Spacer()
|
||||||
|
Text(localization.string("no_averages"))
|
||||||
|
.font(.subheadline)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
Spacer()
|
||||||
|
} else {
|
||||||
|
ForEach(entry.subjectAverages.prefix(maxVisible)) { subject in
|
||||||
|
AverageRow(subject: subject, style: style, showGradeCount: true)
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func averageColor(for value: Double) -> Color {
|
||||||
|
switch value {
|
||||||
|
case 4.5...: return .green
|
||||||
|
case 3.5..<4.5: return .blue
|
||||||
|
case 2.5..<3.5: return .yellow
|
||||||
|
case 1.5..<2.5: return .orange
|
||||||
|
default: return .red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AverageRow: View {
|
||||||
|
let subject: SubjectAverage
|
||||||
|
let style: WidgetStyleType
|
||||||
|
var showGradeCount: Bool = false
|
||||||
|
var compact: Bool = false
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack(spacing: 12) {
|
||||||
|
Text(subject.name)
|
||||||
|
.font(compact ? .footnote : .subheadline)
|
||||||
|
.widgetTextStyle(style, colors: nil)
|
||||||
|
.lineLimit(1)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
if showGradeCount {
|
||||||
|
Text("(\(subject.gradeCount))")
|
||||||
|
.font(.caption2)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(subject.formattedAverage)
|
||||||
|
.font(compact ? .footnote : .subheadline)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.foregroundStyle(subject.averageColor)
|
||||||
|
}
|
||||||
|
.padding(.vertical, compact ? 2 : 4)
|
||||||
|
}
|
||||||
|
}
|
||||||
173
firka/ios/HomeWidgetsExtension/Views/GradesViews.swift
Normal file
173
firka/ios/HomeWidgetsExtension/Views/GradesViews.swift
Normal file
@@ -0,0 +1,173 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import WidgetKit
|
||||||
|
|
||||||
|
struct GradesSmallView: View {
|
||||||
|
let entry: GradesEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var style: WidgetStyleType {
|
||||||
|
(entry.configuration.style ?? .appTheme) == .liquidGlass ? .liquidGlass : .appTheme
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
WidgetBackground(style: style, colors: nil)
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text(localization.string("recent_grades"))
|
||||||
|
.font(.caption)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
|
||||||
|
if let grade = entry.grades.first {
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Text(grade.displayValue)
|
||||||
|
.font(.system(size: 48, weight: .bold))
|
||||||
|
.foregroundStyle(grade.gradeColor)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(grade.subjectNameWithWeight)
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(.medium)
|
||||||
|
.widgetTextStyle(style, colors: nil)
|
||||||
|
.lineLimit(1)
|
||||||
|
|
||||||
|
Text(grade.dateString)
|
||||||
|
.font(.caption)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
} else {
|
||||||
|
Spacer()
|
||||||
|
Text(localization.string("no_grades"))
|
||||||
|
.font(.subheadline)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GradesMediumView: View {
|
||||||
|
let entry: GradesEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var style: WidgetStyleType {
|
||||||
|
(entry.configuration.style ?? .appTheme) == .liquidGlass ? .liquidGlass : .appTheme
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
WidgetBackground(style: style, colors: nil)
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
|
Text(localization.string("recent_grades"))
|
||||||
|
.font(.caption)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
|
||||||
|
if entry.grades.isEmpty {
|
||||||
|
Spacer()
|
||||||
|
Text(localization.string("no_grades"))
|
||||||
|
.font(.subheadline)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
Spacer()
|
||||||
|
} else {
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
ForEach(entry.grades.prefix(3)) { grade in
|
||||||
|
GradeRow(grade: grade, style: style, showTeacher: true, compact: true)
|
||||||
|
}
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
.clipped()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GradesLargeView: View {
|
||||||
|
let entry: GradesEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var style: WidgetStyleType {
|
||||||
|
(entry.configuration.style ?? .appTheme) == .liquidGlass ? .liquidGlass : .appTheme
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
WidgetBackground(style: style, colors: nil)
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 8) {
|
||||||
|
Text(localization.string("recent_grades"))
|
||||||
|
.font(.headline)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.widgetTextStyle(style, colors: nil)
|
||||||
|
|
||||||
|
if entry.grades.isEmpty {
|
||||||
|
Spacer()
|
||||||
|
Text(localization.string("no_grades"))
|
||||||
|
.font(.subheadline)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
Spacer()
|
||||||
|
} else {
|
||||||
|
ForEach(entry.grades.prefix(6)) { grade in
|
||||||
|
GradeRow(grade: grade, style: style, showTeacher: true, showTopic: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
.clipped()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GradeRow: View {
|
||||||
|
let grade: WidgetGrade
|
||||||
|
let style: WidgetStyleType
|
||||||
|
var showTeacher: Bool = false
|
||||||
|
var showTopic: Bool = false
|
||||||
|
var compact: Bool = false
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack(spacing: 12) {
|
||||||
|
Text(grade.displayValue)
|
||||||
|
.font(compact ? .title3 : .title2)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.foregroundStyle(grade.gradeColor)
|
||||||
|
.frame(width: 32)
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: compact ? 1 : 2) {
|
||||||
|
Text(grade.subjectNameWithWeight)
|
||||||
|
.font(compact ? .footnote : .subheadline)
|
||||||
|
.fontWeight(.medium)
|
||||||
|
.widgetTextStyle(style, colors: nil)
|
||||||
|
.lineLimit(1)
|
||||||
|
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
if showTeacher, let teacher = grade.teacherName {
|
||||||
|
Text(teacher)
|
||||||
|
.font(.caption2)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
.lineLimit(1)
|
||||||
|
|
||||||
|
Text("•")
|
||||||
|
.font(.caption2)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(grade.dateString)
|
||||||
|
.font(.caption2)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding(.vertical, compact ? 2 : 4)
|
||||||
|
}
|
||||||
|
}
|
||||||
454
firka/ios/HomeWidgetsExtension/Views/TimetableViews.swift
Normal file
454
firka/ios/HomeWidgetsExtension/Views/TimetableViews.swift
Normal file
@@ -0,0 +1,454 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import WidgetKit
|
||||||
|
|
||||||
|
struct TimetableSmallView: View {
|
||||||
|
let entry: TimetableEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
|
||||||
|
var style: WidgetStyleType {
|
||||||
|
(entry.configuration.style ?? .appTheme) == .liquidGlass ? .liquidGlass : .appTheme
|
||||||
|
}
|
||||||
|
|
||||||
|
var displayLesson: WidgetLesson? {
|
||||||
|
let mode = entry.configuration.displayMode ?? .current
|
||||||
|
if mode == .current {
|
||||||
|
return entry.currentLesson ?? entry.nextLesson
|
||||||
|
} else {
|
||||||
|
return entry.nextLesson
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var isShowingNextLesson: Bool {
|
||||||
|
let mode = entry.configuration.displayMode ?? .current
|
||||||
|
if mode == .current {
|
||||||
|
return entry.currentLesson == nil && entry.nextLesson != nil
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
var liquidGlassPrimary: Color {
|
||||||
|
colorScheme == .dark ? .white : .black
|
||||||
|
}
|
||||||
|
|
||||||
|
var liquidGlassSecondary: Color {
|
||||||
|
colorScheme == .dark ? .white.opacity(0.7) : .black.opacity(0.6)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
WidgetBackground(style: style, colors: nil)
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text(isShowingNextLesson ?
|
||||||
|
localization.string("next_lesson") :
|
||||||
|
localization.string("current_lesson"))
|
||||||
|
.font(.caption)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
|
||||||
|
if let lesson = displayLesson {
|
||||||
|
if entry.isNextSchoolDay {
|
||||||
|
let dateStr = WidgetLocalization.formatShortDate(entry.nextSchoolDayDateString, locale: localization.locale)
|
||||||
|
Text(dateStr)
|
||||||
|
.font(.caption2)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(lesson.displayName)
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.foregroundColor(lesson.isCancelled ? .red :
|
||||||
|
lesson.isSubstitution ? .orange :
|
||||||
|
(style == .liquidGlass ? liquidGlassPrimary : .primary))
|
||||||
|
.lineLimit(2)
|
||||||
|
.fixedSize(horizontal: false, vertical: true)
|
||||||
|
|
||||||
|
Text(lesson.timeString)
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundColor(lesson.isCancelled ? .red.opacity(0.8) :
|
||||||
|
lesson.isSubstitution ? .orange.opacity(0.8) :
|
||||||
|
(style == .liquidGlass ? liquidGlassSecondary : .secondary))
|
||||||
|
|
||||||
|
if let room = lesson.roomName {
|
||||||
|
Text(room)
|
||||||
|
.font(.caption2)
|
||||||
|
.lineLimit(2)
|
||||||
|
.minimumScaleFactor(0.8)
|
||||||
|
.foregroundColor(lesson.isCancelled ? .red.opacity(0.7) :
|
||||||
|
lesson.isSubstitution ? .orange.opacity(0.7) :
|
||||||
|
(style == .liquidGlass ? liquidGlassSecondary : .secondary))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Text(localization.string("no_lessons_ahead"))
|
||||||
|
.font(.subheadline)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TimetableMediumView: View {
|
||||||
|
let entry: TimetableEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var style: WidgetStyleType {
|
||||||
|
(entry.configuration.style ?? .appTheme) == .liquidGlass ? .liquidGlass : .appTheme
|
||||||
|
}
|
||||||
|
|
||||||
|
func isLessonActive(_ lesson: WidgetLesson) -> Bool {
|
||||||
|
let checkDate = entry.date
|
||||||
|
return checkDate >= lesson.start && checkDate <= lesson.end
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentLessonIndex: Int {
|
||||||
|
let checkDate = entry.date
|
||||||
|
if let index = entry.lessons.firstIndex(where: { checkDate >= $0.start && checkDate <= $0.end }) {
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
if let index = entry.lessons.firstIndex(where: { $0.start > checkDate }) {
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
return max(0, entry.lessons.count - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
var hasActiveBreak: Bool {
|
||||||
|
let checkDate = entry.date
|
||||||
|
for (currentLesson, nextLesson) in zip(entry.lessons, entry.lessons.dropFirst()) {
|
||||||
|
if checkDate > currentLesson.end && checkDate < nextLesson.start {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var visibleLessons: [WidgetLesson] {
|
||||||
|
let totalLessons = entry.lessons.count
|
||||||
|
let maxVisible = hasActiveBreak ? 3 : 4
|
||||||
|
|
||||||
|
if totalLessons <= maxVisible {
|
||||||
|
return Array(entry.lessons)
|
||||||
|
}
|
||||||
|
|
||||||
|
var startIndex = max(0, currentLessonIndex - 1)
|
||||||
|
|
||||||
|
startIndex = min(startIndex, totalLessons - maxVisible)
|
||||||
|
|
||||||
|
let endIndex = min(startIndex + maxVisible, totalLessons)
|
||||||
|
return Array(entry.lessons[startIndex..<endIndex])
|
||||||
|
}
|
||||||
|
|
||||||
|
var headerText: String {
|
||||||
|
if entry.isNextSchoolDay {
|
||||||
|
let dateStr = WidgetLocalization.formatShortDate(entry.nextSchoolDayDateString, locale: localization.locale)
|
||||||
|
return localization.string("next_school_day_timetable", dateStr)
|
||||||
|
} else if entry.isNextDay {
|
||||||
|
return localization.string("tomorrow_timetable")
|
||||||
|
} else {
|
||||||
|
return localization.string("today_timetable")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
WidgetBackground(style: style, colors: nil)
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
|
Text(headerText)
|
||||||
|
.font(.caption)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
ForEach(Array(visibleLessons.enumerated()), id: \.element.id) { index, lesson in
|
||||||
|
LessonRow(lesson: lesson, isActive: isLessonActive(lesson), style: style, compact: true)
|
||||||
|
|
||||||
|
if index < visibleLessons.count - 1 {
|
||||||
|
let nextLesson = visibleLessons[index + 1]
|
||||||
|
let isInBreak = entry.date > lesson.end && entry.date < nextLesson.start
|
||||||
|
if isInBreak {
|
||||||
|
let totalBreakMinutes = Int(ceil(nextLesson.start.timeIntervalSince(lesson.end) / 60))
|
||||||
|
BreakIndicatorRow(minutesLeft: totalBreakMinutes, localization: localization, style: style, compact: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
.clipped()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TimetableLargeView: View {
|
||||||
|
let entry: TimetableEntry
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
|
||||||
|
var style: WidgetStyleType {
|
||||||
|
(entry.configuration.style ?? .appTheme) == .liquidGlass ? .liquidGlass : .appTheme
|
||||||
|
}
|
||||||
|
|
||||||
|
func isLessonActive(_ lesson: WidgetLesson) -> Bool {
|
||||||
|
let checkDate = entry.date
|
||||||
|
return checkDate >= lesson.start && checkDate <= lesson.end
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentLessonIndex: Int {
|
||||||
|
let checkDate = entry.date
|
||||||
|
if let index = entry.lessons.firstIndex(where: { checkDate >= $0.start && checkDate <= $0.end }) {
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
if let index = entry.lessons.firstIndex(where: { $0.start > checkDate }) {
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
return max(0, entry.lessons.count - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
var hasActiveBreak: Bool {
|
||||||
|
let checkDate = entry.date
|
||||||
|
for (currentLesson, nextLesson) in zip(entry.lessons, entry.lessons.dropFirst()) {
|
||||||
|
if checkDate > currentLesson.end && checkDate < nextLesson.start {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var visibleLessons: [WidgetLesson] {
|
||||||
|
let totalLessons = entry.lessons.count
|
||||||
|
let maxVisible = hasActiveBreak ? 6 : 7
|
||||||
|
|
||||||
|
if totalLessons <= maxVisible {
|
||||||
|
return Array(entry.lessons)
|
||||||
|
}
|
||||||
|
|
||||||
|
var startIndex = max(0, currentLessonIndex - 1)
|
||||||
|
startIndex = min(startIndex, totalLessons - maxVisible)
|
||||||
|
|
||||||
|
let endIndex = min(startIndex + maxVisible, totalLessons)
|
||||||
|
return Array(entry.lessons[startIndex..<endIndex])
|
||||||
|
}
|
||||||
|
|
||||||
|
var headerText: String {
|
||||||
|
if entry.isNextSchoolDay {
|
||||||
|
let dateStr = WidgetLocalization.formatShortDate(entry.nextSchoolDayDateString, locale: localization.locale)
|
||||||
|
return localization.string("next_school_day_timetable", dateStr)
|
||||||
|
} else if entry.isNextDay {
|
||||||
|
return localization.string("tomorrow_timetable")
|
||||||
|
} else {
|
||||||
|
return localization.string("today_timetable")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
WidgetBackground(style: style, colors: nil)
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
|
Text(headerText)
|
||||||
|
.font(.headline)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.widgetTextStyle(style, colors: nil)
|
||||||
|
|
||||||
|
ForEach(Array(visibleLessons.enumerated()), id: \.element.id) { index, lesson in
|
||||||
|
LessonRow(lesson: lesson, isActive: isLessonActive(lesson), style: style, showRoom: true)
|
||||||
|
|
||||||
|
if index < visibleLessons.count - 1 {
|
||||||
|
let nextLesson = visibleLessons[index + 1]
|
||||||
|
let isInBreak = entry.date > lesson.end && entry.date < nextLesson.start
|
||||||
|
if isInBreak {
|
||||||
|
let totalBreakMinutes = Int(ceil(nextLesson.start.timeIntervalSince(lesson.end) / 60))
|
||||||
|
BreakIndicatorRow(minutesLeft: totalBreakMinutes, localization: localization, style: style)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
.clipped()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct BreakIndicatorRow: View {
|
||||||
|
let minutesLeft: Int
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
let style: WidgetStyleType
|
||||||
|
var compact: Bool = false
|
||||||
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
|
||||||
|
var liquidGlassPrimary: Color {
|
||||||
|
colorScheme == .dark ? .white : .black
|
||||||
|
}
|
||||||
|
|
||||||
|
var liquidGlassSecondary: Color {
|
||||||
|
colorScheme == .dark ? .white.opacity(0.7) : .black.opacity(0.6)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack(spacing: 12) {
|
||||||
|
Text("–")
|
||||||
|
.font(.caption)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.frame(width: 24, height: 24)
|
||||||
|
.background(
|
||||||
|
Circle()
|
||||||
|
.fill(Color.green.opacity(0.3))
|
||||||
|
)
|
||||||
|
.foregroundColor(style == .liquidGlass ? liquidGlassPrimary : .primary)
|
||||||
|
|
||||||
|
Text(localization.string("break_between"))
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
.foregroundColor(style == .liquidGlass ? liquidGlassPrimary : .primary)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Text("\(minutesLeft) \(localization.string("minutes_abbrev"))")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(style == .liquidGlass ? liquidGlassSecondary : .secondary)
|
||||||
|
}
|
||||||
|
.padding(.vertical, compact ? 2 : 4)
|
||||||
|
.padding(.horizontal, 8)
|
||||||
|
.currentLessonGlow(isActive: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct LessonRow: View {
|
||||||
|
let lesson: WidgetLesson
|
||||||
|
let isActive: Bool
|
||||||
|
let style: WidgetStyleType
|
||||||
|
var showRoom: Bool = false
|
||||||
|
var compact: Bool = false
|
||||||
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
|
||||||
|
var lessonTextColor: Color? {
|
||||||
|
if lesson.isCancelled {
|
||||||
|
return .red
|
||||||
|
} else if lesson.isSubstitution {
|
||||||
|
return .orange
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var liquidGlassPrimary: Color {
|
||||||
|
colorScheme == .dark ? .white : .black
|
||||||
|
}
|
||||||
|
|
||||||
|
var liquidGlassSecondary: Color {
|
||||||
|
colorScheme == .dark ? .white.opacity(0.7) : .black.opacity(0.6)
|
||||||
|
}
|
||||||
|
|
||||||
|
var numberBackgroundColor: Color {
|
||||||
|
if lesson.isCancelled {
|
||||||
|
return Color.red.opacity(0.3)
|
||||||
|
} else if lesson.isSubstitution {
|
||||||
|
return Color.orange.opacity(0.3)
|
||||||
|
} else if isActive {
|
||||||
|
return Color.green.opacity(0.3)
|
||||||
|
}
|
||||||
|
return Color.secondary.opacity(0.2)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack(spacing: 12) {
|
||||||
|
if let number = lesson.lessonNumber {
|
||||||
|
Text("\(number)")
|
||||||
|
.font(.caption)
|
||||||
|
.fontWeight(.bold)
|
||||||
|
.frame(width: 24, height: 24)
|
||||||
|
.background(
|
||||||
|
Circle()
|
||||||
|
.fill(numberBackgroundColor)
|
||||||
|
)
|
||||||
|
.foregroundColor(lessonTextColor ?? (style == .liquidGlass ? liquidGlassPrimary : .primary))
|
||||||
|
}
|
||||||
|
|
||||||
|
Text(lesson.displayName)
|
||||||
|
.font(.subheadline)
|
||||||
|
.fontWeight(isActive ? .semibold : .regular)
|
||||||
|
.foregroundColor(lessonTextColor ?? (style == .liquidGlass ? liquidGlassPrimary : .primary))
|
||||||
|
.lineLimit(1)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Text(lesson.timeString)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(lessonTextColor?.opacity(0.8) ?? (style == .liquidGlass ? liquidGlassSecondary : .secondary))
|
||||||
|
|
||||||
|
if showRoom, let room = lesson.roomName {
|
||||||
|
Text(room)
|
||||||
|
.font(.caption2)
|
||||||
|
.padding(.horizontal, 6)
|
||||||
|
.padding(.vertical, 2)
|
||||||
|
.background(
|
||||||
|
Capsule()
|
||||||
|
.fill(lesson.isCancelled ? Color.red.opacity(0.2) :
|
||||||
|
lesson.isSubstitution ? Color.orange.opacity(0.2) :
|
||||||
|
Color.secondary.opacity(0.2))
|
||||||
|
)
|
||||||
|
.foregroundColor(lessonTextColor?.opacity(0.8) ?? (style == .liquidGlass ? liquidGlassSecondary : .secondary))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.vertical, compact ? 2 : 4)
|
||||||
|
.padding(.horizontal, 8)
|
||||||
|
.currentLessonGlow(isActive: isActive)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct BreakView: View {
|
||||||
|
let breakInfo: BreakInfo
|
||||||
|
let localization: WidgetLocalization
|
||||||
|
let style: WidgetStyleType
|
||||||
|
|
||||||
|
var daysRemaining: Int {
|
||||||
|
Calendar.current.dateComponents([.day], from: Date(), to: breakInfo.endDate).day ?? 0
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
WidgetBackground(style: style, colors: nil)
|
||||||
|
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
Image(systemName: "snowflake")
|
||||||
|
.font(.largeTitle)
|
||||||
|
.widgetTextStyle(style, colors: nil)
|
||||||
|
|
||||||
|
Text(localization.string("happy_break", localization.string(breakInfo.nameKey)))
|
||||||
|
.font(.headline)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.widgetTextStyle(style, colors: nil)
|
||||||
|
|
||||||
|
Text(localization.string("days_remaining", daysRemaining))
|
||||||
|
.font(.subheadline)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct EmptyStateView: View {
|
||||||
|
let message: String
|
||||||
|
let style: WidgetStyleType
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
WidgetBackground(style: style, colors: nil)
|
||||||
|
|
||||||
|
VStack(spacing: 8) {
|
||||||
|
Image(systemName: "calendar.badge.exclamationmark")
|
||||||
|
.font(.largeTitle)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
|
||||||
|
Text(message)
|
||||||
|
.font(.subheadline)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.widgetTextStyle(style, colors: nil, isPrimary: false)
|
||||||
|
}
|
||||||
|
.padding()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
102
firka/ios/HomeWidgetsExtension/Views/WidgetStyles.swift
Normal file
102
firka/ios/HomeWidgetsExtension/Views/WidgetStyles.swift
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
import SwiftUI
|
||||||
|
import WidgetKit
|
||||||
|
|
||||||
|
enum WidgetStyleType: String, Codable, CaseIterable {
|
||||||
|
case liquidGlass = "liquid_glass"
|
||||||
|
case appTheme = "app_theme"
|
||||||
|
|
||||||
|
var displayName: String {
|
||||||
|
switch self {
|
||||||
|
case .liquidGlass: return "Liquid Glass"
|
||||||
|
case .appTheme: return "App Theme"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct WidgetBackground: View {
|
||||||
|
let style: WidgetStyleType
|
||||||
|
let colors: WidgetColors?
|
||||||
|
|
||||||
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
switch style {
|
||||||
|
case .liquidGlass:
|
||||||
|
if #available(iOS 26.0, *) {
|
||||||
|
Color.clear
|
||||||
|
} else {
|
||||||
|
Rectangle()
|
||||||
|
.fill(.ultraThinMaterial)
|
||||||
|
}
|
||||||
|
case .appTheme:
|
||||||
|
if let colors = colors {
|
||||||
|
Rectangle()
|
||||||
|
.fill(colors.backgroundColor)
|
||||||
|
} else {
|
||||||
|
Rectangle()
|
||||||
|
.fill(Color(.systemBackground))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct WidgetTextStyle: ViewModifier {
|
||||||
|
let style: WidgetStyleType
|
||||||
|
let colors: WidgetColors?
|
||||||
|
let isPrimary: Bool
|
||||||
|
|
||||||
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
@Environment(\.widgetRenderingMode) var renderingMode
|
||||||
|
|
||||||
|
func body(content: Content) -> some View {
|
||||||
|
switch style {
|
||||||
|
case .liquidGlass:
|
||||||
|
if renderingMode == .accented {
|
||||||
|
content
|
||||||
|
} else {
|
||||||
|
content.foregroundStyle(isPrimary ?
|
||||||
|
(colorScheme == .dark ? .white : .black) :
|
||||||
|
(colorScheme == .dark ? .white.opacity(0.7) : .black.opacity(0.6)))
|
||||||
|
}
|
||||||
|
case .appTheme:
|
||||||
|
if let colors = colors {
|
||||||
|
content.foregroundStyle(isPrimary ? colors.textPrimaryColor : colors.textSecondaryColor)
|
||||||
|
} else {
|
||||||
|
content.foregroundStyle(isPrimary ? .primary : .secondary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension View {
|
||||||
|
func widgetTextStyle(_ style: WidgetStyleType, colors: WidgetColors?, isPrimary: Bool = true) -> some View {
|
||||||
|
modifier(WidgetTextStyle(style: style, colors: colors, isPrimary: isPrimary))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct GlowEffect: ViewModifier {
|
||||||
|
let isActive: Bool
|
||||||
|
let color: Color
|
||||||
|
|
||||||
|
func body(content: Content) -> some View {
|
||||||
|
if isActive {
|
||||||
|
content
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 12)
|
||||||
|
.fill(color.opacity(0.15))
|
||||||
|
)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: 12)
|
||||||
|
.stroke(color.opacity(0.3), lineWidth: 1)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
content
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension View {
|
||||||
|
func currentLessonGlow(isActive: Bool, color: Color = .green) -> some View {
|
||||||
|
modifier(GlowEffect(isActive: isActive, color: color))
|
||||||
|
}
|
||||||
|
}
|
||||||
11
firka/ios/HomeWidgetsExtension/de.lproj/AppShortcuts.strings
Normal file
11
firka/ios/HomeWidgetsExtension/de.lproj/AppShortcuts.strings
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/* Siri Phrases - German */
|
||||||
|
"Next lesson ${applicationName}" = "Nächste Stunde ${applicationName}";
|
||||||
|
"What is my next lesson ${applicationName}" = "Was ist meine nächste Stunde ${applicationName}";
|
||||||
|
"Closest lesson ${applicationName}" = "Nächste anstehende Stunde ${applicationName}";
|
||||||
|
"When is my next lesson ${applicationName}" = "Wann ist meine nächste Stunde ${applicationName}";
|
||||||
|
"Today's timetable ${applicationName}" = "Stundenplan heute ${applicationName}";
|
||||||
|
"What lessons do I have today ${applicationName}" = "Welche Stunden habe ich heute ${applicationName}";
|
||||||
|
"Closest timetable ${applicationName}" = "Nächster Stundenplan ${applicationName}";
|
||||||
|
"When are my next lessons ${applicationName}" = "Wann sind meine nächsten Stunden ${applicationName}";
|
||||||
|
"My average ${applicationName}" = "Mein Durchschnitt ${applicationName}";
|
||||||
|
"What is my average ${applicationName}" = "Wie ist mein Durchschnitt ${applicationName}";
|
||||||
120
firka/ios/HomeWidgetsExtension/de.lproj/Localizable.strings
Normal file
120
firka/ios/HomeWidgetsExtension/de.lproj/Localizable.strings
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/* Widget Titles */
|
||||||
|
"widget_timetable_title" = "Stundenplan";
|
||||||
|
"widget_grades_title" = "Letzte Noten";
|
||||||
|
"widget_averages_title" = "Durchschnitte";
|
||||||
|
|
||||||
|
/* Widget Descriptions */
|
||||||
|
"widget_timetable_description" = "Zeigt deinen täglichen Stundenplan";
|
||||||
|
"widget_grades_description" = "Zeigt deine letzten Noten";
|
||||||
|
"widget_averages_description" = "Zeigt Fachdurchschnitte";
|
||||||
|
|
||||||
|
/* Lock Screen Widget Descriptions */
|
||||||
|
"widget_timetable_lockscreen_description" = "Stundenplan auf dem Sperrbildschirm";
|
||||||
|
"widget_grades_lockscreen_description" = "Noten auf dem Sperrbildschirm";
|
||||||
|
"widget_averages_lockscreen_description" = "Durchschnitte auf dem Sperrbildschirm";
|
||||||
|
|
||||||
|
/* Parameter Titles */
|
||||||
|
"param_style" = "Stil";
|
||||||
|
"param_display_mode_small" = "Anzeige (kleines Widget)";
|
||||||
|
"param_subjects" = "Fächer";
|
||||||
|
|
||||||
|
/* Style Options */
|
||||||
|
"style_type" = "Stil";
|
||||||
|
"style_liquid_glass" = "Liquid Glass";
|
||||||
|
"style_app_theme" = "App-Design";
|
||||||
|
|
||||||
|
/* Display Mode Options */
|
||||||
|
"display_mode_type" = "Anzeigemodus";
|
||||||
|
"display_mode_current" = "Aktuelle Stunde";
|
||||||
|
"display_mode_next" = "Nächste Stunde";
|
||||||
|
|
||||||
|
/* Subject Selection */
|
||||||
|
"subjects_type" = "Fächer";
|
||||||
|
"no_subjects_available" = "Keine Fächer verfügbar";
|
||||||
|
|
||||||
|
/* Control Widget Titles */
|
||||||
|
"control_home_title" = "Firka Startseite";
|
||||||
|
"control_home_label" = "Startseite";
|
||||||
|
"control_home_display" = "Firka - Startseite";
|
||||||
|
"control_home_description" = "Firka Startseite öffnen";
|
||||||
|
"control_grades_title" = "Firka Noten";
|
||||||
|
"control_grades_label" = "Noten";
|
||||||
|
"control_grades_display" = "Firka - Noten";
|
||||||
|
"control_grades_description" = "Firka Noten öffnen";
|
||||||
|
"control_timetable_title" = "Firka Stundenplan";
|
||||||
|
"control_timetable_label" = "Stundenplan";
|
||||||
|
"control_timetable_display" = "Firka - Stundenplan";
|
||||||
|
"control_timetable_description" = "Firka Stundenplan öffnen";
|
||||||
|
|
||||||
|
/* Shortcut Intent Titles & Descriptions */
|
||||||
|
"shortcut_next_lesson_title" = "Nächste Stunde";
|
||||||
|
"shortcut_next_lesson_description" = "Details zur nächsten Stunde";
|
||||||
|
"shortcut_closest_lesson_title" = "Nächste anstehende Stunde";
|
||||||
|
"shortcut_closest_lesson_description" = "Nächste anstehende Stunde (heute, morgen oder nächster Schultag)";
|
||||||
|
"shortcut_today_timetable_title" = "Stundenplan heute";
|
||||||
|
"shortcut_today_timetable_description" = "Der vollständige Stundenplan für heute";
|
||||||
|
"shortcut_tomorrow_timetable_title" = "Stundenplan morgen";
|
||||||
|
"shortcut_tomorrow_timetable_description" = "Der Stundenplan für morgen";
|
||||||
|
"shortcut_closest_timetable_title" = "Nächster Stundenplan";
|
||||||
|
"shortcut_closest_timetable_description" = "Stundenplan des nächsten Schultags (heute, morgen oder nächster Schultag)";
|
||||||
|
"shortcut_recent_grades_title" = "Letzte Noten";
|
||||||
|
"shortcut_recent_grades_description" = "Die letzten Noten";
|
||||||
|
"shortcut_subject_average_title" = "Fachdurchschnitt";
|
||||||
|
"shortcut_subject_average_description" = "Durchschnitt eines Fachs";
|
||||||
|
"shortcut_overall_average_title" = "Gesamtdurchschnitt";
|
||||||
|
"shortcut_overall_average_description" = "Der Gesamtdurchschnitt";
|
||||||
|
|
||||||
|
/* Shortcut Parameters */
|
||||||
|
"shortcut_param_count" = "Anzahl";
|
||||||
|
"shortcut_param_subject" = "Fach";
|
||||||
|
|
||||||
|
/* Shortcut Phrases */
|
||||||
|
"shortcut_phrase_next_lesson" = "Nächste Stunde";
|
||||||
|
"shortcut_phrase_next_lesson_question" = "Was ist meine nächste Stunde";
|
||||||
|
"shortcut_phrase_closest_lesson" = "Nächste anstehende Stunde";
|
||||||
|
"shortcut_phrase_closest_lesson_question" = "Wann ist meine nächste Stunde";
|
||||||
|
"shortcut_phrase_today_timetable" = "Stundenplan heute";
|
||||||
|
"shortcut_phrase_today_timetable_question" = "Welche Stunden habe ich heute";
|
||||||
|
"shortcut_phrase_closest_timetable" = "Nächster Stundenplan";
|
||||||
|
"shortcut_phrase_closest_timetable_question" = "Wann sind meine nächsten Stunden";
|
||||||
|
"shortcut_phrase_overall_average" = "Mein Durchschnitt";
|
||||||
|
"shortcut_phrase_overall_average_question" = "Wie ist mein Durchschnitt";
|
||||||
|
|
||||||
|
/* Shortcut Short Titles */
|
||||||
|
"shortcut_short_next_lesson" = "Nächste Stunde";
|
||||||
|
"shortcut_short_closest_lesson" = "Nächste anstehende";
|
||||||
|
"shortcut_short_today_timetable" = "Stundenplan heute";
|
||||||
|
"shortcut_short_closest_timetable" = "Nächster Stundenplan";
|
||||||
|
"shortcut_short_overall_average" = "Mein Durchschnitt";
|
||||||
|
|
||||||
|
/* Shortcut Errors */
|
||||||
|
"shortcut_error_no_data" = "Keine Daten verfügbar. Öffne die Firka App zum Aktualisieren.";
|
||||||
|
"shortcut_error_no_upcoming_lesson" = "Heute keine weiteren Stunden.";
|
||||||
|
"shortcut_error_no_lessons_today" = "Heute keine Stunden.";
|
||||||
|
"shortcut_error_no_lessons_tomorrow" = "Morgen keine Stunden.";
|
||||||
|
"shortcut_error_subject_not_found" = "Fach nicht gefunden.";
|
||||||
|
|
||||||
|
/* Entity Type Names */
|
||||||
|
"entity_lesson" = "Stunde";
|
||||||
|
"entity_grade" = "Note";
|
||||||
|
"entity_average" = "Durchschnitt";
|
||||||
|
|
||||||
|
/* Entity Property Names */
|
||||||
|
"entity_prop_name" = "Name";
|
||||||
|
"entity_prop_teacher" = "Lehrer";
|
||||||
|
"entity_prop_room" = "Raum";
|
||||||
|
"entity_prop_start_time" = "Startzeit";
|
||||||
|
"entity_prop_end_time" = "Endzeit";
|
||||||
|
"entity_prop_lesson_number" = "Stundennummer";
|
||||||
|
"entity_prop_cancelled" = "Entfällt";
|
||||||
|
"entity_prop_substitution" = "Vertretung";
|
||||||
|
"entity_prop_theme" = "Thema";
|
||||||
|
"entity_prop_subject" = "Fach";
|
||||||
|
"entity_prop_value" = "Wert";
|
||||||
|
"entity_prop_grade" = "Note";
|
||||||
|
"entity_prop_topic" = "Thema";
|
||||||
|
"entity_prop_type" = "Typ";
|
||||||
|
"entity_prop_date" = "Datum";
|
||||||
|
"entity_prop_weight" = "Gewicht";
|
||||||
|
"entity_prop_average" = "Durchschnitt";
|
||||||
|
"entity_prop_grade_count" = "Notenanzahl";
|
||||||
11
firka/ios/HomeWidgetsExtension/en.lproj/AppShortcuts.strings
Normal file
11
firka/ios/HomeWidgetsExtension/en.lproj/AppShortcuts.strings
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/* Siri Phrases - English */
|
||||||
|
"Next lesson ${applicationName}" = "Next lesson ${applicationName}";
|
||||||
|
"What is my next lesson ${applicationName}" = "What is my next lesson ${applicationName}";
|
||||||
|
"Closest lesson ${applicationName}" = "Closest lesson ${applicationName}";
|
||||||
|
"When is my next lesson ${applicationName}" = "When is my next lesson ${applicationName}";
|
||||||
|
"Today's timetable ${applicationName}" = "Today's timetable ${applicationName}";
|
||||||
|
"What lessons do I have today ${applicationName}" = "What lessons do I have today ${applicationName}";
|
||||||
|
"Closest timetable ${applicationName}" = "Closest timetable ${applicationName}";
|
||||||
|
"When are my next lessons ${applicationName}" = "When are my next lessons ${applicationName}";
|
||||||
|
"My average ${applicationName}" = "My average ${applicationName}";
|
||||||
|
"What is my average ${applicationName}" = "What is my average ${applicationName}";
|
||||||
120
firka/ios/HomeWidgetsExtension/en.lproj/Localizable.strings
Normal file
120
firka/ios/HomeWidgetsExtension/en.lproj/Localizable.strings
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/* Widget Titles */
|
||||||
|
"widget_timetable_title" = "Timetable";
|
||||||
|
"widget_grades_title" = "Recent Grades";
|
||||||
|
"widget_averages_title" = "Averages";
|
||||||
|
|
||||||
|
/* Widget Descriptions */
|
||||||
|
"widget_timetable_description" = "Shows your daily timetable";
|
||||||
|
"widget_grades_description" = "Shows your recent grades";
|
||||||
|
"widget_averages_description" = "Shows subject averages";
|
||||||
|
|
||||||
|
/* Lock Screen Widget Descriptions */
|
||||||
|
"widget_timetable_lockscreen_description" = "Timetable on lock screen";
|
||||||
|
"widget_grades_lockscreen_description" = "Grades on lock screen";
|
||||||
|
"widget_averages_lockscreen_description" = "Averages on lock screen";
|
||||||
|
|
||||||
|
/* Parameter Titles */
|
||||||
|
"param_style" = "Style";
|
||||||
|
"param_display_mode_small" = "Display (small widget)";
|
||||||
|
"param_subjects" = "Subjects";
|
||||||
|
|
||||||
|
/* Style Options */
|
||||||
|
"style_type" = "Style";
|
||||||
|
"style_liquid_glass" = "Liquid Glass";
|
||||||
|
"style_app_theme" = "App Theme";
|
||||||
|
|
||||||
|
/* Display Mode Options */
|
||||||
|
"display_mode_type" = "Display Mode";
|
||||||
|
"display_mode_current" = "Current Lesson";
|
||||||
|
"display_mode_next" = "Next Lesson";
|
||||||
|
|
||||||
|
/* Subject Selection */
|
||||||
|
"subjects_type" = "Subjects";
|
||||||
|
"no_subjects_available" = "No subjects available";
|
||||||
|
|
||||||
|
/* Control Widget Titles */
|
||||||
|
"control_home_title" = "Firka Home";
|
||||||
|
"control_home_label" = "Home";
|
||||||
|
"control_home_display" = "Firka - Home";
|
||||||
|
"control_home_description" = "Open Firka home screen";
|
||||||
|
"control_grades_title" = "Firka Grades";
|
||||||
|
"control_grades_label" = "Grades";
|
||||||
|
"control_grades_display" = "Firka - Grades";
|
||||||
|
"control_grades_description" = "Open Firka grades";
|
||||||
|
"control_timetable_title" = "Firka Timetable";
|
||||||
|
"control_timetable_label" = "Timetable";
|
||||||
|
"control_timetable_display" = "Firka - Timetable";
|
||||||
|
"control_timetable_description" = "Open Firka timetable";
|
||||||
|
|
||||||
|
/* Shortcut Intent Titles & Descriptions */
|
||||||
|
"shortcut_next_lesson_title" = "Next lesson";
|
||||||
|
"shortcut_next_lesson_description" = "Get the next lesson details";
|
||||||
|
"shortcut_closest_lesson_title" = "Closest lesson";
|
||||||
|
"shortcut_closest_lesson_description" = "Get the closest lesson (today, tomorrow, or next school day)";
|
||||||
|
"shortcut_today_timetable_title" = "Today's timetable";
|
||||||
|
"shortcut_today_timetable_description" = "Get today's full timetable";
|
||||||
|
"shortcut_tomorrow_timetable_title" = "Tomorrow's timetable";
|
||||||
|
"shortcut_tomorrow_timetable_description" = "Get tomorrow's timetable";
|
||||||
|
"shortcut_closest_timetable_title" = "Closest timetable";
|
||||||
|
"shortcut_closest_timetable_description" = "Get the closest school day's timetable (today, tomorrow, or next school day)";
|
||||||
|
"shortcut_recent_grades_title" = "Recent grades";
|
||||||
|
"shortcut_recent_grades_description" = "Get the most recent grades";
|
||||||
|
"shortcut_subject_average_title" = "Subject average";
|
||||||
|
"shortcut_subject_average_description" = "Get the average for a subject";
|
||||||
|
"shortcut_overall_average_title" = "Overall average";
|
||||||
|
"shortcut_overall_average_description" = "Get the overall academic average";
|
||||||
|
|
||||||
|
/* Shortcut Parameters */
|
||||||
|
"shortcut_param_count" = "Count";
|
||||||
|
"shortcut_param_subject" = "Subject";
|
||||||
|
|
||||||
|
/* Shortcut Phrases */
|
||||||
|
"shortcut_phrase_next_lesson" = "Next lesson";
|
||||||
|
"shortcut_phrase_next_lesson_question" = "What is my next lesson";
|
||||||
|
"shortcut_phrase_closest_lesson" = "Closest lesson";
|
||||||
|
"shortcut_phrase_closest_lesson_question" = "When is my next lesson";
|
||||||
|
"shortcut_phrase_today_timetable" = "Today's timetable";
|
||||||
|
"shortcut_phrase_today_timetable_question" = "What lessons do I have today";
|
||||||
|
"shortcut_phrase_closest_timetable" = "Closest timetable";
|
||||||
|
"shortcut_phrase_closest_timetable_question" = "When are my next lessons";
|
||||||
|
"shortcut_phrase_overall_average" = "My average";
|
||||||
|
"shortcut_phrase_overall_average_question" = "What is my average";
|
||||||
|
|
||||||
|
/* Shortcut Short Titles */
|
||||||
|
"shortcut_short_next_lesson" = "Next lesson";
|
||||||
|
"shortcut_short_closest_lesson" = "Closest lesson";
|
||||||
|
"shortcut_short_today_timetable" = "Today's timetable";
|
||||||
|
"shortcut_short_closest_timetable" = "Closest timetable";
|
||||||
|
"shortcut_short_overall_average" = "My average";
|
||||||
|
|
||||||
|
/* Shortcut Errors */
|
||||||
|
"shortcut_error_no_data" = "No data available. Open the Firka app to refresh.";
|
||||||
|
"shortcut_error_no_upcoming_lesson" = "No more lessons today.";
|
||||||
|
"shortcut_error_no_lessons_today" = "No lessons today.";
|
||||||
|
"shortcut_error_no_lessons_tomorrow" = "No lessons tomorrow.";
|
||||||
|
"shortcut_error_subject_not_found" = "Subject not found.";
|
||||||
|
|
||||||
|
/* Entity Type Names */
|
||||||
|
"entity_lesson" = "Lesson";
|
||||||
|
"entity_grade" = "Grade";
|
||||||
|
"entity_average" = "Average";
|
||||||
|
|
||||||
|
/* Entity Property Names */
|
||||||
|
"entity_prop_name" = "Name";
|
||||||
|
"entity_prop_teacher" = "Teacher";
|
||||||
|
"entity_prop_room" = "Room";
|
||||||
|
"entity_prop_start_time" = "Start time";
|
||||||
|
"entity_prop_end_time" = "End time";
|
||||||
|
"entity_prop_lesson_number" = "Lesson number";
|
||||||
|
"entity_prop_cancelled" = "Cancelled";
|
||||||
|
"entity_prop_substitution" = "Substitution";
|
||||||
|
"entity_prop_theme" = "Theme";
|
||||||
|
"entity_prop_subject" = "Subject";
|
||||||
|
"entity_prop_value" = "Value";
|
||||||
|
"entity_prop_grade" = "Grade";
|
||||||
|
"entity_prop_topic" = "Topic";
|
||||||
|
"entity_prop_type" = "Type";
|
||||||
|
"entity_prop_date" = "Date";
|
||||||
|
"entity_prop_weight" = "Weight";
|
||||||
|
"entity_prop_average" = "Average";
|
||||||
|
"entity_prop_grade_count" = "Grade count";
|
||||||
11
firka/ios/HomeWidgetsExtension/hu.lproj/AppShortcuts.strings
Normal file
11
firka/ios/HomeWidgetsExtension/hu.lproj/AppShortcuts.strings
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
/* Siri Phrases - Hungarian */
|
||||||
|
"Next lesson ${applicationName}" = "Következő óra ${applicationName}";
|
||||||
|
"What is my next lesson ${applicationName}" = "Mi a következő órám ${applicationName}";
|
||||||
|
"Closest lesson ${applicationName}" = "Legközelebbi óra ${applicationName}";
|
||||||
|
"When is my next lesson ${applicationName}" = "Mikor lesz órám ${applicationName}";
|
||||||
|
"Today's timetable ${applicationName}" = "Mai órarend ${applicationName}";
|
||||||
|
"What lessons do I have today ${applicationName}" = "Milyen óráim vannak ma ${applicationName}";
|
||||||
|
"Closest timetable ${applicationName}" = "Legközelebbi órarend ${applicationName}";
|
||||||
|
"When are my next lessons ${applicationName}" = "Mikor lesznek óráim ${applicationName}";
|
||||||
|
"My average ${applicationName}" = "Átlagom ${applicationName}";
|
||||||
|
"What is my average ${applicationName}" = "Mennyi az átlagom ${applicationName}";
|
||||||
120
firka/ios/HomeWidgetsExtension/hu.lproj/Localizable.strings
Normal file
120
firka/ios/HomeWidgetsExtension/hu.lproj/Localizable.strings
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/* Widget Titles */
|
||||||
|
"widget_timetable_title" = "Órarend";
|
||||||
|
"widget_grades_title" = "Legutóbbi jegyek";
|
||||||
|
"widget_averages_title" = "Átlagok";
|
||||||
|
|
||||||
|
/* Widget Descriptions */
|
||||||
|
"widget_timetable_description" = "A napi órarendet mutatja";
|
||||||
|
"widget_grades_description" = "A legutóbbi jegyeidet mutatja";
|
||||||
|
"widget_averages_description" = "A tantárgyi átlagokat mutatja";
|
||||||
|
|
||||||
|
/* Lock Screen Widget Descriptions */
|
||||||
|
"widget_timetable_lockscreen_description" = "Órarend a zárolt képernyőn";
|
||||||
|
"widget_grades_lockscreen_description" = "Jegyek a zárolt képernyőn";
|
||||||
|
"widget_averages_lockscreen_description" = "Átlagok a zárolt képernyőn";
|
||||||
|
|
||||||
|
/* Parameter Titles */
|
||||||
|
"param_style" = "Stílus";
|
||||||
|
"param_display_mode_small" = "Megjelenítés (kis widget)";
|
||||||
|
"param_subjects" = "Tantárgyak";
|
||||||
|
|
||||||
|
/* Style Options */
|
||||||
|
"style_type" = "Stílus";
|
||||||
|
"style_liquid_glass" = "Liquid Glass";
|
||||||
|
"style_app_theme" = "Alkalmazás témája";
|
||||||
|
|
||||||
|
/* Display Mode Options */
|
||||||
|
"display_mode_type" = "Megjelenítési mód";
|
||||||
|
"display_mode_current" = "Jelenlegi óra";
|
||||||
|
"display_mode_next" = "Következő óra";
|
||||||
|
|
||||||
|
/* Subject Selection */
|
||||||
|
"subjects_type" = "Tantárgyak";
|
||||||
|
"no_subjects_available" = "Nincsenek tantárgyak";
|
||||||
|
|
||||||
|
/* Control Widget Titles */
|
||||||
|
"control_home_title" = "Firka Főoldal";
|
||||||
|
"control_home_label" = "Főoldal";
|
||||||
|
"control_home_display" = "Firka - Főoldal";
|
||||||
|
"control_home_description" = "Firka app főoldal megnyitása";
|
||||||
|
"control_grades_title" = "Firka Jegyek";
|
||||||
|
"control_grades_label" = "Jegyek";
|
||||||
|
"control_grades_display" = "Firka - Jegyek";
|
||||||
|
"control_grades_description" = "Firka app jegyek megnyitása";
|
||||||
|
"control_timetable_title" = "Firka Órarend";
|
||||||
|
"control_timetable_label" = "Órarend";
|
||||||
|
"control_timetable_display" = "Firka - Órarend";
|
||||||
|
"control_timetable_description" = "Firka app órarend megnyitása";
|
||||||
|
|
||||||
|
/* Shortcut Intent Titles & Descriptions */
|
||||||
|
"shortcut_next_lesson_title" = "Következő óra";
|
||||||
|
"shortcut_next_lesson_description" = "A következő óra adatai";
|
||||||
|
"shortcut_closest_lesson_title" = "Legközelebbi óra";
|
||||||
|
"shortcut_closest_lesson_description" = "A legközelebbi óra adatai (ma, holnap, vagy a következő tanítási nap)";
|
||||||
|
"shortcut_today_timetable_title" = "Mai órarend";
|
||||||
|
"shortcut_today_timetable_description" = "A mai nap teljes órarendje";
|
||||||
|
"shortcut_tomorrow_timetable_title" = "Holnapi órarend";
|
||||||
|
"shortcut_tomorrow_timetable_description" = "A holnapi nap órarendje";
|
||||||
|
"shortcut_closest_timetable_title" = "Legközelebbi órarend";
|
||||||
|
"shortcut_closest_timetable_description" = "A legközelebbi tanítási nap órarendje (ma, holnap, vagy a következő tanítási nap)";
|
||||||
|
"shortcut_recent_grades_title" = "Legutóbbi jegyek";
|
||||||
|
"shortcut_recent_grades_description" = "A legutóbbi jegyek listája";
|
||||||
|
"shortcut_subject_average_title" = "Tantárgyi átlag";
|
||||||
|
"shortcut_subject_average_description" = "Egy tantárgy átlaga";
|
||||||
|
"shortcut_overall_average_title" = "Összesített átlag";
|
||||||
|
"shortcut_overall_average_description" = "Az összesített tanulmányi átlag";
|
||||||
|
|
||||||
|
/* Shortcut Parameters */
|
||||||
|
"shortcut_param_count" = "Darabszám";
|
||||||
|
"shortcut_param_subject" = "Tantárgy";
|
||||||
|
|
||||||
|
/* Shortcut Phrases */
|
||||||
|
"shortcut_phrase_next_lesson" = "Következő óra";
|
||||||
|
"shortcut_phrase_next_lesson_question" = "Mi a következő órám";
|
||||||
|
"shortcut_phrase_closest_lesson" = "Legközelebbi óra";
|
||||||
|
"shortcut_phrase_closest_lesson_question" = "Mikor lesz órám";
|
||||||
|
"shortcut_phrase_today_timetable" = "Mai órarend";
|
||||||
|
"shortcut_phrase_today_timetable_question" = "Milyen óráim vannak ma";
|
||||||
|
"shortcut_phrase_closest_timetable" = "Legközelebbi órarend";
|
||||||
|
"shortcut_phrase_closest_timetable_question" = "Mikor lesznek óráim";
|
||||||
|
"shortcut_phrase_overall_average" = "Átlagom";
|
||||||
|
"shortcut_phrase_overall_average_question" = "Mennyi az átlagom";
|
||||||
|
|
||||||
|
/* Shortcut Short Titles */
|
||||||
|
"shortcut_short_next_lesson" = "Következő óra";
|
||||||
|
"shortcut_short_closest_lesson" = "Legközelebbi óra";
|
||||||
|
"shortcut_short_today_timetable" = "Mai órarend";
|
||||||
|
"shortcut_short_closest_timetable" = "Legközelebbi órarend";
|
||||||
|
"shortcut_short_overall_average" = "Átlagom";
|
||||||
|
|
||||||
|
/* Shortcut Errors */
|
||||||
|
"shortcut_error_no_data" = "Nincs elérhető adat. Nyisd meg a Firka appot az adatok frissítéséhez.";
|
||||||
|
"shortcut_error_no_upcoming_lesson" = "Ma nincs több órád.";
|
||||||
|
"shortcut_error_no_lessons_today" = "Ma nincs órád.";
|
||||||
|
"shortcut_error_no_lessons_tomorrow" = "Holnap nincs órád.";
|
||||||
|
"shortcut_error_subject_not_found" = "A tantárgy nem található.";
|
||||||
|
|
||||||
|
/* Entity Type Names */
|
||||||
|
"entity_lesson" = "Óra";
|
||||||
|
"entity_grade" = "Jegy";
|
||||||
|
"entity_average" = "Átlag";
|
||||||
|
|
||||||
|
/* Entity Property Names */
|
||||||
|
"entity_prop_name" = "Név";
|
||||||
|
"entity_prop_teacher" = "Tanár";
|
||||||
|
"entity_prop_room" = "Terem";
|
||||||
|
"entity_prop_start_time" = "Kezdés";
|
||||||
|
"entity_prop_end_time" = "Vége";
|
||||||
|
"entity_prop_lesson_number" = "Óraszám";
|
||||||
|
"entity_prop_cancelled" = "Elmarad";
|
||||||
|
"entity_prop_substitution" = "Helyettesítés";
|
||||||
|
"entity_prop_theme" = "Téma";
|
||||||
|
"entity_prop_subject" = "Tantárgy";
|
||||||
|
"entity_prop_value" = "Érték";
|
||||||
|
"entity_prop_grade" = "Jegy";
|
||||||
|
"entity_prop_topic" = "Téma";
|
||||||
|
"entity_prop_type" = "Típus";
|
||||||
|
"entity_prop_date" = "Dátum";
|
||||||
|
"entity_prop_weight" = "Súly";
|
||||||
|
"entity_prop_average" = "Átlag";
|
||||||
|
"entity_prop_grade_count" = "Jegyek száma";
|
||||||
14
firka/ios/LiveActivityWidget.entitlements
Normal file
14
firka/ios/LiveActivityWidget.entitlements
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>aps-environment</key>
|
||||||
|
<string>development</string>
|
||||||
|
<key>com.apple.developer.ubiquity-kvstore-identifier</key>
|
||||||
|
<string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string>
|
||||||
|
<key>com.apple.security.application-groups</key>
|
||||||
|
<array>
|
||||||
|
<string>group.app.firkaa.legacy</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
412
firka/ios/LiveActivityWidget/ActivityAttributes.swift
Normal file
412
firka/ios/LiveActivityWidget/ActivityAttributes.swift
Normal file
@@ -0,0 +1,412 @@
|
|||||||
|
import ActivityKit
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct TimetableActivityAttributes: ActivityAttributes {
|
||||||
|
public struct ContentState: Codable, Hashable {
|
||||||
|
var isBreak: Bool
|
||||||
|
var lessonName: String
|
||||||
|
var lessonTheme: String?
|
||||||
|
var roomName: String?
|
||||||
|
var teacherName: String?
|
||||||
|
var startTime: Date
|
||||||
|
var endTime: Date
|
||||||
|
var lessonNumber: Int?
|
||||||
|
|
||||||
|
var mode: String? // "lesson" | "break" | "seasonalBreak" | "xmas" | "newYearEve" | "newYearDay"
|
||||||
|
var message: String?
|
||||||
|
var season: String?
|
||||||
|
|
||||||
|
var nextLessonName: String?
|
||||||
|
var nextRoomName: String?
|
||||||
|
var nextStartTime: Date?
|
||||||
|
|
||||||
|
var isSubstitution: Bool
|
||||||
|
var isCancelled: Bool
|
||||||
|
var substituteTeacher: String?
|
||||||
|
|
||||||
|
var currentTime: Date
|
||||||
|
|
||||||
|
var labels: Labels?
|
||||||
|
var tokenExpirationWarning: String?
|
||||||
|
var tokenExpired: Bool?
|
||||||
|
var compactTimerText: String?
|
||||||
|
var lessonIcon: String?
|
||||||
|
|
||||||
|
struct Labels: Codable, Hashable {
|
||||||
|
var title: String?
|
||||||
|
var timerLabel: String?
|
||||||
|
var cancelledText: String?
|
||||||
|
var substitutionText: String?
|
||||||
|
var roomLabel: String?
|
||||||
|
var teacherLabel: String?
|
||||||
|
var themeLabel: String?
|
||||||
|
var nextLabel: String?
|
||||||
|
var firstLessonLabel: String?
|
||||||
|
var startTimeLabel: String?
|
||||||
|
var lessonNumberLabel: String?
|
||||||
|
var nextRoomLabel: String?
|
||||||
|
var remainingLabel: String?
|
||||||
|
}
|
||||||
|
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case isBreak
|
||||||
|
case lessonName
|
||||||
|
case lessonTheme
|
||||||
|
case roomName
|
||||||
|
case teacherName
|
||||||
|
case startTime
|
||||||
|
case endTime
|
||||||
|
case lessonNumber
|
||||||
|
case mode
|
||||||
|
case message
|
||||||
|
case season
|
||||||
|
case nextLessonName
|
||||||
|
case nextRoomName
|
||||||
|
case nextStartTime
|
||||||
|
case isSubstitution
|
||||||
|
case isCancelled
|
||||||
|
case substituteTeacher
|
||||||
|
case currentTime
|
||||||
|
case labels
|
||||||
|
case tokenExpirationWarning
|
||||||
|
case tokenExpired
|
||||||
|
case compactTimerText
|
||||||
|
case lessonIcon
|
||||||
|
}
|
||||||
|
|
||||||
|
init(isBreak: Bool, lessonName: String, lessonTheme: String?, roomName: String?, teacherName: String?, startTime: Date, endTime: Date, lessonNumber: Int?, mode: String?, message: String?, season: String?, nextLessonName: String?, nextRoomName: String?, nextStartTime: Date?, isSubstitution: Bool, isCancelled: Bool, substituteTeacher: String?, currentTime: Date, labels: Labels? = nil, tokenExpirationWarning: String? = nil, tokenExpired: Bool? = nil, compactTimerText: String? = nil, lessonIcon: String? = nil) {
|
||||||
|
self.isBreak = isBreak
|
||||||
|
self.lessonName = lessonName
|
||||||
|
self.lessonTheme = lessonTheme
|
||||||
|
self.roomName = roomName
|
||||||
|
self.teacherName = teacherName
|
||||||
|
self.startTime = startTime
|
||||||
|
self.endTime = endTime
|
||||||
|
self.lessonNumber = lessonNumber
|
||||||
|
self.mode = mode
|
||||||
|
self.message = message
|
||||||
|
self.season = season
|
||||||
|
self.nextLessonName = nextLessonName
|
||||||
|
self.nextRoomName = nextRoomName
|
||||||
|
self.nextStartTime = nextStartTime
|
||||||
|
self.isSubstitution = isSubstitution
|
||||||
|
self.isCancelled = isCancelled
|
||||||
|
self.substituteTeacher = substituteTeacher
|
||||||
|
self.currentTime = currentTime
|
||||||
|
self.labels = labels
|
||||||
|
self.tokenExpirationWarning = tokenExpirationWarning
|
||||||
|
self.tokenExpired = tokenExpired
|
||||||
|
self.compactTimerText = compactTimerText
|
||||||
|
self.lessonIcon = lessonIcon
|
||||||
|
}
|
||||||
|
|
||||||
|
init(from decoder: Decoder) throws {
|
||||||
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
|
||||||
|
let isoFormatter = ISO8601DateFormatter()
|
||||||
|
isoFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
||||||
|
|
||||||
|
isBreak = try container.decode(Bool.self, forKey: .isBreak)
|
||||||
|
lessonName = try container.decode(String.self, forKey: .lessonName)
|
||||||
|
lessonTheme = try container.decodeIfPresent(String.self, forKey: .lessonTheme)
|
||||||
|
roomName = try container.decodeIfPresent(String.self, forKey: .roomName)
|
||||||
|
teacherName = try container.decodeIfPresent(String.self, forKey: .teacherName)
|
||||||
|
|
||||||
|
let startTimeStr = try container.decode(String.self, forKey: .startTime)
|
||||||
|
guard let startTimeDate = isoFormatter.date(from: startTimeStr) else {
|
||||||
|
throw DecodingError.dataCorruptedError(forKey: .startTime, in: container, debugDescription: "Invalid startTime format: \(startTimeStr)")
|
||||||
|
}
|
||||||
|
startTime = startTimeDate
|
||||||
|
|
||||||
|
let endTimeStr = try container.decode(String.self, forKey: .endTime)
|
||||||
|
guard let endTimeDate = isoFormatter.date(from: endTimeStr) else {
|
||||||
|
throw DecodingError.dataCorruptedError(forKey: .endTime, in: container, debugDescription: "Invalid endTime format: \(endTimeStr)")
|
||||||
|
}
|
||||||
|
endTime = endTimeDate
|
||||||
|
|
||||||
|
lessonNumber = try container.decodeIfPresent(Int.self, forKey: .lessonNumber)
|
||||||
|
mode = try container.decodeIfPresent(String.self, forKey: .mode)
|
||||||
|
message = try container.decodeIfPresent(String.self, forKey: .message)
|
||||||
|
season = try container.decodeIfPresent(String.self, forKey: .season)
|
||||||
|
nextLessonName = try container.decodeIfPresent(String.self, forKey: .nextLessonName)
|
||||||
|
nextRoomName = try container.decodeIfPresent(String.self, forKey: .nextRoomName)
|
||||||
|
|
||||||
|
if let nextStartTimeStr = try container.decodeIfPresent(String.self, forKey: .nextStartTime) {
|
||||||
|
nextStartTime = isoFormatter.date(from: nextStartTimeStr)
|
||||||
|
} else {
|
||||||
|
nextStartTime = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
isSubstitution = try container.decode(Bool.self, forKey: .isSubstitution)
|
||||||
|
isCancelled = try container.decode(Bool.self, forKey: .isCancelled)
|
||||||
|
substituteTeacher = try container.decodeIfPresent(String.self, forKey: .substituteTeacher)
|
||||||
|
labels = try container.decodeIfPresent(Labels.self, forKey: .labels)
|
||||||
|
tokenExpirationWarning = try container.decodeIfPresent(String.self, forKey: .tokenExpirationWarning)
|
||||||
|
tokenExpired = try container.decodeIfPresent(Bool.self, forKey: .tokenExpired)
|
||||||
|
compactTimerText = try container.decodeIfPresent(String.self, forKey: .compactTimerText)
|
||||||
|
lessonIcon = try container.decodeIfPresent(String.self, forKey: .lessonIcon)
|
||||||
|
|
||||||
|
let currentTimeStr = try container.decode(String.self, forKey: .currentTime)
|
||||||
|
guard let currentTimeDate = isoFormatter.date(from: currentTimeStr) else {
|
||||||
|
throw DecodingError.dataCorruptedError(forKey: .currentTime, in: container, debugDescription: "Invalid currentTime format: \(currentTimeStr)")
|
||||||
|
}
|
||||||
|
currentTime = currentTimeDate
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode(to encoder: Encoder) throws {
|
||||||
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
|
||||||
|
let isoFormatter = ISO8601DateFormatter()
|
||||||
|
isoFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
||||||
|
|
||||||
|
try container.encode(isBreak, forKey: .isBreak)
|
||||||
|
try container.encode(lessonName, forKey: .lessonName)
|
||||||
|
try container.encodeIfPresent(lessonTheme, forKey: .lessonTheme)
|
||||||
|
try container.encodeIfPresent(roomName, forKey: .roomName)
|
||||||
|
try container.encodeIfPresent(teacherName, forKey: .teacherName)
|
||||||
|
|
||||||
|
try container.encode(isoFormatter.string(from: startTime), forKey: .startTime)
|
||||||
|
try container.encode(isoFormatter.string(from: endTime), forKey: .endTime)
|
||||||
|
|
||||||
|
try container.encodeIfPresent(lessonNumber, forKey: .lessonNumber)
|
||||||
|
try container.encodeIfPresent(mode, forKey: .mode)
|
||||||
|
try container.encodeIfPresent(message, forKey: .message)
|
||||||
|
try container.encodeIfPresent(season, forKey: .season)
|
||||||
|
try container.encodeIfPresent(nextLessonName, forKey: .nextLessonName)
|
||||||
|
try container.encodeIfPresent(nextRoomName, forKey: .nextRoomName)
|
||||||
|
|
||||||
|
if let nextStartTime = nextStartTime {
|
||||||
|
try container.encode(isoFormatter.string(from: nextStartTime), forKey: .nextStartTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
try container.encode(isSubstitution, forKey: .isSubstitution)
|
||||||
|
try container.encode(isCancelled, forKey: .isCancelled)
|
||||||
|
try container.encodeIfPresent(substituteTeacher, forKey: .substituteTeacher)
|
||||||
|
try container.encodeIfPresent(labels, forKey: .labels)
|
||||||
|
try container.encodeIfPresent(tokenExpirationWarning, forKey: .tokenExpirationWarning)
|
||||||
|
try container.encodeIfPresent(tokenExpired, forKey: .tokenExpired)
|
||||||
|
try container.encodeIfPresent(compactTimerText, forKey: .compactTimerText)
|
||||||
|
try container.encodeIfPresent(lessonIcon, forKey: .lessonIcon)
|
||||||
|
|
||||||
|
try container.encode(isoFormatter.string(from: currentTime), forKey: .currentTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var studentName: String
|
||||||
|
var schoolName: String
|
||||||
|
}
|
||||||
|
|
||||||
|
extension TimetableActivityAttributes.ContentState {
|
||||||
|
var timeRemaining: TimeInterval {
|
||||||
|
return endTime.timeIntervalSince(currentTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
var isBeforeSchool: Bool {
|
||||||
|
return currentTime < startTime && !isBreak
|
||||||
|
}
|
||||||
|
|
||||||
|
var formattedStartTime: String {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "HH:mm"
|
||||||
|
formatter.timeZone = TimeZone(identifier: "Europe/Budapest")
|
||||||
|
return formatter.string(from: startTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
var formattedEndTime: String {
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "HH:mm"
|
||||||
|
formatter.timeZone = TimeZone(identifier: "Europe/Budapest")
|
||||||
|
return formatter.string(from: endTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
var formattedNextStartTime: String {
|
||||||
|
guard let nextStartTime = nextStartTime else { return "" }
|
||||||
|
let formatter = DateFormatter()
|
||||||
|
formatter.dateFormat = "HH:mm"
|
||||||
|
formatter.timeZone = TimeZone(identifier: "Europe/Budapest")
|
||||||
|
return formatter.string(from: nextStartTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
var timeRemainingText: String {
|
||||||
|
let remaining = timeRemaining
|
||||||
|
|
||||||
|
if remaining < 0 {
|
||||||
|
return "0:00"
|
||||||
|
}
|
||||||
|
|
||||||
|
let hours = Int(remaining) / 3600
|
||||||
|
let minutes = (Int(remaining) % 3600) / 60
|
||||||
|
let seconds = Int(remaining) % 60
|
||||||
|
|
||||||
|
if hours > 0 {
|
||||||
|
return String(format: "%d:%02d:%02d", hours, minutes, seconds)
|
||||||
|
} else if minutes > 0 {
|
||||||
|
return String(format: "%d:%02d", minutes, seconds)
|
||||||
|
} else {
|
||||||
|
return String(format: "0:%02d", seconds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var seasonalRemainingText: String {
|
||||||
|
if let remainingLabel = labels?.remainingLabel, let message = message, !message.isEmpty {
|
||||||
|
return "\(remainingLabel): \(message)"
|
||||||
|
}
|
||||||
|
|
||||||
|
let remaining = max(0, timeRemaining)
|
||||||
|
let hours = Int(remaining) / 3600
|
||||||
|
if hours >= 24 {
|
||||||
|
let days = hours / 24
|
||||||
|
return "Szünetből hátralévő idő: \(days) nap"
|
||||||
|
}
|
||||||
|
return "Szünetből hátralévő idő: \(hours) óra"
|
||||||
|
}
|
||||||
|
|
||||||
|
var seasonalDisplayValue: String {
|
||||||
|
if let message = message, !message.isEmpty {
|
||||||
|
return message
|
||||||
|
}
|
||||||
|
|
||||||
|
let remaining = max(0, timeRemaining)
|
||||||
|
let hours = Int(remaining) / 3600
|
||||||
|
if hours >= 24 {
|
||||||
|
let days = hours / 24
|
||||||
|
return "\(days) nap"
|
||||||
|
}
|
||||||
|
return "\(hours) óra"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension TimetableActivityAttributes.ContentState {
|
||||||
|
func toJSON() -> [String: Any] {
|
||||||
|
var json: [String: Any] = [
|
||||||
|
"isBreak": isBreak,
|
||||||
|
"lessonName": lessonName,
|
||||||
|
"startTime": ISO8601DateFormatter().string(from: startTime),
|
||||||
|
"endTime": ISO8601DateFormatter().string(from: endTime),
|
||||||
|
"isSubstitution": isSubstitution,
|
||||||
|
"isCancelled": isCancelled,
|
||||||
|
"currentTime": ISO8601DateFormatter().string(from: currentTime)
|
||||||
|
]
|
||||||
|
|
||||||
|
if let lessonTheme = lessonTheme {
|
||||||
|
json["lessonTheme"] = lessonTheme
|
||||||
|
}
|
||||||
|
if let roomName = roomName {
|
||||||
|
json["roomName"] = roomName
|
||||||
|
}
|
||||||
|
if let teacherName = teacherName {
|
||||||
|
json["teacherName"] = teacherName
|
||||||
|
}
|
||||||
|
if let lessonNumber = lessonNumber {
|
||||||
|
json["lessonNumber"] = lessonNumber
|
||||||
|
}
|
||||||
|
if let nextLessonName = nextLessonName {
|
||||||
|
json["nextLessonName"] = nextLessonName
|
||||||
|
}
|
||||||
|
if let nextRoomName = nextRoomName {
|
||||||
|
json["nextRoomName"] = nextRoomName
|
||||||
|
}
|
||||||
|
if let nextStartTime = nextStartTime {
|
||||||
|
json["nextStartTime"] = ISO8601DateFormatter().string(from: nextStartTime)
|
||||||
|
}
|
||||||
|
if let substituteTeacher = substituteTeacher {
|
||||||
|
json["substituteTeacher"] = substituteTeacher
|
||||||
|
}
|
||||||
|
if let mode = mode {
|
||||||
|
json["mode"] = mode
|
||||||
|
}
|
||||||
|
if let message = message {
|
||||||
|
json["message"] = message
|
||||||
|
}
|
||||||
|
if let season = season {
|
||||||
|
json["season"] = season
|
||||||
|
}
|
||||||
|
if let tokenExpirationWarning = tokenExpirationWarning {
|
||||||
|
json["tokenExpirationWarning"] = tokenExpirationWarning
|
||||||
|
}
|
||||||
|
if let tokenExpired = tokenExpired {
|
||||||
|
json["tokenExpired"] = tokenExpired
|
||||||
|
}
|
||||||
|
if let compactTimerText = compactTimerText {
|
||||||
|
json["compactTimerText"] = compactTimerText
|
||||||
|
}
|
||||||
|
if let lessonIcon = lessonIcon {
|
||||||
|
json["lessonIcon"] = lessonIcon
|
||||||
|
}
|
||||||
|
|
||||||
|
return json
|
||||||
|
}
|
||||||
|
|
||||||
|
static func fromJSON(_ json: [String: Any]) -> TimetableActivityAttributes.ContentState? {
|
||||||
|
let isoFormatter = ISO8601DateFormatter()
|
||||||
|
isoFormatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
|
||||||
|
|
||||||
|
guard let isBreak = json["isBreak"] as? Bool,
|
||||||
|
let lessonName = json["lessonName"] as? String,
|
||||||
|
let startTimeStr = json["startTime"] as? String,
|
||||||
|
let endTimeStr = json["endTime"] as? String,
|
||||||
|
let isSubstitution = json["isSubstitution"] as? Bool,
|
||||||
|
let isCancelled = json["isCancelled"] as? Bool,
|
||||||
|
let startTime = isoFormatter.date(from: startTimeStr),
|
||||||
|
let endTime = isoFormatter.date(from: endTimeStr) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentTimeStr = json["currentTime"] as? String
|
||||||
|
let currentTime = currentTimeStr.flatMap { isoFormatter.date(from: $0) } ?? Date()
|
||||||
|
|
||||||
|
let nextStartTime: Date?
|
||||||
|
if let nextStartTimeStr = json["nextStartTime"] as? String {
|
||||||
|
nextStartTime = isoFormatter.date(from: nextStartTimeStr)
|
||||||
|
} else {
|
||||||
|
nextStartTime = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let labels: Labels?
|
||||||
|
if let labelsDict = json["labels"] as? [String: Any] {
|
||||||
|
labels = Labels(
|
||||||
|
title: labelsDict["title"] as? String,
|
||||||
|
timerLabel: labelsDict["timerLabel"] as? String,
|
||||||
|
cancelledText: labelsDict["cancelledText"] as? String,
|
||||||
|
substitutionText: labelsDict["substitutionText"] as? String,
|
||||||
|
roomLabel: labelsDict["roomLabel"] as? String,
|
||||||
|
teacherLabel: labelsDict["teacherLabel"] as? String,
|
||||||
|
themeLabel: labelsDict["themeLabel"] as? String,
|
||||||
|
nextLabel: labelsDict["nextLabel"] as? String,
|
||||||
|
firstLessonLabel: labelsDict["firstLessonLabel"] as? String,
|
||||||
|
startTimeLabel: labelsDict["startTimeLabel"] as? String,
|
||||||
|
lessonNumberLabel: labelsDict["lessonNumberLabel"] as? String,
|
||||||
|
nextRoomLabel: labelsDict["nextRoomLabel"] as? String,
|
||||||
|
remainingLabel: labelsDict["remainingLabel"] as? String
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
labels = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return TimetableActivityAttributes.ContentState(
|
||||||
|
isBreak: isBreak,
|
||||||
|
lessonName: lessonName,
|
||||||
|
lessonTheme: json["lessonTheme"] as? String,
|
||||||
|
roomName: json["roomName"] as? String,
|
||||||
|
teacherName: json["teacherName"] as? String,
|
||||||
|
startTime: startTime,
|
||||||
|
endTime: endTime,
|
||||||
|
lessonNumber: json["lessonNumber"] as? Int,
|
||||||
|
mode: json["mode"] as? String,
|
||||||
|
message: json["message"] as? String,
|
||||||
|
season: json["season"] as? String,
|
||||||
|
nextLessonName: json["nextLessonName"] as? String,
|
||||||
|
nextRoomName: json["nextRoomName"] as? String,
|
||||||
|
nextStartTime: nextStartTime,
|
||||||
|
isSubstitution: isSubstitution,
|
||||||
|
isCancelled: isCancelled,
|
||||||
|
substituteTeacher: json["substituteTeacher"] as? String,
|
||||||
|
currentTime: currentTime,
|
||||||
|
labels: labels,
|
||||||
|
tokenExpirationWarning: json["tokenExpirationWarning"] as? String,
|
||||||
|
tokenExpired: json["tokenExpired"] as? Bool,
|
||||||
|
compactTimerText: json["compactTimerText"] as? String,
|
||||||
|
lessonIcon: json["lessonIcon"] as? String
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
18
firka/ios/LiveActivityWidget/ActivityWidgetBundle.swift
Normal file
18
firka/ios/LiveActivityWidget/ActivityWidgetBundle.swift
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
@main
|
||||||
|
struct TimetableWidgetBundle: WidgetBundle {
|
||||||
|
var body: some Widget {
|
||||||
|
if #available(iOS 18.0, *) {
|
||||||
|
TimetableLiveActivity()
|
||||||
|
}
|
||||||
|
|
||||||
|
if #available(iOS 16.2, *),
|
||||||
|
!ProcessInfo.processInfo.isOperatingSystemAtLeast(
|
||||||
|
OperatingSystemVersion(majorVersion: 18, minorVersion: 0, patchVersion: 0)
|
||||||
|
) {
|
||||||
|
TimetableLiveActivityLegacy()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"colors" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"platform" : "ios",
|
||||||
|
"size" : "1024x1024"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"appearances" : [
|
||||||
|
{
|
||||||
|
"appearance" : "luminosity",
|
||||||
|
"value" : "dark"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"idiom" : "universal",
|
||||||
|
"platform" : "ios",
|
||||||
|
"size" : "1024x1024"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"appearances" : [
|
||||||
|
{
|
||||||
|
"appearance" : "luminosity",
|
||||||
|
"value" : "tinted"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"idiom" : "universal",
|
||||||
|
"platform" : "ios",
|
||||||
|
"size" : "1024x1024"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"colors" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"author" : "xcode",
|
||||||
|
"version" : 1
|
||||||
|
}
|
||||||
|
}
|
||||||
11
firka/ios/LiveActivityWidget/Info.plist
Normal file
11
firka/ios/LiveActivityWidget/Info.plist
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>NSExtension</key>
|
||||||
|
<dict>
|
||||||
|
<key>NSExtensionPointIdentifier</key>
|
||||||
|
<string>com.apple.widgetkit-extension</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
921
firka/ios/LiveActivityWidget/LiveActivity.swift
Normal file
921
firka/ios/LiveActivityWidget/LiveActivity.swift
Normal file
@@ -0,0 +1,921 @@
|
|||||||
|
import ActivityKit
|
||||||
|
import WidgetKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
@available(iOS 18.0, *)
|
||||||
|
struct TimetableLiveActivity: Widget {
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
TimetableLiveActivityLegacy.activityConfiguration
|
||||||
|
.supplementalActivityFamilies([.small])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 16.2, *)
|
||||||
|
struct TimetableLiveActivityLegacy: Widget {
|
||||||
|
var body: some WidgetConfiguration {
|
||||||
|
Self.activityConfiguration
|
||||||
|
}
|
||||||
|
|
||||||
|
static var activityConfiguration: ActivityConfiguration<TimetableActivityAttributes> {
|
||||||
|
ActivityConfiguration(for: TimetableActivityAttributes.self) { context in
|
||||||
|
// Lock screen/banner UI
|
||||||
|
TimetableLiveActivityAdaptiveView(context: context)
|
||||||
|
.activityBackgroundTint(Color(red: 0.1, green: 0.15, blue: 0.1))
|
||||||
|
.activitySystemActionForegroundColor(Color.white)
|
||||||
|
} dynamicIsland: { context in
|
||||||
|
let mode = context.state.mode ?? (context.state.isBreak ? "break" : "lesson")
|
||||||
|
let timeFormatter = DateFormatter()
|
||||||
|
timeFormatter.dateFormat = "HH:mm"
|
||||||
|
|
||||||
|
return DynamicIsland {
|
||||||
|
// Expanded UI
|
||||||
|
DynamicIslandExpandedRegion(.leading) {
|
||||||
|
EmptyView()
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicIslandExpandedRegion(.trailing) {
|
||||||
|
let beforeSchoolTime = mode == "beforeSchool" ? {
|
||||||
|
let adjustedDate = context.state.endTime
|
||||||
|
return timeFormatter.string(from: adjustedDate)
|
||||||
|
}() : nil
|
||||||
|
|
||||||
|
if SeasonalIconHelper.isSeasonalMode(mode) {
|
||||||
|
EmptyView()
|
||||||
|
} else if mode == "beforeSchool", let timeString = beforeSchoolTime {
|
||||||
|
Text("\(context.state.labels?.startTimeLabel ?? "Kezdés:") \(timeString)")
|
||||||
|
.font(.system(size: 14, weight: .medium))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
} else {
|
||||||
|
Text(context.state.formattedStartTime + " - " + context.state.formattedEndTime)
|
||||||
|
.font(.system(size: 14, weight: .medium))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicIslandExpandedRegion(.center) {
|
||||||
|
let season = context.state.season ?? ""
|
||||||
|
VStack(spacing: 4) {
|
||||||
|
if mode == "beforeSchool" {
|
||||||
|
HStack(alignment: .center, spacing: 6) {
|
||||||
|
Image(systemName: SeasonalIconHelper.iconName(for: mode, season: season, lessonIcon: context.state.lessonIcon))
|
||||||
|
.font(.system(size: 18))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
Text(context.state.labels?.title ?? "Hamarosan suli")
|
||||||
|
.font(.system(size: 18, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(context.state.labels?.firstLessonLabel ?? "Első órád:")
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text(context.state.lessonName)
|
||||||
|
.font(.system(size: 12, weight: .semibold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let roomName = context.state.roomName {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(context.state.labels?.roomLabel ?? "Terem:")
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text(roomName)
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let teacherName = context.state.teacherName {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(context.state.labels?.teacherLabel ?? "Tanár:")
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text(teacherName)
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if SeasonalIconHelper.isSeasonalMode(mode) {
|
||||||
|
if mode == "xmas" || mode == "newYearEve" || mode == "newYearDay" {
|
||||||
|
HStack(alignment: .center, spacing: 6) {
|
||||||
|
Image(systemName: SeasonalIconHelper.iconName(for: mode, season: season))
|
||||||
|
.font(.system(size: 18))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
Text(context.state.message ?? "Szünet")
|
||||||
|
.font(.system(size: 18, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.lineLimit(2)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
HStack(alignment: .center, spacing: 6) {
|
||||||
|
Image(systemName: SeasonalIconHelper.iconName(for: mode, season: season))
|
||||||
|
.font(.system(size: 18))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
Text(context.state.labels?.title ?? context.state.lessonName)
|
||||||
|
.font(.system(size: 18, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if context.state.isBreak {
|
||||||
|
HStack(alignment: .center, spacing: 6) {
|
||||||
|
Image(systemName: "cup.and.saucer.fill")
|
||||||
|
.font(.system(size: 18))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
Text(context.state.labels?.title ?? "Szünet")
|
||||||
|
.font(.system(size: 18, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let nextLessonName = context.state.nextLessonName {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(context.state.labels?.nextLabel ?? "Következő:")
|
||||||
|
.font(.system(size: 14))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text(nextLessonName)
|
||||||
|
.font(.system(size: 14, weight: .semibold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let nextRoomName = context.state.nextRoomName {
|
||||||
|
Text("\(context.state.labels?.roomLabel ?? "Terem:") \(nextRoomName)")
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
HStack(alignment: .center, spacing: 6) {
|
||||||
|
if let lessonNumber = context.state.lessonNumber {
|
||||||
|
Text("\(lessonNumber).")
|
||||||
|
.font(.system(size: 18, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
Text(context.state.lessonName)
|
||||||
|
.font(.system(size: 18, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !(context.state.isCancelled ?? false) {
|
||||||
|
if let lessonTheme = context.state.lessonTheme, !lessonTheme.isEmpty {
|
||||||
|
Text(lessonTheme)
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack(spacing: 8) {
|
||||||
|
if let roomName = context.state.roomName {
|
||||||
|
Label(roomName, systemImage: "door.left.hand.closed")
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
}
|
||||||
|
|
||||||
|
if context.state.isSubstitution ?? false {
|
||||||
|
Label(context.state.labels?.substitutionText ?? "Helyettesítés", systemImage: "arrow.triangle.2.circlepath")
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.orange)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DynamicIslandExpandedRegion(.bottom) {
|
||||||
|
let season = context.state.season ?? ""
|
||||||
|
VStack(spacing: 4) {
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
if mode == "xmas" || mode == "newYearDay" {
|
||||||
|
EmptyView()
|
||||||
|
} else if mode == "beforeSchool" {
|
||||||
|
if context.state.endTime > context.state.currentTime {
|
||||||
|
Text(timerInterval: context.state.currentTime...context.state.endTime, countsDown: true)
|
||||||
|
.font(.system(size: 24, weight: .bold, design: .rounded))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.monospacedDigit()
|
||||||
|
} else {
|
||||||
|
Text(context.state.formattedEndTime)
|
||||||
|
.font(.system(size: 24, weight: .bold, design: .rounded))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.monospacedDigit()
|
||||||
|
}
|
||||||
|
} else if mode == "seasonalBreak" {
|
||||||
|
Text(context.state.seasonalRemainingText)
|
||||||
|
.font(.system(size: 18, weight: .bold, design: .rounded))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.monospacedDigit()
|
||||||
|
} else if context.state.isCancelled ?? false {
|
||||||
|
Text(context.state.labels?.cancelledText ?? "Elmaradt")
|
||||||
|
.font(.system(size: 20, weight: .bold, design: .rounded))
|
||||||
|
.foregroundColor(.red)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
} else {
|
||||||
|
Text(timerInterval: context.state.currentTime...context.state.endTime, countsDown: true)
|
||||||
|
.font(.system(size: 24, weight: .bold, design: .rounded))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.monospacedDigit()
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Token expiration warning (only for specific modes)
|
||||||
|
let mode3 = context.state.mode ?? (context.state.isBreak ? "break" : "lesson")
|
||||||
|
let showWarningModes = ["newYearEve", "lesson", "break", "seasonalBreak"]
|
||||||
|
if let warning = context.state.tokenExpirationWarning, !warning.isEmpty, showWarningModes.contains(mode3) {
|
||||||
|
let isExpired = context.state.tokenExpired ?? false
|
||||||
|
let warningColor: Color = isExpired ? .red : .orange
|
||||||
|
let warningIcon = isExpired ? "exclamationmark.circle.fill" : "exclamationmark.triangle.fill"
|
||||||
|
|
||||||
|
HStack(spacing: 3) {
|
||||||
|
Image(systemName: warningIcon)
|
||||||
|
.font(.system(size: 8))
|
||||||
|
.foregroundColor(warningColor)
|
||||||
|
Text(warning)
|
||||||
|
.font(.system(size: 8, weight: .semibold))
|
||||||
|
.foregroundColor(warningColor)
|
||||||
|
.lineLimit(1)
|
||||||
|
.minimumScaleFactor(0.6)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} compactLeading: {
|
||||||
|
let season = context.state.season ?? ""
|
||||||
|
let iconName: String = {
|
||||||
|
if SeasonalIconHelper.isSeasonalMode(mode) || mode == "beforeSchool" {
|
||||||
|
return SeasonalIconHelper.iconName(for: mode, season: season, lessonIcon: context.state.lessonIcon)
|
||||||
|
} else {
|
||||||
|
return context.state.isBreak ? "cup.and.saucer.fill" : (context.state.lessonIcon ?? "book.fill")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
Image(systemName: iconName)
|
||||||
|
.font(.system(size: 14))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
} compactTrailing: {
|
||||||
|
let season = context.state.season ?? ""
|
||||||
|
if mode == "xmas" || mode == "newYearDay" {
|
||||||
|
Text("")
|
||||||
|
.frame(width: 50)
|
||||||
|
} else if context.state.isCancelled ?? false {
|
||||||
|
Text("❌")
|
||||||
|
.font(.system(size: 12, weight: .semibold))
|
||||||
|
.frame(width: 50)
|
||||||
|
} else if let compactText = context.state.compactTimerText {
|
||||||
|
Text(compactText)
|
||||||
|
.font(.system(size: 12, weight: .semibold, design: .rounded))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
.frame(width: 50)
|
||||||
|
} else {
|
||||||
|
Text("")
|
||||||
|
.frame(width: 50)
|
||||||
|
}
|
||||||
|
} minimal: {
|
||||||
|
let season = context.state.season ?? ""
|
||||||
|
let iconName: String = {
|
||||||
|
if SeasonalIconHelper.isSeasonalMode(mode) || mode == "beforeSchool" {
|
||||||
|
return SeasonalIconHelper.iconName(for: mode, season: season, lessonIcon: context.state.lessonIcon)
|
||||||
|
} else {
|
||||||
|
return context.state.isBreak ? "cup.and.saucer.fill" : (context.state.lessonIcon ?? "book.fill")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
Image(systemName: iconName)
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 16.2, *)
|
||||||
|
struct TimetableLiveActivityAdaptiveView: View {
|
||||||
|
let context: ActivityViewContext<TimetableActivityAttributes>
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if #available(iOS 18.0, *) {
|
||||||
|
TimetableLiveActivityFamilyView(context: context)
|
||||||
|
} else {
|
||||||
|
TimetableLiveActivityView(context: context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 18.0, *)
|
||||||
|
struct TimetableLiveActivityFamilyView: View {
|
||||||
|
@Environment(\.activityFamily) private var activityFamily
|
||||||
|
let context: ActivityViewContext<TimetableActivityAttributes>
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
switch activityFamily {
|
||||||
|
case .small:
|
||||||
|
SmallActivityView(context: context)
|
||||||
|
case .medium:
|
||||||
|
TimetableLiveActivityView(context: context)
|
||||||
|
@unknown default:
|
||||||
|
TimetableLiveActivityView(context: context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Lock Screen View
|
||||||
|
@available(iOS 16.2, *)
|
||||||
|
struct TimetableLiveActivityView: View {
|
||||||
|
let context: ActivityViewContext<TimetableActivityAttributes>
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
let mode = context.state.mode ?? (context.state.isBreak ? "break" : "lesson")
|
||||||
|
VStack(spacing: 12) {
|
||||||
|
let season = context.state.season ?? ""
|
||||||
|
let screenTimeFormatter = DateFormatter()
|
||||||
|
let _ = { screenTimeFormatter.dateFormat = "HH:mm" }()
|
||||||
|
|
||||||
|
let beforeSchoolTime: String? = mode == "beforeSchool" ? {
|
||||||
|
let adjustedDate = context.state.endTime
|
||||||
|
return screenTimeFormatter.string(from: adjustedDate)
|
||||||
|
}() : nil
|
||||||
|
let iconName: String = {
|
||||||
|
if SeasonalIconHelper.isSeasonalMode(mode) || mode == "beforeSchool" {
|
||||||
|
return SeasonalIconHelper.iconName(for: mode, season: season, lessonIcon: context.state.lessonIcon)
|
||||||
|
} else {
|
||||||
|
return context.state.isBreak ? "cup.and.saucer.fill" : (context.state.lessonIcon ?? "book.fill")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Header
|
||||||
|
HStack {
|
||||||
|
Image(systemName: iconName)
|
||||||
|
.font(.system(size: 24))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
if mode == "beforeSchool" {
|
||||||
|
Text(context.state.labels?.title ?? "Hamarosan suli")
|
||||||
|
.font(.system(size: 20, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
} else if SeasonalIconHelper.isSeasonalMode(mode) {
|
||||||
|
if mode == "xmas" || mode == "newYearEve" || mode == "newYearDay" {
|
||||||
|
Text(context.state.message ?? context.state.lessonName)
|
||||||
|
.font(.system(size: 20, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.lineLimit(2)
|
||||||
|
} else {
|
||||||
|
Text(context.state.labels?.title ?? context.state.lessonName)
|
||||||
|
.font(.system(size: 20, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
} else if context.state.isBreak {
|
||||||
|
Text(context.state.labels?.title ?? "Szünet")
|
||||||
|
.font(.system(size: 20, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
if let nextLessonName = context.state.nextLessonName {
|
||||||
|
Text("\(context.state.labels?.nextLabel ?? "Következő:") \(nextLessonName)")
|
||||||
|
.font(.system(size: 14))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let lessonNumber = context.state.lessonNumber {
|
||||||
|
Text("\(lessonNumber)\(context.state.labels?.lessonNumberLabel ?? ". óra")")
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
}
|
||||||
|
Text(context.state.lessonName)
|
||||||
|
.font(.system(size: 20, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
VStack(alignment: .trailing, spacing: 2) {
|
||||||
|
if SeasonalIconHelper.isSeasonalMode(mode) {
|
||||||
|
EmptyView()
|
||||||
|
} else if mode == "beforeSchool", let timeString = beforeSchoolTime {
|
||||||
|
Text("\(context.state.labels?.startTimeLabel ?? "Kezdés:") \(timeString)")
|
||||||
|
.font(.system(size: 14, weight: .medium))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
} else {
|
||||||
|
Text(context.state.formattedStartTime + " - " + context.state.formattedEndTime)
|
||||||
|
.font(.system(size: 14, weight: .medium))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
|
||||||
|
if SeasonalIconHelper.isSeasonalMode(mode) {
|
||||||
|
EmptyView()
|
||||||
|
} else if mode == "beforeSchool" {
|
||||||
|
EmptyView()
|
||||||
|
} else if context.state.isBreak {
|
||||||
|
if let _ = context.state.nextStartTime {
|
||||||
|
Text("\(context.state.labels?.startTimeLabel ?? "Kezdés:") \(context.state.formattedNextStartTime)")
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
} else {
|
||||||
|
EmptyView()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let roomName = context.state.roomName {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Image(systemName: "door.left.hand.closed")
|
||||||
|
.font(.system(size: 10))
|
||||||
|
Text(roomName)
|
||||||
|
.font(.system(size: 12))
|
||||||
|
}
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
} else {
|
||||||
|
EmptyView()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Content
|
||||||
|
let mode2 = context.state.mode ?? (context.state.isBreak ? "break" : "lesson")
|
||||||
|
if mode2 == "beforeSchool" {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(context.state.labels?.firstLessonLabel ?? "Első órád:")
|
||||||
|
.font(.system(size: 12, weight: .semibold))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text(context.state.lessonName)
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let roomName = context.state.roomName {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(context.state.labels?.roomLabel ?? "Terem:")
|
||||||
|
.font(.system(size: 12, weight: .semibold))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text(roomName)
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let teacherName = context.state.teacherName {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(context.state.labels?.teacherLabel ?? "Tanár:")
|
||||||
|
.font(.system(size: 12, weight: .semibold))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text(teacherName)
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else if SeasonalIconHelper.isSeasonalMode(mode2) {
|
||||||
|
EmptyView()
|
||||||
|
} else if !context.state.isBreak {
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
if !(context.state.isCancelled ?? false) {
|
||||||
|
if let lessonTheme = context.state.lessonTheme, !lessonTheme.isEmpty {
|
||||||
|
HStack {
|
||||||
|
Text(context.state.labels?.themeLabel ?? "Téma:")
|
||||||
|
.font(.system(size: 12, weight: .semibold))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text(lessonTheme)
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.lineLimit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if context.state.isSubstitution ?? false {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Image(systemName: "arrow.triangle.2.circlepath")
|
||||||
|
.font(.system(size: 12))
|
||||||
|
Text(context.state.labels?.substitutionText ?? "Helyettesítés")
|
||||||
|
.font(.system(size: 12, weight: .semibold))
|
||||||
|
if let substituteTeacher = context.state.substituteTeacher {
|
||||||
|
Text("(\(substituteTeacher))")
|
||||||
|
.font(.system(size: 12))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.foregroundColor(.orange)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else if let nextRoomName = context.state.nextRoomName {
|
||||||
|
HStack {
|
||||||
|
Image(systemName: "door.left.hand.closed")
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text("\(context.state.labels?.nextRoomLabel ?? "Következő terem:") \(nextRoomName)")
|
||||||
|
.font(.system(size: 12))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Countdown Timer
|
||||||
|
HStack {
|
||||||
|
Spacer()
|
||||||
|
VStack(spacing: 4) {
|
||||||
|
let mode3 = context.state.mode ?? (context.state.isBreak ? "break" : "lesson")
|
||||||
|
if mode3 == "xmas" || mode3 == "newYearDay" {
|
||||||
|
EmptyView()
|
||||||
|
} else if mode3 == "beforeSchool" {
|
||||||
|
Text(context.state.labels?.timerLabel ?? "Első óra kezdése")
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
|
||||||
|
if context.state.endTime > context.state.currentTime {
|
||||||
|
Text(timerInterval: context.state.currentTime...context.state.endTime, countsDown: true)
|
||||||
|
.font(.system(size: 32, weight: .bold, design: .rounded))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode3, season: season))
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.monospacedDigit()
|
||||||
|
} else {
|
||||||
|
Text(context.state.formattedEndTime)
|
||||||
|
.font(.system(size: 32, weight: .bold, design: .rounded))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode3, season: season))
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.monospacedDigit()
|
||||||
|
}
|
||||||
|
} else if mode3 == "seasonalBreak" {
|
||||||
|
Text(context.state.labels?.remainingLabel ?? "Szünetből hátralévő idő")
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text(context.state.seasonalDisplayValue)
|
||||||
|
.font(.system(size: 32, weight: .bold, design: .rounded))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode3, season: season))
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.monospacedDigit()
|
||||||
|
} else {
|
||||||
|
if context.state.isCancelled ?? false {
|
||||||
|
Text(context.state.labels?.cancelledText ?? "Elmaradt")
|
||||||
|
.font(.system(size: 32, weight: .bold, design: .rounded))
|
||||||
|
.foregroundColor(.red)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
} else {
|
||||||
|
let labelText: String = {
|
||||||
|
if mode3 == "newYearEve" {
|
||||||
|
return context.state.labels?.timerLabel ?? "Új év"
|
||||||
|
} else if mode3 == "beforeSchool" {
|
||||||
|
return context.state.labels?.timerLabel ?? "Első óra kezdése"
|
||||||
|
} else if context.state.isBreak {
|
||||||
|
return context.state.labels?.timerLabel ?? "Szünet vége"
|
||||||
|
} else {
|
||||||
|
return context.state.labels?.timerLabel ?? "Óra vége"
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
Text(labelText)
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(.gray)
|
||||||
|
Text(timerInterval: context.state.currentTime...context.state.endTime, countsDown: true)
|
||||||
|
.font(.system(size: 32, weight: .bold, design: .rounded))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode3, season: season))
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.monospacedDigit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Token expiration warning (only for specific modes)
|
||||||
|
let showWarningModes = ["newYearEve", "lesson", "break", "seasonalBreak"]
|
||||||
|
if let warning = context.state.tokenExpirationWarning, !warning.isEmpty, showWarningModes.contains(mode) {
|
||||||
|
let isExpired = context.state.tokenExpired ?? false
|
||||||
|
let warningColor: Color = isExpired ? .red : .orange
|
||||||
|
let warningIcon = isExpired ? "exclamationmark.circle.fill" : "exclamationmark.triangle.fill"
|
||||||
|
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Image(systemName: warningIcon)
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundColor(warningColor)
|
||||||
|
Text(warning)
|
||||||
|
.font(.system(size: 10, weight: .semibold))
|
||||||
|
.foregroundColor(warningColor)
|
||||||
|
.lineLimit(1)
|
||||||
|
.minimumScaleFactor(0.7)
|
||||||
|
}
|
||||||
|
.padding(.top, 2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(16)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@available(iOS 18.0, *)
|
||||||
|
struct SmallActivityView: View {
|
||||||
|
let context: ActivityViewContext<TimetableActivityAttributes>
|
||||||
|
|
||||||
|
private var mode: String {
|
||||||
|
context.state.mode ?? (context.state.isBreak ? "break" : "lesson")
|
||||||
|
}
|
||||||
|
|
||||||
|
private var season: String {
|
||||||
|
context.state.season ?? ""
|
||||||
|
}
|
||||||
|
|
||||||
|
private var titleText: String {
|
||||||
|
switch mode {
|
||||||
|
case "beforeSchool":
|
||||||
|
return firstNonEmpty([
|
||||||
|
trimmedOrNil(context.state.labels?.title),
|
||||||
|
trimmedOrNil(context.state.lessonName),
|
||||||
|
trimmedOrNil(context.state.message),
|
||||||
|
]) ?? ""
|
||||||
|
case "xmas", "newYearEve", "newYearDay":
|
||||||
|
return firstNonEmpty([
|
||||||
|
trimmedOrNil(context.state.message),
|
||||||
|
trimmedOrNil(context.state.lessonName),
|
||||||
|
trimmedOrNil(context.state.labels?.title),
|
||||||
|
]) ?? ""
|
||||||
|
case "seasonalBreak":
|
||||||
|
return firstNonEmpty([
|
||||||
|
trimmedOrNil(context.state.labels?.title),
|
||||||
|
trimmedOrNil(context.state.lessonName),
|
||||||
|
trimmedOrNil(context.state.message),
|
||||||
|
]) ?? ""
|
||||||
|
case "break":
|
||||||
|
return firstNonEmpty([
|
||||||
|
trimmedOrNil(context.state.labels?.title),
|
||||||
|
trimmedOrNil(context.state.message),
|
||||||
|
]) ?? ""
|
||||||
|
default:
|
||||||
|
return firstNonEmpty([
|
||||||
|
trimmedOrNil(context.state.lessonName),
|
||||||
|
trimmedOrNil(context.state.labels?.title),
|
||||||
|
trimmedOrNil(context.state.message),
|
||||||
|
]) ?? ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var iconName: String {
|
||||||
|
if SeasonalIconHelper.isSeasonalMode(mode) || mode == "beforeSchool" {
|
||||||
|
return SeasonalIconHelper.iconName(for: mode, season: season, lessonIcon: context.state.lessonIcon)
|
||||||
|
}
|
||||||
|
|
||||||
|
return context.state.isBreak ? "cup.and.saucer.fill" : (context.state.lessonIcon ?? "book.fill")
|
||||||
|
}
|
||||||
|
|
||||||
|
private var warningState: (text: String, color: Color, icon: String)? {
|
||||||
|
let showWarningModes = ["newYearEve", "lesson", "break", "seasonalBreak"]
|
||||||
|
guard showWarningModes.contains(mode),
|
||||||
|
let warningText = trimmedOrNil(context.state.tokenExpirationWarning) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let isExpired = context.state.tokenExpired ?? false
|
||||||
|
return (
|
||||||
|
text: warningText,
|
||||||
|
color: isExpired ? .red : .orange,
|
||||||
|
icon: isExpired ? "exclamationmark.circle.fill" : "exclamationmark.triangle.fill"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 3) {
|
||||||
|
HStack(spacing: 5) {
|
||||||
|
Image(systemName: iconName)
|
||||||
|
.font(.system(size: 14))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
|
||||||
|
if mode == "lesson", let lessonNumber = context.state.lessonNumber {
|
||||||
|
Text("\(lessonNumber). \(titleText)")
|
||||||
|
.font(.system(size: 12, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.lineLimit(1)
|
||||||
|
.minimumScaleFactor(0.65)
|
||||||
|
.truncationMode(.tail)
|
||||||
|
} else {
|
||||||
|
Text(titleText)
|
||||||
|
.font(.system(size: 12, weight: .bold))
|
||||||
|
.foregroundColor(.white)
|
||||||
|
.lineLimit(1)
|
||||||
|
.minimumScaleFactor(0.65)
|
||||||
|
.truncationMode(.tail)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
detailsSection
|
||||||
|
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
|
||||||
|
timerSection
|
||||||
|
|
||||||
|
if let warningState = warningState {
|
||||||
|
HStack(spacing: 3) {
|
||||||
|
Image(systemName: warningState.icon)
|
||||||
|
.font(.system(size: 8))
|
||||||
|
.foregroundColor(warningState.color)
|
||||||
|
|
||||||
|
Text(warningState.text)
|
||||||
|
.font(.system(size: 8, weight: .semibold))
|
||||||
|
.foregroundColor(warningState.color)
|
||||||
|
.lineLimit(1)
|
||||||
|
.minimumScaleFactor(0.55)
|
||||||
|
.truncationMode(.tail)
|
||||||
|
}
|
||||||
|
.padding(.top, 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(10)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private var detailsSection: some View {
|
||||||
|
switch mode {
|
||||||
|
case "beforeSchool":
|
||||||
|
labeledDetailLine(
|
||||||
|
label: context.state.labels?.firstLessonLabel,
|
||||||
|
value: context.state.lessonName,
|
||||||
|
color: .white,
|
||||||
|
weight: .semibold
|
||||||
|
)
|
||||||
|
labeledDetailLine(
|
||||||
|
label: context.state.labels?.teacherLabel,
|
||||||
|
value: context.state.teacherName,
|
||||||
|
color: .white,
|
||||||
|
weight: .semibold
|
||||||
|
)
|
||||||
|
labeledDetailLine(
|
||||||
|
label: context.state.labels?.roomLabel,
|
||||||
|
value: context.state.roomName,
|
||||||
|
color: .white,
|
||||||
|
weight: .semibold
|
||||||
|
)
|
||||||
|
|
||||||
|
case "lesson":
|
||||||
|
if context.state.isSubstitution ?? false {
|
||||||
|
if let substitution = trimmedOrNil(context.state.labels?.substitutionText) {
|
||||||
|
if let substituteTeacher = trimmedOrNil(context.state.substituteTeacher) {
|
||||||
|
detailLine("\(substitution) (\(substituteTeacher))", color: .orange)
|
||||||
|
} else {
|
||||||
|
detailLine(substitution, color: .orange)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case "break":
|
||||||
|
labeledDetailLine(
|
||||||
|
label: context.state.labels?.nextLabel,
|
||||||
|
value: context.state.nextLessonName,
|
||||||
|
color: .white,
|
||||||
|
weight: .semibold
|
||||||
|
)
|
||||||
|
labeledDetailLine(
|
||||||
|
label: context.state.labels?.roomLabel,
|
||||||
|
value: context.state.nextRoomName,
|
||||||
|
color: .white,
|
||||||
|
weight: .semibold
|
||||||
|
)
|
||||||
|
|
||||||
|
case "seasonalBreak":
|
||||||
|
if let remainingLabel = trimmedOrNil(context.state.labels?.remainingLabel) {
|
||||||
|
detailLine(remainingLabel)
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
EmptyView()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private var timerSection: some View {
|
||||||
|
switch mode {
|
||||||
|
case "xmas", "newYearDay":
|
||||||
|
EmptyView()
|
||||||
|
|
||||||
|
case "seasonalBreak":
|
||||||
|
if let remainingLabel = trimmedOrNil(context.state.labels?.remainingLabel) {
|
||||||
|
timerLabelLine(remainingLabel)
|
||||||
|
}
|
||||||
|
timerValueText(context.state.seasonalDisplayValue)
|
||||||
|
|
||||||
|
case "newYearEve", "beforeSchool":
|
||||||
|
if let timerLabel = trimmedOrNil(context.state.labels?.timerLabel) {
|
||||||
|
if mode == "beforeSchool" {
|
||||||
|
timerLabelLine(timerLabel, color: .white, weight: .semibold)
|
||||||
|
} else {
|
||||||
|
timerLabelLine(timerLabel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
countdownValueView()
|
||||||
|
|
||||||
|
case "lesson", "break", "loading":
|
||||||
|
if context.state.isCancelled ?? false {
|
||||||
|
if let cancelled = trimmedOrNil(context.state.labels?.cancelledText) {
|
||||||
|
timerValueText(cancelled, color: .red)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let timerLabel = trimmedOrNil(context.state.labels?.timerLabel) {
|
||||||
|
if mode == "lesson" || mode == "break" {
|
||||||
|
timerLabelLine(timerLabel, color: .white, weight: .semibold)
|
||||||
|
} else {
|
||||||
|
timerLabelLine(timerLabel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
countdownValueView()
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
countdownValueView()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func labeledDetailLine(
|
||||||
|
label: String?,
|
||||||
|
value: String?,
|
||||||
|
color: Color = .gray,
|
||||||
|
weight: Font.Weight = .regular
|
||||||
|
) -> some View {
|
||||||
|
if let text = joinedLabelValue(label: label, value: value) {
|
||||||
|
detailLine(text, color: color, weight: weight)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func countdownValueView() -> some View {
|
||||||
|
if context.state.endTime > context.state.currentTime {
|
||||||
|
Text(timerInterval: context.state.currentTime...context.state.endTime, countsDown: true)
|
||||||
|
.font(.system(size: 16, weight: .bold, design: .rounded))
|
||||||
|
.foregroundColor(SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
.monospacedDigit()
|
||||||
|
.lineLimit(1)
|
||||||
|
.minimumScaleFactor(0.75)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
} else {
|
||||||
|
timerValueText(context.state.formattedEndTime)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func detailLine(
|
||||||
|
_ text: String,
|
||||||
|
color: Color = .gray,
|
||||||
|
weight: Font.Weight = .regular
|
||||||
|
) -> some View {
|
||||||
|
Text(text)
|
||||||
|
.font(.system(size: 9, weight: weight))
|
||||||
|
.foregroundColor(color)
|
||||||
|
.lineLimit(1)
|
||||||
|
.minimumScaleFactor(0.6)
|
||||||
|
.truncationMode(.tail)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func timerLabelLine(
|
||||||
|
_ text: String,
|
||||||
|
color: Color = .gray,
|
||||||
|
weight: Font.Weight = .regular
|
||||||
|
) -> some View {
|
||||||
|
Text(text)
|
||||||
|
.font(.system(size: 8, weight: weight))
|
||||||
|
.foregroundColor(color)
|
||||||
|
.lineLimit(1)
|
||||||
|
.minimumScaleFactor(0.65)
|
||||||
|
.truncationMode(.tail)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func timerValueText(_ text: String, color: Color? = nil) -> some View {
|
||||||
|
Text(text)
|
||||||
|
.font(.system(size: 16, weight: .bold, design: .rounded))
|
||||||
|
.foregroundColor(color ?? SeasonalIconHelper.iconColor(for: mode, season: season))
|
||||||
|
.monospacedDigit()
|
||||||
|
.lineLimit(1)
|
||||||
|
.minimumScaleFactor(0.75)
|
||||||
|
.truncationMode(.tail)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func joinedLabelValue(label: String?, value: String?) -> String? {
|
||||||
|
guard let value = trimmedOrNil(value) else { return nil }
|
||||||
|
|
||||||
|
if let label = trimmedOrNil(label) {
|
||||||
|
return "\(label) \(value)"
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
private func firstNonEmpty(_ values: [String?]) -> String? {
|
||||||
|
for value in values {
|
||||||
|
if let value = value, !value.isEmpty {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func trimmedOrNil(_ value: String?) -> String? {
|
||||||
|
guard let value else { return nil }
|
||||||
|
let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
return trimmed.isEmpty ? nil : trimmed
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user