Skip to content

Commit 83c1ce6

Browse files
authored
Fix Parsing Errors of Locations in Calendar Event (#302)
1 parent 8879717 commit 83c1ce6

File tree

14 files changed

+42
-24
lines changed

14 files changed

+42
-24
lines changed

android/app/src/main/kotlin/de/tum/in/tumcampus/widgets/calendar/CalendarWidgetService.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class CalendarWidgetService : RemoteViewsService() {
3232
val widgetData = HomeWidgetPlugin.getData(applicationContext)
3333
val data = widgetData.getString("calendar", null)
3434
if (data != null) {
35-
calendarEvents = Json.decodeFromString<Array<WidgetCalendarItem>>(data).asList()
35+
val json = Json { ignoreUnknownKeys = true }
36+
calendarEvents = json.decodeFromString<Array<WidgetCalendarItem>>(data).asList()
3637
}
3738

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

116117
// Setup event location
117-
remoteViews.setTextViewText(R.id.calendar_widget_event_location, currentItem.location)
118+
if (currentItem.location?.isNotEmpty() == true) {
119+
val locationText = currentItem.location.firstOrNull()
120+
?: applicationContext.getString(R.string.unknown)
121+
remoteViews.setTextViewText(R.id.calendar_widget_event_location, locationText)
122+
}
118123

119124
// Setup action to open calendar
120125
val fillInIntent = Intent().apply {

android/app/src/main/kotlin/de/tum/in/tumcampus/widgets/calendar/WidgetCalendarItem.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data class WidgetCalendarItem(
2323
@Serializable(with = DateTimeSerializer::class)
2424
@SerialName("dtend")
2525
val endDate: LocalDateTime,
26-
val location: String? = null,
26+
val location: List<String>? = null,
2727
val color: Long? = null,
2828
val isVisible: Boolean? = null,
2929
var isFirstOnDay: Boolean = false

android/app/src/main/res/values-de/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<string name="MINUTES">Minuten</string>
1212
<string name="just_now">Gerade eben</string>
1313
<string name="yesterday">Gestern</string>
14+
<string name="unknown">Unbekannt</string>
1415
<plurals name="yearsAgo">
1516
<item quantity="one">Vor %d Jahr</item>
1617
<item quantity="other">Vor %d Jahren</item>

android/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<string name="just_now">moments ago</string>
1313
<string name="yesterday">Yesterday</string>
1414
<string name="event_start_end_format_string" translatable="false">%1$s–%2$s</string>
15+
<string name="unknown">Unknown</string>
1516
<plurals name="yearsAgo">
1617
<item quantity="one">%d year ago</item>
1718
<item quantity="other">%d years ago</item>

android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pluginManagement {
1818

1919
plugins {
2020
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21-
id "com.android.application" version '8.7.2' apply false
21+
id "com.android.application" version '8.7.3' apply false
2222
id "org.jetbrains.kotlin.android" version "1.9.20" apply false
2323
id "org.jetbrains.kotlin.plugin.serialization" version "2.0.21" apply false
2424
id "com.google.gms.google-services" version "4.4.2" apply false

ios/CalendarWidget/CalendarEntry.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct CalendarEntry: Codable, Identifiable {
1414
let status: String
1515
let startDate: Date
1616
let endDate: Date
17-
let location: String?
17+
let location: [String]
1818
let color: Int?
1919

2020
enum CodingKeys: String, CodingKey {

ios/CalendarWidget/CalendarEventView.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,16 @@ struct CalendarEventView: View {
5151

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

54-
if (event.location != nil) {
55-
Text("\(timeText) | \(event.location!)")
56-
.font(.caption2)
57-
.lineLimit(1)
58-
} else {
59-
Text(timeText)
60-
.font(.caption2)
61-
.lineLimit(1)
54+
Group {
55+
if (event.location.isEmpty == false) {
56+
let locationText = event.location.first ?? String(localized: "Unknown")
57+
Text("\(timeText) | \(locationText)")
58+
} else {
59+
Text(timeText)
60+
}
6261
}
62+
.font(.caption2)
63+
.lineLimit(1)
6364
}
6465
.padding(6)
6566
.widgetAccentable(false)

ios/CalendarWidget/CalendarWidget.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ struct Provider: TimelineProvider {
1313
CalendarWidgetEntry(
1414
date: Date(),
1515
entries: [
16-
CalendarEntry(id: "0", title: "Lineare Algebra für Informatik", status: "Test", startDate: Date.now, endDate: Date.now, location: "Galileo Audimax", color: nil),
17-
CalendarEntry(id: "0", title: "Einführung in die Buchführung", status: "Test", startDate: Date.now, endDate: Date.now, location: "Audimax", color: nil)
16+
CalendarEntry(id: "0", title: "Lineare Algebra für Informatik", status: "Test", startDate: Date.now, endDate: Date.now, location: ["Galileo Audimax"], color: nil),
17+
CalendarEntry(id: "0", title: "Einführung in die Buchführung", status: "Test", startDate: Date.now, endDate: Date.now, location: ["Audimax"], color: nil)
1818
],
1919
size: context.family
2020
)

ios/Runner/Localizable.xcstrings

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@
100100
}
101101
}
102102
}
103+
},
104+
"Unknown" : {
105+
"localizations" : {
106+
"de" : {
107+
"stringUnit" : {
108+
"state" : "translated",
109+
"value" : "Unbekannt"
110+
}
111+
}
112+
}
103113
}
104114
},
105115
"version" : "1.0"

lib/base/util/read_list_value.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ List<dynamic> readListValue(Map<dynamic, dynamic> data, String key) {
22
final relevantData = data[key];
33
if (relevantData is List<dynamic>) {
44
return relevantData;
5-
} else if (relevantData is Map<String, dynamic>) {
5+
} else if (relevantData is Map<String, dynamic> || relevantData is String) {
66
return [relevantData];
77
} else {
88
return [];

0 commit comments

Comments
 (0)