Show notification if the vault specified for auto upload doesn't exists

Fixes #386
This commit is contained in:
Julian Raufelder 2021-11-15 15:16:01 +01:00
parent 9b4a5b475d
commit f4eff63db7
No known key found for this signature in database
GPG Key ID: 17EE71F6634E381D
4 changed files with 31 additions and 8 deletions

View File

@ -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<ApplicationComponent>
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()))
}
}
}

View File

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

View File

@ -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");

View File

@ -537,6 +537,7 @@
<string name="notification_auto_upload_failed_general_error">General error occurred during upload.</string>
<string name="notification_auto_upload_failed_due_to_folder_not_exists">Selected folder for upload isn\'t available anymore. Go to settings and choose a new one</string>
<string name="notification_auto_upload_failed_due_to_vault_locked">Vault locked during upload, please reopen vault to continue</string>
<string name="notification_auto_upload_failed_due_to_vault_not_found">Vault specified for auto upload doesn\'t exists anymore.</string>
<string name="notification_cancel_open_writable_file" translatable="false">@string/dialog_button_cancel</string>
<string name="notification_open_writable_file_title">Open writable file</string>