mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-15 08:50:35 +03:00
Provide app okhttp client instance to subsonic api client.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
f007418298
commit
b97e09b14b
@ -36,7 +36,8 @@ private const val READ_TIMEOUT = 60_000L
|
||||
* @author Yahor Berdnikau
|
||||
*/
|
||||
class SubsonicAPIClient(
|
||||
config: SubsonicClientConfiguration
|
||||
config: SubsonicClientConfiguration,
|
||||
baseOkClient: OkHttpClient = OkHttpClient.Builder().build()
|
||||
) {
|
||||
private val versionInterceptor = VersionInterceptor(config.minimalProtocolVersion) {
|
||||
protocolVersion = it
|
||||
@ -59,7 +60,7 @@ class SubsonicAPIClient(
|
||||
wrappedApi.currentApiVersion = field
|
||||
}
|
||||
|
||||
private val okHttpClient = OkHttpClient.Builder()
|
||||
private val okHttpClient = baseOkClient.newBuilder()
|
||||
.readTimeout(READ_TIMEOUT, MILLISECONDS)
|
||||
.apply { if (config.allowSelfSignedCertificate) allowSelfSignedCertificates() }
|
||||
.addInterceptor { chain ->
|
||||
|
@ -6,5 +6,5 @@ import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient
|
||||
const val SUBSONIC_API_CLIENT_CONTEXT = "SubsonicApiClientContext"
|
||||
|
||||
fun Context.subsonicApiModule() = context(SUBSONIC_API_CLIENT_CONTEXT) {
|
||||
bean { return@bean SubsonicAPIClient(get()) }
|
||||
bean { return@bean SubsonicAPIClient(get(), get()) }
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package org.moire.ultrasonic.app
|
||||
|
||||
import android.app.Application
|
||||
import org.koin.android.ext.android.startKoin
|
||||
import org.moire.ultrasonic.di.baseNetworkModule
|
||||
import org.moire.ultrasonic.di.directoriesModule
|
||||
import org.moire.ultrasonic.di.musicServiceModule
|
||||
import org.moire.ultrasonic.util.Util
|
||||
@ -13,6 +14,7 @@ class UApp : Application() {
|
||||
val sharedPreferences = Util.getPreferences(this)
|
||||
startKoin(this, listOf(
|
||||
directoriesModule,
|
||||
baseNetworkModule,
|
||||
musicServiceModule(sharedPreferences)
|
||||
))
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package org.moire.ultrasonic.di
|
||||
|
||||
import okhttp3.OkHttpClient
|
||||
import org.koin.dsl.module.applicationContext
|
||||
|
||||
/**
|
||||
* Provides base network dependencies.
|
||||
*/
|
||||
val baseNetworkModule = applicationContext {
|
||||
bean { OkHttpClient.Builder().build() }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user