forked from upstream-mirrors/quik
Move backup/restore status strings to resources, show completed state
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.common.util.extensions
|
||||
|
||||
import android.content.Context
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.repository.BackupRepository
|
||||
|
||||
fun BackupRepository.Progress.getLabel(context: Context): String? {
|
||||
return when (this) {
|
||||
is BackupRepository.Progress.Parsing -> context.getString(R.string.backup_progress_parsing)
|
||||
is BackupRepository.Progress.Running -> context.getString(R.string.backup_progress_running, count, max)
|
||||
is BackupRepository.Progress.Saving -> context.getString(R.string.backup_progress_saving)
|
||||
is BackupRepository.Progress.Syncing -> context.getString(R.string.backup_progress_syncing)
|
||||
is BackupRepository.Progress.Finished -> context.getString(R.string.backup_progress_finished)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import com.jakewharton.rxbinding2.view.clicks
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.base.QkController
|
||||
import com.moez.QKSMS.common.util.DateFormatter
|
||||
import com.moez.QKSMS.common.util.extensions.getLabel
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.common.widget.PreferenceView
|
||||
@@ -85,24 +86,30 @@ class BackupController : QkController<BackupView, BackupState, BackupPresenter>(
|
||||
|
||||
override fun render(state: BackupState) {
|
||||
when {
|
||||
state.backupProgress is BackupRepository.Progress.Running -> {
|
||||
state.backupProgress.running -> {
|
||||
progressIcon.setImageResource(R.drawable.ic_file_upload_black_24dp)
|
||||
progressTitle.setText(R.string.backup_backing_up)
|
||||
progressSummary.text = state.backupProgress.status
|
||||
progressSummary.text = state.backupProgress.getLabel(activity!!)
|
||||
progressSummary.isVisible = progressSummary.text.isNotEmpty()
|
||||
progressBar.isIndeterminate = state.backupProgress.progress == 0
|
||||
progressBar.progress = state.backupProgress.progress
|
||||
val running = (state.backupProgress as? BackupRepository.Progress.Running)
|
||||
progressBar.isVisible = state.backupProgress.indeterminate || running?.max ?: 0 > 0
|
||||
progressBar.isIndeterminate = state.backupProgress.indeterminate
|
||||
progressBar.max = running?.max ?: 0
|
||||
progressBar.progress = running?.count ?: 0
|
||||
progress.isVisible = true
|
||||
fab.isVisible = false
|
||||
}
|
||||
|
||||
state.restoreProgress is BackupRepository.Progress.Running -> {
|
||||
state.restoreProgress.running -> {
|
||||
progressIcon.setImageResource(R.drawable.ic_file_download_black_24dp)
|
||||
progressTitle.setText(R.string.backup_restoring)
|
||||
progressSummary.text = state.restoreProgress.status
|
||||
progressSummary.text = state.restoreProgress.getLabel(activity!!)
|
||||
progressSummary.isVisible = progressSummary.text.isNotEmpty()
|
||||
progressBar.isIndeterminate = state.restoreProgress.progress == 0
|
||||
progressBar.progress = state.restoreProgress.progress
|
||||
val running = (state.restoreProgress as? BackupRepository.Progress.Running)
|
||||
progressBar.isVisible = state.restoreProgress.indeterminate || running?.max ?: 0 > 0
|
||||
progressBar.isIndeterminate = state.restoreProgress.indeterminate
|
||||
progressBar.max = running?.max ?: 0
|
||||
progressBar.progress = running?.count ?: 0
|
||||
progress.isVisible = true
|
||||
fab.isVisible = false
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.moez.QKSMS.common.util.BillingManager
|
||||
import com.moez.QKSMS.common.util.DateFormatter
|
||||
import com.moez.QKSMS.interactor.PerformBackup
|
||||
import com.moez.QKSMS.repository.BackupRepository
|
||||
import com.moez.QKSMS.service.RestoreBackupService
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
@@ -81,8 +80,8 @@ class BackupPresenter @Inject constructor(
|
||||
{ _, backupProgress, restoreProgress, upgraded ->
|
||||
when {
|
||||
!upgraded -> context.toast(R.string.backup_restore_error_plus)
|
||||
backupProgress is BackupRepository.Progress.Running -> context.toast(R.string.backup_restore_error_backup)
|
||||
restoreProgress is BackupRepository.Progress.Running -> context.toast(R.string.backup_restore_error_restore)
|
||||
backupProgress.running -> context.toast(R.string.backup_restore_error_backup)
|
||||
restoreProgress.running -> context.toast(R.string.backup_restore_error_restore)
|
||||
else -> view.selectFile()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||
*
|
||||
* This file is part of QKSMS.
|
||||
*
|
||||
* QKSMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QKSMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.moez.QKSMS.feature.backup
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.IBinder
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.moez.QKSMS.common.util.extensions.getLabel
|
||||
import com.moez.QKSMS.manager.NotificationManager
|
||||
import com.moez.QKSMS.repository.BackupRepository
|
||||
import dagger.android.AndroidInjection
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import timber.log.Timber
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
class RestoreBackupService : Service() {
|
||||
|
||||
companion object {
|
||||
private const val NOTIFICATION_ID = -1
|
||||
|
||||
private const val ACTION_START = "com.moez.QKSMS.ACTION_START"
|
||||
private const val ACTION_STOP = "com.moez.QKSMS.ACTION_STOP"
|
||||
private const val EXTRA_FILE_PATH = "com.moez.QKSMS.EXTRA_FILE_PATH"
|
||||
|
||||
fun start(context: Context, filePath: String) {
|
||||
val intent = Intent(context, RestoreBackupService::class.java)
|
||||
.setAction(ACTION_START)
|
||||
.putExtra(EXTRA_FILE_PATH, filePath)
|
||||
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
}
|
||||
}
|
||||
|
||||
@Inject lateinit var backupRepo: BackupRepository
|
||||
@Inject lateinit var notificationManager: NotificationManager
|
||||
|
||||
private val notification by lazy { notificationManager.getNotificationForBackup() }
|
||||
|
||||
override fun onCreate() = AndroidInjection.inject(this)
|
||||
|
||||
override fun onBind(intent: Intent?): IBinder? = null
|
||||
|
||||
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
|
||||
super.onStartCommand(intent, flags, startId)
|
||||
when (intent.action) {
|
||||
ACTION_START -> start(intent)
|
||||
ACTION_STOP -> stop()
|
||||
}
|
||||
|
||||
return Service.START_STICKY
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
private fun start(intent: Intent) {
|
||||
val notificationManager = NotificationManagerCompat.from(this)
|
||||
|
||||
startForeground(NOTIFICATION_ID, notification.build())
|
||||
|
||||
backupRepo.getRestoreProgress()
|
||||
.sample(200, TimeUnit.MILLISECONDS, true)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe { progress ->
|
||||
when (progress) {
|
||||
is BackupRepository.Progress.Idle -> stop()
|
||||
|
||||
is BackupRepository.Progress.Running -> {
|
||||
notification
|
||||
.setProgress(progress.max, progress.count, progress.indeterminate)
|
||||
.setContentText(progress.getLabel(this))
|
||||
notificationManager.notify(NOTIFICATION_ID, notification.build())
|
||||
}
|
||||
|
||||
else -> {
|
||||
notification
|
||||
.setProgress(0, 0, progress.indeterminate)
|
||||
.setContentText(progress.getLabel(this))
|
||||
notificationManager.notify(NOTIFICATION_ID, notification.build())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start the restore
|
||||
Observable.just(intent)
|
||||
.map { it.getStringExtra(EXTRA_FILE_PATH) }
|
||||
.map(backupRepo::performRestore)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe({}, Timber::w)
|
||||
}
|
||||
|
||||
private fun stop() {
|
||||
stopForeground(true)
|
||||
stopSelf()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
package com.moez.QKSMS.injection.android
|
||||
|
||||
import com.moez.QKSMS.feature.backup.RestoreBackupService
|
||||
import com.moez.QKSMS.injection.scope.ActivityScope
|
||||
import com.moez.QKSMS.service.HeadlessSmsSendService
|
||||
import com.moez.QKSMS.service.RestoreBackupService
|
||||
import com.moez.QKSMS.service.SendScheduledMessageService
|
||||
import com.moez.QKSMS.service.SendSmsService
|
||||
import dagger.Module
|
||||
|
||||
Reference in New Issue
Block a user