A lightweight, simple, smart and powerful Android routing library.

Related tags

Kotlin router rxjava
Overview

RxRouter

Download

Read this in other languages: 中文English 

A lightweight, simple, smart and powerful Android routing library.

Getting started

Setting up the dependency

Add to your project build.gradle file:

dependencies {
	implementation 'zlc.season:rxrouter:x.y.z'
	annotationProcessor 'zlc.season:rxrouter-compiler:x.y.z'
}

(Please replace x and y and z with the latest version numbers: )

For Kotlin you should use kapt instead of annotationProcessor

Hello World

First add the @url annotation to the activity we need to route:

@Url("this is a url")
class UrlActivity : AppCompatActivity() {
    ...
}

Then create a class that is annotated with @Router to tell RxRouter that there is a router:

@Router
class MainRouter{
}

This class doesn't need to have any remaining code. RxRouter will automatically generate a RouterProvider based on the class name of the class. For example, MainRouter will generate MainRouterProvider.

Then we need to add these routers to RxRouterProviders:

class CustomApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        RxRouterProviders.add(MainRouterProvider())
    }
}

Finally, we can start our performance:

RxRouter.of(context)
        .route("this is a uri")
        .subscribe()

Parameters

Routing with parameters:

With the with method, you can add a series of parameters to this route.

RxRouter.of(context)
        .with(10)                         	//int value
        .with(true)							//boolean value
        .with(20.12)						//double value
        .with("this is a string value")		//string value
        .with(Bundle())						//Bundle value
        .route("this is a uri")
        .subscribe()

No longer needs the onActivityResult method

Want to get the value returned by the route? No longer have to write a bunch of onActivityResult methods! One step in place with RxJava!

RxRouter.of(context)
		.with(false)
        .with(2000)
        .with(9999999999999999)
        .route("this is a uri")
        .subscribe {
            if (it.resultCode == Activity.RESULT_OK) {
                val intent = it.data
                val stringResult = intent.getStringExtra("result")
                result_text.text = stringResult
                stringResult.toast()
            }
        }

If there is a result return, it will be processed in subscribe.

Routing through Class

Do not want to use Url annotations? No problem, RxRouter also supports the original jump of the specified class name, in the same way:

RxRouter.of(context)
        .routeClass(ClassForResultActivity::class.java)
        .subscribe{
            if (it.resultCode == Activity.RESULT_OK) {
                val intent = it.data
                val stringResult = intent.getStringExtra("result")
                result_text.text = stringResult
                stringResult.toast()
            }
        }

Routing through Action

Similarly, RxRouter also supports system Actions and custom Actions.

Routing through custom Action:

<activity android:name=".ActionActivity">
    <intent-filter>
        <action android:name="zlc.season.sample.action" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
RxRouter.of(context)
        .routeAction("zlc.season.sample.action")
        .subscribe({
            "no result".toast()
        }, {
            it.message?.toast()
        })

Routing through system action:

//dial
RxRouter.of(this)
        .addUri(Uri.parse("tel:123456"))
        .routeSystemAction(Intent.ACTION_DIAL)
        .subscribe()

//send message
val bundle = Bundle()
bundle.putString("sms_body", "this is message")
RxRouter.of(this)
        .addUri(Uri.parse("smsto:10086"))
        .with(bundle)
        .routeSystemAction(Intent.ACTION_SENDTO)
        .subscribe()

Firewall

The RxRouter has a small and powerful firewall that can be intercepted according to firewall rules before routing. You can add one or more firewalls.

//create a LoginFirewall
class LoginFirewall : Firewall {
    override fun allow(datagram: Datagram): Boolean {
        if (notLogin) {
            "please log in".toast()
            return false
        }
        return true
    }
}

//Add Firewall to Route
RxRouter.of(this)
        .addFirewall(LoginFirewall())
        .route("this is a url")
        .subscribe()

License

Copyright 2018 Season.Zlc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
🚟 Lightweight, and simple scheduling library made for Kotlin (JVM)
🚟 Lightweight, and simple scheduling library made for Kotlin (JVM)

Haru 🚟 Lightweight, and simple scheduling library made for Kotlin (JVM) Why did you build this? I built this library as a personal usage library to h

Runtime Mobile Security (RMS) 📱🔥  - is a powerful web interface that helps you to manipulate Android and iOS Apps at Runtime
Runtime Mobile Security (RMS) 📱🔥 - is a powerful web interface that helps you to manipulate Android and iOS Apps at Runtime

Runtime Mobile Security (RMS) 📱 🔥 by @mobilesecurity_ Runtime Mobile Security (RMS), powered by FRIDA, is a powerful web interface that helps you to

Lightweight data loading and caching library for android

ColdStorage A lightweight data loading and caching library for android Quicklinks Feature requests: Got a new requirement? Request it here and it will

Clickstream - A Modern, Fast, and Lightweight Android Library Ingestion Platform.
Clickstream - A Modern, Fast, and Lightweight Android Library Ingestion Platform.

Clickstream is an event agnostic, real-time data ingestion platform. Clickstream allows apps to maintain a long-running connection to send data in real-time.

This is powerful android framework
This is powerful android framework

FlairFramework This is an android framework for build complex application with different architectures (MVC ready/MVP/MVVM/MVI ets). It's create on to

A powerful tool (iOS & Android) that focuses on mobile operation behavior!
A powerful tool (iOS & Android) that focuses on mobile operation behavior!

DiDiPrism,中文名:小桔棱镜,是一款专注于移动端操作行为的工具,涵盖APP操作回放、操作检测、以及数据可视化能力。我们在整个方案的实现过程中沉淀出了一套技术框架,希望可以逐步开源出来帮助更多人,同时也希望棱镜在大家的合力下能够更快的成长。 它有哪些亮点? 零入侵 业务代码无需任何适配。 高可

Lightweight compiler plugin intended for Kotlin/JVM library development and symbol visibility control.

Restrikt A Kotlin/JVM compiler plugin to restrict symbols access, from external project sources. This plugin offers two ways to hide symbols: An autom

A powerful Minecraft Server Software coming from the future

Mirai A powerful Minecraft Server Software coming from the future Mirai is ❗ under heavy development ❗ and contributions are welcome! Features 30% fas

Kauth - Open-source powerful minecraft authorization plugin
Kauth - Open-source powerful minecraft authorization plugin

KAuth KAuth is a minecraft plugin for offline-mode authorization on your server.

Comments
  • 用androidannotations无法跳转

    用androidannotations无法跳转

    类库地址:https://github.com/androidannotations/androidannotations/wiki/AvailableAnnotations 使用androidannotations会生成当前类名加_的类,无法实现url跳转,可以加上对androidannotations的支持吗? 类似这样: @Retention(RetentionPolicy.CLASS) @Target(ElementType.TYPE) public @interface Url { String value(); boolean isAA() default false; }

    opened by jielundewode 4
Releases(v0.0.1)
Owner
Season
会写点代码
Season
Kotlin Multiplatform lifecycle-aware business logic components (aka BLoCs) with routing functionality and pluggable UI (Jetpack Compose, SwiftUI, JS React, etc.), inspired by Badoos RIBs fork of the Uber RIBs framework

Decompose Please see the project website for documentation and APIs. Decompose is a Kotlin Multiplatform library for breaking down your code into life

Arkadii Ivanov 819 Dec 29, 2022
Easiest routing for compose-jb

Easiest routing for compose-jb Supported targets: Jvm Js Installation repositories { mavenCentral() } dependencies { implementation("io.githu

null 31 Nov 18, 2022
GardenKollektion - Kademlia routing for forum based IPFS Agents

Kademlia in 30 seconds all gossip nodes have guid all guid pair's have hamming distance (number of XOR bits that are '1') all distances have buckets a

Jim Northrup 1 Feb 28, 2022
A libre smart powered comic book reader for Android.

Seeneva A libre smart powered comic book reader for Android. Translation: Русский • • Features • Speech balloons zooming • OCR and TTS • Performance •

Seeneva comic book reader 130 Jan 7, 2023
A smart colored time selector. Users can select just free time with a handy colorful range selector.

Colored Time Range Selector A smart colored time range selector. Users can select just free time with a handy colorful range selector. Screen Shots Fe

Ehsan Mehranvari 154 Oct 3, 2022
How to structure a growing Gradle project with smart dependency management?

How to set up a larger Gradle project This repo shows one possibility to structure a Gradle project when you want: Centralized and maintainable build

Jendrik Johannes 59 Jan 6, 2023
⏰ A powerful and simple-to-use guilded wrapper made in Kotlin.

⏰ guilded-kt [WIP] A powerful yet simple-to-use guilded wrapper made entirely in Kotlin with supporting multiplatform. Take a look at an example of th

Gabriel 13 Jul 30, 2022
🎲 A powerful and simple-to-use guilded wrapper made in Kotlin.

?? deck [WIP] Deck is a powerful yet simple-to-use guilded wrapper made entirely in Kotlin with support to multiplatform. Implementating In case you'r

Gabriel 13 Jul 30, 2022
A lightweight and simple Kotlin library for deep link handling on Android 🔗.

A lightweight and simple Kotlin library for deep link handling on Android ??.

Jeziel Lago 101 Aug 14, 2022
The most complete and powerful data-binding library and persistence infra for Kotlin 1.3, Android & Splitties Views DSL, JavaFX & TornadoFX, JSON, JDBC & SQLite, SharedPreferences.

Lychee (ex. reactive-properties) Lychee is a library to rule all the data. ToC Approach to declaring data Properties Other data-binding libraries Prop

Mike 112 Dec 9, 2022