Update module download pipeline

This commit is contained in:
topjohnwu
2019-07-26 02:26:02 -07:00
parent 2b1b970e78
commit cdaff5b39c
4 changed files with 18 additions and 27 deletions

View File

@@ -8,8 +8,6 @@ import com.topjohnwu.magisk.data.network.GithubRawApiServices
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.koin.dsl.module
import retrofit2.CallAdapter
import retrofit2.Converter
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.moshi.MoshiConverterFactory
@@ -17,9 +15,8 @@ import se.ansman.kotshi.KotshiJsonAdapterFactory
val networkingModule = module {
single { createOkHttpClient() }
single { createConverterFactory() }
single { createCallAdapterFactory() }
single { createRetrofit(get(), get(), get()) }
single { createMoshiConverterFactory() }
single { createRetrofit(get(), get()) }
single { createApiService<GithubRawApiServices>(get(), Const.Url.GITHUB_RAW_API_URL) }
}
@@ -36,34 +33,25 @@ fun createOkHttpClient(): OkHttpClient {
return builder.build()
}
fun createConverterFactory(): Converter.Factory {
fun createMoshiConverterFactory(): MoshiConverterFactory {
val moshi = Moshi.Builder()
.add(JsonAdapterFactory.INSTANCE)
.add(KotshiJsonAdapterFactory)
.build()
return MoshiConverterFactory.create(moshi)
}
fun createCallAdapterFactory(): CallAdapter.Factory {
return RxJava2CallAdapterFactory.create()
}
fun createRetrofit(
okHttpClient: OkHttpClient,
converterFactory: Converter.Factory,
callAdapterFactory: CallAdapter.Factory
converterFactory: MoshiConverterFactory
): Retrofit.Builder {
return Retrofit.Builder()
.addConverterFactory(converterFactory)
.addCallAdapterFactory(callAdapterFactory)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
}
@KotshiJsonAdapterFactory
abstract class JsonAdapterFactory : JsonAdapter.Factory {
companion object {
val INSTANCE: JsonAdapterFactory = KotshiJsonAdapterFactory
}
}
abstract class JsonAdapterFactory : JsonAdapter.Factory
inline fun <reified T> createApiService(retrofitBuilder: Retrofit.Builder, baseUrl: String): T {
return retrofitBuilder