Tool for using custom stage host in projects with Retrofit & OkHttp
dependencies {
implementation 'com.github.magdevelopment:StageHostSelector:{latest_version}'
}
- Add in application onCreate:
if (BuildConfig.USES_DEV_FEATURES) {
StageHostSelector.init(
context = this,
defaultHostUrl = BuildConfig.API_ENDPOINT,
suggestedUrls = setOf(
"http://example.com/alternative/",
"http://172.21.19.123:3500/",
"http://example.com/alternative/first",
"http://example.com:8080/alternative/first"
)
)
}
- Somewhere on login screen create and add view:
val view = StageHostSelector.createView(this)
// if you are not initialized StageHostSelector, function StageHostSelector.createView(this) return null
if (view != null) appBarLayout.addView(view)
- When creating OkHttp's client add interceptor:
import com.magdv.stagehostselector.addStageHostSelectorInterceptor
val clientBuilder = OkHttpClient.Builder()
...
clientBuilder.addStageHostSelectorInterceptor()
...
clientBuilder.build()