Skip to content

Commit

Permalink
Fixed notifications not following settings for item opening (#108)
Browse files Browse the repository at this point in the history
* follow settings when opening in browser

* use feed specific defaults

* move variables
  • Loading branch information
derdilla authored Oct 23, 2023
1 parent e876cbe commit 6968216
Showing 1 changed file with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import androidx.core.content.ContextCompat
import androidx.core.net.toUri
import androidx.navigation.NavDeepLinkBuilder
import com.nononsenseapps.feeder.R
import com.nononsenseapps.feeder.archmodel.ItemOpener
import com.nononsenseapps.feeder.archmodel.Repository
import com.nononsenseapps.feeder.db.COL_LINK
import com.nononsenseapps.feeder.db.URI_FEEDITEMS
import com.nononsenseapps.feeder.db.room.FeedDao
Expand Down Expand Up @@ -123,7 +125,10 @@ private fun createNotificationChannel(context: Context) {
notificationManager.createNotificationChannel(channel)
}

private fun singleNotification(context: Context, item: FeedItemWithFeed): Notification {
private suspend fun singleNotification(context: Context, item: FeedItemWithFeed): Notification {
val di by closestDI(context)
val repository: Repository by di.instance()

val style = NotificationCompat.BigTextStyle()
val title = item.plainTitle
val text = item.feedDisplayTitle
Expand Down Expand Up @@ -151,42 +156,56 @@ private fun singleNotification(context: Context, item: FeedItemWithFeed): Notifi

builder.setContentText(text)
.setContentTitle(title)
.setContentIntent(pendingIntent)
.setGroup(articleNotificationGroup)
.setGroupAlertBehavior(GROUP_ALERT_SUMMARY)
.setDeleteIntent(getPendingDeleteIntent(context, item))
.setNumber(1)

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

item.enclosureLink?.let { enclosureLink ->
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(enclosureLink))
intent.putExtra(EXTRA_CREATE_NEW_TAB, true)
builder.addAction(
R.drawable.notification_play_circle_outline,
context.getString(R.string.open_enclosed_media),
if (repository.getArticleOpener(item.id) == ItemOpener.DEFAULT_BROWSER && item.link != null) {
builder.setContentIntent(
PendingIntent.getActivity(
context,
item.id.toInt(),
getOpenInDefaultActivityIntent(context, item.id, enclosureLink),
getOpenInDefaultActivityIntent(context, item.id, item.link),
PendingIntent.FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE,
),
)
} else {
builder.setContentIntent(pendingIntent)
}

item.link?.let { link ->
item.enclosureLink?.let { enclosureLink ->
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(enclosureLink))
intent.putExtra(EXTRA_CREATE_NEW_TAB, true)
builder.addAction(
R.drawable.notification_open_in_browser,
context.getString(R.string.open_link_in_browser),
R.drawable.notification_play_circle_outline,
context.getString(R.string.open_enclosed_media),
PendingIntent.getActivity(
context,
item.id.toInt(),
getOpenInDefaultActivityIntent(context, item.id, link),
getOpenInDefaultActivityIntent(context, item.id, enclosureLink),
PendingIntent.FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE,
),
)
}

if (repository.getArticleOpener(item.id) != ItemOpener.DEFAULT_BROWSER) {
item.link?.let { link ->
builder.addAction(
R.drawable.notification_open_in_browser,
context.getString(R.string.open_link_in_browser),
PendingIntent.getActivity(
context,
item.id.toInt(),
getOpenInDefaultActivityIntent(context, item.id, link),
PendingIntent.FLAG_UPDATE_CURRENT or FLAG_IMMUTABLE,
),
)
}
}

builder.addAction(
R.drawable.notification_check,
context.getString(R.string.mark_as_read),
Expand Down

0 comments on commit 6968216

Please sign in to comment.