From c3a8b0c4506d3356573b251d7d8ead347d12a827 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Wed, 12 Oct 2016 21:41:44 +0200 Subject: [PATCH] update job to obey syncedfolder settings --- .../services/SyncedFolderJobService.java | 16 +++++++-------- .../observer/SyncedFolderObserver.java | 20 ++++++++++++------- .../observer/SyncedFolderObserverService.java | 3 +-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/com/owncloud/android/services/SyncedFolderJobService.java b/src/com/owncloud/android/services/SyncedFolderJobService.java index f571cc566a..10d7f046e6 100644 --- a/src/com/owncloud/android/services/SyncedFolderJobService.java +++ b/src/com/owncloud/android/services/SyncedFolderJobService.java @@ -40,6 +40,7 @@ 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.utils.FileStorageUtils; +import com.owncloud.android.utils.MimetypeIconUtil; import java.io.File; import java.util.Date; @@ -51,12 +52,9 @@ import java.util.Date; @TargetApi(Build.VERSION_CODES.LOLLIPOP) public class SyncedFolderJobService extends JobService { private static final String TAG = "SyncedFolderJobService"; - private Context mContext; @Override public int onStartCommand(Intent intent, int flags, int startId) { - // TODO Tobi why is this null? - mContext = MainApp.getAppContext(); return START_NOT_STICKY; } @@ -64,17 +62,17 @@ public class SyncedFolderJobService extends JobService { public boolean onStartJob(JobParameters params) { Log_OC.d(TAG, "startJob: " + params.getJobId()); - // TODO Tobi just for testing! Context context = MainApp.getAppContext(); - Account account = AccountUtils.getCurrentOwnCloudAccount(context); - PersistableBundle bundle = params.getExtras(); String filePath = bundle.getString("filePath"); - String remoteFolder = bundle.getString("remoteFolder"); + String remoteFolder = bundle.getString("remotePath"); Long dateTaken = bundle.getLong("dateTaken"); Boolean subfolderByDate = bundle.getInt("subfolderByDate") == 1; + Account account = AccountUtils.getOwnCloudAccountByName(context, bundle.getString("account")); + Integer uploadBehaviour = bundle.getInt("uploadBehaviour"); File file = new File(filePath); + String mimeType = MimetypeIconUtil.getBestMimeTypeByFilename(file.getAbsolutePath()); FileUploader.UploadRequester requester = new FileUploader.UploadRequester(); requester.uploadNewFile( @@ -82,8 +80,8 @@ public class SyncedFolderJobService extends JobService { account, filePath, FileStorageUtils.getInstantUploadFilePath(remoteFolder, file.getName(), dateTaken, subfolderByDate), - FileUploader.LOCAL_BEHAVIOUR_FORGET, - "image/jpg", + uploadBehaviour, + mimeType, true, // create parent folder if not existent UploadFileOperation.CREATED_AS_INSTANT_PICTURE ); diff --git a/src/com/owncloud/android/services/observer/SyncedFolderObserver.java b/src/com/owncloud/android/services/observer/SyncedFolderObserver.java index cd7911a077..0bd5912ed1 100644 --- a/src/com/owncloud/android/services/observer/SyncedFolderObserver.java +++ b/src/com/owncloud/android/services/observer/SyncedFolderObserver.java @@ -11,6 +11,7 @@ import android.os.PersistableBundle; import android.util.Log; import com.owncloud.android.MainApp; +import com.owncloud.android.datamodel.SyncedFolder; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.services.SyncedFolderJobService; import com.owncloud.android.utils.RecursiveFileObserver; @@ -24,15 +25,15 @@ class SyncedFolderObserver extends RecursiveFileObserver { private static final int MY_BACKGROUND_JOB = 0; public static final String TAG = "SyncedFolderObserver"; - private String remoteFolder; + private SyncedFolder syncedFolder; - public SyncedFolderObserver(String path, String remoteFolder) { - super(path, FileObserver.CREATE + FileObserver.MOVED_TO); + public SyncedFolderObserver(SyncedFolder syncedFolder) { + super(syncedFolder.getLocalPath(), FileObserver.CREATE + FileObserver.MOVED_TO); context = MainApp.getAppContext(); - this.remoteFolder = remoteFolder; - Log_OC.d("SyncedFolderObserver", "Started watching: " + path); + this.syncedFolder = syncedFolder; + Log_OC.d("SyncedFolderObserver", "Started watching: " + syncedFolder.getLocalPath()); } @@ -40,15 +41,20 @@ class SyncedFolderObserver extends RecursiveFileObserver { @Override public void onEvent(int event, String path) { PersistableBundle bundle = new PersistableBundle(); + // TODO extract bundle.putString("filePath", path); - bundle.putString("remoteFolder", remoteFolder); + bundle.putString("remotePath", syncedFolder.getRemotePath()); bundle.putLong("dateTaken", new Date().getTime()); + bundle.putString("account", syncedFolder.getAccount()); + bundle.putInt("uploadBehaviour", syncedFolder.getUploadAction()); + bundle.putInt("subfolderByDate", syncedFolder.getSubfolderByDate() ? 1 : 0); JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE); JobInfo job = new JobInfo.Builder( MY_BACKGROUND_JOB, new ComponentName(context, SyncedFolderJobService.class)) - .setRequiresCharging(false) + .setRequiresCharging(syncedFolder.getChargingOnly()) + // TODO change to UNMETERED after developing .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY) .setExtras(bundle) .build(); diff --git a/src/com/owncloud/android/services/observer/SyncedFolderObserverService.java b/src/com/owncloud/android/services/observer/SyncedFolderObserverService.java index 608325bd16..617748fe38 100644 --- a/src/com/owncloud/android/services/observer/SyncedFolderObserverService.java +++ b/src/com/owncloud/android/services/observer/SyncedFolderObserverService.java @@ -24,8 +24,7 @@ public class SyncedFolderObserverService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { for (SyncedFolder syncedFolder : mProvider.getSyncedFolders()) { - SyncedFolderObserver observer = new SyncedFolderObserver(syncedFolder.getLocalPath(), - syncedFolder.getRemotePath()); + SyncedFolderObserver observer = new SyncedFolderObserver(syncedFolder); observer.startWatching(); syncedFolderObservers.add(observer);