From 4a2001ef570cd62b38f9f571ea81a8d6c59bcc4d Mon Sep 17 00:00:00 2001 From: Jonas Kalderstam Date: Tue, 4 Aug 2015 12:44:11 +0200 Subject: [PATCH] Do not override existing arguments Fixes #40 Signed-off-by: Jonas Kalderstam --- .../filepicker/AbstractFilePickerFragment.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java b/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java index 6f7ef87..d7136df 100644 --- a/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java +++ b/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java @@ -103,7 +103,12 @@ public abstract class AbstractFilePickerFragment extends Fragment } /** - * Set before making the fragment visible. + * Set before making the fragment visible. This method will re-use the existing + * arguments bundle in the fragment if it exists so extra arguments will not + * be overwritten. This allows you to set any extra arguments in the fragment + * constructor if you wish. + * + * The key/value-pairs listed below will be overwritten however. * * @param startPath path to directory the picker will show upon start * @param mode what is allowed to be selected (dirs, files, both) @@ -112,7 +117,12 @@ public abstract class AbstractFilePickerFragment extends Fragment */ public void setArgs(final String startPath, final int mode, final boolean allowMultiple, final boolean allowDirCreate) { - Bundle b = new Bundle(); + // There might have been arguments set elsewhere, if so do not overwrite them. + Bundle b = getArguments(); + if (b == null) { + b = new Bundle(); + } + if (startPath != null) { b.putString(KEY_START_PATH, startPath); }