package cn.f_ms.runtimepermission.simple;

/**
 * SimpleRuntimePermissionHelper
 *
 * @author _Ms
 * @time 2017/4/26
 */

public class SimpleRuntimePermissionHelper {

    public static class PermissionRequest {

        interface OnExecuteListener {
            void onExecute(PermissionRequest permissionRequest);
        }

        private OnExecuteListener mOnExecuteListener;
        private String[] permissions;
        private SimpleRuntimePermission.PermissionListener resultListener;
        private ShowRequestPermissionRationaleListener showRequestPermissionRationaleListener;

        PermissionRequest(OnExecuteListener listener) {
            if (listener == null) {
                throw new IllegalArgumentException("OnExecuteListener can't be empty");
            }
            mOnExecuteListener = listener;
        }

        public PermissionRequest permission(String... permissions) {
            this.permissions = permissions;
            return this;
        }

        public PermissionRequest showPermissionRationaleListener(ShowRequestPermissionRationaleListener showRequestPermissionRationaleListener) {
            this.showRequestPermissionRationaleListener = showRequestPermissionRationaleListener;
            return this;
        }

        public void execute(SimpleRuntimePermission.PermissionListener resultListener) {
            this.resultListener = resultListener;
            mOnExecuteListener.onExecute(this);
        }

        String[] permissions() { return permissions; }

        SimpleRuntimePermission.PermissionListener resultListener() { return resultListener; }

        ShowRequestPermissionRationaleListener showPermissionRationaleListener() { return showRequestPermissionRationaleListener; }
    }

    public static PermissionRequest with(final SimpleRuntimePermission simpleRuntimePermission) {
        if (simpleRuntimePermission == null) {
            throw new IllegalArgumentException("SimpleRuntimePermission argement can't be null");
        }

        return new PermissionRequest(new PermissionRequest.OnExecuteListener() {
            @Override
            public void onExecute(PermissionRequest request) {

                simpleRuntimePermission.request(
                        request.resultListener(),
                        request.showPermissionRationaleListener(),
                        request.permissions()
                );
            }
        });
    }
}

@@ -218,279 +218,103 @@
     
-interface OnExecuteListener %7B%0A            void onExecute(PermissionRequest permissionRequest);%0A        %7D%0A%0A        private OnExecuteListener mOnExecuteListener;%0A        private String%5B%5D permissions;%0A        private SimpleRuntimePermission.PermissionListener resultListener
+private SimpleRuntimePermission mSimpleRuntimePermission;%0A        private String%5B%5D mPermissions
 ;%0A  
@@ -358,33 +358,34 @@
 tionaleListener 
-s
+mS
 howRequestPermis
@@ -438,62 +438,98 @@
 est(
-OnExecuteListener listener) %7B%0A            if (listener
+SimpleRuntimePermission simpleRuntimePermission) %7B%0A            if (simpleRuntimePermission
  == 
@@ -588,33 +588,39 @@
 eption(%22
-OnExecuteListener
+simpleRuntimePermission
  can't b
@@ -625,13 +625,12 @@
  be 
-empty
+null
 %22);%0A
@@ -635,32 +635,33 @@
 ;%0A            %7D%0A
+%0A
             mOnE
@@ -661,36 +661,57 @@
    m
-OnExecuteListener = listener
+SimpleRuntimePermission = simpleRuntimePermission
 ;%0A  
@@ -805,17 +805,18 @@
    this.
-p
+mP
 ermissio
@@ -1032,17 +1032,18 @@
    this.
-s
+mS
 howReque
@@ -1231,32 +1231,33 @@
 sultListener) %7B%0A
+%0A
             this
@@ -1252,21 +1252,20 @@
         
-this.
+if (
 resultLi
@@ -1276,136 +1276,325 @@
 er =
- resultListener;%0A            mOnExecuteListener.onExecute(this);%0A        %7D%0A%0A        String%5B%5D permissions() %7B return permissions;
+= null) %7B%0A                throw new IllegalArgumentException(%22resultListener can't be null%22);%0A            %7D%0A%0A            if (mPermissions == null%0A                    %7C%7C mPermissions.length == 0) %7B%0A                throw new IllegalArgumentException(%22Permission can't be empty/null, please set permission%22);%0A           
  %7D%0A%0A
@@ -1601,16 +1601,21 @@
         
+ 
+   m
 SimpleRu
@@ -1634,52 +1634,36 @@
 ion.
-PermissionListener resultListener() %7B return
+request(%0A                   
  res
@@ -1673,20 +1673,17 @@
 Listener
-; %7D%0A
+,
 %0A       
@@ -1683,16 +1683,34 @@
         
+            this.m
 ShowRequ
@@ -1743,91 +1743,70 @@
 ener
- showPermissionRationaleListener() %7B return showRequestPermissionRationaleListener;
+,%0A                    this.mPermissions%0A            );%0A       
  %7D%0A 
@@ -2106,392 +2106,31 @@
 est(
-new PermissionRequest.OnExecuteListener() %7B%0A            @Override%0A            public void onExecute(PermissionRequest request) %7B%0A%0A                simpleRuntimePermission.request(%0A                        request.resultListener(),%0A                        request.showPermissionRationaleListener(),%0A                        request.permissions()%0A                );%0A            %7D%0A        %7D
+simpleRuntimePermission
 );%0A 

change SimpleRuntimePermissionHelper inner impl