mirror of
https://github.com/mihonapp/mihon.git
synced 2025-03-13 16:20:08 +01:00
Add 'show entry' to download notifications
Signed-off-by: Catting <5874051+mm12@users.noreply.github.com>
This commit is contained in:
parent
5dc6569a68
commit
77aec29aaf
@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.util.system.cancelNotification
|
|||||||
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
||||||
import eu.kanade.tachiyomi.util.system.notify
|
import eu.kanade.tachiyomi.util.system.notify
|
||||||
import tachiyomi.core.common.i18n.stringResource
|
import tachiyomi.core.common.i18n.stringResource
|
||||||
|
import tachiyomi.domain.manga.model.Manga
|
||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
@ -83,6 +84,12 @@ internal class DownloadNotifier(private val context: Context) {
|
|||||||
context.stringResource(MR.strings.action_pause),
|
context.stringResource(MR.strings.action_pause),
|
||||||
NotificationReceiver.pauseDownloadsPendingBroadcast(context),
|
NotificationReceiver.pauseDownloadsPendingBroadcast(context),
|
||||||
)
|
)
|
||||||
|
addAction(
|
||||||
|
R.drawable.ic_book_24dp,
|
||||||
|
context.stringResource(MR.strings.action_show_manga),
|
||||||
|
|
||||||
|
NotificationReceiver.openEntryPendingActivity(context, download.manga.id),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val downloadingProgressText = context.stringResource(
|
val downloadingProgressText = context.stringResource(
|
||||||
@ -160,9 +167,10 @@ internal class DownloadNotifier(private val context: Context) {
|
|||||||
*
|
*
|
||||||
* @param reason the text to show.
|
* @param reason the text to show.
|
||||||
* @param timeout duration after which to automatically dismiss the notification.
|
* @param timeout duration after which to automatically dismiss the notification.
|
||||||
|
* @param mangaId the id of the entry being warned about
|
||||||
* Only works on Android 8+.
|
* Only works on Android 8+.
|
||||||
*/
|
*/
|
||||||
fun onWarning(reason: String, timeout: Long? = null, contentIntent: PendingIntent? = null) {
|
fun onWarning(reason: String, timeout: Long? = null, contentIntent: PendingIntent? = null, mangaId: Long? = null) {
|
||||||
with(errorNotificationBuilder) {
|
with(errorNotificationBuilder) {
|
||||||
setContentTitle(context.stringResource(MR.strings.download_notifier_downloader_title))
|
setContentTitle(context.stringResource(MR.strings.download_notifier_downloader_title))
|
||||||
setStyle(NotificationCompat.BigTextStyle().bigText(reason))
|
setStyle(NotificationCompat.BigTextStyle().bigText(reason))
|
||||||
@ -170,6 +178,14 @@ internal class DownloadNotifier(private val context: Context) {
|
|||||||
setAutoCancel(true)
|
setAutoCancel(true)
|
||||||
clearActions()
|
clearActions()
|
||||||
setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
|
setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
|
||||||
|
if (mangaId != null) {
|
||||||
|
addAction(
|
||||||
|
R.drawable.ic_book_24dp,
|
||||||
|
context.stringResource(MR.strings.action_show_manga),
|
||||||
|
|
||||||
|
NotificationReceiver.openEntryPendingActivity(context, mangaId),
|
||||||
|
)
|
||||||
|
}
|
||||||
setProgress(0, 0, false)
|
setProgress(0, 0, false)
|
||||||
timeout?.let { setTimeoutAfter(it) }
|
timeout?.let { setTimeoutAfter(it) }
|
||||||
contentIntent?.let { setContentIntent(it) }
|
contentIntent?.let { setContentIntent(it) }
|
||||||
@ -187,8 +203,9 @@ internal class DownloadNotifier(private val context: Context) {
|
|||||||
*
|
*
|
||||||
* @param error string containing error information.
|
* @param error string containing error information.
|
||||||
* @param chapter string containing chapter title.
|
* @param chapter string containing chapter title.
|
||||||
|
* @param mangaId the id of the entry that was errored on
|
||||||
*/
|
*/
|
||||||
fun onError(error: String? = null, chapter: String? = null, mangaTitle: String? = null) {
|
fun onError(error: String? = null, chapter: String? = null, mangaTitle: String? = null, mangaId: Long? = null) {
|
||||||
// Create notification
|
// Create notification
|
||||||
with(errorNotificationBuilder) {
|
with(errorNotificationBuilder) {
|
||||||
setContentTitle(
|
setContentTitle(
|
||||||
@ -198,6 +215,14 @@ internal class DownloadNotifier(private val context: Context) {
|
|||||||
setSmallIcon(R.drawable.ic_warning_white_24dp)
|
setSmallIcon(R.drawable.ic_warning_white_24dp)
|
||||||
clearActions()
|
clearActions()
|
||||||
setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
|
setContentIntent(NotificationHandler.openDownloadManagerPendingActivity(context))
|
||||||
|
if (mangaId != null) {
|
||||||
|
addAction(
|
||||||
|
R.drawable.ic_book_24dp,
|
||||||
|
context.stringResource(MR.strings.action_show_manga),
|
||||||
|
|
||||||
|
NotificationReceiver.openEntryPendingActivity(context, mangaId),
|
||||||
|
)
|
||||||
|
}
|
||||||
setProgress(0, 0, false)
|
setProgress(0, 0, false)
|
||||||
|
|
||||||
show(Notifications.ID_DOWNLOAD_CHAPTER_ERROR)
|
show(Notifications.ID_DOWNLOAD_CHAPTER_ERROR)
|
||||||
|
@ -302,6 +302,7 @@ class Downloader(
|
|||||||
context.stringResource(MR.strings.download_queue_size_warning),
|
context.stringResource(MR.strings.download_queue_size_warning),
|
||||||
WARNING_NOTIF_TIMEOUT_MS,
|
WARNING_NOTIF_TIMEOUT_MS,
|
||||||
NotificationHandler.openUrl(context, LibraryUpdateNotifier.HELP_WARNING_URL),
|
NotificationHandler.openUrl(context, LibraryUpdateNotifier.HELP_WARNING_URL),
|
||||||
|
manga.id,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
DownloadJob.start(context)
|
DownloadJob.start(context)
|
||||||
@ -324,6 +325,7 @@ class Downloader(
|
|||||||
context.stringResource(MR.strings.download_insufficient_space),
|
context.stringResource(MR.strings.download_insufficient_space),
|
||||||
download.chapter.name,
|
download.chapter.name,
|
||||||
download.manga.title,
|
download.manga.title,
|
||||||
|
download.manga.id,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -407,7 +409,7 @@ class Downloader(
|
|||||||
// If the page list threw, it will resume here
|
// If the page list threw, it will resume here
|
||||||
logcat(LogPriority.ERROR, error)
|
logcat(LogPriority.ERROR, error)
|
||||||
download.status = Download.State.ERROR
|
download.status = Download.State.ERROR
|
||||||
notifier.onError(error.message, download.chapter.name, download.manga.title)
|
notifier.onError(error.message, download.chapter.name, download.manga.title, download.manga.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,7 +459,7 @@ class Downloader(
|
|||||||
// Mark this page as error and allow to download the remaining
|
// Mark this page as error and allow to download the remaining
|
||||||
page.progress = 0
|
page.progress = 0
|
||||||
page.status = Page.State.ERROR
|
page.status = Page.State.ERROR
|
||||||
notifier.onError(e.message, download.chapter.name, download.manga.title)
|
notifier.onError(e.message, download.chapter.name, download.manga.title, download.manga.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,8 +18,10 @@ import eu.kanade.tachiyomi.util.system.notificationManager
|
|||||||
import eu.kanade.tachiyomi.util.system.toShareIntent
|
import eu.kanade.tachiyomi.util.system.toShareIntent
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import logcat.LogPriority
|
||||||
import tachiyomi.core.common.Constants
|
import tachiyomi.core.common.Constants
|
||||||
import tachiyomi.core.common.util.lang.launchIO
|
import tachiyomi.core.common.util.lang.launchIO
|
||||||
|
import tachiyomi.core.common.util.system.logcat
|
||||||
import tachiyomi.domain.chapter.interactor.GetChapter
|
import tachiyomi.domain.chapter.interactor.GetChapter
|
||||||
import tachiyomi.domain.chapter.interactor.UpdateChapter
|
import tachiyomi.domain.chapter.interactor.UpdateChapter
|
||||||
import tachiyomi.domain.chapter.model.Chapter
|
import tachiyomi.domain.chapter.model.Chapter
|
||||||
@ -108,6 +110,11 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
downloadChapters(urls, mangaId)
|
downloadChapters(urls, mangaId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Open an entry's page
|
||||||
|
// ACTION_OPEN_ENTRY -> {
|
||||||
|
// val mangaId = intent.getLongExtra(EXTRA_MANGA_ID, -1)
|
||||||
|
// openEntry(context, mangaId)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,6 +167,19 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private fun openEntry(context: Context, mangaId: Long){ // TODO: open manga
|
||||||
|
// val manga = runBlocking { getManga.await(mangaId) }
|
||||||
|
// if (manga != null){
|
||||||
|
// val intent = Intent(context,MainActivity::class.java).apply {
|
||||||
|
// flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
|
// }
|
||||||
|
// context.startActivity(intent)
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// context.toast(MR.strings.error_no_match)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method called when user wants to stop a backup restore job.
|
* Method called when user wants to stop a backup restore job.
|
||||||
*
|
*
|
||||||
@ -248,6 +268,8 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
private const val ACTION_OPEN_CHAPTER = "$ID.$NAME.ACTION_OPEN_CHAPTER"
|
private const val ACTION_OPEN_CHAPTER = "$ID.$NAME.ACTION_OPEN_CHAPTER"
|
||||||
private const val ACTION_DOWNLOAD_CHAPTER = "$ID.$NAME.ACTION_DOWNLOAD_CHAPTER"
|
private const val ACTION_DOWNLOAD_CHAPTER = "$ID.$NAME.ACTION_DOWNLOAD_CHAPTER"
|
||||||
|
|
||||||
|
private const val ACTION_OPEN_ENTRY = "$ID.$NAME.ACTION_OPEN_ENTRY"
|
||||||
|
|
||||||
private const val ACTION_RESUME_DOWNLOADS = "$ID.$NAME.ACTION_RESUME_DOWNLOADS"
|
private const val ACTION_RESUME_DOWNLOADS = "$ID.$NAME.ACTION_RESUME_DOWNLOADS"
|
||||||
private const val ACTION_PAUSE_DOWNLOADS = "$ID.$NAME.ACTION_PAUSE_DOWNLOADS"
|
private const val ACTION_PAUSE_DOWNLOADS = "$ID.$NAME.ACTION_PAUSE_DOWNLOADS"
|
||||||
private const val ACTION_CLEAR_DOWNLOADS = "$ID.$NAME.ACTION_CLEAR_DOWNLOADS"
|
private const val ACTION_CLEAR_DOWNLOADS = "$ID.$NAME.ACTION_CLEAR_DOWNLOADS"
|
||||||
@ -484,6 +506,26 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns [PendingIntent] that opens the manga info controller
|
||||||
|
*
|
||||||
|
* @param context context of application
|
||||||
|
* @param mangaId id of the entry to open
|
||||||
|
*/
|
||||||
|
internal fun openEntryPendingActivity(context: Context, mangaId: Long): PendingIntent {
|
||||||
|
val newIntent =
|
||||||
|
Intent(context, MainActivity::class.java).setAction(Constants.SHORTCUT_MANGA)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
|
.putExtra(Constants.MANGA_EXTRA, mangaId)
|
||||||
|
.putExtra("notificationId", mangaId.hashCode())
|
||||||
|
return PendingIntent.getActivity(
|
||||||
|
context,
|
||||||
|
mangaId.hashCode(),
|
||||||
|
newIntent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns [PendingIntent] that starts a service which stops the library update
|
* Returns [PendingIntent] that starts a service which stops the library update
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user