Created
November 25, 2019 13:49
-
-
Save cesarioputera/91aa804226dc383ccbeb25aa6b2b3528 to your computer and use it in GitHub Desktop.
Routing via Interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Feature module | |
class HomeActivity : Activity { | |
//another code | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
BaseRouter.route(context, "blibli://login") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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