mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-14 21:18:56 +01:00
Added code to prevent OutOfMemory error. Made notification optional. Can now save image on long press. Bug fixes
This commit is contained in:
@@ -47,6 +47,8 @@ class DownloadManager(
|
||||
private val threadsSubject = BehaviorSubject.create<Int>()
|
||||
private var threadsSubscription: Subscription? = null
|
||||
|
||||
private var notificationSubscription: Subscription? = null
|
||||
|
||||
val queue = DownloadQueue()
|
||||
|
||||
val imageFilenameRegex = "[^\\sa-zA-Z0-9.-]".toRegex()
|
||||
@@ -66,6 +68,12 @@ class DownloadManager(
|
||||
downloadNotifier.multipleDownloadThreads = it > 1
|
||||
}
|
||||
|
||||
notificationSubscription = preferences.showMangaDownloadNotification().asObservable()
|
||||
.subscribe {
|
||||
downloadNotifier.onClear()
|
||||
downloadNotifier.showNotification = it
|
||||
}
|
||||
|
||||
downloadsSubscription = downloadsQueueSubject.flatMap { Observable.from(it) }
|
||||
.lift(DynamicConcurrentMergeOperator<Download, Download>({ downloadChapter(it) }, threadsSubject))
|
||||
.onBackpressureBuffer()
|
||||
@@ -107,6 +115,10 @@ class DownloadManager(
|
||||
threadsSubscription?.unsubscribe()
|
||||
}
|
||||
|
||||
if (notificationSubscription != null) {
|
||||
notificationSubscription?.unsubscribe()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Create a download object for every chapter and add them to the downloads queue
|
||||
@@ -188,7 +200,7 @@ class DownloadManager(
|
||||
DiskUtils.createDirectory(download.directory)
|
||||
|
||||
val pageListObservable: Observable<List<Page>> = if (download.pages == null)
|
||||
// Pull page list from network and add them to download object
|
||||
// Pull page list from network and add them to download object
|
||||
download.source.fetchPageListFromNetwork(download.chapter)
|
||||
.doOnNext { pages ->
|
||||
download.pages = pages
|
||||
|
||||
@@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.download.model.Download
|
||||
import eu.kanade.tachiyomi.data.download.model.DownloadQueue
|
||||
import eu.kanade.tachiyomi.util.notificationManager
|
||||
import eu.kanade.tachiyomi.util.toast
|
||||
|
||||
/**
|
||||
* DownloadNotifier is used to show notifications when downloading one or multiple chapters.
|
||||
@@ -40,6 +41,11 @@ class DownloadNotifier(private val context: Context) {
|
||||
*/
|
||||
internal var multipleDownloadThreads = false
|
||||
|
||||
/**
|
||||
* Value determining if notification should be shown
|
||||
*/
|
||||
internal var showNotification = true
|
||||
|
||||
/**
|
||||
* Called when download progress changes.
|
||||
* Note: Only accepted when multi download active.
|
||||
@@ -47,9 +53,8 @@ class DownloadNotifier(private val context: Context) {
|
||||
* @param queue the queue containing downloads.
|
||||
*/
|
||||
internal fun onProgressChange(queue: DownloadQueue) {
|
||||
if (multipleDownloadThreads) {
|
||||
if (multipleDownloadThreads && showNotification)
|
||||
doOnProgressChange(null, queue)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,9 +65,8 @@ class DownloadNotifier(private val context: Context) {
|
||||
* @param queue the queue containing downloads
|
||||
*/
|
||||
internal fun onProgressChange(download: Download, queue: DownloadQueue) {
|
||||
if (!multipleDownloadThreads) {
|
||||
if (!multipleDownloadThreads && showNotification)
|
||||
doOnProgressChange(download, queue)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,7 +90,7 @@ class DownloadNotifier(private val context: Context) {
|
||||
}
|
||||
|
||||
// Create notification
|
||||
with (notificationBuilder) {
|
||||
with(notificationBuilder) {
|
||||
// Check if icon needs refresh
|
||||
if (!isDownloading) {
|
||||
setSmallIcon(android.R.drawable.stat_sys_download)
|
||||
@@ -127,17 +131,18 @@ class DownloadNotifier(private val context: Context) {
|
||||
* @param download download object containing download information
|
||||
*/
|
||||
private fun onComplete(download: Download?) {
|
||||
// Create notification.
|
||||
with(notificationBuilder) {
|
||||
setContentTitle(download?.chapter?.name ?: context.getString(R.string.app_name))
|
||||
setContentText(context.getString(R.string.update_check_notification_download_complete))
|
||||
setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||
setProgress(0, 0, false)
|
||||
if (showNotification) {
|
||||
// Create notification.
|
||||
with(notificationBuilder) {
|
||||
setContentTitle(download?.chapter?.name ?: context.getString(R.string.app_name))
|
||||
setContentText(context.getString(R.string.update_check_notification_download_complete))
|
||||
setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||
setProgress(0, 0, false)
|
||||
}
|
||||
|
||||
// Show notification.
|
||||
context.notificationManager.notify(notificationId, notificationBuilder.build())
|
||||
}
|
||||
|
||||
// Show notification.
|
||||
context.notificationManager.notify(notificationId, notificationBuilder.build())
|
||||
|
||||
// Reset initial values
|
||||
isDownloading = false
|
||||
initialQueueSize = 0
|
||||
@@ -158,14 +163,17 @@ class DownloadNotifier(private val context: Context) {
|
||||
*/
|
||||
internal fun onError(error: String? = null, chapter: String? = null) {
|
||||
// Create notification
|
||||
with(notificationBuilder) {
|
||||
setContentTitle(chapter ?: context.getString(R.string.download_notifier_title_error))
|
||||
setContentText(error ?: context.getString(R.string.download_notifier_unkown_error))
|
||||
setSmallIcon(android.R.drawable.stat_sys_warning)
|
||||
setProgress(0, 0, false)
|
||||
if (showNotification) {
|
||||
with(notificationBuilder) {
|
||||
setContentTitle(chapter ?: context.getString(R.string.download_notifier_title_error))
|
||||
setContentText(error ?: context.getString(R.string.download_notifier_unkown_error))
|
||||
setSmallIcon(android.R.drawable.stat_sys_warning)
|
||||
setProgress(0, 0, false)
|
||||
}
|
||||
context.notificationManager.notify(Constants.NOTIFICATION_DOWNLOAD_CHAPTER_ERROR_ID, notificationBuilder.build())
|
||||
} else {
|
||||
context.toast(error ?: context.getString(R.string.download_notifier_unkown_error))
|
||||
}
|
||||
context.notificationManager.notify(Constants.NOTIFICATION_DOWNLOAD_CHAPTER_ERROR_ID, notificationBuilder.build())
|
||||
|
||||
// Reset download information
|
||||
onClear()
|
||||
isDownloading = false
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package eu.kanade.tachiyomi.data.download
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.support.v4.app.NotificationCompat
|
||||
import eu.kanade.tachiyomi.Constants
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.util.decodeSampledBitmap
|
||||
import eu.kanade.tachiyomi.util.notificationManager
|
||||
import java.io.File
|
||||
|
||||
@@ -52,9 +51,9 @@ class ImageNotifier(private val context: Context) {
|
||||
|
||||
/**
|
||||
* Called when image download is complete
|
||||
* @param bitmap image file containing downloaded page image
|
||||
* @param file image file containing downloaded page image
|
||||
*/
|
||||
fun onComplete(bitmap: Bitmap, file: File) {
|
||||
fun onComplete(file: File) {
|
||||
with(notificationBuilder) {
|
||||
if (isDownloading) {
|
||||
setProgress(0, 0, false)
|
||||
@@ -62,8 +61,8 @@ class ImageNotifier(private val context: Context) {
|
||||
}
|
||||
setContentTitle(context.getString(R.string.picture_saved))
|
||||
setSmallIcon(R.drawable.ic_insert_photo_black_24dp)
|
||||
setLargeIcon(bitmap)
|
||||
setStyle(NotificationCompat.BigPictureStyle().bigPicture(bitmap))
|
||||
setLargeIcon(file.decodeSampledBitmap(100, 100))
|
||||
setStyle(NotificationCompat.BigPictureStyle().bigPicture(file.decodeSampledBitmap(1024, 1024)))
|
||||
setAutoCancel(true)
|
||||
|
||||
// Clear old actions if they exist
|
||||
@@ -84,10 +83,6 @@ class ImageNotifier(private val context: Context) {
|
||||
context.notificationManager.notify(notificationId, notificationBuilder.build())
|
||||
}
|
||||
|
||||
fun onComplete(file: File) {
|
||||
onComplete(convertToBitmap(file), file)
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the notification message
|
||||
*/
|
||||
@@ -112,13 +107,4 @@ class ImageNotifier(private val context: Context) {
|
||||
isDownloading = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts file to bitmap
|
||||
*/
|
||||
fun convertToBitmap(image: File): Bitmap {
|
||||
val options = BitmapFactory.Options()
|
||||
options.inPreferredConfig = Bitmap.Config.ARGB_8888
|
||||
return BitmapFactory.decodeFile(image.absolutePath, options)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,10 @@ class PreferenceKeys(context: Context) {
|
||||
|
||||
val removeAfterMarkedAsRead = context.getString(R.string.pref_remove_after_marked_as_read_key)
|
||||
|
||||
val showMangaDownloadNotification = context.getString(R.string.pref_notifications_manga_download_key)
|
||||
|
||||
val showSavePageNotification = context.getString(R.string.pref_notifications_single_page_key)
|
||||
|
||||
val libraryUpdateInterval = context.getString(R.string.pref_library_update_interval_key)
|
||||
|
||||
val libraryUpdateRestriction = context.getString(R.string.pref_library_update_restriction_key)
|
||||
|
||||
@@ -122,6 +122,10 @@ class PreferencesHelper(context: Context) {
|
||||
|
||||
fun removeAfterMarkedAsRead() = prefs.getBoolean(keys.removeAfterMarkedAsRead, false)
|
||||
|
||||
fun showMangaDownloadNotification() = rxPrefs.getBoolean(keys.showMangaDownloadNotification, true)
|
||||
|
||||
fun showSavePageNotification() = prefs.getBoolean(keys.showSavePageNotification, false)
|
||||
|
||||
fun libraryUpdateInterval() = rxPrefs.getInteger(keys.libraryUpdateInterval, 0)
|
||||
|
||||
fun libraryUpdateRestriction() = prefs.getStringSet(keys.libraryUpdateRestriction, emptySet())
|
||||
|
||||
Reference in New Issue
Block a user