22
33import android .app .Application ;
44import android .content .Context ;
5- import android .widget .Toast ;
65
6+
7+ import org .jetbrains .annotations .NotNull ;
8+
9+ import cn .wzbos .android .rudolph .RouteType ;
710import cn .wzbos .android .rudolph .Rudolph ;
811import cn .wzbos .android .rudolph .Interceptor ;
12+ import cn .wzbos .android .rudolph .router .ActivityRouter ;
913import cn .wzbos .android .rudolph .router .Router ;
14+ import cn .wzbos .samplea .AppUserRouter ;
15+ import cn .wzbos .samplea .LoginActivityRouter ;
1016
1117/**
1218 * Created by wuzongbo on 2017/4/11.
@@ -29,10 +35,22 @@ private void InitRouter() {
2935 Rudolph .init (this );
3036 Rudolph .addInterceptor (new Interceptor () {
3137 @ Override
32- public boolean intercept (Context context , Router routeInfo ) {
33- if ("/test4" .equalsIgnoreCase (routeInfo .getRawUrl ())) {
34- Toast .makeText (MyApplication .this , "intercept,path:" + routeInfo .getRawUrl (), Toast .LENGTH_SHORT ).show ();
35- return true ;
38+ public boolean intercept (Context context , @ NotNull Router <?> router ) {
39+ if ("isNeedLogin" .equals (router .getRouteTag ()) && !AppUserRouter .get ().isLogin ()) {
40+ if (router .getRouteType () == RouteType .ACTIVITY ) {
41+ ActivityRouter activityRouter = (ActivityRouter ) router ;
42+ LoginActivityRouter .builder ()
43+ .to (activityRouter .getRawUrl ())
44+ .toExtras (activityRouter .getExtras ())
45+ .transition (activityRouter .getEnterAnim (), activityRouter .getExitAnim ())
46+ .flags (activityRouter .getFlags ())
47+ .options (activityRouter .getOptions ())
48+ .build ()
49+ .start (context );
50+ return true ;
51+
52+ }
53+
3654 }
3755 return false ;
3856 }
0 commit comments