Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Parsing Errors of Locations in Calendar Event #302

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class CalendarWidgetService : RemoteViewsService() {
val widgetData = HomeWidgetPlugin.getData(applicationContext)
val data = widgetData.getString("calendar", null)
if (data != null) {
calendarEvents = Json.decodeFromString<Array<WidgetCalendarItem>>(data).asList()
val json = Json { ignoreUnknownKeys = true }
calendarEvents = json.decodeFromString<Array<WidgetCalendarItem>>(data).asList()
}

calendarEvents.filter { widgetCalendarItem ->
Expand Down Expand Up @@ -114,7 +115,11 @@ class CalendarWidgetService : RemoteViewsService() {
remoteViews.setTextViewText(R.id.calendar_widget_event_time, eventTime)

// Setup event location
remoteViews.setTextViewText(R.id.calendar_widget_event_location, currentItem.location)
if (currentItem.location?.isNotEmpty() == true) {
val locationText = currentItem.location.firstOrNull()
?: applicationContext.getString(R.string.unknown)
remoteViews.setTextViewText(R.id.calendar_widget_event_location, locationText)
}

// Setup action to open calendar
val fillInIntent = Intent().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ data class WidgetCalendarItem(
@Serializable(with = DateTimeSerializer::class)
@SerialName("dtend")
val endDate: LocalDateTime,
val location: String? = null,
val location: List<String>? = null,
val color: Long? = null,
val isVisible: Boolean? = null,
var isFirstOnDay: Boolean = false
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<string name="MINUTES">Minuten</string>
<string name="just_now">Gerade eben</string>
<string name="yesterday">Gestern</string>
<string name="unknown">Unbekannt</string>
<plurals name="yearsAgo">
<item quantity="one">Vor %d Jahr</item>
<item quantity="other">Vor %d Jahren</item>
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<string name="just_now">moments ago</string>
<string name="yesterday">Yesterday</string>
<string name="event_start_end_format_string" translatable="false">%1$s–%2$s</string>
<string name="unknown">Unknown</string>
<plurals name="yearsAgo">
<item quantity="one">%d year ago</item>
<item quantity="other">%d years ago</item>
Expand Down
2 changes: 1 addition & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version '8.7.2' apply false
id "com.android.application" version '8.7.3' apply false
id "org.jetbrains.kotlin.android" version "1.9.20" apply false
id "org.jetbrains.kotlin.plugin.serialization" version "2.0.21" apply false
id "com.google.gms.google-services" version "4.4.2" apply false
Expand Down
2 changes: 1 addition & 1 deletion ios/CalendarWidget/CalendarEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct CalendarEntry: Codable, Identifiable {
let status: String
let startDate: Date
let endDate: Date
let location: String?
let location: [String]
let color: Int?

enum CodingKeys: String, CodingKey {
Expand Down
17 changes: 9 additions & 8 deletions ios/CalendarWidget/CalendarEventView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ struct CalendarEventView: View {

let timeText = "\(timeFormatter.string(from: event.startDate)) - \(timeFormatter.string(from: event.endDate))"

if (event.location != nil) {
Text("\(timeText) | \(event.location!)")
.font(.caption2)
.lineLimit(1)
} else {
Text(timeText)
.font(.caption2)
.lineLimit(1)
Group {
if (event.location.isEmpty == false) {
let locationText = event.location.first ?? String(localized: "Unknown")
Text("\(timeText) | \(locationText)")
} else {
Text(timeText)
}
}
.font(.caption2)
.lineLimit(1)
}
.padding(6)
.widgetAccentable(false)
Expand Down
4 changes: 2 additions & 2 deletions ios/CalendarWidget/CalendarWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ struct Provider: TimelineProvider {
CalendarWidgetEntry(
date: Date(),
entries: [
CalendarEntry(id: "0", title: "Lineare Algebra für Informatik", status: "Test", startDate: Date.now, endDate: Date.now, location: "Galileo Audimax", color: nil),
CalendarEntry(id: "0", title: "Einführung in die Buchführung", status: "Test", startDate: Date.now, endDate: Date.now, location: "Audimax", color: nil)
CalendarEntry(id: "0", title: "Lineare Algebra für Informatik", status: "Test", startDate: Date.now, endDate: Date.now, location: ["Galileo Audimax"], color: nil),
CalendarEntry(id: "0", title: "Einführung in die Buchführung", status: "Test", startDate: Date.now, endDate: Date.now, location: ["Audimax"], color: nil)
],
size: context.family
)
Expand Down
10 changes: 10 additions & 0 deletions ios/Runner/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@
}
}
}
},
"Unknown" : {
"localizations" : {
"de" : {
"stringUnit" : {
"state" : "translated",
"value" : "Unbekannt"
}
}
}
}
},
"version" : "1.0"
Expand Down
2 changes: 1 addition & 1 deletion lib/base/util/read_list_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ List<dynamic> readListValue(Map<dynamic, dynamic> data, String key) {
final relevantData = data[key];
if (relevantData is List<dynamic>) {
return relevantData;
} else if (relevantData is Map<String, dynamic>) {
} else if (relevantData is Map<String, dynamic> || relevantData is String) {
return [relevantData];
} else {
return [];
Expand Down
2 changes: 1 addition & 1 deletion lib/calendarComponent/model/calendar_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CalendarEvent extends Searchable {
final DateTime startDate;
@JsonKey(name: "dtend")
final DateTime endDate;
@JsonKey(readValue: readListValue)
@JsonKey(name: "location", readValue: readListValue)
final List<String> locations;

int? color;
Expand Down
4 changes: 2 additions & 2 deletions lib/calendarComponent/model/calendar_event.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,10 @@ packages:
dependency: transitive
description:
name: io
sha256: "2ec25704aba361659e10e3e5f5d672068d332fc8ac516421d483a11e5cbd061e"
sha256: dfd5a80599cf0165756e3181807ed3e77daf6dd4137caaad72d0b7931597650b
url: "https://pub.dev"
source: hosted
version: "1.0.4"
version: "1.0.5"
js:
dependency: transitive
description:
Expand Down Expand Up @@ -1185,10 +1185,10 @@ packages:
dependency: transitive
description:
name: quick_actions_ios
sha256: "402596dea62a1028960b93f7651ec22be0e2a91e4fbf92a1c62d3b95f8ff95a5"
sha256: "837b7e6b5973784d3da56b8c959b446b215914f20405d88cd7d22a2fb94e4e4c"
url: "https://pub.dev"
source: hosted
version: "1.1.1"
version: "1.2.0"
quick_actions_platform_interface:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: campus_flutter
description: "TUM Campus App"
publish_to: 'none'
version: 5.1.2+1
version: 5.1.3+1

environment:
sdk: '>=3.2.3 <4.0.0'
Expand Down