mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-31 21:41:33 +00:00
#1626 Add share as a notification action
This commit is contained in:
parent
660b2bc956
commit
eacb5a5e20
4 changed files with 41 additions and 1 deletions
|
@ -167,6 +167,7 @@
|
||||||
<receiver android:name=".util.NotifyDismissReceiver" android:exported="false" />
|
<receiver android:name=".util.NotifyDismissReceiver" android:exported="false" />
|
||||||
<receiver android:name=".util.NotifySaveReceiver" android:exported="false" />
|
<receiver android:name=".util.NotifySaveReceiver" android:exported="false" />
|
||||||
<receiver android:name=".util.NotifyMarkreadReceiver" android:exported="false" />
|
<receiver android:name=".util.NotifyMarkreadReceiver" android:exported="false" />
|
||||||
|
<receiver android:name=".util.NotifyShareReceiver" android:exported="false" />
|
||||||
<receiver android:name=".widget.WidgetProvider"
|
<receiver android:name=".widget.WidgetProvider"
|
||||||
android:exported="false">
|
android:exported="false">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|
|
@ -800,6 +800,7 @@ abstract class Reading : NbActivity(), OnPageChangeListener, ScrollChangeListene
|
||||||
companion object {
|
companion object {
|
||||||
const val EXTRA_FEEDSET = "feed_set"
|
const val EXTRA_FEEDSET = "feed_set"
|
||||||
const val EXTRA_STORY_HASH = "story_hash"
|
const val EXTRA_STORY_HASH = "story_hash"
|
||||||
|
const val EXTRA_STORY = "story"
|
||||||
private const val BUNDLE_STARTING_UNREAD = "starting_unread"
|
private const val BUNDLE_STARTING_UNREAD = "starting_unread"
|
||||||
|
|
||||||
/** special value for starting story hash that jumps to the first unread. */
|
/** special value for starting story hash that jumps to the first unread. */
|
||||||
|
|
|
@ -128,6 +128,10 @@ public class NotificationUtils {
|
||||||
markreadIntent.putExtra(Reading.EXTRA_STORY_HASH, story.storyHash);
|
markreadIntent.putExtra(Reading.EXTRA_STORY_HASH, story.storyHash);
|
||||||
PendingIntent markreadPendingIntent = PendingIntentUtils.getImmutableBroadcast(context.getApplicationContext(), story.hashCode(), markreadIntent, 0);
|
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));
|
String feedTitle = cursor.getString(cursor.getColumnIndex(DatabaseConstants.FEED_TITLE));
|
||||||
StringBuilder title = new StringBuilder();
|
StringBuilder title = new StringBuilder();
|
||||||
title.append(feedTitle).append(": ").append(story.title);
|
title.append(feedTitle).append(": ").append(story.title);
|
||||||
|
@ -144,8 +148,9 @@ public class NotificationUtils {
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setOnlyAlertOnce(true)
|
.setOnlyAlertOnce(true)
|
||||||
.setWhen(story.timestamp)
|
.setWhen(story.timestamp)
|
||||||
.addAction(0, "Save", savePendingIntent)
|
|
||||||
.addAction(0, "Mark Read", markreadPendingIntent)
|
.addAction(0, "Mark Read", markreadPendingIntent)
|
||||||
|
.addAction(0, "Save", savePendingIntent)
|
||||||
|
.addAction(0, "Share", sharePendingIntent)
|
||||||
.setColor(NOTIFY_COLOUR);
|
.setColor(NOTIFY_COLOUR);
|
||||||
if (feedIcon != null) {
|
if (feedIcon != null) {
|
||||||
nb.setLargeIcon(feedIcon);
|
nb.setLargeIcon(feedIcon);
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue