Upload instantly when auto upload enabled and vault unlocked (#181)

This commit is contained in:
Julian Raufelder 2021-10-05 01:06:23 +02:00
parent e60333865f
commit 8ebee7bfc2
No known key found for this signature in database
GPG Key ID: 17EE71F6634E381D
6 changed files with 38 additions and 5 deletions

View File

@ -120,6 +120,17 @@ class CryptomatorApp : MultiDexApplication(), HasComponent<ApplicationComponent>
}, BIND_AUTO_CREATE)
}
fun startAutoUpload() {
val sharedPreferencesHandler = SharedPreferencesHandler(applicationContext())
if(sharedPreferencesHandler.usePhotoUpload()) {
val vault = applicationComponent.vaultRepository().load(sharedPreferencesHandler.photoUploadVault())
if(vault.isUnlocked) {
val cloud = applicationComponent.cloudRepository().decryptedViewOf(vault)
applicationContext().startService(AutoUploadService.startAutoUploadIntent(applicationContext(), cloud))
}
}
}
private fun setupLogging() {
setupLoggingFramework()
setup()

View File

@ -212,7 +212,7 @@ public class AutoUploadService extends Service {
public void onCreate() {
super.onCreate();
Timber.tag("AutoUploadService").d("created");
notification = new AutoUploadNotification(this, 5);
notification = new AutoUploadNotification(this, 0);
}
@Override

View File

@ -13,6 +13,7 @@ import android.net.Uri
import android.os.Handler
import android.provider.MediaStore
import org.cryptomator.domain.exception.FatalBackendException
import org.cryptomator.presentation.CryptomatorApp
import org.cryptomator.presentation.R
import org.cryptomator.presentation.util.FileUtil
import org.cryptomator.presentation.util.ResourceHelper
@ -38,6 +39,8 @@ class PhotoContentJob : JobService() {
runningParams = params
var filesCaptured = false
params.triggeredContentAuthorities?.let {
if (params.triggeredContentUris != null) {
val ids = getIds(params)
@ -49,6 +52,8 @@ class PhotoContentJob : JobService() {
fileUtil.addImageToAutoUploads(dir)
Timber.tag("PhotoContentJob").i("Added file to UploadList")
Timber.tag("PhotoContentJob").d(String.format("Added file to UploadList %s", dir))
filesCaptured = true
} catch (e: FatalBackendException) {
Timber.tag("PhotoContentJob").e(e, "Failed to add image to auto upload list")
} catch (e: SecurityException) {
@ -65,6 +70,10 @@ class PhotoContentJob : JobService() {
}
} ?: Timber.tag("PhotoContentJob").w("No photos content")
if(filesCaptured && SharedPreferencesHandler(applicationContext).usePhotoUploadInstant()) {
(application as CryptomatorApp).startAutoUpload()
}
handler.post(worker)
return false
}

View File

@ -242,6 +242,8 @@
<string name="screen_settings_section_auto_photo_upload_vault">Choose vault for upload</string>
<string name="screen_settings_section_auto_photo_upload_toggle">Activate</string>
<string name="screen_settings_section_auto_photo_upload_toggle_summary">Capture images in the background and once the selected vault is unlocked, start upload</string>
<string name="screen_settings_section_auto_photo_upload_toggle_instant_upload">Upload instant</string>
<string name="screen_settings_section_auto_photo_upload_toggle_instant_upload_summary">Upload directly if the vault is unlocked</string>
<string name="screen_settings_section_auto_photo_upload_only_wifi_toggle">Upload only using WIFI</string>
<string name="screen_settings_section_auto_photo_upload_including_videos">Upload videos</string>

View File

@ -105,6 +105,12 @@
android:summary="@string/screen_settings_section_auto_photo_upload_toggle_summary"
android:title="@string/screen_settings_section_auto_photo_upload_toggle" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="photoUploadInstant"
android:summary="@string/screen_settings_section_auto_photo_upload_toggle_instant_upload_summary"
android:title="@string/screen_settings_section_auto_photo_upload_toggle_instant_upload" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="photoUploadOnlyUsingWifi"

View File

@ -129,14 +129,18 @@ constructor(context: Context) : SharedPreferences.OnSharedPreferenceChangeListen
defaultSharedPreferences.clear()
}
fun autoPhotoUploadOnlyUsingWifi(): Boolean {
return defaultSharedPreferences.getValue(PHOTO_UPLOAD_ONLY_USING_WIFI)
}
fun usePhotoUpload(): Boolean {
return defaultSharedPreferences.getValue(PHOTO_UPLOAD, false)
}
fun usePhotoUploadInstant(): Boolean {
return defaultSharedPreferences.getValue(PHOTO_UPLOAD_INSTANT, true)
}
fun autoPhotoUploadOnlyUsingWifi(): Boolean {
return defaultSharedPreferences.getValue(PHOTO_UPLOAD_ONLY_USING_WIFI)
}
fun photoUploadVault(): Long {
return defaultSharedPreferences.getValue(PHOTO_UPLOAD_VAULT, 0)
}
@ -249,6 +253,7 @@ constructor(context: Context) : SharedPreferences.OnSharedPreferenceChangeListen
const val SECURE_SCREEN = "secureScreen"
const val SCREEN_STYLE_MODE = "screenStyleMode"
const val PHOTO_UPLOAD = "photoUpload"
const val PHOTO_UPLOAD_INSTANT = "photoUploadInstant"
const val PHOTO_UPLOAD_ONLY_USING_WIFI = "photoUploadOnlyUsingWifi"
const val PHOTO_UPLOAD_VAULT = "photoUploadVault"
const val PHOTO_UPLOAD_FOLDER = "photoUploadFolder"