|
|
|
@ -8,10 +8,13 @@ import eu.kanade.tachiyomi.data.download.model.Download
|
|
|
|
|
import eu.kanade.tachiyomi.data.notification.NotificationHandler
|
|
|
|
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
|
|
|
|
import eu.kanade.tachiyomi.data.notification.Notifications
|
|
|
|
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
|
|
|
|
import eu.kanade.tachiyomi.util.lang.chop
|
|
|
|
|
import eu.kanade.tachiyomi.util.system.notificationBuilder
|
|
|
|
|
import eu.kanade.tachiyomi.util.system.notificationManager
|
|
|
|
|
import java.util.regex.Pattern
|
|
|
|
|
import uy.kohesive.injekt.Injekt
|
|
|
|
|
import uy.kohesive.injekt.api.get
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* DownloadNotifier is used to show notifications when downloading one or multiple chapters.
|
|
|
|
@ -24,6 +27,8 @@ internal class DownloadNotifier(private val context: Context) {
|
|
|
|
|
setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val preferences by lazy { Injekt.get<PreferencesHelper>() }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Status of download. Used for correct notification icon.
|
|
|
|
|
*/
|
|
|
|
@ -87,12 +92,19 @@ internal class DownloadNotifier(private val context: Context) {
|
|
|
|
|
NotificationReceiver.pauseDownloadsPendingBroadcast(context))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val downloadingProgressText = context.getString(R.string.chapter_downloading_progress)
|
|
|
|
|
.format(download.downloadedImages, download.pages!!.size)
|
|
|
|
|
|
|
|
|
|
if (preferences.hideNotificationContent()) {
|
|
|
|
|
setContentTitle(downloadingProgressText)
|
|
|
|
|
} else {
|
|
|
|
|
val title = download.manga.title.chop(15)
|
|
|
|
|
val quotedTitle = Pattern.quote(title)
|
|
|
|
|
val chapter = download.chapter.name.replaceFirst("$quotedTitle[\\s]*[-]*[\\s]*".toRegex(RegexOption.IGNORE_CASE), "")
|
|
|
|
|
setContentTitle("$title - $chapter".chop(30))
|
|
|
|
|
setContentText(context.getString(R.string.chapter_downloading_progress)
|
|
|
|
|
.format(download.downloadedImages, download.pages!!.size))
|
|
|
|
|
setContentText(downloadingProgressText)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setProgress(download.pages!!.size, download.downloadedImages, false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|