Эх сурвалжийг харах

Better handling

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 жил өмнө
parent
commit
a5a6476e00

+ 6 - 0
src/main/AndroidManifest.xml

@@ -120,6 +120,12 @@
             android:label="@string/app_name"
             android:theme="@style/Theme.ownCloud.Fullscreen" />
 
+        <service
+            android:name=".jobs.M1ContentObserverJob"
+            android:permission="android.permission.BIND_JOB_SERVICE" >
+
+        </service>
+
         <service
             android:name=".authentication.AccountAuthenticatorService"
             android:exported="true" >

+ 62 - 54
src/main/java/com/owncloud/android/jobs/FilesSyncJob.java

@@ -31,6 +31,7 @@ import android.text.TextUtils;
 
 import com.evernote.android.job.Job;
 import com.evernote.android.job.JobManager;
+import com.evernote.android.job.util.support.PersistableBundleCompat;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.FilesystemDataProvider;
@@ -55,6 +56,8 @@ import java.util.TimeZone;
 public class FilesSyncJob extends Job {
     public static final String TAG = "FilesSyncJob";
 
+    public static String SKIP_CUSTOM = "skipCustom";
+
     @NonNull
     @Override
     protected Result onRunJob(Params params) {
@@ -67,10 +70,13 @@ public class FilesSyncJob extends Job {
                 TAG);
         wakeLock.acquire();
 
+        PersistableBundleCompat bundle = params.getExtras();
+        final boolean skipCustom = bundle.getBoolean(SKIP_CUSTOM, false);
+
         if (JobManager.instance().getAllJobsForTag(FilesSyncJob.TAG).size() == 1) {
 
             FilesSyncHelper.restartJobsIfNeeded();
-            FilesSyncHelper.insertAllDBEntries();
+            FilesSyncHelper.insertAllDBEntries(skipCustom);
 
             // Create all the providers we'll need
             final FilesystemDataProvider filesystemDataProvider = new FilesystemDataProvider(contentResolver);
@@ -78,63 +84,65 @@ public class FilesSyncJob extends Job {
 
             for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
                 if (syncedFolder.isEnabled()) {
-                    for (String path : filesystemDataProvider.getFilesForUpload(syncedFolder.getLocalPath(),
-                            Long.toString(syncedFolder.getId()))) {
-                        if (JobManager.instance().getAllJobRequests().size() < 80) {
-                            File file = new File(path);
-
-                            Long lastModificationTime = file.lastModified();
-                            final Locale currentLocale = context.getResources().getConfiguration().locale;
-
-                            if (MediaFolder.IMAGE == syncedFolder.getType()) {
-                                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);
-                                        if (!TextUtils.isEmpty(exifDate)) {
-                                            ParsePosition pos = new ParsePosition(0);
-                                            SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss",
-                                                    currentLocale);
-                                            sFormatter.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
-                                            Date dateTime = sFormatter.parse(exifDate, pos);
-                                            lastModificationTime = dateTime.getTime();
+                    if (!skipCustom || MediaFolder.CUSTOM != syncedFolder.getType()) {
+                        for (String path : filesystemDataProvider.getFilesForUpload(syncedFolder.getLocalPath(),
+                                Long.toString(syncedFolder.getId()))) {
+                            if (JobManager.instance().getAllJobRequests().size() < 80) {
+                                File file = new File(path);
+
+                                Long lastModificationTime = file.lastModified();
+                                final Locale currentLocale = context.getResources().getConfiguration().locale;
+
+                                if (MediaFolder.IMAGE == syncedFolder.getType()) {
+                                    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);
+                                            if (!TextUtils.isEmpty(exifDate)) {
+                                                ParsePosition pos = new ParsePosition(0);
+                                                SimpleDateFormat sFormatter = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss",
+                                                        currentLocale);
+                                                sFormatter.setTimeZone(TimeZone.getTimeZone(TimeZone.getDefault().getID()));
+                                                Date dateTime = sFormatter.parse(exifDate, pos);
+                                                lastModificationTime = dateTime.getTime();
+                                            }
+
+                                        } catch (IOException e) {
+                                            Log_OC.d(TAG, "Failed to get the proper time " + e.getLocalizedMessage());
                                         }
-
-                                    } catch (IOException e) {
-                                        Log_OC.d(TAG, "Failed to get the proper time " + e.getLocalizedMessage());
                                     }
                                 }
-                            }
 
-                            boolean needsCharging = syncedFolder.getChargingOnly();
-                            boolean needsWifi = syncedFolder.getWifiOnly();
-
-                            String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
-
-                            Account account = AccountUtils.getOwnCloudAccountByName(context, syncedFolder.getAccount());
-
-                            requester.uploadFileWithOverwrite(
-                                    context,
-                                    account,
-                                    file.getAbsolutePath(),
-                                    FileStorageUtils.getInstantUploadFilePath(
-                                            currentLocale,
-                                            syncedFolder.getRemotePath(), file.getName(),
-                                            lastModificationTime,
-                                            syncedFolder.getSubfolderByDate()),
-                                    syncedFolder.getUploadAction(),
-                                    mimeType,
-                                    true,           // create parent folder if not existent
-                                    UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
-                                    needsWifi,
-                                    needsCharging,
-                                    true
-                            );
-
-                            filesystemDataProvider.updateFilesystemFileAsSentForUpload(path,
-                                    Long.toString(syncedFolder.getId()));
+                                boolean needsCharging = syncedFolder.getChargingOnly();
+                                boolean needsWifi = syncedFolder.getWifiOnly();
+
+                                String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
+
+                                Account account = AccountUtils.getOwnCloudAccountByName(context, syncedFolder.getAccount());
+
+                                requester.uploadFileWithOverwrite(
+                                        context,
+                                        account,
+                                        file.getAbsolutePath(),
+                                        FileStorageUtils.getInstantUploadFilePath(
+                                                currentLocale,
+                                                syncedFolder.getRemotePath(), file.getName(),
+                                                lastModificationTime,
+                                                syncedFolder.getSubfolderByDate()),
+                                        syncedFolder.getUploadAction(),
+                                        mimeType,
+                                        true,           // create parent folder if not existent
+                                        UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
+                                        needsWifi,
+                                        needsCharging,
+                                        true
+                                );
+
+                                filesystemDataProvider.updateFilesystemFileAsSentForUpload(path,
+                                        Long.toString(syncedFolder.getId()));
+                            }
                         }
                     }
                 }

+ 5 - 0
src/main/java/com/owncloud/android/jobs/M1ContentObserverJob.java

@@ -27,6 +27,7 @@ import android.os.Build;
 import android.support.annotation.RequiresApi;
 
 import com.evernote.android.job.JobRequest;
+import com.evernote.android.job.util.support.PersistableBundleCompat;
 import com.owncloud.android.utils.FilesSyncHelper;
 
 import java.util.concurrent.TimeUnit;
@@ -40,6 +41,10 @@ public class M1ContentObserverJob extends JobService {
             if (params.getJobId() == FilesSyncHelper.ContentSyncJobId) {
                 if (params.getTriggeredContentAuthorities() != null && params.getTriggeredContentUris() != null
                         && params.getTriggeredContentUris().length > 0) {
+
+                    PersistableBundleCompat persistableBundleCompat = new PersistableBundleCompat();
+                    persistableBundleCompat.putBoolean(FilesSyncJob.SKIP_CUSTOM, true);
+
                     new JobRequest.Builder(FilesSyncJob.TAG)
                             .setExecutionWindow(1, TimeUnit.SECONDS.toMillis(2))
                             .setBackoffCriteria(TimeUnit.SECONDS.toMillis(5), JobRequest.BackoffPolicy.LINEAR)

+ 2 - 1
src/main/java/com/owncloud/android/utils/FilesSyncHelper.java

@@ -142,13 +142,14 @@ public class FilesSyncHelper {
         }
     }
 
-    public static void insertAllDBEntries() {
+    public static void insertAllDBEntries(boolean skipCustom) {
         final Context context = MainApp.getAppContext();
         final ContentResolver contentResolver = context.getContentResolver();
         SyncedFolderProvider syncedFolderProvider = new SyncedFolderProvider(contentResolver);
 
         for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
             if (syncedFolder.isEnabled()) {
+                if (!skipCustom || MediaFolder.CUSTOM != syncedFolder.getType())
                 insertAllDBEntriesForSyncedFolder(syncedFolder);
             }
         }