Skip to content

Commit

Permalink
update sample codes
Browse files Browse the repository at this point in the history
  • Loading branch information
yjfnypeu committed May 9, 2018
1 parent 841b3c5 commit d880300
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

### 我希望的router框架所能支持的功能

```

- 可自动解析标准url参数。
- 可传递bundle所支持的所有数据类型,能与原生做到无缝对接。
- 支持拦截器.方便对于部分页面跳转时需要检查是否登录.并跳转登录界面做统一配置
Expand All @@ -16,7 +16,7 @@
- 能支持原生跳转的各种方式,如请求码.转场动画的设置.
- 能灵活配置route规则.方便对各种开发环境灵活做兼容适配.如插件化.组件化
- 启动动作路由时。支持切换运行线程。
```


### 效果图

Expand Down
13 changes: 6 additions & 7 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<activity android:name=".IntentPrinterActivity" />
<activity android:name=".UserActivity" />
<activity android:name=".ResultActivity" />
<activity android:name=".ArgsActivity" />
</application>

</manifest>
4 changes: 4 additions & 0 deletions sample/src/main/java/com/lzh/nonview/router/demo/App.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,5 +23,7 @@ class App : Application() {
// 开启Router日志打印
Router.DEBUG = true

// 配置Parceler转换器
Parceler.setDefaultConverter(FastJsonConverter::class.java)
}
}
65 changes: 65 additions & 0 deletions sample/src/main/java/com/lzh/nonview/router/demo/ArgsActivity.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 26 additions & 1 deletion sample/src/main/java/com/lzh/nonview/router/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
17 changes: 17 additions & 0 deletions sample/src/main/java/com/lzh/nonview/router/demo/pojo/User.kt
Original file line number Diff line number Diff line change
@@ -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)"
}

}
6 changes: 6 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Button
android:id="@+id/toArgsActivity"
android:text="跳转到Arg参数自动解析示例页"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

</ScrollView>
Expand Down

0 comments on commit d880300

Please sign in to comment.