mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
refactor: Simplify code
This commit is contained in:
parent
83a8abe07c
commit
7719847106
2 changed files with 13 additions and 10 deletions
|
@ -34,7 +34,7 @@ import yokai.domain.storage.StorageManager
|
|||
class BackupCreatorJob(private val context: Context, workerParams: WorkerParameters) :
|
||||
CoroutineWorker(context, workerParams) {
|
||||
|
||||
val notifier = BackupNotifier(context.localeContext)
|
||||
private val notifier = BackupNotifier(context.localeContext)
|
||||
|
||||
override suspend fun doWork(): Result {
|
||||
val isAutoBackup = inputData.getBoolean(IS_AUTO_BACKUP_KEY, true)
|
||||
|
@ -82,8 +82,9 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
|
|||
|
||||
companion object {
|
||||
fun isManualJobRunning(context: Context): Boolean {
|
||||
val list = context.workManager.getWorkInfosByTag(TAG_MANUAL).get()
|
||||
return list.find { it.state == WorkInfo.State.RUNNING } != null
|
||||
return context.workManager
|
||||
.getWorkInfosByTag(TAG_MANUAL).get()
|
||||
.find { it.state == WorkInfo.State.RUNNING } != null
|
||||
}
|
||||
|
||||
fun setupTask(context: Context, prefInterval: Int? = null) {
|
||||
|
|
|
@ -30,13 +30,15 @@ class BackupRestoreJob(val context: Context, workerParams: WorkerParameters) : C
|
|||
private val restorer = BackupRestorer(context, notifier)
|
||||
|
||||
override suspend fun getForegroundInfo(): ForegroundInfo {
|
||||
val notification = notifier.showRestoreProgress(progress = -1).build()
|
||||
val id = Notifications.ID_RESTORE_PROGRESS
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
ForegroundInfo(id, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
|
||||
} else {
|
||||
ForegroundInfo(id, notification)
|
||||
}
|
||||
return ForegroundInfo(
|
||||
Notifications.ID_RESTORE_PROGRESS,
|
||||
notifier.showRestoreProgress(progress = -1).build(),
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
|
||||
} else {
|
||||
0
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun doWork(): Result {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue