refactor: Simplify code

This commit is contained in:
Ahmad Ansori Palembani 2024-09-24 06:48:18 +07:00
parent 83a8abe07c
commit 7719847106
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
2 changed files with 13 additions and 10 deletions

View file

@ -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) {

View file

@ -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 {