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) :
|
class BackupCreatorJob(private val context: Context, workerParams: WorkerParameters) :
|
||||||
CoroutineWorker(context, workerParams) {
|
CoroutineWorker(context, workerParams) {
|
||||||
|
|
||||||
val notifier = BackupNotifier(context.localeContext)
|
private val notifier = BackupNotifier(context.localeContext)
|
||||||
|
|
||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
val isAutoBackup = inputData.getBoolean(IS_AUTO_BACKUP_KEY, true)
|
val isAutoBackup = inputData.getBoolean(IS_AUTO_BACKUP_KEY, true)
|
||||||
|
@ -82,8 +82,9 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun isManualJobRunning(context: Context): Boolean {
|
fun isManualJobRunning(context: Context): Boolean {
|
||||||
val list = context.workManager.getWorkInfosByTag(TAG_MANUAL).get()
|
return context.workManager
|
||||||
return list.find { it.state == WorkInfo.State.RUNNING } != null
|
.getWorkInfosByTag(TAG_MANUAL).get()
|
||||||
|
.find { it.state == WorkInfo.State.RUNNING } != null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setupTask(context: Context, prefInterval: Int? = 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)
|
private val restorer = BackupRestorer(context, notifier)
|
||||||
|
|
||||||
override suspend fun getForegroundInfo(): ForegroundInfo {
|
override suspend fun getForegroundInfo(): ForegroundInfo {
|
||||||
val notification = notifier.showRestoreProgress(progress = -1).build()
|
return ForegroundInfo(
|
||||||
val id = Notifications.ID_RESTORE_PROGRESS
|
Notifications.ID_RESTORE_PROGRESS,
|
||||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
notifier.showRestoreProgress(progress = -1).build(),
|
||||||
ForegroundInfo(id, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
} else {
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
|
||||||
ForegroundInfo(id, notification)
|
} else {
|
||||||
}
|
0
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun doWork(): Result {
|
override suspend fun doWork(): Result {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue