Skip to content

Instantly share code, notes, and snippets.

@cesarioputera
Created November 25, 2019 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cesarioputera/91aa804226dc383ccbeb25aa6b2b3528 to your computer and use it in GitHub Desktop.
Save cesarioputera/91aa804226dc383ccbeb25aa6b2b3528 to your computer and use it in GitHub Desktop.
Routing via Interface
//Base Modules
object BaseRouter {
private lateinit var mIBaseRouters: IBaseRouter
fun init(router: IBaseRouter) {
mIBaseRouters = router
}
fun route(context: Context, url: String): Boolean {
return mIBaseRouters.routeTo(context, url)
}
interface IBaseRouter {
fun routeTo(context: Context, url: String): Boolean
}
}
//Feature module
class HomeActivity : Activity {
//another code
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
BaseRouter.route(context, "blibli://login")
}
}
//App Module
class Router @Inject constructor() : BaseRouter.IBaseRouter {
init {
BaseRouter.init(this)
}
override fun routeTo(context: Context, url: String): Boolean {
return routeTarget(context, url)
}
fun routeTarget(context: Context?, @NotNull url: String): Boolean {
if(url.contains(login)){
//intent to LoginActivity.kt
return true
} else if (...){
//another intent
return true
} else {
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment