Show notification if the vault specified for auto upload doesn't exists
Fixes #386
This commit is contained in:
parent
9b4a5b475d
commit
f4eff63db7
@ -12,6 +12,7 @@ import androidx.multidex.MultiDexApplication
|
|||||||
import org.cryptomator.data.cloud.crypto.Cryptors
|
import org.cryptomator.data.cloud.crypto.Cryptors
|
||||||
import org.cryptomator.data.cloud.crypto.CryptorsModule
|
import org.cryptomator.data.cloud.crypto.CryptorsModule
|
||||||
import org.cryptomator.data.repository.RepositoryModule
|
import org.cryptomator.data.repository.RepositoryModule
|
||||||
|
import org.cryptomator.domain.Vault
|
||||||
import org.cryptomator.presentation.di.HasComponent
|
import org.cryptomator.presentation.di.HasComponent
|
||||||
import org.cryptomator.presentation.di.component.ApplicationComponent
|
import org.cryptomator.presentation.di.component.ApplicationComponent
|
||||||
import org.cryptomator.presentation.di.component.DaggerApplicationComponent
|
import org.cryptomator.presentation.di.component.DaggerApplicationComponent
|
||||||
@ -123,10 +124,12 @@ class CryptomatorApp : MultiDexApplication(), HasComponent<ApplicationComponent>
|
|||||||
fun startAutoUpload() {
|
fun startAutoUpload() {
|
||||||
val sharedPreferencesHandler = SharedPreferencesHandler(applicationContext())
|
val sharedPreferencesHandler = SharedPreferencesHandler(applicationContext())
|
||||||
if (checkToStartAutoImageUpload(sharedPreferencesHandler)) {
|
if (checkToStartAutoImageUpload(sharedPreferencesHandler)) {
|
||||||
val vault = applicationComponent.vaultRepository().load(sharedPreferencesHandler.photoUploadVault())
|
val vault: Vault? = applicationComponent.vaultRepository().load(sharedPreferencesHandler.photoUploadVault())
|
||||||
if (vault.isUnlocked) {
|
if (vault?.isUnlocked == true) {
|
||||||
val cloud = applicationComponent.cloudRepository().decryptedViewOf(vault)
|
val cloud = applicationComponent.cloudRepository().decryptedViewOf(vault)
|
||||||
applicationContext().startService(AutoUploadService.startAutoUploadIntent(applicationContext(), cloud))
|
applicationContext().startService(AutoUploadService.startAutoUploadIntent(applicationContext(), cloud))
|
||||||
|
} else if (vault == null) {
|
||||||
|
applicationContext().startService(AutoUploadService.vaultNotFoundUploadIntent(applicationContext()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,10 @@ class AutoUploadNotification(private val context: Context, private val amountOfP
|
|||||||
showErrorWithMessage(context.getString(R.string.notification_auto_upload_failed_general_error))
|
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) {
|
private fun showErrorWithMessage(message: String) {
|
||||||
builder.setContentIntent(startTheActivity())
|
builder.setContentIntent(startTheActivity())
|
||||||
builder //
|
builder //
|
||||||
|
@ -47,8 +47,9 @@ import static org.cryptomator.domain.usecases.cloud.UploadFile.anUploadFile;
|
|||||||
|
|
||||||
public class AutoUploadService extends Service {
|
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_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 static Cloud cloud;
|
||||||
private AutoUploadNotification notification;
|
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) {
|
public static Intent cancelAutoUploadIntent(Context context) {
|
||||||
Intent cancelAutoUploadIntent = new Intent(context, AutoUploadService.class);
|
Intent cancelAutoUploadIntent = new Intent(context, AutoUploadService.class);
|
||||||
cancelAutoUploadIntent.setAction(ACTION_CANCEL_AUTO_UPLOAD);
|
cancelAutoUploadIntent.setAction(ACTION_CANCEL_AUTO_UPLOAD);
|
||||||
return cancelAutoUploadIntent;
|
return cancelAutoUploadIntent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Intent startAutoUploadIntent(Context context, Cloud myCloud) {
|
public static Intent vaultNotFoundUploadIntent(Context context) {
|
||||||
cloud = myCloud;
|
Intent cancelAutoUploadIntent = new Intent(context, AutoUploadService.class);
|
||||||
Intent startAutoUpload = new Intent(context, AutoUploadService.class);
|
cancelAutoUploadIntent.setAction(ACTION_VAULT_NOT_FOUND);
|
||||||
startAutoUpload.setAction(ACTION_START_AUTO_UPLOAD);
|
return cancelAutoUploadIntent;
|
||||||
return startAutoUpload;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startBackgroundImageUpload(Cloud cloud) {
|
private void startBackgroundImageUpload(Cloud cloud) {
|
||||||
@ -228,6 +235,9 @@ public class AutoUploadService extends Service {
|
|||||||
cancelled = true;
|
cancelled = true;
|
||||||
|
|
||||||
hideNotification();
|
hideNotification();
|
||||||
|
} else if(isVaultNotFound(intent)) {
|
||||||
|
Timber.tag("AutoUploadService").i("Received show vault not found notification");
|
||||||
|
notification.showVaultNotFoundNotification();
|
||||||
}
|
}
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
}
|
}
|
||||||
@ -242,6 +252,11 @@ public class AutoUploadService extends Service {
|
|||||||
&& ACTION_CANCEL_AUTO_UPLOAD.equals(intent.getAction());
|
&& ACTION_CANCEL_AUTO_UPLOAD.equals(intent.getAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isVaultNotFound(Intent intent) {
|
||||||
|
return intent != null //
|
||||||
|
&& ACTION_VAULT_NOT_FOUND.equals(intent.getAction());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
Timber.tag("AutoUploadService").i("onDestroyed");
|
Timber.tag("AutoUploadService").i("onDestroyed");
|
||||||
|
@ -537,6 +537,7 @@
|
|||||||
<string name="notification_auto_upload_failed_general_error">General error occurred during upload.</string>
|
<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_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_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_cancel_open_writable_file" translatable="false">@string/dialog_button_cancel</string>
|
||||||
<string name="notification_open_writable_file_title">Open writable file</string>
|
<string name="notification_open_writable_file_title">Open writable file</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user