Remove last slash from uploads path (video/image) when showing them on settings view...
authorjabarros <jabarros@solidgear.es>
Thu, 20 Nov 2014 08:39:10 +0000 (09:39 +0100)
committerjabarros <jabarros@solidgear.es>
Thu, 20 Nov 2014 08:39:10 +0000 (09:39 +0100)
src/com/owncloud/android/ui/activity/Preferences.java
src/com/owncloud/android/ui/adapter/FileListListAdapter.java
src/com/owncloud/android/utils/DisplayUtils.java

index 3a5c5b4..9c11f0a 100644 (file)
@@ -70,7 +70,6 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
     private static final int ACTION_SELECT_UPLOAD_PATH = 1;
     private static final int ACTION_SELECT_UPLOAD_VIDEO_PATH = 2;
 
-
     private DbHandler mDbHandler;
     private CheckBoxPreference pCode;
     private Preference pAboutApp;
@@ -255,6 +254,9 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
             mPrefInstantUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                     @Override
                     public boolean onPreferenceClick(Preference preference) {
+                        if (!mUploadPath.endsWith(OCFile.PATH_SEPARATOR)) {
+                            mUploadPath += OCFile.PATH_SEPARATOR;
+                        }
                         Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
                         intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadPath);
                         startActivityForResult(intent, ACTION_SELECT_UPLOAD_PATH);
@@ -269,6 +271,9 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
             mPrefInstantVideoUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                     @Override
                     public boolean onPreferenceClick(Preference preference) {
+                        if (!mUploadVideoPath.endsWith(OCFile.PATH_SEPARATOR)) {
+                            mUploadVideoPath += OCFile.PATH_SEPARATOR;
+                        }
                         Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
                         intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadVideoPath);
                         startActivityForResult(intent, ACTION_SELECT_UPLOAD_VIDEO_PATH);
@@ -406,7 +411,13 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
 
             mUploadPath = folderToUpload.getRemotePath();
 
+            mUploadPath = DisplayUtils.getPathWithoutLastSlash(mUploadPath);
+
+            // Show the path on summary preference
+            mPrefInstantUploadPath.setSummary(mUploadPath);
+
             saveInstantUploadPathOnPreferences();
+
         } else if (requestCode == ACTION_SELECT_UPLOAD_VIDEO_PATH && (resultCode == RESULT_OK || 
                 resultCode == UploadPathActivity.RESULT_OK_SET_UPLOAD_PATH)){
 
@@ -414,6 +425,11 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
 
             mUploadVideoPath = folderToUploadVideo.getRemotePath();
 
+            mUploadVideoPath = DisplayUtils.getPathWithoutLastSlash(mUploadVideoPath);
+
+            // Show the video path on summary preference
+            mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
+
             saveInstantUploadVideoPathOnPreferences();
         }
     }
@@ -540,7 +556,6 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
      * Save the "Instant Upload Path" on preferences
      */
     private void saveInstantUploadPathOnPreferences() {
-        mPrefInstantUploadPath.setSummary(mUploadPath);
         SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());        
         SharedPreferences.Editor editor = appPrefs.edit();
         editor.putString("instant_upload_path", mUploadPath);
@@ -560,7 +575,6 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
      * Save the "Instant Video Upload Path" on preferences
      */
     private void saveInstantUploadVideoPathOnPreferences() {
-        mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
         SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());        
         SharedPreferences.Editor editor = appPrefs.edit();
         editor.putString("instant_video_upload_path", mUploadVideoPath);
index 1035632..1df1211 100644 (file)
@@ -47,7 +47,6 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncDrawable;\r
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;\r
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;\r
-import com.owncloud.android.lib.common.utils.Log_OC;\r
 import com.owncloud.android.ui.activity.ComponentsGetter;\r
 import com.owncloud.android.utils.DisplayUtils;\r
 import com.owncloud.android.utils.FileStorageUtils;\r
index da81f53..a1afb89 100644 (file)
@@ -29,11 +29,11 @@ import java.util.Set;
 import android.annotation.TargetApi;\r
 import android.content.Context;\r
 import android.os.Build;\r
-import android.text.format.DateFormat;\r
 import android.text.format.DateUtils;\r
 \r
 import com.owncloud.android.MainApp;\r
 import com.owncloud.android.R;\r
+import com.owncloud.android.datamodel.OCFile;\r
 \r
 /**\r
  * A helper class for some string operations.\r
@@ -320,4 +320,17 @@ public class DisplayUtils {
         \r
         return dateString.toString().split(",")[0];
     }\r
+\r
+    /**\r
+     * Update the passed path removing the last "/" if it is not the root folder\r
+     * @param path\r
+     */\r
+    public static String getPathWithoutLastSlash(String path) {\r
+\r
+        // Remove last slash from path\r
+        if (path.length() > 1 && path.charAt(path.length()-1) == OCFile.PATH_SEPARATOR.charAt(0)) {\r
+            path = path.substring(0, path.length()-1);\r
+        }\r
+        return path;\r
+    }\r
 }\r