diff --git a/gradle.properties b/gradle.properties index 009cc723..0069b48e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # Project-wide Gradle settings. -VERSION_NAME=2.0.3 -VERSION_CODE=13 +VERSION_NAME=2.0.4 +VERSION_CODE=14 GROUP=com.nononsenseapps PROJECT_NAME=com.nononsenseapps:filepicker diff --git a/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java b/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java index 314d9a2e..e2309bc2 100644 --- a/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java +++ b/library/src/main/java/com/nononsenseapps/filepicker/AbstractFilePickerFragment.java @@ -98,6 +98,10 @@ protected FileItemAdapter getDummyAdapter() { public AbstractFilePickerFragment() { checkedItems = new HashSet<>(); checkedVisibleViewHolders = new HashSet<>(); + + // Retain this fragment across configuration changes, to allow + // asynctasks and such to be used with ease. + setRetainInstance(true); } /** @@ -236,9 +240,26 @@ public void onAttach(Activity activity) { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - // Retain this fragment across configuration changes. - setRetainInstance(true); + setHasOptionsMenu(true); + } + + /** + * Called when the fragment's activity has been created and this + * fragment's view hierarchy instantiated. It can be used to do final + * initialization once these pieces are in place, such as retrieving + * views or restoring state. It is also useful for fragments that use + * {@link #setRetainInstance(boolean)} to retain their instance, + * as this callback tells the fragment when it is fully associated with + * the new activity instance. This is called after {@link #onCreateView} + * and before {@link #onViewStateRestored(Bundle)}. + * + * @param savedInstanceState If the fragment is being re-created from + * a previous saved state, this is the state. + */ + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); // Only if we have no state if (currentPath == null) { if (savedInstanceState != null) { @@ -268,8 +289,6 @@ public void onCreate(Bundle savedInstanceState) { } refresh(); - - setHasOptionsMenu(true); } @Override diff --git a/library/src/main/java/com/nononsenseapps/filepicker/NewItemFragment.java b/library/src/main/java/com/nononsenseapps/filepicker/NewItemFragment.java index 6167e7cb..73da81e4 100644 --- a/library/src/main/java/com/nononsenseapps/filepicker/NewItemFragment.java +++ b/library/src/main/java/com/nononsenseapps/filepicker/NewItemFragment.java @@ -22,6 +22,7 @@ import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v7.app.AlertDialog; import android.text.Editable; @@ -45,9 +46,9 @@ public void setListener(final OnNewFolderListener listener) { @Override public void onAttach(Activity activity) { super.onAttach(activity); - setRetainInstance(true); } + @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); diff --git a/release-notes.md b/release-notes.md index a5777caf..6fd91d15 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,3 +1,6 @@ +# 2.0.4 +Handle device rotation, fixes #15. + # 2.0.3 Fix a crash because of fauly view initiation. Item layout's imageview now has fixed size.