mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 01:11:48 +01:00
Now uses glide for notification
This commit is contained in:
parent
4975787afa
commit
414b8c9f21
@ -47,8 +47,6 @@ class DownloadManager(
|
|||||||
private val threadsSubject = BehaviorSubject.create<Int>()
|
private val threadsSubject = BehaviorSubject.create<Int>()
|
||||||
private var threadsSubscription: Subscription? = null
|
private var threadsSubscription: Subscription? = null
|
||||||
|
|
||||||
private var notificationSubscription: Subscription? = null
|
|
||||||
|
|
||||||
val queue = DownloadQueue()
|
val queue = DownloadQueue()
|
||||||
|
|
||||||
val imageFilenameRegex = "[^\\sa-zA-Z0-9.-]".toRegex()
|
val imageFilenameRegex = "[^\\sa-zA-Z0-9.-]".toRegex()
|
||||||
@ -68,12 +66,6 @@ class DownloadManager(
|
|||||||
downloadNotifier.multipleDownloadThreads = it > 1
|
downloadNotifier.multipleDownloadThreads = it > 1
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationSubscription = preferences.showMangaDownloadNotification().asObservable()
|
|
||||||
.subscribe {
|
|
||||||
downloadNotifier.onClear()
|
|
||||||
downloadNotifier.showNotification = it
|
|
||||||
}
|
|
||||||
|
|
||||||
downloadsSubscription = downloadsQueueSubject.flatMap { Observable.from(it) }
|
downloadsSubscription = downloadsQueueSubject.flatMap { Observable.from(it) }
|
||||||
.lift(DynamicConcurrentMergeOperator<Download, Download>({ downloadChapter(it) }, threadsSubject))
|
.lift(DynamicConcurrentMergeOperator<Download, Download>({ downloadChapter(it) }, threadsSubject))
|
||||||
.onBackpressureBuffer()
|
.onBackpressureBuffer()
|
||||||
@ -115,10 +107,6 @@ class DownloadManager(
|
|||||||
threadsSubscription?.unsubscribe()
|
threadsSubscription?.unsubscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notificationSubscription != null) {
|
|
||||||
notificationSubscription?.unsubscribe()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a download object for every chapter and add them to the downloads queue
|
// Create a download object for every chapter and add them to the downloads queue
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package eu.kanade.tachiyomi.data.download
|
package eu.kanade.tachiyomi.data.download
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.graphics.Bitmap
|
||||||
import android.support.v4.app.NotificationCompat
|
import android.support.v4.app.NotificationCompat
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
|
import com.bumptech.glide.request.animation.GlideAnimation
|
||||||
|
import com.bumptech.glide.request.target.SimpleTarget
|
||||||
import eu.kanade.tachiyomi.Constants
|
import eu.kanade.tachiyomi.Constants
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.util.decodeSampledBitmap
|
|
||||||
import eu.kanade.tachiyomi.util.notificationManager
|
import eu.kanade.tachiyomi.util.notificationManager
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@ -61,8 +64,27 @@ class ImageNotifier(private val context: Context) {
|
|||||||
}
|
}
|
||||||
setContentTitle(context.getString(R.string.picture_saved))
|
setContentTitle(context.getString(R.string.picture_saved))
|
||||||
setSmallIcon(R.drawable.ic_insert_photo_black_24dp)
|
setSmallIcon(R.drawable.ic_insert_photo_black_24dp)
|
||||||
setLargeIcon(file.decodeSampledBitmap(100, 100))
|
Glide.with(context).load(file).asBitmap().into(object : SimpleTarget<Bitmap>(100, 100) {
|
||||||
setStyle(NotificationCompat.BigPictureStyle().bigPicture(file.decodeSampledBitmap(1024, 1024)))
|
/**
|
||||||
|
* The method that will be called when the resource load has finished.
|
||||||
|
* @param resource the loaded resource.
|
||||||
|
*/
|
||||||
|
override fun onResourceReady(resource: Bitmap?, glideAnimation: GlideAnimation<in Bitmap>?) {
|
||||||
|
setLargeIcon(resource)
|
||||||
|
context.notificationManager.notify(notificationId, notificationBuilder.build())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Glide.with(context).load(file).asBitmap().into(object : SimpleTarget<Bitmap>(512, 384) {
|
||||||
|
/**
|
||||||
|
* The method that will be called when the resource load has finished.
|
||||||
|
* @param resource the loaded resource.
|
||||||
|
*/
|
||||||
|
override fun onResourceReady(resource: Bitmap?, glideAnimation: GlideAnimation<in Bitmap>?) {
|
||||||
|
setStyle(NotificationCompat.BigPictureStyle().bigPicture(resource))
|
||||||
|
context.notificationManager.notify(notificationId, notificationBuilder.build())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
setAutoCancel(true)
|
setAutoCancel(true)
|
||||||
|
|
||||||
// Clear old actions if they exist
|
// Clear old actions if they exist
|
||||||
|
@ -72,10 +72,6 @@ class PreferenceKeys(context: Context) {
|
|||||||
|
|
||||||
val removeAfterMarkedAsRead = context.getString(R.string.pref_remove_after_marked_as_read_key)
|
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 libraryUpdateInterval = context.getString(R.string.pref_library_update_interval_key)
|
||||||
|
|
||||||
val libraryUpdateRestriction = context.getString(R.string.pref_library_update_restriction_key)
|
val libraryUpdateRestriction = context.getString(R.string.pref_library_update_restriction_key)
|
||||||
|
@ -122,10 +122,6 @@ class PreferencesHelper(context: Context) {
|
|||||||
|
|
||||||
fun removeAfterMarkedAsRead() = prefs.getBoolean(keys.removeAfterMarkedAsRead, false)
|
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 libraryUpdateInterval() = rxPrefs.getInteger(keys.libraryUpdateInterval, 0)
|
||||||
|
|
||||||
fun libraryUpdateRestriction() = prefs.getStringSet(keys.libraryUpdateRestriction, emptySet())
|
fun libraryUpdateRestriction() = prefs.getStringSet(keys.libraryUpdateRestriction, emptySet())
|
||||||
|
@ -610,10 +610,7 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
|||||||
|
|
||||||
//Check if file doesn't already exist
|
//Check if file doesn't already exist
|
||||||
if (destFile.exists()) {
|
if (destFile.exists()) {
|
||||||
if (prefs.showSavePageNotification())
|
|
||||||
imageNotifier.onComplete(destFile)
|
imageNotifier.onComplete(destFile)
|
||||||
else
|
|
||||||
context.toast(context.getString(R.string.page_downloaded, destFile.path))
|
|
||||||
} else {
|
} else {
|
||||||
if (inputFile.exists()) {
|
if (inputFile.exists()) {
|
||||||
// Copy file
|
// Copy file
|
||||||
@ -624,10 +621,7 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
|
|||||||
{ imageNotifier.onComplete(it) },
|
{ imageNotifier.onComplete(it) },
|
||||||
{ error ->
|
{ error ->
|
||||||
Timber.e(error.message)
|
Timber.e(error.message)
|
||||||
if (prefs.showSavePageNotification())
|
|
||||||
imageNotifier.onError(error.message)
|
imageNotifier.onError(error.message)
|
||||||
else
|
|
||||||
context.toast(error.message)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
package eu.kanade.tachiyomi.util
|
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.BitmapFactory
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
fun File.decodeSampledBitmap(reqWidth: Int, reqHeight: Int): Bitmap {
|
|
||||||
// First decode with inJustDecodeBounds=true to check dimensions
|
|
||||||
val options = BitmapFactory.Options()
|
|
||||||
options.inJustDecodeBounds = true
|
|
||||||
BitmapFactory.decodeFile(this.absolutePath, options)
|
|
||||||
|
|
||||||
// Calculate inSampleSize
|
|
||||||
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight)
|
|
||||||
|
|
||||||
// Decode bitmap with inSampleSize set
|
|
||||||
options.inJustDecodeBounds = false;
|
|
||||||
return BitmapFactory.decodeFile(this.absolutePath, options)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun calculateInSampleSize(options: BitmapFactory.Options, reqWidth: Int, reqHeight: Int): Int {
|
|
||||||
// Raw height and width of image
|
|
||||||
val height = options.outHeight
|
|
||||||
val width = options.outWidth
|
|
||||||
var inSampleSize = 1
|
|
||||||
|
|
||||||
if (height > reqHeight || width > reqWidth) {
|
|
||||||
|
|
||||||
val halfHeight = height / 2
|
|
||||||
val halfWidth = width / 2
|
|
||||||
|
|
||||||
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
|
|
||||||
// height and width larger than the requested height and width.
|
|
||||||
while (halfHeight / inSampleSize >= reqHeight && halfWidth / inSampleSize >= reqWidth) {
|
|
||||||
inSampleSize *= 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return inSampleSize
|
|
||||||
}
|
|
@ -176,8 +176,8 @@
|
|||||||
|
|
||||||
<string-array name="reader_image_options">
|
<string-array name="reader_image_options">
|
||||||
<item>@string/set_as_cover</item>
|
<item>@string/set_as_cover</item>
|
||||||
<item>@string/share_image</item>
|
<item>@string/action_share</item>
|
||||||
<item>@string/save_image</item>
|
<item>@string/action_save</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="reader_image_options_values">
|
<string-array name="reader_image_options_values">
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
<string name="action_sort">Sort</string>
|
<string name="action_sort">Sort</string>
|
||||||
<string name="action_install">Install</string>
|
<string name="action_install">Install</string>
|
||||||
<string name="action_share">Share</string>
|
<string name="action_share">Share</string>
|
||||||
|
<string name="action_save">Save</string>
|
||||||
|
|
||||||
<!-- Operations -->
|
<!-- Operations -->
|
||||||
<string name="deleting">Deleting…</string>
|
<string name="deleting">Deleting…</string>
|
||||||
@ -282,8 +283,6 @@
|
|||||||
<!-- Reader activity -->
|
<!-- Reader activity -->
|
||||||
<string name="custom_filter">Custom filter</string>
|
<string name="custom_filter">Custom filter</string>
|
||||||
<string name="set_as_cover">Set as cover</string>
|
<string name="set_as_cover">Set as cover</string>
|
||||||
<string name="share_image">Share image</string>
|
|
||||||
<string name="save_image">Save image</string>
|
|
||||||
<string name="cover_updated">Cover updated</string>
|
<string name="cover_updated">Cover updated</string>
|
||||||
<string name="page_downloaded">Page copied to %1$s</string>
|
<string name="page_downloaded">Page copied to %1$s</string>
|
||||||
<string name="downloading">Downloading…</string>
|
<string name="downloading">Downloading…</string>
|
||||||
|
@ -40,21 +40,6 @@
|
|||||||
android:summary="%s"
|
android:summary="%s"
|
||||||
android:title="@string/pref_remove_after_read" />
|
android:title="@string/pref_remove_after_read" />
|
||||||
|
|
||||||
<PreferenceCategory
|
|
||||||
android:persistent="false"
|
|
||||||
android:title="@string/pref_notifications" />
|
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:defaultValue="true"
|
|
||||||
android:key="@string/pref_notifications_manga_download_key"
|
|
||||||
android:title="@string/pref_notifications_manga_download" />
|
|
||||||
|
|
||||||
<SwitchPreference
|
|
||||||
android:defaultValue="false"
|
|
||||||
android:key="@string/pref_notifications_single_page_key"
|
|
||||||
android:title="@string/pref_notifications_single_page" />
|
|
||||||
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user