mirror of
https://github.com/nextcloud/android.git
synced 2024-11-29 02:38:58 +03:00
remember last path which was used on local file selection
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
b061b1a557
commit
59d0b99121
2 changed files with 38 additions and 4 deletions
|
@ -42,6 +42,7 @@ public final class PreferenceManager {
|
|||
* Value handled by the app without direct access in the UI.
|
||||
*/
|
||||
private static final String AUTO_PREF__LAST_UPLOAD_PATH = "last_upload_path";
|
||||
private static final String AUTO_PREF__UPLOAD_FROM_LOCAL_LAST_PATH = "upload_from_local_last_path";
|
||||
private static final String AUTO_PREF__UPLOAD_FILE_EXTENSION_MAP_URL = "prefs_upload_file_extension_map_url";
|
||||
private static final String AUTO_PREF__UPLOAD_FILE_EXTENSION_URL = "prefs_upload_file_extension_url";
|
||||
private static final String AUTO_PREF__UPLOADER_BEHAVIOR = "prefs_uploader_behaviour";
|
||||
|
@ -186,6 +187,27 @@ public final class PreferenceManager {
|
|||
saveStringPreference(context, AUTO_PREF__LAST_UPLOAD_PATH, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last local path where the user selected to do an upload from.
|
||||
*
|
||||
* @param context Caller {@link Context}, used to access to shared preferences manager.
|
||||
* @return path Absolute path to a folder, as previously stored by
|
||||
* {@link #setUploadFromLocalLastPath(Context, String)}, or empty String if never saved before.
|
||||
*/
|
||||
public static String getUploadFromLocalLastPath(Context context) {
|
||||
return getDefaultSharedPreferences(context).getString(AUTO_PREF__UPLOAD_FROM_LOCAL_LAST_PATH, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the path where the user selected to do the last local upload of a file from.
|
||||
*
|
||||
* @param context Caller {@link Context}, used to access to shared preferences manager.
|
||||
* @param path Absolute path to a folder.
|
||||
*/
|
||||
public static void setUploadFromLocalLastPath(Context context, String path) {
|
||||
saveStringPreference(context, AUTO_PREF__UPLOAD_FROM_LOCAL_LAST_PATH, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the lock preference configured by the user.
|
||||
*
|
||||
|
|
|
@ -126,13 +126,23 @@ public class UploadFilesActivity extends FileActivity implements
|
|||
mLocalFolderPickerMode = extras.getBoolean(KEY_LOCAL_FOLDER_PICKER_MODE, false);
|
||||
}
|
||||
|
||||
if(savedInstanceState != null) {
|
||||
if (savedInstanceState != null) {
|
||||
mCurrentDir = new File(savedInstanceState.getString(UploadFilesActivity.KEY_DIRECTORY_PATH, Environment
|
||||
.getExternalStorageDirectory().getAbsolutePath()));
|
||||
mSelectAll = savedInstanceState.getBoolean(UploadFilesActivity.KEY_ALL_SELECTED, false);
|
||||
} else {
|
||||
String lastUploadFrom = PreferenceManager.getUploadFromLocalLastPath(this);
|
||||
|
||||
if (!lastUploadFrom.isEmpty()) {
|
||||
mCurrentDir = new File(lastUploadFrom);
|
||||
|
||||
while (!mCurrentDir.exists()) {
|
||||
mCurrentDir = mCurrentDir.getParentFile();
|
||||
}
|
||||
} else {
|
||||
mCurrentDir = Environment.getExternalStorageDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
mAccountOnCreation = getAccount();
|
||||
|
||||
|
@ -487,9 +497,11 @@ public class UploadFilesActivity extends FileActivity implements
|
|||
finish();
|
||||
|
||||
} else if (v.getId() == R.id.upload_files_btn_upload) {
|
||||
if(mLocalFolderPickerMode) {
|
||||
PreferenceManager.setUploadFromLocalLastPath(this, mCurrentDir.getAbsolutePath());
|
||||
|
||||
if (mLocalFolderPickerMode) {
|
||||
Intent data = new Intent();
|
||||
if(mCurrentDir != null) {
|
||||
if (mCurrentDir != null) {
|
||||
data.putExtra(EXTRA_CHOSEN_FILES, mCurrentDir.getAbsolutePath());
|
||||
}
|
||||
setResult(RESULT_OK, data);
|
||||
|
|
Loading…
Reference in a new issue