All Projects → twocity → Linker

twocity / Linker

A light weight URI routing framework for Android.

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to Linker

Router
Stars: ✭ 41 (-28.07%)
Mutual labels:  router
Ng Router Loader
Webpack loader for NgModule lazy loading using the angular router
Stars: ✭ 47 (-17.54%)
Mutual labels:  router
Svelte Store Router
Store-based router for Svelte
Stars: ✭ 54 (-5.26%)
Mutual labels:  router
Vanilla Ui Router
Simple vanilla JavaScript router
Stars: ✭ 42 (-26.32%)
Mutual labels:  router
Restify Router
A router interface for restify that lets you aggregate route definitions and apply to a restify server
Stars: ✭ 45 (-21.05%)
Mutual labels:  router
Lantern
Lantern官方版本下载 蓝灯 翻墙 代理 科学上网 外网 加速器 梯子 路由 lantern proxy vpn censorship-circumvention censorship gfw accelerator
Stars: ✭ 10,238 (+17861.4%)
Mutual labels:  router
Redux Json Router
Declarative, Redux-first routing for React/Redux browser applications.
Stars: ✭ 37 (-35.09%)
Mutual labels:  router
Dragon
⚡A powerful HTTP router and URL matcher for building Deno web servers.
Stars: ✭ 56 (-1.75%)
Mutual labels:  router
Webvr Webpack Boilerplate
A webvr multi-scenes Single-page application for three.js, webpack
Stars: ✭ 47 (-17.54%)
Mutual labels:  router
Rainbow
An Express router middleware for RESTful API base on file path.
Stars: ✭ 53 (-7.02%)
Mutual labels:  router
Flouter
A router for Flutter based on Navigator 2.0 and Regexp
Stars: ✭ 43 (-24.56%)
Mutual labels:  router
React Redux Antdesign Webpack Starter
react + redux + ant design + react-router 4 + webpack 4 starter
Stars: ✭ 44 (-22.81%)
Mutual labels:  router
Hyper Router
Simple routing middleware for rust HTTP library hyper.
Stars: ✭ 51 (-10.53%)
Mutual labels:  router
Cve 2018 18852
CERIO RCE CVE-2018-18852, authenticated (vendor defaults) web-based RCE as root user.
Stars: ✭ 42 (-26.32%)
Mutual labels:  router
Summer
Vertx router with JAX-RS
Stars: ✭ 54 (-5.26%)
Mutual labels:  router
Url Mapper
Take a URL and map to functions, parsing params
Stars: ✭ 39 (-31.58%)
Mutual labels:  router
Flowzard
Isolates navigation from UI and Business logic with simple wizard like mechanism.
Stars: ✭ 49 (-14.04%)
Mutual labels:  router
Apprun
AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.
Stars: ✭ 1,087 (+1807.02%)
Mutual labels:  router
Ska
Simple Karma Attack
Stars: ✭ 55 (-3.51%)
Mutual labels:  router
Urljects
Deprecated! (Django routing without urls.py files, inspired by Flask.)
Stars: ✭ 53 (-7.02%)
Mutual labels:  router

Linker Build Status

Linker provides an annotation-based API to handle URI routing for Android. This library is written in kotlin, and the generated codes are also pure kotlin.

Dependencies

Add the following to your build.gradle file:

dependencies {
	api 'me.twocities:linker:0.0.5'
	kapt 'me.twocities:linker-compiler:0.0.5'
}

Usage

There are two parts of Linker: annotations and LinkResolver

Annotations

@Link for activity

Use annotation @Link indicate which URI was respect:

@Link("link://product/detail{id})
class ProductActivity: AppCompatActivity {
}

@LinkPath @LinkQuery for parameters

@Link("link://product/detail/{id})
class ProductActivity: AppCompatActivity {
  @LinkPath("id") lateinit var productId: String
  @LinkQuery("title") lateinit var productTitle: String
}

After annotation processing, an extension function bindLinkParams() of ProductActivity will be generated, you can use it to get values of @LinkPath @LinkQuery params:

override fun onCreate(savedInstanceState: Bundle?) {
  super.onCreate(savedInstanceState)
  bindLinkParams()
}

@LinkModule for module

// generate LinkerExampleLinkModule
@LinkModule
class ExampleLinkModule

After annotation processing, a module class was generated, will contains informations of all defined @Link, @LinkPath, @LinkQuery. The generated class will be used to decided which uri will be routed.

@LinkModule supports multi android's library module.

@LinkResolverBuilder for builder

// generate LinkerExampleLinkResolverBuilder
@LinkResolverBuilder(modules = arrayOf(ExampleLinkModule::class, LibraryLinkModule::class))
interface ExampleLinkResolverBuilder

This will generate a LinkResolver's builder:

val resolver = LinkerExampleLinkResolverBuilder(context).build()

LinkResolver

The definition of LinkResolver is much simpler:

interface LinkResolver {
  fun resolve(link: String): Result
}

Function resolve will parse the given link, and then return a Result, which has a nullable property of Intent, it will be null if no responding activities was found,

Routing:

val result = resolver.resolve("link//product/detail/123")
if (result.success()) startActivity(result.intent)

Thanks to kotlin, we can simplify this by writing extension function like this:

startActivity("link://product/detail/123")

see ObjectGraph for more details.

Advance

Linker also provide other mechanisms: Interceptor, FallbackHandler, which you can change the behavior of a link. You can add interceptors or set fallback handler by the generated builder class:

 val resolver = LinkerBuilder(context)
        .addInterceptor(HttpUrlInterceptor(context))
        .setFallbackHandler(DefaultUrlHandler(context))
        .setListener(ResolverListener())
        .build()

the Listener will be notified when an link was resolved.

Interceptors

The interceptor will give you an ability to change a link's intent, or put extra values to activity

// An interceptor handles how http(s) url was resolved
class HttpUrlInterceptor(private val context: Context) : Interceptor {
  override fun intercept(link: String, metadata: LinkMetadata?): Intent? {
    if (link.startsWith("http") or link.startsWith("https")) {
      // since `LINK` will be passed to intent automatically, we can return the intent directly
      return Intent(context, SimpleBrowserActivity::class.java)
    }
    return null
  }
}

FallbackHandler

If there's no activities match with the given link, or no interceptors has intercepted, the fallback handler be called. The [FallbackHandler] gives you the ability to handle unknown link: start another activity or show an error page.

TODO

  • [ ] Generate link's builder when compiling
  • [ ] Support multi links for per activity
  • [ ] More unit tests

Credit

License

Apache License, Version 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].