Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 57c4c05

Browse files
authored
🐛 Fix buggy Mastodon error notifications (#318)
fixes #313
1 parent 5a1d4f6 commit 57c4c05

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

app/src/main/kotlin/de/hbch/traewelling/api/models/notifications/Notification.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,15 @@ enum class NotificationType {
287287
override val channel = NotificationChannelType.MastodonError
288288
override val category = android.app.Notification.CATEGORY_ERROR
289289
override fun getHeadline(context: Context, notification: Notification): String {
290+
return context.getString(R.string.mastodon_share_error)
291+
}
292+
override fun getBody(context: Context, notification: Notification): String {
290293
val obj = getData(notification)
291-
var headline = ""
294+
var body = ""
292295
if (obj != null) {
293-
headline = context.getString(R.string.status_not_shared_on_mastodon, obj.status.id)
296+
body = context.getString(R.string.status_not_shared_on_mastodon, obj.httpResponseCode)
294297
}
295-
return headline
298+
return body
296299
}
297300
override fun getOnClick(notification: Notification): (NavHostController) -> Unit {
298301
val data = getData(notification)
@@ -322,7 +325,7 @@ enum class NotificationType {
322325
private fun getData(notification: Notification): MastodonNotSentData? {
323326
val gson = Gson()
324327
val data = notification.data
325-
val targetType = object: TypeToken<UserFollowedData>() {}.type
328+
val targetType = object: TypeToken<MastodonNotSentData>() {}.type
326329
return gson.fromJson<Any>(gson.toJson(data), targetType) as? MastodonNotSentData
327330
}
328331
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<string name="travelling_with_from_to">Fahrt mit %1$s von %2$s nach %3$s</string>
161161
<string name="follow_request_approved">\@%1$s hat deine Folgeanfrage bestätigt!</string>
162162
<string name="follow_request_issued">\@%1$s möchte dir folgen!</string>
163+
<string name="mastodon_share_error">Fehler beim Posten auf Mastodon!</string>
163164
<string name="status_not_shared_on_mastodon">Dein Check-In wurde aufgrund von Fehler %1$d nicht auf Mastodon geteilt.</string>
164165
<string name="map_view">Kartenansicht</string>
165166
<string name="configure_map">Hier kannst du die Kartenansicht konfigurieren.</string>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
<string name="travelling_with_from_to">Ride with %1$s from %2$s to %3$s</string>
165165
<string name="follow_request_approved">\@%1$s approved your follow request!</string>
166166
<string name="follow_request_issued">\@%1$s would like to follow you!</string>
167+
<string name="mastodon_share_error">Error when sharing to Mastodon!</string>
167168
<string name="status_not_shared_on_mastodon">Your check-in wasn\'t shared to Mastodon due to error %1$d.</string>
168169
<string name="map_view">Map view</string>
169170
<string name="configure_map">Here you can configure the map view.</string>

0 commit comments

Comments
 (0)