Move restore progress dialog to notification

This commit is contained in:
arkon
2020-04-21 21:53:15 -04:00
parent fc2c465bac
commit f69f78db34
6 changed files with 68 additions and 69 deletions
@@ -58,20 +58,10 @@ import uy.kohesive.injekt.injectLazy
class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
/**
* Database.
*/
internal val databaseHelper: DatabaseHelper by injectLazy()
/**
* Source manager.
*/
internal val sourceManager: SourceManager by injectLazy()
/**
* Tracking manager
*/
internal val trackManager: TrackManager by injectLazy()
private val preferences: PreferencesHelper by injectLazy()
/**
* Version of parser
@@ -84,11 +74,6 @@ class BackupManager(val context: Context, version: Int = CURRENT_VERSION) {
*/
var parser: Gson = initParser()
/**
* Preferences
*/
private val preferences: PreferencesHelper by injectLazy()
/**
* Set version of parser
*
@@ -81,6 +81,12 @@ class BackupRestoreService : Service() {
*/
fun stop(context: Context) {
context.stopService(Intent(context, BackupRestoreService::class.java))
val errorIntent = Intent(BackupConst.INTENT_FILTER).apply {
putExtra(BackupConst.ACTION, BackupConst.ACTION_RESTORE_ERROR)
putExtra(BackupConst.EXTRA_ERROR_MESSAGE, context.getString(R.string.restoring_backup_canceled))
}
context.sendLocalBroadcast(errorIntent)
}
}
@@ -456,7 +462,7 @@ class BackupRestoreService : Service() {
amount: Int,
title: String,
errors: Int,
content: String = getString(R.string.dialog_restoring_backup, title.chop(15))
content: String = title.chop(30)
) {
val intent = Intent(BackupConst.INTENT_FILTER).apply {
putExtra(BackupConst.EXTRA_PROGRESS, progress)
@@ -9,6 +9,7 @@ import android.os.Build
import android.os.Handler
import eu.kanade.tachiyomi.BuildConfig.APPLICATION_ID as ID
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.backup.BackupRestoreService
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga
@@ -61,6 +62,8 @@ class NotificationReceiver : BroadcastReceiver() {
// Share backup file
ACTION_SHARE_BACKUP -> shareBackup(context, intent.getParcelableExtra(EXTRA_URI),
intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1))
ACTION_CANCEL_RESTORE -> cancelRestore(context,
intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1))
// Cancel library update and dismiss notification
ACTION_CANCEL_LIBRARY_UPDATE -> cancelLibraryUpdate(context, Notifications.ID_LIBRARY_PROGRESS)
// Open reader activity
@@ -170,6 +173,17 @@ class NotificationReceiver : BroadcastReceiver() {
DiskUtil.scanMedia(context, file)
}
/**
* Method called when user wants to stop a backup restore job.
*
* @param context context of application
* @param notificationId id of notification
*/
private fun cancelRestore(context: Context, notificationId: Int) {
BackupRestoreService.stop(context)
Handler().post { dismissNotification(context, notificationId) }
}
/**
* Method called when user wants to stop a library update
*
@@ -222,6 +236,9 @@ class NotificationReceiver : BroadcastReceiver() {
// Called to launch send intent.
private const val ACTION_SHARE_BACKUP = "$ID.$NAME.SEND_BACKUP"
// Called to cancel backup restore job.
private const val ACTION_CANCEL_RESTORE = "$ID.$NAME.CANCEL_RESTORE"
// Called to cancel library update.
private const val ACTION_CANCEL_LIBRARY_UPDATE = "$ID.$NAME.CANCEL_LIBRARY_UPDATE"
@@ -475,7 +492,7 @@ class NotificationReceiver : BroadcastReceiver() {
* @param notificationId id of notification
* @return [PendingIntent]
*/
internal fun shareBackup(context: Context, uri: Uri, notificationId: Int): PendingIntent {
internal fun shareBackupPendingBroadcast(context: Context, uri: Uri, notificationId: Int): PendingIntent {
val intent = Intent(context, NotificationReceiver::class.java).apply {
action = ACTION_SHARE_BACKUP
putExtra(EXTRA_URI, uri)
@@ -491,7 +508,7 @@ class NotificationReceiver : BroadcastReceiver() {
* @param uri uri of error log file
* @return [PendingIntent]
*/
internal fun openErrorLog(context: Context, uri: Uri): PendingIntent {
internal fun openErrorLogPendingActivity(context: Context, uri: Uri): PendingIntent {
val intent = Intent().apply {
action = Intent.ACTION_VIEW
setDataAndType(uri, "text/plain")
@@ -499,5 +516,20 @@ class NotificationReceiver : BroadcastReceiver() {
}
return PendingIntent.getActivity(context, 0, intent, 0)
}
/**
* Returns [PendingIntent] that cancels a backup restore job.
*
* @param context context of application
* @param notificationId id of notification
* @return [PendingIntent]
*/
internal fun cancelRestorePendingBroadcast(context: Context, notificationId: Int): PendingIntent {
val intent = Intent(context, NotificationReceiver::class.java).apply {
action = ACTION_CANCEL_RESTORE
putExtra(EXTRA_NOTIFICATION_ID, notificationId)
}
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
}
}