Fix sharing saved pages from notification
Related to #8327 Deleting doesn't seem to do anything still, but at least doesn't throw an exception. Also removed behavior of dismissing notification after sharing/deleting pages/backups in case you want to do something again afterwards. Users can manually dismiss the notification whenever they want.
This commit is contained in:
parent
427fbfdf5e
commit
1f259f9298
@ -79,11 +79,7 @@ class BackupNotifier(private val context: Context) {
|
|||||||
addAction(
|
addAction(
|
||||||
R.drawable.ic_share_24dp,
|
R.drawable.ic_share_24dp,
|
||||||
context.stringResource(MR.strings.action_share),
|
context.stringResource(MR.strings.action_share),
|
||||||
NotificationReceiver.shareBackupPendingBroadcast(
|
NotificationReceiver.shareBackupPendingBroadcast(context, unifile.uri),
|
||||||
context,
|
|
||||||
unifile.uri,
|
|
||||||
Notifications.ID_BACKUP_COMPLETE,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
show(Notifications.ID_BACKUP_COMPLETE)
|
show(Notifications.ID_BACKUP_COMPLETE)
|
||||||
|
@ -7,6 +7,7 @@ import android.content.Intent
|
|||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
|
import com.hippo.unifile.UniFile
|
||||||
import eu.kanade.tachiyomi.data.backup.BackupRestoreJob
|
import eu.kanade.tachiyomi.data.backup.BackupRestoreJob
|
||||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
||||||
@ -14,7 +15,6 @@ import eu.kanade.tachiyomi.data.updater.AppUpdateDownloadJob
|
|||||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||||
import eu.kanade.tachiyomi.util.storage.DiskUtil
|
import eu.kanade.tachiyomi.util.storage.DiskUtil
|
||||||
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
|
||||||
import eu.kanade.tachiyomi.util.system.cancelNotification
|
import eu.kanade.tachiyomi.util.system.cancelNotification
|
||||||
import eu.kanade.tachiyomi.util.system.getParcelableExtraCompat
|
import eu.kanade.tachiyomi.util.system.getParcelableExtraCompat
|
||||||
import eu.kanade.tachiyomi.util.system.notificationManager
|
import eu.kanade.tachiyomi.util.system.notificationManager
|
||||||
@ -35,7 +35,6 @@ import tachiyomi.i18n.MR
|
|||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.io.File
|
|
||||||
import eu.kanade.tachiyomi.BuildConfig.APPLICATION_ID as ID
|
import eu.kanade.tachiyomi.BuildConfig.APPLICATION_ID as ID
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,15 +63,13 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
ACTION_SHARE_IMAGE ->
|
ACTION_SHARE_IMAGE ->
|
||||||
shareImage(
|
shareImage(
|
||||||
context,
|
context,
|
||||||
intent.getStringExtra(EXTRA_FILE_LOCATION)!!,
|
intent.getStringExtra(EXTRA_URI)!!.toUri(),
|
||||||
intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1),
|
|
||||||
)
|
)
|
||||||
// Delete image from path and dismiss notification
|
// Delete image from path and dismiss notification
|
||||||
ACTION_DELETE_IMAGE ->
|
ACTION_DELETE_IMAGE ->
|
||||||
deleteImage(
|
deleteImage(
|
||||||
context,
|
context,
|
||||||
intent.getStringExtra(EXTRA_FILE_LOCATION)!!,
|
intent.getStringExtra(EXTRA_URI)!!.toUri(),
|
||||||
intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1),
|
|
||||||
)
|
)
|
||||||
// Share backup file
|
// Share backup file
|
||||||
ACTION_SHARE_BACKUP ->
|
ACTION_SHARE_BACKUP ->
|
||||||
@ -80,7 +77,6 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
context,
|
context,
|
||||||
intent.getParcelableExtraCompat(EXTRA_URI)!!,
|
intent.getParcelableExtraCompat(EXTRA_URI)!!,
|
||||||
"application/x-protobuf+gzip",
|
"application/x-protobuf+gzip",
|
||||||
intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1),
|
|
||||||
)
|
)
|
||||||
ACTION_CANCEL_RESTORE -> cancelRestore(context)
|
ACTION_CANCEL_RESTORE -> cancelRestore(context)
|
||||||
// Cancel library update and dismiss notification
|
// Cancel library update and dismiss notification
|
||||||
@ -137,12 +133,10 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
* Called to start share intent to share image
|
* Called to start share intent to share image
|
||||||
*
|
*
|
||||||
* @param context context of application
|
* @param context context of application
|
||||||
* @param path path of file
|
* @param uri path of file
|
||||||
* @param notificationId id of notification
|
|
||||||
*/
|
*/
|
||||||
private fun shareImage(context: Context, path: String, notificationId: Int) {
|
private fun shareImage(context: Context, uri: Uri) {
|
||||||
dismissNotification(context, notificationId)
|
context.startActivity(uri.toShareIntent(context))
|
||||||
context.startActivity(File(path).getUriCompat(context).toShareIntent(context))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -150,10 +144,8 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
*
|
*
|
||||||
* @param context context of application
|
* @param context context of application
|
||||||
* @param path path of file
|
* @param path path of file
|
||||||
* @param notificationId id of notification
|
|
||||||
*/
|
*/
|
||||||
private fun shareFile(context: Context, uri: Uri, fileMimeType: String, notificationId: Int) {
|
private fun shareFile(context: Context, uri: Uri, fileMimeType: String) {
|
||||||
dismissNotification(context, notificationId)
|
|
||||||
context.startActivity(uri.toShareIntent(context, fileMimeType))
|
context.startActivity(uri.toShareIntent(context, fileMimeType))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,17 +172,11 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
/**
|
/**
|
||||||
* Called to delete image
|
* Called to delete image
|
||||||
*
|
*
|
||||||
* @param path path of file
|
* @param uri path of file
|
||||||
* @param notificationId id of notification
|
|
||||||
*/
|
*/
|
||||||
private fun deleteImage(context: Context, path: String, notificationId: Int) {
|
private fun deleteImage(context: Context, uri: Uri) {
|
||||||
dismissNotification(context, notificationId)
|
UniFile.fromUri(context, uri)?.delete()
|
||||||
|
DiskUtil.scanMedia(context, uri)
|
||||||
// Delete file
|
|
||||||
val file = File(path)
|
|
||||||
file.delete()
|
|
||||||
|
|
||||||
DiskUtil.scanMedia(context, file.toUri())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -409,18 +395,17 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns [PendingIntent] that starts a service which cancels the notification and starts a share activity
|
* Returns [PendingIntent] that starts a share activity
|
||||||
*
|
*
|
||||||
* @param context context of application
|
* @param context context of application
|
||||||
* @param path location path of file
|
* @param uri location path of file
|
||||||
* @param notificationId id of notification
|
* @param notificationId id of notification
|
||||||
* @return [PendingIntent]
|
* @return [PendingIntent]
|
||||||
*/
|
*/
|
||||||
internal fun shareImagePendingBroadcast(context: Context, path: String, notificationId: Int): PendingIntent {
|
internal fun shareImagePendingBroadcast(context: Context, uri: Uri): PendingIntent {
|
||||||
val intent = Intent(context, NotificationReceiver::class.java).apply {
|
val intent = Intent(context, NotificationReceiver::class.java).apply {
|
||||||
action = ACTION_SHARE_IMAGE
|
action = ACTION_SHARE_IMAGE
|
||||||
putExtra(EXTRA_FILE_LOCATION, path)
|
putExtra(EXTRA_URI, uri.toString())
|
||||||
putExtra(EXTRA_NOTIFICATION_ID, notificationId)
|
|
||||||
}
|
}
|
||||||
return PendingIntent.getBroadcast(
|
return PendingIntent.getBroadcast(
|
||||||
context,
|
context,
|
||||||
@ -434,15 +419,13 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
* Returns [PendingIntent] that starts a service which removes an image from disk
|
* Returns [PendingIntent] that starts a service which removes an image from disk
|
||||||
*
|
*
|
||||||
* @param context context of application
|
* @param context context of application
|
||||||
* @param path location path of file
|
* @param uri location path of file
|
||||||
* @param notificationId id of notification
|
|
||||||
* @return [PendingIntent]
|
* @return [PendingIntent]
|
||||||
*/
|
*/
|
||||||
internal fun deleteImagePendingBroadcast(context: Context, path: String, notificationId: Int): PendingIntent {
|
internal fun deleteImagePendingBroadcast(context: Context, uri: Uri): PendingIntent {
|
||||||
val intent = Intent(context, NotificationReceiver::class.java).apply {
|
val intent = Intent(context, NotificationReceiver::class.java).apply {
|
||||||
action = ACTION_DELETE_IMAGE
|
action = ACTION_DELETE_IMAGE
|
||||||
putExtra(EXTRA_FILE_LOCATION, path)
|
putExtra(EXTRA_URI, uri.toString())
|
||||||
putExtra(EXTRA_NOTIFICATION_ID, notificationId)
|
|
||||||
}
|
}
|
||||||
return PendingIntent.getBroadcast(
|
return PendingIntent.getBroadcast(
|
||||||
context,
|
context,
|
||||||
@ -625,14 +608,12 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
*
|
*
|
||||||
* @param context context of application
|
* @param context context of application
|
||||||
* @param uri uri of backup file
|
* @param uri uri of backup file
|
||||||
* @param notificationId id of notification
|
|
||||||
* @return [PendingIntent]
|
* @return [PendingIntent]
|
||||||
*/
|
*/
|
||||||
internal fun shareBackupPendingBroadcast(context: Context, uri: Uri, notificationId: Int): PendingIntent {
|
internal fun shareBackupPendingBroadcast(context: Context, uri: Uri): PendingIntent {
|
||||||
val intent = Intent(context, NotificationReceiver::class.java).apply {
|
val intent = Intent(context, NotificationReceiver::class.java).apply {
|
||||||
action = ACTION_SHARE_BACKUP
|
action = ACTION_SHARE_BACKUP
|
||||||
putExtra(EXTRA_URI, uri)
|
putExtra(EXTRA_URI, uri)
|
||||||
putExtra(EXTRA_NOTIFICATION_ID, notificationId)
|
|
||||||
}
|
}
|
||||||
return PendingIntent.getBroadcast(
|
return PendingIntent.getBroadcast(
|
||||||
context,
|
context,
|
||||||
|
@ -81,13 +81,13 @@ class SaveImageNotifier(private val context: Context) {
|
|||||||
addAction(
|
addAction(
|
||||||
R.drawable.ic_share_24dp,
|
R.drawable.ic_share_24dp,
|
||||||
context.stringResource(MR.strings.action_share),
|
context.stringResource(MR.strings.action_share),
|
||||||
NotificationReceiver.shareImagePendingBroadcast(context, uri.path!!, notificationId),
|
NotificationReceiver.shareImagePendingBroadcast(context, uri),
|
||||||
)
|
)
|
||||||
// Delete action
|
// Delete action
|
||||||
addAction(
|
addAction(
|
||||||
R.drawable.ic_delete_24dp,
|
R.drawable.ic_delete_24dp,
|
||||||
context.stringResource(MR.strings.action_delete),
|
context.stringResource(MR.strings.action_delete),
|
||||||
NotificationReceiver.deleteImagePendingBroadcast(context, uri.path!!, notificationId),
|
NotificationReceiver.deleteImagePendingBroadcast(context, uri),
|
||||||
)
|
)
|
||||||
|
|
||||||
updateNotification()
|
updateNotification()
|
||||||
|
Loading…
Reference in New Issue
Block a user