ソースを参照

Remove last slash from uploads path (video/image) when showing them on settings view and they are not root folder

jabarros 10 年 前
コミット
aa16b13ab9

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

@@ -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_PATH = 1;
     private static final int ACTION_SELECT_UPLOAD_VIDEO_PATH = 2;
     private static final int ACTION_SELECT_UPLOAD_VIDEO_PATH = 2;
 
 
-
     private DbHandler mDbHandler;
     private DbHandler mDbHandler;
     private CheckBoxPreference pCode;
     private CheckBoxPreference pCode;
     private Preference pAboutApp;
     private Preference pAboutApp;
@@ -255,6 +254,9 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
             mPrefInstantUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
             mPrefInstantUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                     @Override
                     @Override
                     public boolean onPreferenceClick(Preference preference) {
                     public boolean onPreferenceClick(Preference preference) {
+                        if (!mUploadPath.endsWith(OCFile.PATH_SEPARATOR)) {
+                            mUploadPath += OCFile.PATH_SEPARATOR;
+                        }
                         Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
                         Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
                         intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadPath);
                         intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadPath);
                         startActivityForResult(intent, ACTION_SELECT_UPLOAD_PATH);
                         startActivityForResult(intent, ACTION_SELECT_UPLOAD_PATH);
@@ -269,6 +271,9 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
             mPrefInstantVideoUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
             mPrefInstantVideoUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() {
                     @Override
                     @Override
                     public boolean onPreferenceClick(Preference preference) {
                     public boolean onPreferenceClick(Preference preference) {
+                        if (!mUploadVideoPath.endsWith(OCFile.PATH_SEPARATOR)) {
+                            mUploadVideoPath += OCFile.PATH_SEPARATOR;
+                        }
                         Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
                         Intent intent = new Intent(Preferences.this, UploadPathActivity.class);
                         intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadVideoPath);
                         intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadVideoPath);
                         startActivityForResult(intent, ACTION_SELECT_UPLOAD_VIDEO_PATH);
                         startActivityForResult(intent, ACTION_SELECT_UPLOAD_VIDEO_PATH);
@@ -406,7 +411,13 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
 
 
             mUploadPath = folderToUpload.getRemotePath();
             mUploadPath = folderToUpload.getRemotePath();
 
 
+            mUploadPath = DisplayUtils.getPathWithoutLastSlash(mUploadPath);
+
+            // Show the path on summary preference
+            mPrefInstantUploadPath.setSummary(mUploadPath);
+
             saveInstantUploadPathOnPreferences();
             saveInstantUploadPathOnPreferences();
+
         } else if (requestCode == ACTION_SELECT_UPLOAD_VIDEO_PATH && (resultCode == RESULT_OK || 
         } else if (requestCode == ACTION_SELECT_UPLOAD_VIDEO_PATH && (resultCode == RESULT_OK || 
                 resultCode == UploadPathActivity.RESULT_OK_SET_UPLOAD_PATH)){
                 resultCode == UploadPathActivity.RESULT_OK_SET_UPLOAD_PATH)){
 
 
@@ -414,6 +425,11 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
 
 
             mUploadVideoPath = folderToUploadVideo.getRemotePath();
             mUploadVideoPath = folderToUploadVideo.getRemotePath();
 
 
+            mUploadVideoPath = DisplayUtils.getPathWithoutLastSlash(mUploadVideoPath);
+
+            // Show the video path on summary preference
+            mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
+
             saveInstantUploadVideoPathOnPreferences();
             saveInstantUploadVideoPathOnPreferences();
         }
         }
     }
     }
@@ -540,7 +556,6 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa
      * Save the "Instant Upload Path" on preferences
      * Save the "Instant Upload Path" on preferences
      */
      */
     private void saveInstantUploadPathOnPreferences() {
     private void saveInstantUploadPathOnPreferences() {
-        mPrefInstantUploadPath.setSummary(mUploadPath);
         SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());        
         SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());        
         SharedPreferences.Editor editor = appPrefs.edit();
         SharedPreferences.Editor editor = appPrefs.edit();
         editor.putString("instant_upload_path", mUploadPath);
         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
      * Save the "Instant Video Upload Path" on preferences
      */
      */
     private void saveInstantUploadVideoPathOnPreferences() {
     private void saveInstantUploadVideoPathOnPreferences() {
-        mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath);
         SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());        
         SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());        
         SharedPreferences.Editor editor = appPrefs.edit();
         SharedPreferences.Editor editor = appPrefs.edit();
         editor.putString("instant_video_upload_path", mUploadVideoPath);
         editor.putString("instant_video_upload_path", mUploadVideoPath);

+ 0 - 1
src/com/owncloud/android/ui/adapter/FileListListAdapter.java

@@ -47,7 +47,6 @@ import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncDrawable;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncDrawable;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
-import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.activity.ComponentsGetter;
 import com.owncloud.android.ui.activity.ComponentsGetter;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.DisplayUtils;
 import com.owncloud.android.utils.FileStorageUtils;
 import com.owncloud.android.utils.FileStorageUtils;

+ 14 - 1
src/com/owncloud/android/utils/DisplayUtils.java

@@ -29,11 +29,11 @@ import java.util.Set;
 import android.annotation.TargetApi;
 import android.annotation.TargetApi;
 import android.content.Context;
 import android.content.Context;
 import android.os.Build;
 import android.os.Build;
-import android.text.format.DateFormat;
 import android.text.format.DateUtils;
 import android.text.format.DateUtils;
 
 
 import com.owncloud.android.MainApp;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.R;
+import com.owncloud.android.datamodel.OCFile;
 
 
 /**
 /**
  * A helper class for some string operations.
  * A helper class for some string operations.
@@ -320,4 +320,17 @@ public class DisplayUtils {
         
         
         return dateString.toString().split(",")[0];
         return dateString.toString().split(",")[0];
     }
     }
+
+    /**
+     * Update the passed path removing the last "/" if it is not the root folder
+     * @param path
+     */
+    public static String getPathWithoutLastSlash(String path) {
+
+        // Remove last slash from path
+        if (path.length() > 1 && path.charAt(path.length()-1) == OCFile.PATH_SEPARATOR.charAt(0)) {
+            path = path.substring(0, path.length()-1);
+        }
+        return path;
+    }
 }
 }