#1626 Add share as a notification action

This commit is contained in:
Andrei 2022-09-11 12:36:57 -07:00
parent 660b2bc956
commit eacb5a5e20
4 changed files with 41 additions and 1 deletions

View file

@ -167,6 +167,7 @@
<receiver android:name=".util.NotifyDismissReceiver" android:exported="false" />
<receiver android:name=".util.NotifySaveReceiver" android:exported="false" />
<receiver android:name=".util.NotifyMarkreadReceiver" android:exported="false" />
<receiver android:name=".util.NotifyShareReceiver" android:exported="false" />
<receiver android:name=".widget.WidgetProvider"
android:exported="false">
<intent-filter>

View file

@ -800,6 +800,7 @@ abstract class Reading : NbActivity(), OnPageChangeListener, ScrollChangeListene
companion object {
const val EXTRA_FEEDSET = "feed_set"
const val EXTRA_STORY_HASH = "story_hash"
const val EXTRA_STORY = "story"
private const val BUNDLE_STARTING_UNREAD = "starting_unread"
/** special value for starting story hash that jumps to the first unread. */

View file

@ -128,6 +128,10 @@ public class NotificationUtils {
markreadIntent.putExtra(Reading.EXTRA_STORY_HASH, story.storyHash);
PendingIntent markreadPendingIntent = PendingIntentUtils.getImmutableBroadcast(context.getApplicationContext(), story.hashCode(), markreadIntent, 0);
Intent shareIntent = new Intent(context, NotifyShareReceiver.class);
shareIntent.putExtra(Reading.EXTRA_STORY, story);
PendingIntent sharePendingIntent = PendingIntentUtils.getImmutableBroadcast(context.getApplicationContext(), story.hashCode(), shareIntent, 0);
String feedTitle = cursor.getString(cursor.getColumnIndex(DatabaseConstants.FEED_TITLE));
StringBuilder title = new StringBuilder();
title.append(feedTitle).append(": ").append(story.title);
@ -144,8 +148,9 @@ public class NotificationUtils {
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setWhen(story.timestamp)
.addAction(0, "Save", savePendingIntent)
.addAction(0, "Mark Read", markreadPendingIntent)
.addAction(0, "Save", savePendingIntent)
.addAction(0, "Share", sharePendingIntent)
.setColor(NOTIFY_COLOUR);
if (feedIcon != null) {
nb.setLargeIcon(feedIcon);

View file

@ -0,0 +1,33 @@
package com.newsblur.util
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.newsblur.activity.Reading
import com.newsblur.database.BlurDatabaseHelper
import com.newsblur.domain.Story
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
@AndroidEntryPoint
class NotifyShareReceiver : BroadcastReceiver() {
@Inject
lateinit var feedUtils: FeedUtils
@Inject
lateinit var dbHelper: BlurDatabaseHelper
override fun onReceive(context: Context, intent: Intent) {
val story = intent.getSerializableExtra(Reading.EXTRA_STORY) as? Story?
NotificationUtils.cancel(context, story?.storyHash.hashCode())
story?.let {
NBScope.executeAsyncTask(
doInBackground = {
dbHelper.putStoryDismissed(it.storyHash)
feedUtils.shareStory(it, "", it.sourceUserId, context)
}
)
}
}
}