diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupController.kt b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupController.kt index b51cad3a665c63bf6a70cc3a350e964a12871786..77cd1847ddc79a97f52f93c25c8cf318ce69f36f 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupController.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupController.kt @@ -166,6 +166,16 @@ class BackupController : QkController( backup.summary = state.lastBackup adapter.data = state.backups + + fabIcon.setImageResource(when (state.upgraded) { + true -> R.drawable.ic_file_upload_black_24dp + false -> R.drawable.ic_star_black_24dp + }) + + fabLabel.setText(when (state.upgraded) { + true -> R.string.backup_now + false -> R.string.title_qksms_plus + }) } override fun activityVisible(): Observable<*> = activityVisibleSubject @@ -193,4 +203,4 @@ class BackupController : QkController( override fun stopRestore() = stopRestoreDialog.show() -} \ No newline at end of file +} diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupPresenter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupPresenter.kt index 8d945e2e663d3bc719437744e77add7b74ef7c2f..ae2ee694ed079253d83accd7cce6f46f28ca66fb 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupPresenter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/backup/BackupPresenter.kt @@ -25,6 +25,7 @@ import com.moez.QKSMS.common.base.QkPresenter import com.moez.QKSMS.common.util.DateFormatter import com.moez.QKSMS.common.util.extensions.makeToast import com.moez.QKSMS.interactor.PerformBackup +import com.moez.QKSMS.manager.BillingManager import com.moez.QKSMS.manager.PermissionManager import com.moez.QKSMS.repository.BackupRepository import com.uber.autodispose.android.lifecycle.scope @@ -38,6 +39,7 @@ import javax.inject.Inject class BackupPresenter @Inject constructor( private val backupRepo: BackupRepository, + private val billingManager: BillingManager, private val context: Context, private val dateFormatter: DateFormatter, private val navigator: Navigator, @@ -71,6 +73,9 @@ class BackupPresenter @Inject constructor( } .startWith(context.getString(R.string.backup_loading)) .subscribe { lastBackup -> newState { copy(lastBackup = lastBackup) } } + + disposables += billingManager.upgradeStatus + .subscribe { upgraded -> newState { copy(upgraded = upgraded) } } } override fun bindIntents(view: BackupView) { @@ -84,9 +89,11 @@ class BackupPresenter @Inject constructor( view.restoreClicks() .withLatestFrom( backupRepo.getBackupProgress(), - backupRepo.getRestoreProgress()) - { _, backupProgress, restoreProgress -> + backupRepo.getRestoreProgress(), + billingManager.upgradeStatus) + { _, backupProgress, restoreProgress, upgraded -> when { + !upgraded -> context.makeToast(R.string.backup_restore_error_plus) backupProgress.running -> context.makeToast(R.string.backup_restore_error_backup) restoreProgress.running -> context.makeToast(R.string.backup_restore_error_restore) !permissionManager.hasStorage() -> view.requestStoragePermission() @@ -113,6 +120,16 @@ class BackupPresenter @Inject constructor( .autoDisposable(view.scope()) .subscribe { backupRepo.stopRestore() } + view.fabClicks() + .withLatestFrom(billingManager.upgradeStatus) { _, upgraded -> upgraded } + .autoDisposable(view.scope()) + .subscribe { upgraded -> + when { + !upgraded -> navigator.showQksmsPlusActivity("backup_fab") + !permissionManager.hasStorage() -> view.requestStoragePermission() + upgraded -> performBackup.execute(Unit) + } + } } -} \ No newline at end of file +}