|
@@ -15,8 +15,6 @@ import androidx.annotation.Nullable;
|
|
|
import androidx.core.app.ActivityCompat;
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
|
|
|
-import com.benyanyi.permissionlib.msg.FailureMsg;
|
|
|
-
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -29,10 +27,10 @@ import java.util.List;
|
|
|
public final class PermissionFragment extends Fragment {
|
|
|
|
|
|
private PermissionDialogInfo info;
|
|
|
- private int code1 = 0x101;
|
|
|
- private int code2 = 0x102;
|
|
|
- private int requestCode = 0x103;
|
|
|
- private int permissionCode;
|
|
|
+ private final int code1 = 0x31;
|
|
|
+ private final int code2 = 0x32;
|
|
|
+ private int permissionCode = 0x30;
|
|
|
+ private boolean isStop = false;
|
|
|
|
|
|
private List<String> oList = new ArrayList<>();
|
|
|
|
|
@@ -43,6 +41,7 @@ public final class PermissionFragment extends Fragment {
|
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setRetainInstance(true);
|
|
|
+ this.isStop = false;
|
|
|
}
|
|
|
|
|
|
void setPermissions(String[] permissions) {
|
|
@@ -57,12 +56,12 @@ public final class PermissionFragment extends Fragment {
|
|
|
this.callBack = callBack;
|
|
|
}
|
|
|
|
|
|
- void startForPermissionResult(int permissionCode) {
|
|
|
- this.permissionCode = permissionCode;
|
|
|
+ void startForPermissionResult() {
|
|
|
if (checkPermission()) {
|
|
|
if (this.callBack != null) {
|
|
|
- this.callBack.onPermissionSuccess(this.permissionCode);
|
|
|
- this.callBack.onPermissionComplete(this.permissionCode);
|
|
|
+ this.callBack.onPermissionSuccess();
|
|
|
+ this.callBack.onPermissionComplete();
|
|
|
+ PermissionHelper.removeFragment();
|
|
|
}
|
|
|
} else {
|
|
|
requestPermission(code1);
|
|
@@ -147,11 +146,9 @@ public final class PermissionFragment extends Fragment {
|
|
|
} else {
|
|
|
dialog.dismiss();
|
|
|
if (callBack != null) {
|
|
|
- FailureMsg failureMsg = new FailureMsg();
|
|
|
- failureMsg.setFailurePermissions(PermissionFragment.this.oList.toArray(new String[0]));
|
|
|
- failureMsg.setPermissionCode(permissionCode);
|
|
|
- callBack.onPermissionFailure(failureMsg);
|
|
|
- callBack.onPermissionComplete(permissionCode);
|
|
|
+ callBack.onPermissionFailure(PermissionFragment.this.oList.toArray(new String[0]));
|
|
|
+ callBack.onPermissionComplete();
|
|
|
+ PermissionHelper.removeFragment();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -170,8 +167,9 @@ public final class PermissionFragment extends Fragment {
|
|
|
boolean boo = list.isEmpty() && (this.code1 == requestCode || this.code2 == requestCode);
|
|
|
if (boo) {
|
|
|
if (this.callBack != null) {
|
|
|
- this.callBack.onPermissionSuccess(this.permissionCode);
|
|
|
- this.callBack.onPermissionComplete(this.permissionCode);
|
|
|
+ this.callBack.onPermissionSuccess();
|
|
|
+ this.callBack.onPermissionComplete();
|
|
|
+ PermissionHelper.removeFragment();
|
|
|
}
|
|
|
} else {
|
|
|
oList = list;
|
|
@@ -196,18 +194,44 @@ public final class PermissionFragment extends Fragment {
|
|
|
@Override
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
- if (this.requestCode == requestCode) {
|
|
|
+ int requestCode1 = 0x33;
|
|
|
+ if (requestCode1 == requestCode) {
|
|
|
requestPermission(this.code2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ if (this.isStop) {
|
|
|
+ if (checkPermission()) {
|
|
|
+ if (this.callBack != null) {
|
|
|
+ this.callBack.onPermissionSuccess();
|
|
|
+ this.callBack.onPermissionComplete();
|
|
|
+ PermissionHelper.removeFragment();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (this.callBack != null) {
|
|
|
+ this.callBack.onPermissionFailure(this.oList.toArray(new String[0]));
|
|
|
+ this.callBack.onPermissionComplete();
|
|
|
+ PermissionHelper.removeFragment();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.isStop = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStop() {
|
|
|
+ super.onStop();
|
|
|
+ this.isStop = true;
|
|
|
+ }
|
|
|
+
|
|
|
private void setFailure() {
|
|
|
if (this.callBack != null) {
|
|
|
- FailureMsg failureMsg = new FailureMsg();
|
|
|
- failureMsg.setPermissionCode(this.permissionCode);
|
|
|
- failureMsg.setFailurePermissions(this.oList.toArray(new String[0]));
|
|
|
- this.callBack.onPermissionFailure(failureMsg);
|
|
|
- this.callBack.onPermissionComplete(this.permissionCode);
|
|
|
+ this.callBack.onPermissionFailure(this.oList.toArray(new String[0]));
|
|
|
+ this.callBack.onPermissionComplete();
|
|
|
+ PermissionHelper.removeFragment();
|
|
|
}
|
|
|
}
|
|
|
|