Skip to content

Commit

Permalink
make auto upload light working again
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasKaminsky committed Aug 9, 2017
1 parent 0f02b1d commit efd1167
Showing 1 changed file with 54 additions and 11 deletions.
65 changes: 54 additions & 11 deletions src/main/java/com/owncloud/android/jobs/FilesSyncJob.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Nextcloud Android client application
*
* @author Mario Danic
Expand All @@ -24,6 +24,7 @@
import android.accounts.Account;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.os.PowerManager;
import android.support.annotation.NonNull;
import android.support.media.ExifInterface;
Expand All @@ -32,14 +33,17 @@
import com.evernote.android.job.Job;
import com.evernote.android.job.util.support.PersistableBundleCompat;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.FilesystemDataProvider;
import com.owncloud.android.datamodel.MediaFolderType;
import com.owncloud.android.datamodel.SyncedFolder;
import com.owncloud.android.datamodel.SyncedFolderProvider;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.UploadFileOperation;
import com.owncloud.android.ui.activity.Preferences;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.FilesSyncHelper;
import com.owncloud.android.utils.MimeTypeUtil;
Expand Down Expand Up @@ -78,6 +82,9 @@ protected Result onRunJob(Params params) {
PersistableBundleCompat bundle = params.getExtras();
final boolean skipCustom = bundle.getBoolean(SKIP_CUSTOM, false);

Resources resources = MainApp.getAppContext().getResources();
boolean lightVersion = resources.getBoolean(R.bool.syncedFolder_light);

FilesSyncHelper.restartJobsIfNeeded();
FilesSyncHelper.insertAllDBEntries(skipCustom);

Expand All @@ -95,9 +102,9 @@ protected Result onRunJob(Params params) {
final Locale currentLocale = context.getResources().getConfiguration().locale;

if (MediaFolderType.IMAGE == syncedFolder.getType()) {
String mimetypeString = FileStorageUtils.getMimeTypeFromName(file.getAbsolutePath());
if ("image/jpeg".equalsIgnoreCase(mimetypeString) || "image/tiff".
equalsIgnoreCase(mimetypeString)) {
String mimeTypeString = FileStorageUtils.getMimeTypeFromName(file.getAbsolutePath());
if ("image/jpeg".equalsIgnoreCase(mimeTypeString) || "image/tiff".
equalsIgnoreCase(mimeTypeString)) {
try {
ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
String exifDate = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
Expand All @@ -116,23 +123,46 @@ protected Result onRunJob(Params params) {
}
}

boolean needsCharging = syncedFolder.getChargingOnly();
boolean needsWifi = syncedFolder.getWifiOnly();

String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());

Account account = AccountUtils.getOwnCloudAccountByName(context, syncedFolder.getAccount());

String remotePath;
boolean subfolderByDate;
Integer uploadAction;
boolean needsCharging;
boolean needsWifi;

if (lightVersion) {
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(
context.getContentResolver());

needsCharging = resources.getBoolean(R.bool.syncedFolder_light_on_charging);
needsWifi = account == null || arbitraryDataProvider.getBooleanValue(account.name,
Preferences.SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI);
String uploadActionString = resources.getString(R.string.syncedFolder_light_upload_behaviour);
uploadAction = getUploadAction(uploadActionString);

subfolderByDate = resources.getBoolean(R.bool.syncedFolder_light_use_subfolders);

remotePath = resources.getString(R.string.syncedFolder_remote_folder);
} else {
needsCharging = syncedFolder.getChargingOnly();
needsWifi = syncedFolder.getWifiOnly();
uploadAction = syncedFolder.getUploadAction();
subfolderByDate = syncedFolder.getSubfolderByDate();
remotePath = syncedFolder.getRemotePath();
}

requester.uploadFileWithOverwrite(
context,
account,
file.getAbsolutePath(),
FileStorageUtils.getInstantUploadFilePath(
currentLocale,
syncedFolder.getRemotePath(), file.getName(),
lastModificationTime,
syncedFolder.getSubfolderByDate()),
syncedFolder.getUploadAction(),
remotePath, file.getName(),
lastModificationTime, subfolderByDate),
uploadAction,
mimeType,
true, // create parent folder if not existent
UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
Expand All @@ -150,4 +180,17 @@ protected Result onRunJob(Params params) {
wakeLock.release();
return Result.SUCCESS;
}

private Integer getUploadAction(String action) {
switch (action) {
case "LOCAL_BEHAVIOUR_FORGET":
return FileUploader.LOCAL_BEHAVIOUR_FORGET;
case "LOCAL_BEHAVIOUR_MOVE":
return FileUploader.LOCAL_BEHAVIOUR_MOVE;
case "LOCAL_BEHAVIOUR_DELETE":
return FileUploader.LOCAL_BEHAVIOUR_DELETE;
default:
return FileUploader.LOCAL_BEHAVIOUR_FORGET;
}
}
}

0 comments on commit efd1167

Please sign in to comment.