33import android .app .Activity ;
44import android .content .Context ;
55import android .net .Uri ;
6- import android .os .Build ;
76import android .support .annotation .NonNull ;
87import android .support .v4 .app .Fragment ;
98
109import com .yanzhenjie .permission .AndPermission ;
11- import com .yanzhenjie .permission .option .Option ;
1210import com .yanzhenjie .permission .runtime .Permission ;
1311
1412import java .io .File ;
2119 */
2220public class AnyPermission {
2321
24- private final Context mContext ;
25- private final Option mOption ;
22+ private final ContextHolder mContextHolder ;
2623
2724 public static AnyPermission with (@ NonNull final Context context ) {
2825 return new AnyPermission (context );
@@ -41,60 +38,52 @@ public static AnyPermission with(@NonNull final android.app.Fragment fragment) {
4138 }
4239
4340 private AnyPermission (final Context context ){
44- mContext = context ;
45- mOption = AndPermission .with (context );
41+ mContextHolder = new ContextHolder (context );
4642 }
4743
4844 private AnyPermission (final Activity activity ){
49- mContext = activity ;
50- mOption = AndPermission .with (activity );
45+ mContextHolder = new ContextHolder (activity );
5146 }
5247
5348 private AnyPermission (final Fragment fragment ){
54- mContext = fragment .getContext ();
55- mOption = AndPermission .with (fragment );
49+ mContextHolder = new ContextHolder (fragment );
5650 }
5751
5852 private AnyPermission (final android .app .Fragment fragment ){
59- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
60- mContext = fragment .getContext ();
61- } else {
62- mContext = fragment .getActivity ();
63- }
64- mOption = AndPermission .with (fragment );
53+ mContextHolder = new ContextHolder (fragment );
6554 }
6655
6756 public String name (String permission ) {
68- return Permission .transformText (mContext , permission ).get (0 );
57+ return Permission .transformText (mContextHolder . getContext () , permission ).get (0 );
6958 }
7059
7160 public Uri fileUri (File file ) {
72- return AndPermission .getFileUri (mContext , file );
61+ return AndPermission .getFileUri (mContextHolder . getContext () , file );
7362 }
7463
7564 public RuntimeRequester runtime (int requestCodeWhenGoSetting ) {
76- return new RuntimeRequester (mOption , mContext , requestCodeWhenGoSetting );
65+ return new RuntimeRequester (mContextHolder . getOption (), mContextHolder . getContext () , requestCodeWhenGoSetting );
7766 }
7867
7968 public InstallRequester install (File apkFile ) {
80- return new InstallRequester (mOption , apkFile );
69+ return new InstallRequester (mContextHolder . getOption () , apkFile );
8170 }
8271
8372 public OverlayRequester overlay () {
84- return new OverlayRequester (mOption );
73+ return new OverlayRequester (mContextHolder . getOption () );
8574 }
8675
8776 @ Deprecated
8877 public SettingRequester setting () {
89- return new SettingRequester (mOption );
78+ return new SettingRequester (mContextHolder . getOption () );
9079 }
9180
9281 public NotificationShowRequester notificationShow () {
93- return new NotificationShowRequester (mOption );
82+ return new NotificationShowRequester (mContextHolder . getOption () );
9483 }
9584
9685 public NotificationAccessRequester notificationAccess () {
97- return new NotificationAccessRequester (mOption );
86+ return new NotificationAccessRequester (mContextHolder . getOption () );
9887 }
9988
10089}
0 commit comments