2 Star 1 Fork 0

Ultra-Dejavu/Router-Android

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

祖传路由项目

State-of-the-art Shitcode

简单的说功能大部分和阿里美团的路由都半斤八两吧,以前公司拿来做组件化拆分的,支持编译时注册以及增量编译等等,整体kt重构过一次。

支持参数跳转,以及startActivityForResult操作,并提供成功失败回掉监听等。

同时项目升级了kapt版本,已经支持kapt的增量编译了。

新增了ksp支持,速度可以比kapt更快,理论上优化25%以上的注解解释器速度,同时ksp由于已经支持增编以及编译缓存,所以性能更好更优异。

wmrouter 增量编译

如果使用wmrouter的各位,可以直接用我的插件替换工程内的路由初始化,应该能解决项目编译的问题。基本测试都通过了。

buildscript {
    dependencies {
        classpath 'com.kronos.plugin:AutoRegister:0.5.5'
          }
}
apply plugin: 'router-register'
AutoRegister {
    REGISTER_PACKAGE_NAME = "com.sankuai.waimai.router.generated.service"
    REGISTER_CLASS_NAME = "com.sankuai.waimai.router.generated.ServiceLoaderInit"
    REGISTER_FUNCTION_NAME = "init"
    REGISTER_CLASS_FUNCTION_NAME = "init"
}

使用大法

  1. 根目录 build.gradle 添加
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.kronos.plugin:AutoRegister:0.5.4'
    }
}
  1. 项目目录增加路由注册插件
apply plugin: 'router-register'

dependencies {
    compile 'com.github.leifzhang:routerLib:0.5.1'
    kapt "com.github.leifzhang:compiler:0.5.1"
}
万一你不想用plugin了,我给你准备了一个慢一点的还在方式,以前偷的arouter的类反射机制的。
dependencies {
    // 如果你不要用transform
    implementation project(':EmptyLoader')
}
  1. ActivityRouterCallback添加注解
@BindRouter(urls = {"https://wwww.github.com"})
public class TestActivity extends Activity {

}
@BindRouter(urls = {"https://wwww.baidu.com"}, interceptors = {TestInterceptor.class})
public class SimpleCallBack implements RouterCallback {
    @Override
    public void run(RouterContext context) {
        Toast.makeText(context.getContext(), "testing", Toast.LENGTH_SHORT).show();
    }
}

  1. 万一有高仿的路由出现,可以这样
 @BindRouter(urls = { "https://github.com/leifzhang"}, weight=10)
 public class TestActivity extends Activity {

 }
  1. 启动一个路由跳转

直接启动可以用这个:

    Router.sharedRouter().open("https://github.com/leifzhang", this);

复杂的多参数传递可以用这个:

  val request = KRequest("https://www.baidu.com/test", onSuccess = {
                    Log.i("KRequest", "onSuccess")
                }, onFail = {
                    Log.i("KRequest", "onFail")
                }).apply {
                    activityResultCode = 12345
                }.start(this)

DSL 版本

            request("https://www.baidu.com/test") {
                activityResultCode = 12345
                success {

                }
                fail {

                }
                bundle {
                    putString("1234", "1234")
                }
            }.start(this)

通过dsl的形式也可以使用路由

协程版本

    GlobalScope.launch {
                  val result = request("https://www.baidu.com/test") {
                      activityResultCode = 12345
                      bundle {
                          putString("1234", "1234")
                      }
                  }.dispatcher(this@MainActivity)
                  delay(1000)
                  withContext(Dispatchers.Main) {
                      Toast.makeText(
                          this@MainActivity,
                          if (result) "成功了" else "失败了",
                          Toast.LENGTH_SHORT
                      ).show()
                  }
              }

可以通过协程的形式,挂起恢复的获取到返回值。

如果是Module的特别注意

kapt {
    arguments {
        arg("ROUTER_MODULE_NAME", project.getName())
    }
}

使用ksp

这次新增的ksp可以完美和kapt进行支持,ksp compiler 暂时只支持全量kotlin

plugins {
    // 这个 id 就是在 versionPlugin 文件夹下 build.gradle.kts.kts 文件内定义的id
    id("com.android.library")
    id("com.google.devtools.ksp") version "1.4.30-1.0.0-alpha04"
}

dependencies {
    // 使用ksp进行注解生成
    ksp(project(":kspCompiler"))
}

// 子模块可以加上这个
ksp {
    arg("ROUTER_MODULE_NAME", project.name)
}

有事?

可以qq找我 454327998

The MIT License (MIT) Copyright (c) 2016 Teacher Rou Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

通过注解实现路由跳转规则 同时增加ksp支持 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Kotlin
1
https://gitee.com/leifzhang/Router-Android.git
git@gitee.com:leifzhang/Router-Android.git
leifzhang
Router-Android
Router-Android
master

搜索帮助