浏览代码

Applied changes after CR

David A. Velasco 9 年之前
父节点
当前提交
8118334678

+ 91 - 0
src/com/owncloud/android/db/PreferenceManager.java

@@ -0,0 +1,91 @@
+/**
+ * ownCloud Android client application
+ *
+ * @author David A. Velasco
+ * Copyright (C) 2016 ownCloud Inc.
+ * <p/>
+ * 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.
+ * <p/>
+ * 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.
+ * <p/>
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package com.owncloud.android.db;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+
+/**
+ * Helper to simplify reading of Preferences all around the app
+ */
+
+public class PreferenceManager {
+
+    /**
+     * Constant to access value of last path selected by the user to upload a file shared from other app.
+     * Value handled by the app without direct access in the UI.
+     */
+    private static final String AUTO_PREF__LAST_UPLOAD_PATH = "last_upload_path";
+
+    public static boolean instantPictureUploadEnabled(Context context) {
+        return android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
+                "instant_uploading",
+                false
+        );
+    }
+
+    public static boolean instantVideoUploadEnabled(Context context) {
+        return android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
+                "instant_video_uploading",
+                false
+        );
+    }
+
+    public static boolean instantPictureUploadViaWiFiOnly(Context context) {
+        return android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
+                "instant_upload_on_wifi",
+                false
+        );
+    }
+
+    public static boolean instantVideoUploadViaWiFiOnly(Context context) {
+        return android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
+                "instant_video_upload_on_wifi",
+                false
+        );
+    }
+
+    /**
+     * Gets the path where the user selected to do the last upload of a file shared from other app.
+     *
+     * @param context   Caller {@link Context}, used to access to shared preferences manager.
+     * @return path     Absolute path to a folder, as previously stored by {@link #setLastUploadPath(String, Context)},
+     *                  or empty String if never saved before.
+     */
+    public static String getLastUploadPath(Context context) {
+        SharedPreferences appPreferences = android.preference.PreferenceManager
+            .getDefaultSharedPreferences(context.getApplicationContext());
+        return appPreferences.getString(AUTO_PREF__LAST_UPLOAD_PATH, "");
+    }
+
+    /**
+     * Saves the path where the user selected to do the last upload of a file shared from other app.
+     *
+     * @param path      Absolute path to a folder.
+     * @param context   Caller {@link Context}, used to access to shared preferences manager.
+     */
+    public static void setLastUploadPath(String path, Context context) {
+        SharedPreferences.Editor appPrefs = android.preference.PreferenceManager
+            .getDefaultSharedPreferences(context.getApplicationContext()).edit();
+        appPrefs.putString(AUTO_PREF__LAST_UPLOAD_PATH, path);
+        appPrefs.apply();
+    }
+
+}

+ 0 - 59
src/com/owncloud/android/db/PreferenceReader.java

@@ -1,59 +0,0 @@
-/**
- * ownCloud Android client application
- *
- * @author David A. Velasco
- * Copyright (C) 2016 ownCloud Inc.
- * <p/>
- * 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.
- * <p/>
- * 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.
- * <p/>
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.owncloud.android.db;
-
-import android.content.Context;
-import android.preference.PreferenceManager;
-
-/**
- * Helper to simplify reading of Preferences all around the app
- */
-
-public class PreferenceReader {
-
-    public static boolean instantPictureUploadEnabled(Context context) {
-        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
-                "instant_uploading",
-                false
-        );
-    }
-
-    public static boolean instantVideoUploadEnabled(Context context) {
-        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
-                "instant_video_uploading",
-                false
-        );
-    }
-
-    public static boolean instantPictureUploadViaWiFiOnly(Context context) {
-        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
-                "instant_upload_on_wifi",
-                false
-        );
-    }
-
-    public static boolean instantVideoUploadViaWiFiOnly(Context context) {
-        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
-                "instant_video_upload_on_wifi",
-                false
-        );
-    }
-
-}

+ 4 - 5
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java

@@ -28,13 +28,12 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.database.Cursor;
-import android.preference.PreferenceManager;
 import android.provider.MediaStore.Images;
 import android.provider.MediaStore.Video;
 import android.support.v4.content.ContextCompat;
 
 import com.owncloud.android.authentication.AccountUtils;
-import com.owncloud.android.db.PreferenceReader;
+import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.operations.UploadFileOperation;
@@ -87,7 +86,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
 
         Log_OC.i(TAG, "New photo received");
 
-        if (!PreferenceReader.instantPictureUploadEnabled(context)) {
+        if (!PreferenceManager.instantPictureUploadEnabled(context)) {
             Log_OC.d(TAG, "Instant picture upload disabled, ignoring new picture");
             return;
         }
@@ -144,7 +143,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
     }
 
     private Integer getUploadBehaviour(Context context) {
-        SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(context);
+        SharedPreferences appPreferences = android.preference.PreferenceManager.getDefaultSharedPreferences(context);
         String behaviour = appPreferences.getString("prefs_instant_behaviour", "NOTHING");
 
         if (behaviour.equalsIgnoreCase("NOTHING")) {
@@ -165,7 +164,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
 
         Log_OC.i(TAG, "New video received");
 
-        if (!PreferenceReader.instantVideoUploadEnabled(context)) {
+        if (!PreferenceManager.instantVideoUploadEnabled(context)) {
             Log_OC.d(TAG, "Instant video upload disabled, ignoring new video");
             return;
         }

+ 5 - 5
src/com/owncloud/android/files/services/ConnectivityActionReceiver.java

@@ -30,7 +30,7 @@ import android.net.wifi.WifiInfo;
 import android.net.wifi.WifiManager;
 import android.os.Bundle;
 
-import com.owncloud.android.db.PreferenceReader;
+import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.db.UploadResult;
 import com.owncloud.android.lib.common.utils.Log_OC;
 
@@ -155,10 +155,10 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
     private void wifiConnected(Context context) {
         // for the moment, only recovery of instant uploads, similar to behaviour in release 1.9.1
         if (
-                (PreferenceReader.instantPictureUploadEnabled(context) &&
-                        PreferenceReader.instantPictureUploadViaWiFiOnly(context)) ||
-                (PreferenceReader.instantVideoUploadEnabled(context) &&
-                        PreferenceReader.instantVideoUploadViaWiFiOnly(context))
+                (PreferenceManager.instantPictureUploadEnabled(context) &&
+                        PreferenceManager.instantPictureUploadViaWiFiOnly(context)) ||
+                (PreferenceManager.instantVideoUploadEnabled(context) &&
+                        PreferenceManager.instantVideoUploadViaWiFiOnly(context))
                 ) {
             Log_OC.d(TAG, "Requesting retry of instant uploads (& friends)");
             FileUploader.UploadRequester requester = new FileUploader.UploadRequester();

+ 6 - 6
src/com/owncloud/android/operations/UploadFileOperation.java

@@ -27,7 +27,7 @@ import android.net.Uri;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.db.OCUpload;
-import com.owncloud.android.db.PreferenceReader;
+import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
@@ -157,9 +157,9 @@ public class UploadFileOperation extends SyncOperation {
 
         mAccount = account;
         mFile = obtainNewOCFileToUpload(
-                upload.getRemotePath(),
-                upload.getLocalPath(),
-                upload.getMimeType()
+            upload.getRemotePath(),
+            upload.getLocalPath(),
+            upload.getMimeType()
         );
         mRemotePath = upload.getRemotePath();
         mChunked = chunked;
@@ -444,10 +444,10 @@ public class UploadFileOperation extends SyncOperation {
      */
     private boolean delayForWifi() {
         boolean delayInstantPicture = (
-            isInstantPicture() &&  PreferenceReader.instantPictureUploadViaWiFiOnly(mContext)
+            isInstantPicture() &&  PreferenceManager.instantPictureUploadViaWiFiOnly(mContext)
         );
         boolean delayInstantVideo = (
-            isInstantVideo() && PreferenceReader.instantVideoUploadViaWiFiOnly(mContext)
+            isInstantVideo() && PreferenceManager.instantVideoUploadViaWiFiOnly(mContext)
         );
         return (
             (delayInstantPicture || delayInstantVideo) &&

+ 8 - 23
src/com/owncloud/android/ui/activity/Uploader.java

@@ -3,6 +3,8 @@
  *
  *  @author Bartek Przybylski
  *  @author masensio
+ *  @author Juan Carlos González Cabrero
+ *  @author David A. Velasco
  *  Copyright (C) 2012  Bartek Przybylski
  *  Copyright (C) 2016 ownCloud Inc.
  *
@@ -34,12 +36,10 @@ import android.content.IntentFilter;
 import android.content.DialogInterface.OnCancelListener;
 import android.content.DialogInterface.OnClickListener;
 import android.content.Intent;
-import android.content.SharedPreferences;
 import android.content.res.Resources.NotFoundException;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Parcelable;
-import android.preference.PreferenceManager;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
@@ -60,6 +60,7 @@ import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountAuthenticator;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.db.PreferenceManager;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@@ -534,11 +535,7 @@ public class Uploader extends FileActivity
 
         } finally {
             // Save the path to shared preferences; even if upload is not possible, user chose the folder
-            SharedPreferences.Editor appPrefs = PreferenceManager
-                .getDefaultSharedPreferences(getApplicationContext()).edit();
-            appPrefs.putString("last_upload_path", mUploadPath);
-            appPrefs.apply();
-
+            PreferenceManager.setLastUploadPath(mUploadPath, this);
         }
     }
 
@@ -644,15 +641,12 @@ public class Uploader extends FileActivity
                     "initializing mStorageManager");
         }
 
-        SharedPreferences appPreferences = PreferenceManager
-                .getDefaultSharedPreferences(getApplicationContext());
-
-        String last_path = appPreferences.getString("last_upload_path", "");
+        String lastPath = PreferenceManager.getLastUploadPath(this);
         // "/" equals root-directory
-        if (last_path.equals("/")) {
+        if (lastPath.equals("/")) {
             mParents.add("");
         } else {
-            String[] dir_names = last_path.split("/");
+            String[] dir_names = lastPath.split("/");
             mParents.clear();
             for (String dir : dir_names)
                 mParents.add(dir);
@@ -900,16 +894,7 @@ public class Uploader extends FileActivity
         }
 
         /**
-         * Set the callback to null so we don't accidentally leak the
-         * Activity instance.
-         */
-        @Override
-        public void onDetach() {
-            super.onDetach();
-        }
-
-        /**
-         * Sets the task to retain accross configuration changes
+         * Sets the task to retain across configuration changes
          *
          * @param task  Task to retain
          */

+ 3 - 1
src/com/owncloud/android/ui/asynctasks/CopyAndUploadContentUrisTask.java

@@ -2,7 +2,9 @@
  *   ownCloud Android client application
  *
  *   @author masensio
- *   Copyright (C) 2015 ownCloud Inc.
+ *   @author Juan Carlos González Cabrero
+ *   @author David A. Velasco
+ *   Copyright (C) 2016 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,