浏览代码

Merge pull request #1292 from nextcloud/autoUploadLight

Make auto upload light working again
Andy Scherzinger 7 年之前
父节点
当前提交
2b2fb45732

+ 1 - 1
scripts/lint/lint-results.txt

@@ -1,2 +1,2 @@
 DO NOT TOUCH; GENERATED BY DRONE
 DO NOT TOUCH; GENERATED BY DRONE
-      <span class="mdl-layout-title">Lint Report: 3 errors and 653 warnings</span>
+      <span class="mdl-layout-title">Lint Report: 3 errors and 646 warnings</span>

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

@@ -1,4 +1,4 @@
-/**
+/*
  * Nextcloud Android client application
  * Nextcloud Android client application
  *
  *
  * @author Mario Danic
  * @author Mario Danic
@@ -24,6 +24,7 @@ package com.owncloud.android.jobs;
 import android.accounts.Account;
 import android.accounts.Account;
 import android.content.ContentResolver;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Context;
+import android.content.res.Resources;
 import android.os.PowerManager;
 import android.os.PowerManager;
 import android.support.annotation.NonNull;
 import android.support.annotation.NonNull;
 import android.support.media.ExifInterface;
 import android.support.media.ExifInterface;
@@ -32,7 +33,9 @@ import android.text.TextUtils;
 import com.evernote.android.job.Job;
 import com.evernote.android.job.Job;
 import com.evernote.android.job.util.support.PersistableBundleCompat;
 import com.evernote.android.job.util.support.PersistableBundleCompat;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.MainApp;
+import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.authentication.AccountUtils;
+import com.owncloud.android.datamodel.ArbitraryDataProvider;
 import com.owncloud.android.datamodel.FilesystemDataProvider;
 import com.owncloud.android.datamodel.FilesystemDataProvider;
 import com.owncloud.android.datamodel.MediaFolderType;
 import com.owncloud.android.datamodel.MediaFolderType;
 import com.owncloud.android.datamodel.SyncedFolder;
 import com.owncloud.android.datamodel.SyncedFolder;
@@ -40,6 +43,7 @@ import com.owncloud.android.datamodel.SyncedFolderProvider;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.operations.UploadFileOperation;
 import com.owncloud.android.operations.UploadFileOperation;
+import com.owncloud.android.ui.activity.Preferences;
 import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.FilesSyncHelper;
 import com.owncloud.android.utils.FilesSyncHelper;
 import com.owncloud.android.utils.MimeTypeUtil;
 import com.owncloud.android.utils.MimeTypeUtil;
@@ -78,6 +82,9 @@ public class FilesSyncJob extends Job {
         PersistableBundleCompat bundle = params.getExtras();
         PersistableBundleCompat bundle = params.getExtras();
         final boolean skipCustom = bundle.getBoolean(SKIP_CUSTOM, false);
         final boolean skipCustom = bundle.getBoolean(SKIP_CUSTOM, false);
 
 
+        Resources resources = MainApp.getAppContext().getResources();
+        boolean lightVersion = resources.getBoolean(R.bool.syncedFolder_light);
+
         FilesSyncHelper.restartJobsIfNeeded();
         FilesSyncHelper.restartJobsIfNeeded();
         FilesSyncHelper.insertAllDBEntries(skipCustom);
         FilesSyncHelper.insertAllDBEntries(skipCustom);
 
 
@@ -95,9 +102,9 @@ public class FilesSyncJob extends Job {
                     final Locale currentLocale = context.getResources().getConfiguration().locale;
                     final Locale currentLocale = context.getResources().getConfiguration().locale;
 
 
                     if (MediaFolderType.IMAGE == syncedFolder.getType()) {
                     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 {
                             try {
                                 ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
                                 ExifInterface exifInterface = new ExifInterface(file.getAbsolutePath());
                                 String exifDate = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
                                 String exifDate = exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
@@ -116,23 +123,46 @@ public class FilesSyncJob extends Job {
                         }
                         }
                     }
                     }
 
 
-                    boolean needsCharging = syncedFolder.getChargingOnly();
-                    boolean needsWifi = syncedFolder.getWifiOnly();
-
                     String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
                     String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
 
 
                     Account account = AccountUtils.getOwnCloudAccountByName(context, syncedFolder.getAccount());
                     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(
                     requester.uploadFileWithOverwrite(
                             context,
                             context,
                             account,
                             account,
                             file.getAbsolutePath(),
                             file.getAbsolutePath(),
                             FileStorageUtils.getInstantUploadFilePath(
                             FileStorageUtils.getInstantUploadFilePath(
                                     currentLocale,
                                     currentLocale,
-                                    syncedFolder.getRemotePath(), file.getName(),
-                                    lastModificationTime,
-                                    syncedFolder.getSubfolderByDate()),
-                            syncedFolder.getUploadAction(),
+                                    remotePath, file.getName(),
+                                    lastModificationTime, subfolderByDate),
+                            uploadAction,
                             mimeType,
                             mimeType,
                             true,           // create parent folder if not existent
                             true,           // create parent folder if not existent
                             UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
                             UploadFileOperation.CREATED_AS_INSTANT_PICTURE,
@@ -150,4 +180,17 @@ public class FilesSyncJob extends Job {
         wakeLock.release();
         wakeLock.release();
         return Result.SUCCESS;
         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;
+        }
+    }
 }
 }

+ 17 - 11
src/main/java/com/owncloud/android/ui/activity/Preferences.java

@@ -339,17 +339,23 @@ public class Preferences extends PreferenceActivity
         }
         }
 
 
         mExpertMode = (SwitchPreference) findPreference("expert_mode");
         mExpertMode = (SwitchPreference) findPreference("expert_mode");
-        mExpertMode.setOnPreferenceClickListener(new OnPreferenceClickListener() {
-            @Override
-            public boolean onPreferenceClick(Preference preference) {
-                SharedPreferences appPrefs =
-                        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
-                SharedPreferences.Editor editor = appPrefs.edit();
-                editor.putBoolean("expert_mode", mExpertMode.isChecked());
-                editor.apply();
-                return true;
-            }
-        });
+
+        if (getResources().getBoolean(R.bool.syncedFolder_light)) {
+            preferenceCategoryDetails.removePreference(mExpertMode);
+        } else {
+            mExpertMode = (SwitchPreference) findPreference("expert_mode");
+            mExpertMode.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+                @Override
+                public boolean onPreferenceClick(Preference preference) {
+                    SharedPreferences appPrefs =
+                            PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+                    SharedPreferences.Editor editor = appPrefs.edit();
+                    editor.putBoolean("expert_mode", mExpertMode.isChecked());
+                    editor.apply();
+                    return true;
+                }
+            });
+        }
 
 
         PreferenceCategory preferenceCategoryMore = (PreferenceCategory) findPreference("more");
         PreferenceCategory preferenceCategoryMore = (PreferenceCategory) findPreference("more");
         preferenceCategoryMore.setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_more),
         preferenceCategoryMore.setTitle(ThemeUtils.getColoredTitle(getString(R.string.prefs_category_more),

+ 0 - 27
src/main/res/anim/disappear.xml

@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  ownCloud Android client application
-
-  Copyright (C) 2012  Bartek Przybylski
-  Copyright (C) 2015 ownCloud Inc.
-
-  This program is free software: you can redistribute it and/or modify
-  it under the terms of the GNU General Public License version 2,
-  as published by the Free Software Foundation.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.
--->
-<set xmlns:android="http://schemas.android.com/apk/res/android">
-
-	<alpha
-		android:interpolator="@android:anim/decelerate_interpolator"
-		android:fromAlpha="1.0" android:toAlpha="0.0"
-		android:duration="400"
-	/>
-</set>