From: jabarros Date: Thu, 20 Nov 2014 08:39:10 +0000 (+0100) Subject: Remove last slash from uploads path (video/image) when showing them on settings view... X-Git-Tag: oc-android-1.7.0_signed~15^2~5^2^2~6 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/aa16b13ab999cc6947d7a102e75ddaed27e761ec?hp=--cc Remove last slash from uploads path (video/image) when showing them on settings view and they are not root folder --- aa16b13ab999cc6947d7a102e75ddaed27e761ec diff --git a/src/com/owncloud/android/ui/activity/Preferences.java b/src/com/owncloud/android/ui/activity/Preferences.java index 3a5c5b4d..9c11f0a8 100644 --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/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_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); diff --git a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/com/owncloud/android/ui/adapter/FileListListAdapter.java index 10356320..1df1211c 100644 --- a/src/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/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.files.services.FileDownloader.FileDownloaderBinder; 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.utils.DisplayUtils; import com.owncloud.android.utils.FileStorageUtils; diff --git a/src/com/owncloud/android/utils/DisplayUtils.java b/src/com/owncloud/android/utils/DisplayUtils.java index da81f539..a1afb894 100644 --- a/src/com/owncloud/android/utils/DisplayUtils.java +++ b/src/com/owncloud/android/utils/DisplayUtils.java @@ -29,11 +29,11 @@ import java.util.Set; import android.annotation.TargetApi; import android.content.Context; import android.os.Build; -import android.text.format.DateFormat; import android.text.format.DateUtils; import com.owncloud.android.MainApp; import com.owncloud.android.R; +import com.owncloud.android.datamodel.OCFile; /** * A helper class for some string operations. @@ -320,4 +320,17 @@ public class DisplayUtils { 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; + } }