From: tobiasKaminsky Date: Fri, 9 Oct 2015 15:20:47 +0000 (+0200) Subject: Prepare preferences and project to use user defined storage path X-Git-Tag: beta-20151128~5^2~9 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/1587a1cdb5322a099298161db91207f1d6f48096?ds=inline;hp=--cc Prepare preferences and project to use user defined storage path --- 1587a1cdb5322a099298161db91207f1d6f48096 diff --git a/res/values/strings.xml b/res/values/strings.xml index 320eea1a..0dcca4c8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -368,6 +368,8 @@ %1$d files %1$d files, 1 folder %1$d files, %2$d folders + Storage path + Common Sharing Share with Users and Groups diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 4823a83f..18ab5b08 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -18,6 +18,11 @@ along with this program. If not, see . --> + + + diff --git a/src/com/owncloud/android/MainApp.java b/src/com/owncloud/android/MainApp.java index c805f9f7..4f0ee624 100644 --- a/src/com/owncloud/android/MainApp.java +++ b/src/com/owncloud/android/MainApp.java @@ -23,10 +23,13 @@ package com.owncloud.android; import android.app.Activity; import android.app.Application; import android.content.Context; +import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; +import android.os.Environment; +import android.preference.PreferenceManager; import com.owncloud.android.authentication.PassCodeManager; import com.owncloud.android.datamodel.ThumbnailsCacheManager; @@ -54,6 +57,8 @@ public class MainApp extends Application { private static Context mContext; + private static String storagePath; + // TODO Enable when "On Device" is recovered? // TODO better place // private static boolean mOnlyOnDevice = false; @@ -62,7 +67,12 @@ public class MainApp extends Application { public void onCreate(){ super.onCreate(); MainApp.mContext = getApplicationContext(); - + + SharedPreferences appPrefs = + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + MainApp.storagePath = appPrefs.getString("storage_path", Environment. + getExternalStorageDirectory().getAbsolutePath()); + boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso)); OwnCloudClientManagerFactory.setUserAgent(getUserAgent()); @@ -135,6 +145,14 @@ public class MainApp extends Application { return MainApp.mContext; } + public static String getStoragePath(){ + return MainApp.storagePath; + } + + public static void setStoragePath(String path){ + MainApp.storagePath = path; + } + // Methods to obtain Strings referring app_name // From AccountAuthenticator // public static final String ACCOUNT_TYPE = "owncloud"; diff --git a/src/com/owncloud/android/ui/activity/Preferences.java b/src/com/owncloud/android/ui/activity/Preferences.java index e1c5c10d..6310532f 100644 --- a/src/com/owncloud/android/ui/activity/Preferences.java +++ b/src/com/owncloud/android/ui/activity/Preferences.java @@ -35,6 +35,7 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; import android.net.Uri; import android.os.Bundle; +import android.os.Environment; import android.os.Handler; import android.os.IBinder; import android.preference.CheckBoxPreference; @@ -76,6 +77,7 @@ import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.files.services.FileUploader; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.services.OperationsService; +import com.owncloud.android.ui.PreferenceWithLongSummary; import com.owncloud.android.ui.RadioButtonPreference; import com.owncloud.android.utils.DisplayUtils; @@ -116,6 +118,8 @@ public class Preferences extends PreferenceActivity protected FileDownloader.FileDownloaderBinder mDownloaderBinder = null; protected FileUploader.FileUploaderBinder mUploaderBinder = null; private ServiceConnection mDownloadServiceConnection, mUploadServiceConnection = null; + private PreferenceWithLongSummary mPrefStoragePath; + private String mStoragePath; @SuppressWarnings("deprecation") @Override @@ -363,6 +367,32 @@ public class Preferences extends PreferenceActivity } } + mPrefStoragePath = (PreferenceWithLongSummary)findPreference("storage_path"); + if (mPrefStoragePath != null){ + + mPrefStoragePath.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + MainApp.setStoragePath((String) newValue); + return true; + } + }); + +// mPrefStoragePath.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); +//// return true; +// } +// }); + } + mPrefInstantUploadPath = findPreference("instant_upload_path"); if (mPrefInstantUploadPath != null){ @@ -436,6 +466,7 @@ public class Preferences extends PreferenceActivity } loadInstantUploadPath(); + loadStoragePath(); loadInstantUploadVideoPath(); /* ComponentsGetter */ @@ -788,6 +819,17 @@ public class Preferences extends PreferenceActivity } /** + * Load storage path set on preferences + */ + private void loadStoragePath() { + SharedPreferences appPrefs = + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + mStoragePath = appPrefs.getString("storage_path", Environment.getExternalStorageDirectory() + .getAbsolutePath()); + mPrefStoragePath.setSummary(mStoragePath); + } + + /** * Save the "Instant Upload Path" on preferences */ private void saveInstantUploadPathOnPreferences() { @@ -802,10 +844,7 @@ public class Preferences extends PreferenceActivity * 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); + mPrefInstantVideoUploadPath.setSummary(MainApp.getStoragePath()); } /** diff --git a/src/com/owncloud/android/utils/FileStorageUtils.java b/src/com/owncloud/android/utils/FileStorageUtils.java index 1740ca58..6fcf285a 100644 --- a/src/com/owncloud/android/utils/FileStorageUtils.java +++ b/src/com/owncloud/android/utils/FileStorageUtils.java @@ -55,8 +55,9 @@ public class FileStorageUtils { public static final String getSavePath(String accountName) { - File sdCard = Environment.getExternalStorageDirectory(); - return sdCard.getAbsolutePath() + "/" + MainApp.getDataFolder() + "/" + Uri.encode(accountName, "@"); +// File sdCard = Environment.getExternalStorageDirectory(); + + return MainApp.getStoragePath() + "/" + MainApp.getDataFolder() + "/" + Uri.encode(accountName, "@"); // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B }