diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/notification/ImageNotificationReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/notification/ImageNotificationReceiver.kt
index 09377f77c0..6aae6857d1 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/notification/ImageNotificationReceiver.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/notification/ImageNotificationReceiver.kt
@@ -4,12 +4,11 @@ import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
-import android.net.Uri
import android.support.v4.content.FileProvider
import eu.kanade.tachiyomi.BuildConfig
-import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.util.notificationManager
import java.io.File
+import eu.kanade.tachiyomi.Constants.NOTIFICATION_DOWNLOAD_IMAGE_ID as defaultNotification
/**
* The BroadcastReceiver of [ImageNotifier]
@@ -18,21 +17,16 @@ import java.io.File
class ImageNotificationReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
- ACTION_SHARE_IMAGE -> {
- shareImage(context, intent.getStringExtra(EXTRA_FILE_LOCATION))
- context.notificationManager.cancel(intent.getIntExtra(NOTIFICATION_ID, 5))
- }
- ACTION_SHOW_IMAGE ->
- showImage(context, intent.getStringExtra(EXTRA_FILE_LOCATION))
ACTION_DELETE_IMAGE -> {
deleteImage(intent.getStringExtra(EXTRA_FILE_LOCATION))
- context.notificationManager.cancel(intent.getIntExtra(NOTIFICATION_ID, 5))
+ context.notificationManager.cancel(intent.getIntExtra(NOTIFICATION_ID, defaultNotification))
}
}
}
/**
* Called to delete image
+ *
* @param path path of file
*/
private fun deleteImage(path: String) {
@@ -40,60 +34,42 @@ class ImageNotificationReceiver : BroadcastReceiver() {
if (file.exists()) file.delete()
}
- /**
- * Called to start share intent to share image
- * @param context context of application
- * @param path path of file
- */
- private fun shareImage(context: Context, path: String) {
- val intent = Intent(Intent.ACTION_SEND).apply {
- flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK
- putExtra(Intent.EXTRA_STREAM, Uri.parse(path))
- type = "image/*"
- }
- context.startActivity(Intent.createChooser(intent, context.getString(R.string.action_share)))
- }
-
- /**
- * Called to show image in gallery application
- * @param context context of application
- * @param path path of file
- */
- private fun showImage(context: Context, path: String) {
- val intent = Intent(Intent.ACTION_VIEW).apply {
- flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
- val uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", File(path))
- setDataAndType(uri, "image/*")
- }
- context.startActivity(intent)
- }
-
companion object {
- private const val ACTION_SHARE_IMAGE = "eu.kanade.SHARE_IMAGE"
-
- private const val ACTION_SHOW_IMAGE = "eu.kanade.SHOW_IMAGE"
-
private const val ACTION_DELETE_IMAGE = "eu.kanade.DELETE_IMAGE"
private const val EXTRA_FILE_LOCATION = "file_location"
private const val NOTIFICATION_ID = "notification_id"
- internal fun shareImageIntent(context: Context, path: String, notificationId: Int): PendingIntent {
- val intent = Intent(context, ImageNotificationReceiver::class.java).apply {
- action = ACTION_SHARE_IMAGE
- putExtra(EXTRA_FILE_LOCATION, path)
- putExtra(NOTIFICATION_ID, notificationId)
+ /**
+ * Called to start share intent to share image
+ *
+ * @param context context of application
+ * @param path path of file
+ */
+ internal fun shareImageIntent(context: Context, path: String): PendingIntent {
+ val intent = Intent(Intent.ACTION_SEND).apply {
+ val uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", File(path))
+ putExtra(Intent.EXTRA_STREAM, uri)
+ flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
+ type = "image/*"
}
- return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
+ return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
+ /**
+ * Called to show image in gallery application
+ *
+ * @param context context of application
+ * @param path path of file
+ */
internal fun showImageIntent(context: Context, path: String): PendingIntent {
- val intent = Intent(context, ImageNotificationReceiver::class.java).apply {
- action = ACTION_SHOW_IMAGE
- putExtra(EXTRA_FILE_LOCATION, path)
+ val intent = Intent(Intent.ACTION_VIEW).apply {
+ flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
+ val uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".provider", File(path))
+ setDataAndType(uri, "image/*")
}
- return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
+ return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
internal fun deleteImageIntent(context: Context, path: String, notificationId: Int): PendingIntent {
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/notification/ImageNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/notification/ImageNotifier.kt
index ca49eece42..97b38a065f 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/notification/ImageNotifier.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/notification/ImageNotifier.kt
@@ -62,7 +62,7 @@ class ImageNotifier(private val context: Context) {
// Share action
addAction(R.drawable.ic_share_grey_24dp,
context.getString(R.string.action_share),
- ImageNotificationReceiver.shareImageIntent(context, file.absolutePath, notificationId))
+ ImageNotificationReceiver.shareImageIntent(context, file.absolutePath))
// Delete action
addAction(R.drawable.ic_delete_grey_24dp,
context.getString(R.string.action_delete),
diff --git a/app/src/main/res/menu/chapter_single.xml b/app/src/main/res/menu/chapter_single.xml
index 01b6b5c6da..eab89ed70e 100644
--- a/app/src/main/res/menu/chapter_single.xml
+++ b/app/src/main/res/menu/chapter_single.xml
@@ -6,6 +6,11 @@
android:title="@string/action_download"
android:visible="true" />
+
+
@@ -14,10 +19,6 @@
android:title="@string/action_remove_bookmark"
android:visible="true" />
-
-