Merge with develop
authorMagnus Sjoqvist <magnus.b.j.sjoqvist@gmail.com>
Mon, 20 Oct 2014 12:38:13 +0000 (14:38 +0200)
committerMagnus Sjoqvist <magnus.b.j.sjoqvist@gmail.com>
Mon, 20 Oct 2014 12:38:13 +0000 (14:38 +0200)
1  2 
res/values/strings.xml
res/xml/preferences.xml
src/com/owncloud/android/ui/activity/Preferences.java

diff --combined res/values/strings.xml
@@@ -31,9 -31,7 +31,9 @@@
      <string name="prefs_recommend">Recommend to a friend</string>
      <string name="prefs_feedback">Feedback</string>
      <string name="prefs_imprint">Imprint</string>
 -    
 +    <string name="prefs_remember_last_share_location">Remember share location</string>
 +    <string name="prefs_remember_last_upload_location_summary">Remember last share upload location</string>
 +
        <string name="recommend_subject">"Try %1$s on your smartphone!"</string>
        <string name="recommend_text">"I want to invite you to use %1$s on your smartphone!\nDownload here: %2$s"</string>
  
      <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="network_error_socket_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
        <string name="network_error_connect_timeout_exception">An error occurred while waiting for the server, the operation couldn\'t have been done</string>
        <string name="network_host_not_available">The operation couldn\'t be completed, server is unavailable</string>
 +
        <string name="empty"></string>
        
        <string name="forbidden_permissions">You do not have permission %s</string>
        <string name="move_file_invalid_overwrite">The file exists already in the destination folder</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>
diff --combined res/xml/preferences.xml
      <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:key="save_last_upload_location"
 +        android:title="@string/prefs_remember_last_share_location"
 +        android:summary="@string/prefs_remember_last_upload_location_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>
        
        <PreferenceCategory android:title="@string/prefs_category_more" android:key="more">
@@@ -68,4 -71,4 +74,4 @@@
        </PreferenceCategory>
      
  
- </PreferenceScreen>
+ </PreferenceScreen>
@@@ -51,7 -51,6 +51,7 @@@ import com.owncloud.android.R
  import com.owncloud.android.authentication.AccountUtils;
  import com.owncloud.android.authentication.AuthenticatorActivity;
  import com.owncloud.android.db.DbHandler;
 +import com.owncloud.android.ui.CheckBoxPreferenceWithLongTitle;
  import com.owncloud.android.lib.common.utils.Log_OC;
  import com.owncloud.android.ui.LongClickableCheckBoxPreference;
  import com.owncloud.android.utils.DisplayUtils;
@@@ -69,13 -68,13 +69,14 @@@ public class Preferences extends Sherlo
  
      private DbHandler mDbHandler;
      private CheckBoxPreference pCode;
 +    private CheckBoxPreference pSaveLocation;
      private Preference pAboutApp;
  
      private PreferenceCategory mAccountsPrefCategory = null;
      private final Handler mHandler = new Handler();
      private String mAccountName;
      private boolean mShowContextMenu = false;
+     private String mUploadPath;
  
  
      @SuppressWarnings("deprecation")
@@@ -89,7 -88,9 +90,9 @@@
          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");
  
              
          }
  
 +        pSaveLocation = (CheckBoxPreferenceWithLongTitle) findPreference("save_last_upload_location");
 +        if(pSaveLocation != null){
 +            pSaveLocation.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
 +                @Override
 +                public boolean onPreferenceChange(Preference preference, Object newValue) {
 +                    //The saved path is removed when the preference is turned off
 +                    if( newValue instanceof Boolean  && !(Boolean) newValue) {
 +                        SharedPreferences.Editor appPrefs = PreferenceManager
 +                                       .getDefaultSharedPreferences(getApplicationContext()).edit();
 +                        appPrefs.remove("last_upload_path");
 +                        appPrefs.commit();
 +                    }
 +                    return true;
 +                }
 +            });
 +        }
 +
 +
          PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("more");
          
          boolean helpEnabled = getResources().getBoolean(R.bool.help_enabled);
                  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");
      }
  
      @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
  
      }
  
+     /**
+      * 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();
+     }
  }