remember last path which was used on local file selection

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2018-09-25 11:31:27 +02:00 committed by AndyScherzinger
parent b061b1a557
commit 59d0b99121
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
2 changed files with 38 additions and 4 deletions

View file

@ -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.
*

View file

@ -126,12 +126,22 @@ 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 {
mCurrentDir = Environment.getExternalStorageDirectory();
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);