From f4eff63db77bcfef3249611c6bc8b773d20a5b7e Mon Sep 17 00:00:00 2001 From: Julian Raufelder Date: Mon, 15 Nov 2021 15:16:01 +0100 Subject: [PATCH] Show notification if the vault specified for auto upload doesn't exists Fixes #386 --- .../presentation/CryptomatorApp.kt | 7 +++-- .../service/AutoUploadNotification.kt | 4 +++ .../service/AutoUploadService.java | 27 ++++++++++++++----- presentation/src/main/res/values/strings.xml | 1 + 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/presentation/src/main/java/org/cryptomator/presentation/CryptomatorApp.kt b/presentation/src/main/java/org/cryptomator/presentation/CryptomatorApp.kt index 5abeb02f..487a6497 100644 --- a/presentation/src/main/java/org/cryptomator/presentation/CryptomatorApp.kt +++ b/presentation/src/main/java/org/cryptomator/presentation/CryptomatorApp.kt @@ -12,6 +12,7 @@ import androidx.multidex.MultiDexApplication import org.cryptomator.data.cloud.crypto.Cryptors import org.cryptomator.data.cloud.crypto.CryptorsModule import org.cryptomator.data.repository.RepositoryModule +import org.cryptomator.domain.Vault import org.cryptomator.presentation.di.HasComponent import org.cryptomator.presentation.di.component.ApplicationComponent import org.cryptomator.presentation.di.component.DaggerApplicationComponent @@ -123,10 +124,12 @@ class CryptomatorApp : MultiDexApplication(), HasComponent fun startAutoUpload() { val sharedPreferencesHandler = SharedPreferencesHandler(applicationContext()) if (checkToStartAutoImageUpload(sharedPreferencesHandler)) { - val vault = applicationComponent.vaultRepository().load(sharedPreferencesHandler.photoUploadVault()) - if (vault.isUnlocked) { + val vault: Vault? = applicationComponent.vaultRepository().load(sharedPreferencesHandler.photoUploadVault()) + if (vault?.isUnlocked == true) { val cloud = applicationComponent.cloudRepository().decryptedViewOf(vault) applicationContext().startService(AutoUploadService.startAutoUploadIntent(applicationContext(), cloud)) + } else if (vault == null) { + applicationContext().startService(AutoUploadService.vaultNotFoundUploadIntent(applicationContext())) } } } diff --git a/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadNotification.kt b/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadNotification.kt index 55816ef3..c22b439a 100644 --- a/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadNotification.kt +++ b/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadNotification.kt @@ -96,6 +96,10 @@ class AutoUploadNotification(private val context: Context, private val amountOfP showErrorWithMessage(context.getString(R.string.notification_auto_upload_failed_general_error)) } + fun showVaultNotFoundNotification() { + showErrorWithMessage(context.getString(R.string.notification_auto_upload_failed_due_to_vault_not_found)) + } + private fun showErrorWithMessage(message: String) { builder.setContentIntent(startTheActivity()) builder // diff --git a/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadService.java b/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadService.java index 452934c7..1ce3585a 100644 --- a/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadService.java +++ b/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadService.java @@ -47,8 +47,9 @@ import static org.cryptomator.domain.usecases.cloud.UploadFile.anUploadFile; public class AutoUploadService extends Service { - private static final String ACTION_CANCEL_AUTO_UPLOAD = "CANCEL_AUTO_UPLOAD"; private static final String ACTION_START_AUTO_UPLOAD = "START_AUTO_UPLOAD"; + private static final String ACTION_CANCEL_AUTO_UPLOAD = "CANCEL_AUTO_UPLOAD"; + private static final String ACTION_VAULT_NOT_FOUND = "VAULT_NOT_FOUND"; private static Cloud cloud; private AutoUploadNotification notification; @@ -69,17 +70,23 @@ public class AutoUploadService extends Service { } }; + public static Intent startAutoUploadIntent(Context context, Cloud myCloud) { + cloud = myCloud; + Intent startAutoUpload = new Intent(context, AutoUploadService.class); + startAutoUpload.setAction(ACTION_START_AUTO_UPLOAD); + return startAutoUpload; + } + public static Intent cancelAutoUploadIntent(Context context) { Intent cancelAutoUploadIntent = new Intent(context, AutoUploadService.class); cancelAutoUploadIntent.setAction(ACTION_CANCEL_AUTO_UPLOAD); return cancelAutoUploadIntent; } - public static Intent startAutoUploadIntent(Context context, Cloud myCloud) { - cloud = myCloud; - Intent startAutoUpload = new Intent(context, AutoUploadService.class); - startAutoUpload.setAction(ACTION_START_AUTO_UPLOAD); - return startAutoUpload; + public static Intent vaultNotFoundUploadIntent(Context context) { + Intent cancelAutoUploadIntent = new Intent(context, AutoUploadService.class); + cancelAutoUploadIntent.setAction(ACTION_VAULT_NOT_FOUND); + return cancelAutoUploadIntent; } private void startBackgroundImageUpload(Cloud cloud) { @@ -228,6 +235,9 @@ public class AutoUploadService extends Service { cancelled = true; hideNotification(); + } else if(isVaultNotFound(intent)) { + Timber.tag("AutoUploadService").i("Received show vault not found notification"); + notification.showVaultNotFoundNotification(); } return START_STICKY; } @@ -242,6 +252,11 @@ public class AutoUploadService extends Service { && ACTION_CANCEL_AUTO_UPLOAD.equals(intent.getAction()); } + private boolean isVaultNotFound(Intent intent) { + return intent != null // + && ACTION_VAULT_NOT_FOUND.equals(intent.getAction()); + } + @Override public void onDestroy() { Timber.tag("AutoUploadService").i("onDestroyed"); diff --git a/presentation/src/main/res/values/strings.xml b/presentation/src/main/res/values/strings.xml index 8ed2c79e..dc4213ef 100644 --- a/presentation/src/main/res/values/strings.xml +++ b/presentation/src/main/res/values/strings.xml @@ -537,6 +537,7 @@ General error occurred during upload. Selected folder for upload isn\'t available anymore. Go to settings and choose a new one Vault locked during upload, please reopen vault to continue + Vault specified for auto upload doesn\'t exists anymore. @string/dialog_button_cancel Open writable file