diff --git a/.gitignore b/.gitignore index 39fb081..09b993d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ *.iml .gradle /local.properties -/.idea/workspace.xml -/.idea/libraries +/.idea .DS_Store /build /captures diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 66e2f6f..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml deleted file mode 100644 index 57927c5..0000000 --- a/.idea/markdown-navigator/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index bfd3ad3..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index cad800c..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/library/src/main/java/com/vansuita/pickimage/dialog/PickImageBaseDialog.java b/library/src/main/java/com/vansuita/pickimage/dialog/PickImageBaseDialog.java index 2826d74..5af8916 100644 --- a/library/src/main/java/com/vansuita/pickimage/dialog/PickImageBaseDialog.java +++ b/library/src/main/java/com/vansuita/pickimage/dialog/PickImageBaseDialog.java @@ -36,6 +36,7 @@ public abstract class PickImageBaseDialog extends DialogFragment implements IPickClick { protected static final String SETUP_TAG = "SETUP_TAG"; + protected static final String RESOLVER_STATE_TAG = "resolverState"; public static final String DIALOG_FRAGMENT_TAG = PickImageBaseDialog.class.getSimpleName(); private PickSetup setup; @@ -68,7 +69,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, View view = inflater.inflate(dialog, null, false); onAttaching(); - onInitialize(); + onInitialize(savedInstanceState); if (isValidProviders()) { onBindViewsHolders(view); @@ -86,6 +87,16 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, return view; } + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + Bundle resolverState = new Bundle(); + this.resolver.onSaveInstanceState(resolverState); + + outState.putBundle(RESOLVER_STATE_TAG, resolverState); + } + private void onAttaching() { if (onClick == null) { if (getActivity() instanceof IPickClick) { @@ -103,14 +114,19 @@ private void onAttaching() { } - protected void onInitialize() { + protected void onInitialize(Bundle savedInstanceState) { if (getDialog().getWindow() != null) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); } this.setup = (PickSetup) getArguments().getSerializable(SETUP_TAG); - this.resolver = new IntentResolver(getActivity(), setup); + + Bundle resolverState = null; + if (savedInstanceState != null) { + resolverState = savedInstanceState.getBundle(RESOLVER_STATE_TAG); + } + this.resolver = new IntentResolver(getActivity(), setup, resolverState); } @@ -163,8 +179,9 @@ private void onBindViewListeners() { @Override public void onClick(View view) { if (view.getId() == R.id.cancel) { - if (onPickCancel != null) + if (onPickCancel != null) { onPickCancel.onCancelClick(); + } dismiss(); } else { if (view.getId() == R.id.camera) { diff --git a/library/src/main/java/com/vansuita/pickimage/dialog/PickImageDialog.java b/library/src/main/java/com/vansuita/pickimage/dialog/PickImageDialog.java index 34e76ee..c705c97 100644 --- a/library/src/main/java/com/vansuita/pickimage/dialog/PickImageDialog.java +++ b/library/src/main/java/com/vansuita/pickimage/dialog/PickImageDialog.java @@ -1,5 +1,6 @@ package com.vansuita.pickimage.dialog; +import android.Manifest; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Bundle; @@ -114,7 +115,16 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis if (granted) { if (!launchSystemDialog()) { - if (grantResults.length == 1) { + // See if the CAMERA permission is among the granted ones + int cameraIndex = -1; + for (int i = 0; i < permissions.length; i++) { + if (permissions[cameraIndex].equals(Manifest.permission.CAMERA)) { + cameraIndex = i; + break; + } + } + + if (cameraIndex != -1) { launchGallery(); } else { launchCamera(); @@ -126,13 +136,10 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis if (grantResults.length > 1) Keep.with(getActivity()).askedForPermission(); } - - } } - /* public static void forceDismiss(FragmentManager fm) { Fragment fragment = fm.findFragmentByTag(PickImageDialog.DIALOG_FRAGMENT_TAG); diff --git a/library/src/main/java/com/vansuita/pickimage/resolver/IntentResolver.java b/library/src/main/java/com/vansuita/pickimage/resolver/IntentResolver.java index 0de6e4b..9c5b4c7 100644 --- a/library/src/main/java/com/vansuita/pickimage/resolver/IntentResolver.java +++ b/library/src/main/java/com/vansuita/pickimage/resolver/IntentResolver.java @@ -8,9 +8,11 @@ import android.content.pm.ResolveInfo; import android.net.Uri; import android.os.Build; +import android.os.Bundle; import android.os.Environment; import android.os.Parcelable; import android.provider.MediaStore; +import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; @@ -35,6 +37,8 @@ public class IntentResolver { public static final int REQUESTER = 99; + public static final String SAVE_FILE_PATH_TAG = "savePath"; + private Activity activity; private PickSetup setup; @@ -42,9 +46,14 @@ public class IntentResolver { private Intent cameraIntent; private File saveFile; - public IntentResolver(Activity activity, PickSetup setup) { + + public IntentResolver(Activity activity, PickSetup setup, Bundle savedInstanceState) { this.activity = activity; this.setup = setup; + + if (savedInstanceState != null) { + onRestoreInstanceState(savedInstanceState); + } } private Intent loadSystemPackages(Intent intent) { @@ -241,4 +250,18 @@ public boolean fromCamera(Intent data) { public Activity getActivity() { return activity; } + + private void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { + final String saveFilePath = savedInstanceState.getString(SAVE_FILE_PATH_TAG); + + if (saveFilePath != null) { + saveFile = new File(saveFilePath); + } + } + + public void onSaveInstanceState(@NonNull Bundle outState) { + if (saveFile != null) { + outState.putString(SAVE_FILE_PATH_TAG, saveFile.getAbsolutePath()); + } + } }