Skip to content

Commit

Permalink
✨ Support mention notifications (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
jheubuch authored Apr 3, 2024
1 parent 82d623f commit 169547f
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,49 @@ enum class NotificationType {
val targetType = object: TypeToken<MastodonNotSentData>() {}.type
return gson.fromJson<Any>(gson.toJson(data), targetType) as? MastodonNotSentData
}
},
UserMentioned {
override val icon = R.drawable.ic_user_mention
override val channel = NotificationChannelType.UserMentioned
override fun getHeadline(context: Context, notification: Notification): String {
val data = getData(notification)
var headline = ""
if (data != null) {
headline = context.getString(R.string.user_mentioned_you, data.creator.username)
}
return headline
}
override fun getOnClick(notification: Notification): (NavHostController) -> Unit {
val data = getData(notification)
var onClick: (NavHostController) -> Unit = { }
if (data != null) {
onClick = {
it.navigate("status-details/${data.status.id}")
}
}
return onClick
}
override fun getIntent(context: Context, notification: Notification): Intent? {
val data = getData(notification)
var intent: Intent? = null
if (data != null) {
intent = Intent(
Intent.ACTION_VIEW,
TraewelldroidUriBuilder()
.appendPath("status")
.appendPath(data.status.id.toString())
.build()
)
}
return intent
}

private fun getData(notification: Notification): UserMentionedData? {
val gson = Gson()
val data = notification.data
val targetType = object: TypeToken<UserMentionedData>() {}.type
return gson.fromJson<Any>(gson.toJson(data), targetType) as? UserMentionedData
}
};

abstract val icon: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ enum class NotificationChannelType {
override val importance = NotificationManager.IMPORTANCE_HIGH
override val title = R.string.channel_mastodon_errors
override val description = R.string.channel_description_mastodon_errors
},
UserMentioned {
override val importance = NotificationManager.IMPORTANCE_HIGH
override val title = R.string.channel_mentions
override val description = R.string.channel_description_mentions
};
abstract val title: Int
abstract val description: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,8 @@ data class MastodonNotSentData(
val status: NotificationStatus,
val httpResponseCode: Int
)

data class UserMentionedData(
val status: NotificationStatus,
val creator: NotificationUser
)
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_tag.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:tint="?attr/colorControlNormal" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M17.63,5.84C17.27,5.33 16.67,5 16,5L5,5.01C3.9,5.01 3,5.9 3,7v10c0,1.1 0.9,1.99 2,1.99L16,19c0.67,0 1.27,-0.33 1.63,-0.84L22,12l-4.37,-6.16z"/>
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/ic_taxi.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#000000"
<vector android:height="24dp" android:tint="?attr/colorControlNormal"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M18.92,6.01C18.72,5.42 18.16,5 17.5,5L15,5L15,3L9,3v2L6.5,5c-0.66,0 -1.21,0.42 -1.42,1.01L3,12v8c0,0.55 0.45,1 1,1h1c0.55,0 1,-0.45 1,-1v-1h12v1c0,0.55 0.45,1 1,1h1c0.55,0 1,-0.45 1,-1v-8l-2.08,-5.99zM6.5,16c-0.83,0 -1.5,-0.67 -1.5,-1.5S5.67,13 6.5,13s1.5,0.67 1.5,1.5S7.33,16 6.5,16zM17.5,16c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5 1.5,0.67 1.5,1.5 -0.67,1.5 -1.5,1.5zM5,11l1.5,-4.5h11L19,11L5,11z"/>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_user_mention.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="?attr/colorControlNormal" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10h5v-2h-5c-4.34,0 -8,-3.66 -8,-8s3.66,-8 8,-8 8,3.66 8,8v1.43c0,0.79 -0.71,1.57 -1.5,1.57s-1.5,-0.78 -1.5,-1.57L17,12c0,-2.76 -2.24,-5 -5,-5s-5,2.24 -5,5 2.24,5 5,5c1.38,0 2.64,-0.56 3.54,-1.47 0.65,0.89 1.77,1.47 2.96,1.47 1.97,0 3.5,-1.6 3.5,-3.57L22,12c0,-5.52 -4.48,-10 -10,-10zM12,15c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3z"/>

</vector>
3 changes: 3 additions & 0 deletions app/src/main/res/values-de-rDE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
<string name="follow_request_issued">\@%1$s möchte dir folgen!</string>
<string name="mastodon_share_error">Fehler beim Posten auf Mastodon!</string>
<string name="status_not_shared_on_mastodon">Dein Check-In wurde aufgrund von Fehler %1$d nicht auf Mastodon geteilt.</string>
<string name="user_mentioned_you">\@%1$s hat dich in einem Status erwähnt.</string>
<string name="map_view">Kartenansicht</string>
<string name="configure_map">Hier kannst du die Kartenansicht konfigurieren.</string>
<string name="standard_layer">Standard</string>
Expand Down Expand Up @@ -215,6 +216,8 @@
<string name="channel_description_event_suggestions">Bearbeitete Eventvorschläge</string>
<string name="channel_likes">Gefällt mir-Angaben</string>
<string name="channel_description_likes">Nutzer:innen, denen deine Check-Ins gefallen</string>
<string name="channel_mentions">Erwähnungen</string>
<string name="channel_description_mentions">Nutzer:innen, die dich in deren Check-Ins erwähnen</string>
<string name="select_up_distributor">Unified Push-Distributor wählen</string>
<string name="no_up_distributor_found">Es wurde kein Unified Push Distributor gefunden. Bitte installiere einen deiner Wahl und starte die App neu.</string>
<string name="selected_up_distributor">Gewählter UnifiedPush Distributor: %1$s</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
<string name="follow_request_issued">\@%1$s would like to follow you!</string>
<string name="mastodon_share_error">Error when sharing to Mastodon!</string>
<string name="status_not_shared_on_mastodon">Your check-in wasn\'t shared to Mastodon due to error %1$d.</string>
<string name="user_mentioned_you">\@%1$s mentioned you in their status.</string>
<string name="map_view">Map view</string>
<string name="configure_map">Here you can configure the map view.</string>
<string name="openrailwaymap" translatable="false">OpenRailwayMap</string>
Expand Down Expand Up @@ -220,6 +221,8 @@
<string name="channel_description_event_suggestions">Processed event suggestions</string>
<string name="channel_likes">Likes</string>
<string name="channel_description_likes">Users liking your check-ins</string>
<string name="channel_mentions">Mentions</string>
<string name="channel_description_mentions">Users mentioning you in their check-ins</string>
<string name="select_up_distributor">Select UnifiedPush distributor</string>
<string name="no_up_distributor_found">No UnifiedPush distributor was found. Please install one of your choice and restart the app.</string>
<string name="selected_up_distributor">Selected UnifiedPush distributor: %1$s</string>
Expand Down

0 comments on commit 169547f

Please sign in to comment.