mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
Convert dependency inject ("di") package to kotlin (#5976)
* Convert a batch of easier modules * Convert the NetworkingModule to kotlin * Converted the ApplicationlessInjection to kotlin * Convert CommonsDaggerAppCompatActivity to kotlin * Convert CommonsDaggerContentProvider to kotlin * Convert CommonsDaggerIntentService to kotlin * Convert CommonsDaggerService to kotlin * Convert CommonsDaggerSupportFragment to kotlin * Convert CommonsDaggerBroadcastReceiver to kotlin * Convert CommonsApplicationModule to kotlin * Fix imports and make them consistent
This commit is contained in:
parent
dac3657536
commit
1e5521b434
41 changed files with 1274 additions and 1465 deletions
|
|
@ -8,7 +8,7 @@ import retrofit2.converter.gson.GsonConverterFactory
|
|||
class CommonsServiceFactory(
|
||||
private val okHttpClient: OkHttpClient,
|
||||
) {
|
||||
private val builder: Retrofit.Builder by lazy {
|
||||
val builder: Retrofit.Builder by lazy {
|
||||
// All instances of retrofit share this configuration, but create it lazily
|
||||
Retrofit
|
||||
.Builder()
|
||||
|
|
@ -17,15 +17,11 @@ class CommonsServiceFactory(
|
|||
.addConverterFactory(GsonConverterFactory.create(GsonUtil.getDefaultGson()))
|
||||
}
|
||||
|
||||
private val retrofitCache: MutableMap<String, Retrofit> = mutableMapOf()
|
||||
val retrofitCache: MutableMap<String, Retrofit> = mutableMapOf()
|
||||
|
||||
fun <T : Any> create(
|
||||
baseUrl: String,
|
||||
service: Class<T>,
|
||||
): T =
|
||||
retrofitCache
|
||||
.getOrPut(baseUrl) {
|
||||
// Cache instances of retrofit based on API backend
|
||||
builder.baseUrl(baseUrl).build()
|
||||
}.create(service)
|
||||
inline fun <reified T: Any> create(baseUrl: String): T =
|
||||
retrofitCache.getOrPut(baseUrl) {
|
||||
// Cache instances of retrofit based on API backend
|
||||
builder.baseUrl(baseUrl).build()
|
||||
}.create(T::class.java)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue