@ -1,132 +0,0 @@
|
|||||||
package eu.kanade.tachiyomi.data.download
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
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.R
|
|
||||||
import eu.kanade.tachiyomi.util.notificationManager
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
|
|
||||||
class ImageNotifier(private val context: Context) {
|
|
||||||
/**
|
|
||||||
* Notification builder.
|
|
||||||
*/
|
|
||||||
private val notificationBuilder = NotificationCompat.Builder(context)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Id of the notification.
|
|
||||||
*/
|
|
||||||
private val notificationId: Int
|
|
||||||
get() = Constants.NOTIFICATION_DOWNLOAD_IMAGE_ID
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Status of download. Used for correct notification icon.
|
|
||||||
*/
|
|
||||||
private var isDownloading = false
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when download progress changes.
|
|
||||||
* @param progress progress value in range [0,100]
|
|
||||||
*/
|
|
||||||
fun onProgressChange(progress: Int) {
|
|
||||||
with(notificationBuilder) {
|
|
||||||
if (!isDownloading) {
|
|
||||||
setContentTitle(context.getString(R.string.saving_picture))
|
|
||||||
setSmallIcon(android.R.drawable.stat_sys_download)
|
|
||||||
setLargeIcon(null)
|
|
||||||
setStyle(null)
|
|
||||||
// Clear old actions if they exist
|
|
||||||
if (!mActions.isEmpty())
|
|
||||||
mActions.clear()
|
|
||||||
isDownloading = true
|
|
||||||
}
|
|
||||||
|
|
||||||
setProgress(100, progress, false)
|
|
||||||
}
|
|
||||||
// Displays the progress bar on notification
|
|
||||||
context.notificationManager.notify(notificationId, notificationBuilder.build())
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when image download is complete
|
|
||||||
* @param file image file containing downloaded page image
|
|
||||||
*/
|
|
||||||
fun onComplete(file: File) {
|
|
||||||
with(notificationBuilder) {
|
|
||||||
if (isDownloading) {
|
|
||||||
setProgress(0, 0, false)
|
|
||||||
isDownloading = false
|
|
||||||
}
|
|
||||||
setContentTitle(context.getString(R.string.picture_saved))
|
|
||||||
setSmallIcon(R.drawable.ic_insert_photo_black_24dp)
|
|
||||||
Glide.with(context).load(file).asBitmap().into(object : SimpleTarget<Bitmap>(96, 96) {
|
|
||||||
/**
|
|
||||||
* 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>(720, 1280) {
|
|
||||||
/**
|
|
||||||
* 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)
|
|
||||||
|
|
||||||
// Clear old actions if they exist
|
|
||||||
if (!mActions.isEmpty())
|
|
||||||
mActions.clear()
|
|
||||||
|
|
||||||
setContentIntent(ImageNotificationReceiver.showImageIntent(context, file.absolutePath))
|
|
||||||
// Share action
|
|
||||||
addAction(R.drawable.ic_share_white_24dp,
|
|
||||||
context.getString(R.string.action_share),
|
|
||||||
ImageNotificationReceiver.shareImageIntent(context, file.absolutePath, notificationId))
|
|
||||||
// Delete action
|
|
||||||
addAction(R.drawable.ic_delete_white_24dp,
|
|
||||||
context.getString(R.string.action_delete),
|
|
||||||
ImageNotificationReceiver.deleteImageIntent(context, file.absolutePath, notificationId))
|
|
||||||
}
|
|
||||||
// Displays the progress bar on notification
|
|
||||||
context.notificationManager.notify(notificationId, notificationBuilder.build())
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears the notification message
|
|
||||||
*/
|
|
||||||
internal fun onClear() {
|
|
||||||
context.notificationManager.cancel(notificationId)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called on error while downloading image
|
|
||||||
* @param error string containing error information
|
|
||||||
*/
|
|
||||||
internal fun onError(error: String?) {
|
|
||||||
// Create notification
|
|
||||||
with(notificationBuilder) {
|
|
||||||
setContentTitle(context.getString(R.string.download_notifier_title_error))
|
|
||||||
setContentText(error ?: context.getString(R.string.download_notifier_unkown_error))
|
|
||||||
setSmallIcon(android.R.drawable.ic_menu_report_image)
|
|
||||||
setProgress(0, 0, false)
|
|
||||||
}
|
|
||||||
context.notificationManager.notify(notificationId, notificationBuilder.build())
|
|
||||||
isDownloading = false
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,93 @@
|
|||||||
|
package eu.kanade.tachiyomi.ui.reader.notification
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.support.v4.app.NotificationCompat
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||||
|
import com.bumptech.glide.request.animation.GlideAnimation
|
||||||
|
import com.bumptech.glide.request.target.SimpleTarget
|
||||||
|
import eu.kanade.tachiyomi.Constants
|
||||||
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.util.notificationManager
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class used to show BigPictureStyle notifications
|
||||||
|
*/
|
||||||
|
class ImageNotifier(private val context: Context) {
|
||||||
|
/**
|
||||||
|
* Notification builder.
|
||||||
|
*/
|
||||||
|
private val notificationBuilder = NotificationCompat.Builder(context)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Id of the notification.
|
||||||
|
*/
|
||||||
|
private val notificationId: Int
|
||||||
|
get() = Constants.NOTIFICATION_DOWNLOAD_IMAGE_ID
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when image download/copy is complete
|
||||||
|
* @param file image file containing downloaded page image
|
||||||
|
*/
|
||||||
|
fun onComplete(file: File) {
|
||||||
|
with(notificationBuilder) {
|
||||||
|
Glide.with(context).load(file).asBitmap().diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(object : SimpleTarget<Bitmap>(720, 1280) {
|
||||||
|
/**
|
||||||
|
* 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>?) {
|
||||||
|
setContentTitle(context.getString(R.string.picture_saved))
|
||||||
|
setSmallIcon(R.drawable.ic_insert_photo_white_24dp)
|
||||||
|
setStyle(NotificationCompat.BigPictureStyle().bigPicture(resource))
|
||||||
|
setLargeIcon(resource)
|
||||||
|
setAutoCancel(true)
|
||||||
|
// Clear old actions if they exist
|
||||||
|
if (!mActions.isEmpty())
|
||||||
|
mActions.clear()
|
||||||
|
|
||||||
|
setContentIntent(ImageNotificationReceiver.showImageIntent(context, file.absolutePath))
|
||||||
|
// Share action
|
||||||
|
addAction(R.drawable.ic_share_grey_24dp,
|
||||||
|
context.getString(R.string.action_share),
|
||||||
|
ImageNotificationReceiver.shareImageIntent(context, file.absolutePath, notificationId))
|
||||||
|
// Delete action
|
||||||
|
addAction(R.drawable.ic_delete_grey_24dp,
|
||||||
|
context.getString(R.string.action_delete),
|
||||||
|
ImageNotificationReceiver.deleteImageIntent(context, file.absolutePath, notificationId))
|
||||||
|
updateNotification()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the notification message
|
||||||
|
*/
|
||||||
|
fun onClear() {
|
||||||
|
context.notificationManager.cancel(notificationId)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateNotification() {
|
||||||
|
// Displays the progress bar on notification
|
||||||
|
context.notificationManager.notify(notificationId, notificationBuilder.build())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on error while downloading image
|
||||||
|
* @param error string containing error information
|
||||||
|
*/
|
||||||
|
fun onError(error: String?) {
|
||||||
|
// Create notification
|
||||||
|
with(notificationBuilder) {
|
||||||
|
setContentTitle(context.getString(R.string.download_notifier_title_error))
|
||||||
|
setContentText(error ?: context.getString(R.string.unknown_error))
|
||||||
|
setSmallIcon(android.R.drawable.ic_menu_report_image)
|
||||||
|
}
|
||||||
|
updateNotification()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
After Width: | Height: | Size: 485 B |
After Width: | Height: | Size: 247 B |
After Width: | Height: | Size: 928 B |
After Width: | Height: | Size: 367 B |
After Width: | Height: | Size: 185 B |
After Width: | Height: | Size: 554 B |
After Width: | Height: | Size: 594 B |
After Width: | Height: | Size: 304 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 695 B |
After Width: | Height: | Size: 450 B |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 570 B |
After Width: | Height: | Size: 2.7 KiB |
@ -1,9 +0,0 @@
|
|||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="24dp"
|
|
||||||
android:height="24dp"
|
|
||||||
android:viewportHeight="24.0"
|
|
||||||
android:viewportWidth="24.0">
|
|
||||||
<path
|
|
||||||
android:fillColor="#FF000000"
|
|
||||||
android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z" />
|
|
||||||
</vector>
|
|
After Width: | Height: | Size: 185 B |