Merge pull request #658 from owncloud/instant_upload_path_chooseable
authorDavid A. Velasco <dvelasco@owncloud.com>
Mon, 20 Oct 2014 11:56:18 +0000 (13:56 +0200)
committerDavid A. Velasco <dvelasco@owncloud.com>
Mon, 20 Oct 2014 11:56:18 +0000 (13:56 +0200)
Instant upload path chooseable

.travis.yml
res/values/strings.xml
res/xml/preferences.xml
src/com/owncloud/android/operations/CreateFolderOperation.java
src/com/owncloud/android/ui/activity/Preferences.java
src/com/owncloud/android/utils/FileStorageUtils.java

index d205021..50b73d1 100644 (file)
@@ -1,15 +1,20 @@
-language: java
+language: android
+android:
+  components:
+    - build-tools-20.0.0
+    - android-19
+    - android-17
+    - android-14
+    - extra-android-support
+  licenses:
+    - 'android-sdk-license-5be876d5'
+    - 'android-sdk-license-598b93a6'
+  
 jdk: oraclejdk7
+
 before_install:
-  # Install base Android SDK
-    - sudo apt-get update -qq
-    - sudo apt-get install -qq libstdc++6:i386 lib32z1 expect
-    - export COMPONENTS="build-tools-20.0.0,android-14,android-17,android-19,sysimg-19,extra-android-support"
-    - export LICENSES="android-sdk-license-5be876d5|android-sdk-license-598b93a6"
-    - curl -3L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS --accept=$LICENSES
-    - source ~/.android-sdk-installer/env
-    - rm pom.xml
-    - ./setup_env.sh
+  - rm pom.xml
+  - ./setup_env.sh
 
 script:
   - ant clean
index 4c7cf34..b021ed7 100644 (file)
     <string name="preview_image_error_unknown_format">This image cannot be shown</string>
     
     <string name="error__upload__local_file_not_copied">%1$s could not be copied to %2$s local folder</string>
+    <string name="prefs_instant_upload_path_title">Upload Path</string>
 
        <string name="share_link_no_support_share_api">Sorry, sharing is not enabled on your server. Please contact your
                administrator.</string>
        <string name="move_file_error">An error occurred while trying to move this file or folder</string>
        <string name="forbidden_permissions_move">to move this file</string>
 
+       <string name="prefs_category_instant_uploading">Instant Uploads</string>
+       <string name="prefs_category_security">Security</string>
+
 </resources>
index 945e853..3b8b3e8 100644 (file)
     <PreferenceCategory android:title="@string/prefs_category_accounts" android:key="accounts_category">
     </PreferenceCategory>
     
-       <PreferenceCategory android:title="@string/prefs_category_general">
-    <!-- ListPreference
-        android:key="select_oc_account"
-        android:title="@string/prefs_select_oc_account"
-        android:summary="@string/prefs_summary_select_oc_account" 
-        / -->
-    <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:title="@string/prefs_pincode" android:key="set_pincode" 
+       <PreferenceCategory android:title="@string/prefs_category_security">
+           <!-- ListPreference
+               android:key="select_oc_account"
+               android:title="@string/prefs_select_oc_account"
+               android:summary="@string/prefs_summary_select_oc_account"
+               / -->
+           <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:title="@string/prefs_pincode" android:key="set_pincode" 
                         android:summary="@string/prefs_pincode_summary"/>
-    <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading" 
-                        android:title="@string/prefs_instant_upload"  
-                        android:summary="@string/prefs_instant_upload_summary"/>
-    <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:dependency="instant_uploading" 
-                                       android:disableDependentsState="true" 
-                                       android:title="@string/instant_upload_on_wifi" 
-                                       android:key="instant_upload_on_wifi"/>
-    <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_video_uploading" 
-                        android:title="@string/prefs_instant_video_upload"  
-                        android:summary="@string/prefs_instant_video_upload_summary"/>
-    <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:dependency="instant_video_uploading" 
-                                       android:disableDependentsState="true" 
-                                       android:title="@string/instant_video_upload_on_wifi" 
-                                       android:key="instant_video_upload_on_wifi"/>
-    <!-- DISABLED FOR RELEASE UNTIL FIXED 
-    CheckBoxPreference android:key="log_to_file" 
-                        android:title="@string/prefs_log_title"  
-                        android:summary="@string/prefs_log_summary"/>
-       <Preference             android:key="log_history" 
-                        android:title="@string/prefs_log_title_history"  
-                        android:summary="@string/prefs_log_summary_history"/ -->
+       </PreferenceCategory>
+
+    <PreferenceCategory android:title="@string/prefs_category_instant_uploading">
+           <EditTextPreference android:title="@string/prefs_instant_upload_path_title"
+                                               android:defaultValue="@string/instant_upload_path"
+                                               android:key="instant_upload_path"/>
+           <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_uploading"
+                               android:title="@string/prefs_instant_upload"
+                               android:summary="@string/prefs_instant_upload_summary"/>
+           <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:dependency="instant_uploading"
+                                               android:disableDependentsState="true"
+                                               android:title="@string/instant_upload_on_wifi"
+                                               android:key="instant_upload_on_wifi"/>
+           <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:key="instant_video_uploading"
+                               android:title="@string/prefs_instant_video_upload"
+                               android:summary="@string/prefs_instant_video_upload_summary"/>
+           <com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle android:dependency="instant_video_uploading"
+                                               android:disableDependentsState="true"
+                                               android:title="@string/instant_video_upload_on_wifi"
+                                               android:key="instant_video_upload_on_wifi"/>
+           <!-- DISABLED FOR RELEASE UNTIL FIXED
+           CheckBoxPreference android:key="log_to_file"
+                               android:title="@string/prefs_log_title"
+                               android:summary="@string/prefs_log_summary"/>
+               <Preference             android:key="log_history"
+                               android:title="@string/prefs_log_title_history"
+                               android:summary="@string/prefs_log_summary_history"/ -->
                         
     </PreferenceCategory>
        
@@ -65,4 +71,4 @@
        </PreferenceCategory>
     
 
-</PreferenceScreen>
\ No newline at end of file
+</PreferenceScreen>
index b0e7ed9..4df8b3d 100644 (file)
@@ -84,21 +84,36 @@ public class CreateFolderOperation extends SyncOperation implements OnRemoteOper
        }
     }
 
-    
     /**
      * Save new directory in local database
      */
     public void saveFolderInDB() {
-        OCFile newDir = new OCFile(mRemotePath);
-        newDir.setMimetype("DIR");
-        long parentId = getStorageManager().getFileByPath(FileStorageUtils.getParentPath(mRemotePath)).getFileId();
-        newDir.setParentId(parentId);
-        newDir.setModificationTimestamp(System.currentTimeMillis());
-        getStorageManager().saveFile(newDir);
+        if (mCreateFullPath && getStorageManager().
+                getFileByPath(FileStorageUtils.getParentPath(mRemotePath)) == null){// When parent
+                                                                                    // of remote path
+                                                                                    // is not created 
+            String[] subFolders = mRemotePath.split("/");
+            String composedRemotePath = "/";
 
-        Log_OC.d(TAG, "Create directory " + mRemotePath + " in Database");
+            // For each antecesor folders create them recursively
+            for (int i=0; i<subFolders.length; i++) {
+                String subFolder =  subFolders[i];
+                if (!subFolder.isEmpty()) {
+                    composedRemotePath = composedRemotePath + subFolder + "/";
+                    mRemotePath = composedRemotePath;
+                    saveFolderInDB();
+                }
+            }
+        } else { // Create directory on DB
+            OCFile newDir = new OCFile(mRemotePath);
+            newDir.setMimetype("DIR");
+            long parentId = getStorageManager().
+                    getFileByPath(FileStorageUtils.getParentPath(mRemotePath)).getFileId();
+            newDir.setParentId(parentId);
+            newDir.setModificationTimestamp(System.currentTimeMillis());
+            getStorageManager().saveFile(newDir);
 
+            Log_OC.d(TAG, "Create directory " + mRemotePath + " in Database");
+        }
     }
-
-
 }
index 9ac6e27..d078b1e 100644 (file)
@@ -74,6 +74,7 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
     private final Handler mHandler = new Handler();
     private String mAccountName;
     private boolean mShowContextMenu = false;
+    private String mUploadPath;
 
 
     @SuppressWarnings("deprecation")
@@ -87,7 +88,9 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
         actionBar.setIcon(DisplayUtils.getSeasonalIconId());
         actionBar.setDisplayHomeAsUpEnabled(true);
         actionBar.setTitle(R.string.actionbar_settings);
-        
+
+        loadInstantUploadPath();
+
         // Load the accounts category for adding the list of accounts
         mAccountsPrefCategory = (PreferenceCategory) findPreference("accounts_category");
 
@@ -239,6 +242,16 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
                 preferenceCategory.removePreference(pImprint);
             }
         }
+
+        Preference pInstantUploadPathApp = (Preference) findPreference("instant_upload_path");
+
+        pInstantUploadPathApp.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+            @Override
+            public boolean onPreferenceChange(Preference preference, Object newValue) {
+                mUploadPath = updateInstantUploadPath(newValue.toString());
+                return true;
+            }
+        });
             
         /* About App */
        pAboutApp = (Preference) findPreference("about_app");
@@ -255,6 +268,12 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
     }
 
     @Override
+    protected void onPause() {
+        saveInstantUploadPathOnPreferences();
+        super.onPause();
+    }
+
+    @Override
     public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
 
         // Filter for only showing contextual menu when long press on the
@@ -462,4 +481,47 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
 
     }
 
+    /**
+     * Update the upload path checking that it is a correct path
+     * @param uploadPath: path write by user
+     * @return String: uploadPath
+     */
+    private String updateInstantUploadPath(String uploadPath) {
+        String slashString = "/";
+
+        // If slashes are duplicated, replace them for only one slash
+        uploadPath = uploadPath.replaceAll("/+", slashString);
+
+        // Remove last slash from path
+        if (uploadPath.length() > 0 && uploadPath.charAt(uploadPath.length()-1) == slashString.charAt(0)) {
+            uploadPath = uploadPath.substring(0, uploadPath.length()-1);
+        }
+
+        if (uploadPath.isEmpty()) { // Set default instant upload path
+            uploadPath = getString(R.string.instant_upload_path);
+        }else {
+            if (!uploadPath.startsWith(slashString)) { // Add initial slash on path if necessary
+                uploadPath = slashString.concat(uploadPath);
+            }
+        }
+        return uploadPath;
+    }
+
+    /**
+     * Load upload path set on preferences
+     */
+    private void loadInstantUploadPath() {
+        SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
+        mUploadPath = appPrefs.getString("instant_upload_path", getString(R.string.instant_upload_path));
+    }
+
+    /**
+     * Save the "Instant Upload Path" on preferences
+     */
+    private void saveInstantUploadPathOnPreferences() {
+        SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());        
+        SharedPreferences.Editor editor = appPrefs.edit();
+        editor.putString("instant_upload_path", mUploadPath);
+        editor.commit();
+    }
 }
index 58dda0d..3895821 100644 (file)
@@ -26,6 +26,8 @@ import com.owncloud.android.lib.resources.files.RemoteFile;
 
 import android.annotation.SuppressLint;
 import android.content.Context;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
 import android.net.Uri;
 import android.os.Environment;
 import android.os.StatFs;
@@ -73,7 +75,9 @@ public class FileStorageUtils {
     }
 
     public static String getInstantUploadFilePath(Context context, String fileName) {
-        String uploadPath = context.getString(R.string.instant_upload_path);
+        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
+        String uploadPathdef = context.getString(R.string.instant_upload_path);
+        String uploadPath = pref.getString("instant_upload_path", uploadPathdef);
         String value = uploadPath + OCFile.PATH_SEPARATOR +  (fileName == null ? "" : fileName);
         return value;
     }
@@ -120,4 +124,4 @@ public class FileStorageUtils {
         return file;
     }
   
-}
\ No newline at end of file
+}