Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamlover authored May 9, 2018
2 parents 089887e + 98ddeb9 commit 5092e66
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 201 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
/.idea
.DS_Store
/build
/captures
Expand Down
22 changes: 0 additions & 22 deletions .idea/compiler.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/copyright/profiles_settings.xml

This file was deleted.

19 changes: 0 additions & 19 deletions .idea/gradle.xml

This file was deleted.

3 changes: 0 additions & 3 deletions .idea/markdown-navigator/profiles_settings.xml

This file was deleted.

115 changes: 0 additions & 115 deletions .idea/misc.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/modules.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
}


Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,16 +37,23 @@
public class IntentResolver {

public static final int REQUESTER = 99;
public static final String SAVE_FILE_PATH_TAG = "savePath";

private Activity activity;

private PickSetup setup;
private Intent galleryIntent;
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) {
Expand Down Expand Up @@ -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());
}
}
}

0 comments on commit 5092e66

Please sign in to comment.