Fixes to notifcation actions, such as starting a opening a chapter

This commit is contained in:
Jay 2019-11-03 23:35:17 -08:00
parent cc5c9a4699
commit 1b545c9e4d
7 changed files with 39 additions and 22 deletions

View File

@ -170,7 +170,8 @@ internal class DownloadNotifier(private val context: Context) {
setSmallIcon(android.R.drawable.stat_sys_download_done) setSmallIcon(android.R.drawable.stat_sys_download_done)
setAutoCancel(true) setAutoCancel(true)
clearActions() clearActions()
setContentIntent(NotificationReceiver.openChapterPendingBroadcast(context, download.manga, download.chapter)) setContentIntent(NotificationReceiver.openChapterPendingBroadcast(context, download
.manga, download.chapter, Notifications.ID_DOWNLOAD_CHAPTER))
setProgress(0, 0, false) setProgress(0, 0, false)
} }

View File

@ -480,7 +480,8 @@ class LibraryUpdateService(
val chapter = chapters.sortedByDescending { it.source_order }.find { !it.read } val chapter = chapters.sortedByDescending { it.source_order }.find { !it.read }
if (chapter != null) { if (chapter != null) {
addAction(R.drawable.ic_in_library_24dp, getString(R.string.action_start_reading), addAction(R.drawable.ic_in_library_24dp, getString(R.string.action_start_reading),
NotificationReceiver.openChapterPendingBroadcast(context, onlyManga, chapter)) NotificationReceiver.openChapterPendingBroadcast(context, onlyManga,
chapter, Notifications.ID_NEW_CHAPTERS))
} }
} }
priority = NotificationCompat.PRIORITY_HIGH priority = NotificationCompat.PRIORITY_HIGH

View File

@ -1,12 +1,17 @@
package eu.kanade.tachiyomi.data.notification package eu.kanade.tachiyomi.data.notification
import android.app.Activity
import android.app.KeyguardManager
import android.app.Notification import android.app.Notification
import android.app.PendingIntent import android.app.PendingIntent
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.ClipData import android.content.ClipData
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Handler import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
@ -82,6 +87,7 @@ class NotificationReceiver : BroadcastReceiver() {
* @param notificationId id of notification * @param notificationId id of notification
*/ */
private fun shareImage(context: Context, path: String, notificationId: Int) { private fun shareImage(context: Context, path: String, notificationId: Int) {
val km = context.getSystemService(Activity.KEYGUARD_SERVICE) as KeyguardManager
// Create intent // Create intent
val intent = Intent(Intent.ACTION_SEND).apply { val intent = Intent(Intent.ACTION_SEND).apply {
val uri = File(path).getUriCompat(context) val uri = File(path).getUriCompat(context)
@ -91,12 +97,7 @@ class NotificationReceiver : BroadcastReceiver() {
type = "image/*" type = "image/*"
} }
// Close Navigation Shade // Close Navigation Shade
context.sendBroadcast(Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
// Launch share activity
val shareIntent = Intent.createChooser(intent, context.getString(R.string
.action_share))
shareIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
context.startActivity(shareIntent)
} }
/** /**
@ -262,12 +263,17 @@ class NotificationReceiver : BroadcastReceiver() {
* @return [PendingIntent] * @return [PendingIntent]
*/ */
internal fun shareImagePendingBroadcast(context: Context, path: String, notificationId: Int): PendingIntent { internal fun shareImagePendingBroadcast(context: Context, path: String, notificationId: Int): PendingIntent {
val intent = Intent(context, NotificationReceiver::class.java).apply { //val shareIntent = ShareStartingActivity.newIntent(context, path)
action = ACTION_SHARE_IMAGE val shareIntent = Intent(Intent.ACTION_SEND).apply {
putExtra(EXTRA_FILE_LOCATION, path) val uri = File(path).getUriCompat(context)
putExtra(EXTRA_NOTIFICATION_ID, notificationId) putExtra(Intent.EXTRA_STREAM, uri)
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_CLEAR_TOP
clipData = ClipData.newRawUri(null, uri)
type = "image/*"
} }
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) //val shareIntent2 = Intent.createChooser(shareIntent, context.getString(R.string.action_share))
return PendingIntent.getActivity(context, 0, shareIntent, PendingIntent
.FLAG_CANCEL_CURRENT)
} }
/** /**
@ -294,13 +300,10 @@ class NotificationReceiver : BroadcastReceiver() {
* @param manga manga of chapter * @param manga manga of chapter
* @param chapter chapter that needs to be opened * @param chapter chapter that needs to be opened
*/ */
internal fun openChapterPendingBroadcast(context: Context, manga: Manga, chapter: Chapter): PendingIntent { internal fun openChapterPendingBroadcast(context: Context, manga: Manga, chapter:
val intent = Intent(context, NotificationReceiver::class.java).apply { Chapter, notificationId: Int): PendingIntent {
action = ACTION_OPEN_CHAPTER val newIntent = ReaderActivity.newIntent(context, manga, chapter, notificationId)
putExtra(EXTRA_MANGA_ID, manga.id) return PendingIntent.getActivity(context, 0, newIntent, PendingIntent.FLAG_UPDATE_CURRENT)
putExtra(EXTRA_CHAPTER_ID, chapter.id)
}
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
} }
/** /**

View File

@ -21,6 +21,7 @@ import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
@ -119,10 +120,13 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>(),
const val VERTICAL = 3 const val VERTICAL = 3
const val WEBTOON = 4 const val WEBTOON = 4
fun newIntent(context: Context, manga: Manga, chapter: Chapter): Intent { fun newIntent(context: Context, manga: Manga, chapter: Chapter, notificationId:Int? =
null):
Intent {
val intent = Intent(context, ReaderActivity::class.java) val intent = Intent(context, ReaderActivity::class.java)
intent.putExtra("manga", manga.id) intent.putExtra("manga", manga.id)
intent.putExtra("chapter", chapter.id) intent.putExtra("chapter", chapter.id)
intent.putExtra("notificationId", notificationId)
return intent return intent
} }
} }
@ -142,6 +146,10 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>(),
if (presenter.needsInit()) { if (presenter.needsInit()) {
val manga = intent.extras!!.getLong("manga", -1) val manga = intent.extras!!.getLong("manga", -1)
val chapter = intent.extras!!.getLong("chapter", -1) val chapter = intent.extras!!.getLong("chapter", -1)
val notificationId = intent.extras!!.getInt("notificationId", -1)
if (notificationId > 0) {
applicationContext.notificationManager.cancel(notificationId)
}
if (manga == -1L || chapter == -1L) { if (manga == -1L || chapter == -1L) {
finish() finish()

View File

@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.reader
import android.content.Context import android.content.Context
import android.graphics.Bitmap import android.graphics.Bitmap
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.glide.GlideApp import eu.kanade.tachiyomi.data.glide.GlideApp
@ -57,6 +58,7 @@ class SaveImageNotifier(private val context: Context) {
setStyle(NotificationCompat.BigPictureStyle().bigPicture(image)) setStyle(NotificationCompat.BigPictureStyle().bigPicture(image))
setLargeIcon(image) setLargeIcon(image)
setAutoCancel(true) setAutoCancel(true)
color = ContextCompat.getColor(context, R.color.colorAccentLight)
// Clear old actions if they exist // Clear old actions if they exist
if (!mActions.isEmpty()) if (!mActions.isEmpty())
mActions.clear() mActions.clear()

View File

@ -7,4 +7,5 @@
<color name="cardBackground">@color/colorDarkPrimary</color> <color name="cardBackground">@color/colorDarkPrimary</color>
<color name="rippleColor">@color/md_white_1000_20</color> <color name="rippleColor">@color/md_white_1000_20</color>
<color name="dialogBackground">@color/md_grey_800</color> <color name="dialogBackground">@color/md_grey_800</color>
<color name="colorAccent">#3399FF</color>
</resources> </resources>

View File

@ -9,6 +9,7 @@
<color name="snackbarBackground">#323232</color> <color name="snackbarBackground">#323232</color>
<color name="dialogBackground">@color/md_white_1000</color> <color name="dialogBackground">@color/md_white_1000</color>
<color name="rippleColor">@color/md_black_1000_12</color> <color name="rippleColor">@color/md_black_1000_12</color>
<color name="colorAccent">@color/md_blue_A400</color>
<!-- Dark Application Colors --> <!-- Dark Application Colors -->
<color name="colorDarkPrimary">#212121</color> <color name="colorDarkPrimary">#212121</color>
<color name="colorDarkPrimaryDark">#212121</color> <color name="colorDarkPrimaryDark">#212121</color>