diff --git a/README.md b/README.md
index c94ef9d..8cbaca3 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@
### 我希望的router框架所能支持的功能
-```
+
- 可自动解析标准url参数。
- 可传递bundle所支持的所有数据类型,能与原生做到无缝对接。
- 支持拦截器.方便对于部分页面跳转时需要检查是否登录.并跳转登录界面做统一配置
@@ -16,7 +16,7 @@
- 能支持原生跳转的各种方式,如请求码.转场动画的设置.
- 能灵活配置route规则.方便对各种开发环境灵活做兼容适配.如插件化.组件化
- 启动动作路由时。支持切换运行线程。
-```
+
### 效果图
diff --git a/sample/build.gradle b/sample/build.gradle
index 8e60f2e..4db1967 100644
--- a/sample/build.gradle
+++ b/sample/build.gradle
@@ -27,9 +27,8 @@ android {
}
}
-def AAVersion = '4.3.0'
-def PARCELER_VERSION="1.3.9"
-def ROUTER_VERSION="2.6.1"
+def parceler_version="1.3.9"
+def router_version="2.6.1"
def butterknife_version='8.8.1'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
@@ -39,11 +38,11 @@ dependencies {
compile "com.jakewharton:butterknife:$butterknife_version"
kapt "com.jakewharton:butterknife-compiler:$butterknife_version"
- kapt "com.github.yjfnypeu.Parceler:compiler:$PARCELER_VERSION"
- compile "com.github.yjfnypeu.Parceler:api:$PARCELER_VERSION"
+ kapt "com.github.yjfnypeu.Parceler:compiler:$parceler_version"
+ compile "com.github.yjfnypeu.Parceler:api:$parceler_version"
-// compile "com.github.yjfnypeu.Router:router-api:$ROUTER_VERSION"
-// kapt "com.github.yjfnypeu.Router:router-compiler:$ROUTER_VERSION"
+// compile "com.github.yjfnypeu.Router:router-api:$router_version"
+// kapt "com.github.yjfnypeu.Router:router-compiler:$router_version"
compile project(':routerlib')
kapt project(':compiler')
diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml
index d55c278..15a4b6a 100644
--- a/sample/src/main/AndroidManifest.xml
+++ b/sample/src/main/AndroidManifest.xml
@@ -22,6 +22,7 @@
+
\ No newline at end of file
diff --git a/sample/src/main/java/com/lzh/nonview/router/demo/App.kt b/sample/src/main/java/com/lzh/nonview/router/demo/App.kt
index 5a2ade9..73f9d31 100644
--- a/sample/src/main/java/com/lzh/nonview/router/demo/App.kt
+++ b/sample/src/main/java/com/lzh/nonview/router/demo/App.kt
@@ -1,8 +1,10 @@
package com.lzh.nonview.router.demo
import android.app.Application
+import com.alibaba.fastjson.support.spring.FastJsonContainer
import com.haoge.studio.RouterRuleCreator
import com.lzh.compiler.parceler.Parceler
+import com.lzh.compiler.parceler.annotation.FastJsonConverter
import com.lzh.nonview.router.Router
import com.lzh.nonview.router.RouterConfiguration
import com.lzh.nonview.router.anno.RouteConfig
@@ -21,5 +23,7 @@ class App : Application() {
// 开启Router日志打印
Router.DEBUG = true
+ // 配置Parceler转换器
+ Parceler.setDefaultConverter(FastJsonConverter::class.java)
}
}
diff --git a/sample/src/main/java/com/lzh/nonview/router/demo/ArgsActivity.kt b/sample/src/main/java/com/lzh/nonview/router/demo/ArgsActivity.kt
new file mode 100644
index 0000000..25dc2d7
--- /dev/null
+++ b/sample/src/main/java/com/lzh/nonview/router/demo/ArgsActivity.kt
@@ -0,0 +1,65 @@
+package com.lzh.nonview.router.demo
+
+import android.os.Bundle
+import android.widget.TextView
+import com.lzh.compiler.parceler.annotation.Arg
+import com.lzh.nonview.router.anno.RouterRule
+import com.lzh.nonview.router.demo.pojo.User
+
+/**
+ * 此页面用于介绍如何结合[Parceler](https://github.com/JumeiRdGroup/Parceler)框架的
+ * Arg注解进行**自动参数类型解析传递**
+ *
+ * DATE: 2018/5/8
+ *
+ * AUTHOR: haoge
+ */
+@RouterRule("parceler-args")
+class ArgsActivity:BaseActivity() {
+
+ // 基本java数据类型
+ @Arg
+ var mBoolean:Boolean? = null
+ @Arg
+ var mInt:Int? = null
+ @Arg
+ var mByte:Byte? = null
+ @Arg
+ var mShort:Short? = null
+ @Arg
+ var mChar:Char? = null
+ @Arg
+ var mFloat:Float? = null
+ @Arg
+ var mLong:Long? = null
+ @Arg
+ var mDouble:Double? = null
+ // 其他类型
+ @Arg
+ var mString:String? = null
+ // 非可序列化对象
+ @Arg
+ var mUser: User? = null
+ @Arg
+ var mUrl:String? = null
+
+ val mPrinter:TextView by lazy { findViewById(R.id.printer_tv) as TextView }
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ setContentView(R.layout.activity_intent_printer)
+ val message = StringBuilder()
+ message.append("boolean value is $mBoolean\n")
+ message.append("int value is $mInt\n")
+ message.append("byte value is $mByte\n")
+ message.append("short value is $mShort\n")
+ message.append("char value is $mChar\n")
+ message.append("float value is $mFloat\n")
+ message.append("long value is $mLong\n")
+ message.append("double value is $mDouble\n")
+ message.append("string value is $mString\n")
+ message.append("user value is $mUser\n")
+ message.append("url value is $mUrl\n")
+ mPrinter.text = message
+ }
+}
\ No newline at end of file
diff --git a/sample/src/main/java/com/lzh/nonview/router/demo/BaseActivity.kt b/sample/src/main/java/com/lzh/nonview/router/demo/BaseActivity.kt
index 624847d..bd8d8df 100644
--- a/sample/src/main/java/com/lzh/nonview/router/demo/BaseActivity.kt
+++ b/sample/src/main/java/com/lzh/nonview/router/demo/BaseActivity.kt
@@ -4,11 +4,15 @@ import android.app.Activity
import android.content.Intent
import android.os.Bundle
import butterknife.ButterKnife
+import com.lzh.compiler.parceler.BundleFactory
import com.lzh.compiler.parceler.Parceler
import com.lzh.nonview.router.RouterConfiguration
abstract class BaseActivity : Activity() {
+
+ protected val bundleFactory by lazy { Parceler.createFactory(intent?.extras) }
+
// Parceler基础注入配置
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
diff --git a/sample/src/main/java/com/lzh/nonview/router/demo/MainActivity.kt b/sample/src/main/java/com/lzh/nonview/router/demo/MainActivity.kt
index 2a679c3..51cb859 100644
--- a/sample/src/main/java/com/lzh/nonview/router/demo/MainActivity.kt
+++ b/sample/src/main/java/com/lzh/nonview/router/demo/MainActivity.kt
@@ -3,13 +3,14 @@ package com.lzh.nonview.router.demo
import android.content.Intent
import android.net.Uri
import android.os.Bundle
-import android.util.Log
import android.widget.Toast
import butterknife.OnClick
+import com.alibaba.fastjson.JSON
import com.lzh.compiler.parceler.Parceler
import com.lzh.nonview.router.Router
import com.lzh.nonview.router.anno.RouterRule
import com.lzh.nonview.router.demo.interceptors.LoginInterceptor
+import com.lzh.nonview.router.demo.pojo.User
import com.lzh.nonview.router.exception.NotFoundException
import com.lzh.nonview.router.launcher.Launcher
import com.lzh.nonview.router.module.RouteRule
@@ -93,4 +94,28 @@ class MainActivity : BaseActivity() {
.resultCallback { resultCode, data -> Toast.makeText(this, "返回码是$resultCode", Toast.LENGTH_SHORT).show() }
.open(this)
}
+
+ @OnClick(R.id.toArgsActivity)
+ fun toArgsActivity() {
+ val url = Uri.parse("haoge://page/parceler-args")
+ .buildUpon()
+ // 添加基本数据类型
+ .appendQueryParameter("mBoolean", "true")
+ .appendQueryParameter("mByte", "0")
+ .appendQueryParameter("mShort", "1")
+ .appendQueryParameter("mChar", "c")
+ .appendQueryParameter("mInt", "3")
+ .appendQueryParameter("mFloat", "3.14")
+ .appendQueryParameter("mDouble", "3.14")
+ .appendQueryParameter("mLong", "5")
+ .appendQueryParameter("mString", "HaogeStudio")
+ // 非可序列化对象可通过json格式传递
+ .appendQueryParameter("mUser", JSON.toJSONString(User("HaogeStudio")))
+ // 转义字符串。比如参数中需要传递网址时
+ // appendQueryParameter本身会将数据先进行转义后再拼接上。所以此处是转义的链接
+ .appendQueryParameter("mUrl", "https://www.baidu.com")
+ .build()
+
+ Router.create(url).open(this)
+ }
}
diff --git a/sample/src/main/java/com/lzh/nonview/router/demo/pojo/User.kt b/sample/src/main/java/com/lzh/nonview/router/demo/pojo/User.kt
new file mode 100644
index 0000000..36d4ea4
--- /dev/null
+++ b/sample/src/main/java/com/lzh/nonview/router/demo/pojo/User.kt
@@ -0,0 +1,17 @@
+package com.lzh.nonview.router.demo.pojo
+
+/**
+ * DATE: 2018/5/8
+ * AUTHOR: haoge
+ */
+class User() {
+ var name:String? = null
+ constructor(name:String?):this() {
+ this.name = name
+ }
+
+ override fun toString(): String {
+ return "User(name=$name)"
+ }
+
+}
\ No newline at end of file
diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml
index 22d1a46..ccd5c20 100644
--- a/sample/src/main/res/layout/activity_main.xml
+++ b/sample/src/main/res/layout/activity_main.xml
@@ -57,6 +57,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
+
+