Skip to content

Commit 6968216

Browse files
authored
Fixed notifications not following settings for item opening (#108)
* follow settings when opening in browser * use feed specific defaults * move variables
1 parent e876cbe commit 6968216

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

app/src/main/java/com/nononsenseapps/feeder/model/RssNotifications.kt

+32-13
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import androidx.core.content.ContextCompat
2323
import androidx.core.net.toUri
2424
import androidx.navigation.NavDeepLinkBuilder
2525
import com.nononsenseapps.feeder.R
26+
import com.nononsenseapps.feeder.archmodel.ItemOpener
27+
import com.nononsenseapps.feeder.archmodel.Repository
2628
import com.nononsenseapps.feeder.db.COL_LINK
2729
import com.nononsenseapps.feeder.db.URI_FEEDITEMS
2830
import com.nononsenseapps.feeder.db.room.FeedDao
@@ -123,7 +125,10 @@ private fun createNotificationChannel(context: Context) {
123125
notificationManager.createNotificationChannel(channel)
124126
}
125127

126-
private fun singleNotification(context: Context, item: FeedItemWithFeed): Notification {
128+
private suspend fun singleNotification(context: Context, item: FeedItemWithFeed): Notification {
129+
val di by closestDI(context)
130+
val repository: Repository by di.instance()
131+
127132
val style = NotificationCompat.BigTextStyle()
128133
val title = item.plainTitle
129134
val text = item.feedDisplayTitle
@@ -151,42 +156,56 @@ private fun singleNotification(context: Context, item: FeedItemWithFeed): Notifi
151156

152157
builder.setContentText(text)
153158
.setContentTitle(title)
154-
.setContentIntent(pendingIntent)
155159
.setGroup(articleNotificationGroup)
156160
.setGroupAlertBehavior(GROUP_ALERT_SUMMARY)
157161
.setDeleteIntent(getPendingDeleteIntent(context, item))
158162
.setNumber(1)
159163

160164
// Note that notifications must use PNG resources, because there is no compatibility for vector drawables here
161165

162-
item.enclosureLink?.let { enclosureLink ->
163-
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(enclosureLink))
164-
intent.putExtra(EXTRA_CREATE_NEW_TAB, true)
165-
builder.addAction(
166-
R.drawable.notification_play_circle_outline,
167-
context.getString(R.string.open_enclosed_media),
166+
if (repository.getArticleOpener(item.id) == ItemOpener.DEFAULT_BROWSER && item.link != null) {
167+
builder.setContentIntent(
168168
PendingIntent.getActivity(
169169
context,
170170
item.id.toInt(),
171-
getOpenInDefaultActivityIntent(context, item.id, enclosureLink),
171+
getOpenInDefaultActivityIntent(context, item.id, item.link),
172172
PendingIntent.FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE,
173173
),
174174
)
175+
} else {
176+
builder.setContentIntent(pendingIntent)
175177
}
176178

177-
item.link?.let { link ->
179+
item.enclosureLink?.let { enclosureLink ->
180+
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(enclosureLink))
181+
intent.putExtra(EXTRA_CREATE_NEW_TAB, true)
178182
builder.addAction(
179-
R.drawable.notification_open_in_browser,
180-
context.getString(R.string.open_link_in_browser),
183+
R.drawable.notification_play_circle_outline,
184+
context.getString(R.string.open_enclosed_media),
181185
PendingIntent.getActivity(
182186
context,
183187
item.id.toInt(),
184-
getOpenInDefaultActivityIntent(context, item.id, link),
188+
getOpenInDefaultActivityIntent(context, item.id, enclosureLink),
185189
PendingIntent.FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE,
186190
),
187191
)
188192
}
189193

194+
if (repository.getArticleOpener(item.id) != ItemOpener.DEFAULT_BROWSER) {
195+
item.link?.let { link ->
196+
builder.addAction(
197+
R.drawable.notification_open_in_browser,
198+
context.getString(R.string.open_link_in_browser),
199+
PendingIntent.getActivity(
200+
context,
201+
item.id.toInt(),
202+
getOpenInDefaultActivityIntent(context, item.id, link),
203+
PendingIntent.FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE,
204+
),
205+
)
206+
}
207+
}
208+
190209
builder.addAction(
191210
R.drawable.notification_check,
192211
context.getString(R.string.mark_as_read),

0 commit comments

Comments
 (0)