/** * Navigation to the route with path. * <p> * Creates a navigation router with the arguments supplied to this builder. * <p> * There will only ever be one instance of this class, * and the instance (which is created the first time it is accessed, * in a thread-safe manner) has got the same name as the class. * <p> * Used in Kotlin: * Nav.setPath("").setContext(activity).go() * <p> * Used in Java: * Nav.INSTANCE.setPath("").setContext(activity).go(); * * @author lishide * @date 2020/6/18 */ object Nav {
/** * Set the path. * * @param path Where you go. * @return This Builder object to allow for chaining of calls to set methods. * @see ARouter.build(String) */ funsetPath(path: String): Nav { this.path = path returnthis }
/** * Set the context. * * @param context Activity and so on. * @return This Builder object to allow for chaining of calls to set methods. */ funsetContext(context: Context?): Nav { mContext = context returnthis }
/** * Set the bundle. * <p> * BE ATTENTION TO THIS METHOD WAS <P>SET, NOT ADD!</P> * * @param bundle bundle * @return This Builder object to allow for chaining of calls to set methods. * @see Postcard.with(Bundle) */ funsetBundle(bundle: Bundle?): Nav { this.bundle = bundle returnthis }
/** * Set special flags controlling how this intent is handled. * * @param flag Flags of route * @return This Builder object to allow for chaining of calls to set methods. * @see Postcard.withFlags */ funsetFlag(flag: Int): Nav { this.flag = flag returnthis }
/** * Set the requestCode. * * @param requestCode requestCode * @return This Builder object to allow for chaining of calls to set methods. */ funsetRequestCode(requestCode: Int): Nav { this.requestCode = requestCode returnthis }
/** * Set normal transition anim. * * @param enterAnim enter * @param exitAnim exit * @return This Builder object to allow for chaining of calls to set methods. * @see Postcard.withTransition */ funsetTransition(@AnimRes enterAnim: Int, @AnimRes exitAnim: Int): Nav { this.enterAnim = enterAnim this.exitAnim = exitAnim returnthis }
/** * Creates an {@link ARouter} with the arguments supplied to this builder. * <p> * Calling this method navigation to the route with path in postcard. */ fungo() { if (path.isNullOrEmpty()) { println("path can not be empty") return }
val postcard = ARouter.getInstance().build(path) if (null != bundle) { postcard.with(bundle) } if (flag != -1) { postcard.withFlags(flag) } if (enterAnim != -1 && exitAnim != -1) { postcard.withTransition(enterAnim, exitAnim) } if (null == mContext) { postcard.navigation() } else { if (requestCode != -1 && mContext is Activity) { postcard.navigation(mContext as Activity?, requestCode, LoginNavigationCallbackImpl()) } else { postcard.navigation(mContext, LoginNavigationCallbackImpl()) } }
initialize() }
}
Used in Kotlin: Nav.setPath("").setContext(activity).go()
Used in Java: Nav.INSTANCE.setPath("").setContext(activity).go();