1313import cn .f_ms .runtimepermission .simple .ShowRequestPermissionRationaleListener ;
1414import cn .f_ms .runtimepermission .simple .SimpleRuntimePermission ;
1515import cn .f_ms .runtimepermission .simple .SimpleRuntimePermissionHelper ;
16+ import cn .f_ms .runtimepermission .simple .rxjava1 .None ;
1617import cn .f_ms .runtimepermission .simple .rxjava2 .PermissionException ;
1718import cn .f_ms .runtimepermission .simple .rxjava2 .RxSimpleRuntimePermission ;
1819import io .reactivex .Observable ;
@@ -64,9 +65,7 @@ private void requestPermissionWithRxJava2(final String requestSuccessStr) {
6465 .compose (rxSimpleRuntimePermission .<String >compose (new MyShowRequestPermissionRationaleListener (mActivity ), Manifest .permission .READ_CONTACTS , Manifest .permission .CALL_PHONE ))
6566 .subscribe (new Observer <String >() {
6667 @ Override
67- public void onSubscribe (@ NonNull Disposable d ) {
68-
69- }
68+ public void onSubscribe (@ NonNull Disposable d ) {}
7069
7170 @ Override
7271 public void onNext (@ NonNull String s ) {
@@ -75,37 +74,34 @@ public void onNext(@NonNull String s) {
7574
7675 @ Override
7776 public void onError (@ NonNull Throwable e ) {
78-
77+ if (e instanceof PermissionException ) {
78+ Toast .makeText (mActivity , e .getMessage (), Toast .LENGTH_SHORT ).show ();
79+ }
7980 }
8081
8182 @ Override
82- public void onComplete () {
83-
84- }
83+ public void onComplete () {}
8584 });
8685 }
8786
88- private void requestPermissionWithRxJava1 (String requestSuccessStr ) {
87+ private void requestPermissionWithRxJava1 (final String requestSuccessStr ) {
8988 cn .f_ms .runtimepermission .simple .rxjava1 .RxSimpleRuntimePermission rxSimpleRuntimePermission = new cn .f_ms .runtimepermission .simple .rxjava1 .RxSimpleRuntimePermission (mActivity );
9089
91- rx .Observable .just (requestSuccessStr )
92- .compose (rxSimpleRuntimePermission .<String >compose (new MyShowRequestPermissionRationaleListener (mActivity ), Manifest .permission .READ_CONTACTS , Manifest .permission .CALL_PHONE ))
93- .subscribe (new Subscriber <String >() {
90+ rxSimpleRuntimePermission .request (new MyShowRequestPermissionRationaleListener (mActivity ), Manifest .permission .READ_CONTACTS , Manifest .permission .CALL_PHONE )
91+ .subscribe (new Subscriber <None >() {
9492 @ Override
95- public void onCompleted () {
96-
97- }
93+ public void onCompleted () {}
9894
9995 @ Override
10096 public void onError (Throwable e ) {
101- if (e instanceof PermissionException ) {
97+ if (e instanceof cn . f_ms . runtimepermission . simple . rxjava1 . PermissionException ) {
10298 Toast .makeText (mActivity , e .getMessage (), Toast .LENGTH_SHORT ).show ();
10399 }
104100 }
105101
106102 @ Override
107- public void onNext (String s ) {
108- Toast .makeText (mActivity , s , Toast .LENGTH_SHORT ).show ();
103+ public void onNext (None none ) {
104+ Toast .makeText (mActivity , requestSuccessStr , Toast .LENGTH_SHORT ).show ();
109105 }
110106 });
111107 }
0 commit comments