From: jabarros Date: Wed, 19 Nov 2014 09:14:27 +0000 (+0100) Subject: Add new preference on settings for setting the upload video path X-Git-Tag: oc-android-1.7.0_signed~15^2~5^2^2~8 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/a2de2f28ab6167e4003f0283b50b98dd0e73a598?ds=inline Add new preference on settings for setting the upload video path --- diff --git a/res/values/strings.xml b/res/values/strings.xml index 38d43c03..d6b54574 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -317,4 +317,7 @@ Instant Uploads Security + + Upload Video Path + diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index b71a5e5b..6f04a295 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -40,6 +40,7 @@ android:disableDependentsState="true" android:title="@string/instant_upload_on_wifi" android:key="instant_upload_on_wifi"/> + diff --git a/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java b/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java index efaa803c..c1c3e9ca 100644 --- a/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java +++ b/src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java @@ -161,7 +161,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver { Intent i = new Intent(context, FileUploader.class); i.putExtra(FileUploader.KEY_ACCOUNT, account); i.putExtra(FileUploader.KEY_LOCAL_FILE, file_path); - i.putExtra(FileUploader.KEY_REMOTE_FILE, FileStorageUtils.getInstantUploadFilePath(context, file_name)); + i.putExtra(FileUploader.KEY_REMOTE_FILE, FileStorageUtils.getInstantVideoUploadFilePath(context, file_name)); i.putExtra(FileUploader.KEY_UPLOAD_TYPE, FileUploader.UPLOAD_SINGLE_FILE); i.putExtra(FileUploader.KEY_MIME_TYPE, mime_type); i.putExtra(FileUploader.KEY_INSTANT_UPLOAD, true); diff --git a/src/com/owncloud/android/ui/activity/Preferences.java b/src/com/owncloud/android/ui/activity/Preferences.java index 4239c0ec..3a5c5b4d 100644 --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/src/com/owncloud/android/ui/activity/Preferences.java @@ -68,6 +68,8 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa private static final String TAG = "OwnCloudPreferences"; 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; @@ -79,6 +81,8 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa private boolean mShowContextMenu = false; private String mUploadPath; private Preference mPrefInstantUploadPath; + private Preference mPrefInstantVideoUploadPath; + private String mUploadVideoPath; @SuppressWarnings("deprecation") @@ -258,6 +262,20 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa } }); } + + mPrefInstantVideoUploadPath = findPreference("instant_video_upload_path"); + if (mPrefInstantVideoUploadPath != null){ + + mPrefInstantVideoUploadPath.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Intent intent = new Intent(Preferences.this, UploadPathActivity.class); + intent.putExtra(UploadPathActivity.KEY_INSTANT_UPLOAD_PATH, mUploadVideoPath); + startActivityForResult(intent, ACTION_SELECT_UPLOAD_VIDEO_PATH); + return true; + } + }); + } /* About App */ pAboutApp = (Preference) findPreference("about_app"); @@ -273,12 +291,12 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa } loadInstantUploadPath(); + loadInstantUploadVideoPath(); } @Override protected void onPause() { - saveInstantUploadPathOnPreferences(); super.onPause(); } @@ -384,11 +402,19 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa if (requestCode == ACTION_SELECT_UPLOAD_PATH && (resultCode == RESULT_OK || resultCode == UploadPathActivity.RESULT_OK_SET_UPLOAD_PATH)){ - OCFile folderToMoveAt = (OCFile) data.getParcelableExtra(UploadPathActivity.EXTRA_CURRENT_FOLDER); + OCFile folderToUpload = (OCFile) data.getParcelableExtra(UploadPathActivity.EXTRA_CURRENT_FOLDER); - mUploadPath = folderToMoveAt.getRemotePath(); + mUploadPath = folderToUpload.getRemotePath(); saveInstantUploadPathOnPreferences(); + } else if (requestCode == ACTION_SELECT_UPLOAD_VIDEO_PATH && (resultCode == RESULT_OK || + resultCode == UploadPathActivity.RESULT_OK_SET_UPLOAD_PATH)){ + + OCFile folderToUploadVideo = (OCFile) data.getParcelableExtra(UploadPathActivity.EXTRA_CURRENT_FOLDER); + + mUploadVideoPath = folderToUploadVideo.getRemotePath(); + + saveInstantUploadVideoPathOnPreferences(); } } @@ -520,4 +546,24 @@ public class Preferences extends SherlockPreferenceActivity implements AccountMa editor.putString("instant_upload_path", mUploadPath); editor.commit(); } + + /** + * Load upload video path set on preferences + */ + private void loadInstantUploadVideoPath() { + SharedPreferences appPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + mUploadVideoPath = appPrefs.getString("instant_video_upload_path", getString(R.string.instant_upload_path)); + mPrefInstantVideoUploadPath.setSummary(mUploadVideoPath); + } + + /** + * 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); + editor.commit(); + } } diff --git a/src/com/owncloud/android/utils/FileStorageUtils.java b/src/com/owncloud/android/utils/FileStorageUtils.java index 3895821d..892a1ca8 100644 --- a/src/com/owncloud/android/utils/FileStorageUtils.java +++ b/src/com/owncloud/android/utils/FileStorageUtils.java @@ -81,6 +81,20 @@ public class FileStorageUtils { String value = uploadPath + OCFile.PATH_SEPARATOR + (fileName == null ? "" : fileName); return value; } + + /** + * Gets the composed path when video is or must be stored + * @param context + * @param fileName: video file name + * @return String: video file path composed + */ + public static String getInstantVideoUploadFilePath(Context context, String fileName) { + SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); + String uploadVideoPathdef = context.getString(R.string.instant_upload_path); + String uploadVideoPath = pref.getString("instant_video_upload_path", uploadVideoPathdef); + String value = uploadVideoPath + OCFile.PATH_SEPARATOR + (fileName == null ? "" : fileName); + return value; + } public static String getParentPath(String remotePath) { String parentPath = new File(remotePath).getParent();