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

View file

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