2018-06-23 22:18:08 +02:00
|
|
|
@file:JvmName("MusicServiceModule")
|
|
|
|
package org.moire.ultrasonic.di
|
|
|
|
|
2020-06-13 19:04:31 +02:00
|
|
|
import kotlin.math.abs
|
2020-10-02 18:47:21 +02:00
|
|
|
import okhttp3.logging.HttpLoggingInterceptor
|
2020-09-18 09:37:19 +02:00
|
|
|
import org.koin.android.ext.koin.androidContext
|
|
|
|
import org.koin.core.qualifier.named
|
|
|
|
import org.koin.dsl.module
|
2018-06-23 22:18:08 +02:00
|
|
|
import org.moire.ultrasonic.BuildConfig
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions
|
2018-06-23 22:30:11 +02:00
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicClientConfiguration
|
2020-09-18 09:37:19 +02:00
|
|
|
import org.moire.ultrasonic.data.ActiveServerProvider
|
2021-06-07 13:17:00 +02:00
|
|
|
import org.moire.ultrasonic.imageloader.ImageLoader
|
2020-09-30 18:17:57 +02:00
|
|
|
import org.moire.ultrasonic.log.TimberOkHttpLogger
|
2018-06-23 22:18:08 +02:00
|
|
|
import org.moire.ultrasonic.service.CachedMusicService
|
|
|
|
import org.moire.ultrasonic.service.MusicService
|
|
|
|
import org.moire.ultrasonic.service.OfflineMusicService
|
|
|
|
import org.moire.ultrasonic.service.RESTMusicService
|
2021-02-04 20:15:58 +01:00
|
|
|
import org.moire.ultrasonic.subsonic.DownloadHandler
|
2021-06-07 13:17:00 +02:00
|
|
|
import org.moire.ultrasonic.subsonic.ImageLoaderProvider
|
2021-02-04 20:15:58 +01:00
|
|
|
import org.moire.ultrasonic.subsonic.NetworkAndStorageChecker
|
|
|
|
import org.moire.ultrasonic.subsonic.ShareHandler
|
2018-06-23 22:18:08 +02:00
|
|
|
import org.moire.ultrasonic.util.Constants
|
|
|
|
|
2021-03-01 17:24:25 +01:00
|
|
|
/**
|
|
|
|
* This Koin module contains the registration of classes related to the Music Services
|
|
|
|
*/
|
2018-06-23 22:18:08 +02:00
|
|
|
internal const val ONLINE_MUSIC_SERVICE = "OnlineMusicService"
|
|
|
|
internal const val OFFLINE_MUSIC_SERVICE = "OfflineMusicService"
|
|
|
|
|
2020-09-18 09:37:19 +02:00
|
|
|
val musicServiceModule = module {
|
2018-06-23 22:49:46 +02:00
|
|
|
|
2020-09-18 09:37:19 +02:00
|
|
|
single(named("ServerInstance")) {
|
2021-05-09 10:25:04 +02:00
|
|
|
return@single ActiveServerProvider.getActiveServerId()
|
2020-06-13 19:04:31 +02:00
|
|
|
}
|
2018-06-23 22:18:08 +02:00
|
|
|
|
2020-09-18 09:37:19 +02:00
|
|
|
single(named("ServerID")) {
|
|
|
|
val serverInstance = get<Int>(named("ServerInstance"))
|
|
|
|
val serverUrl = get<ActiveServerProvider>().getActiveServer().url
|
|
|
|
return@single abs("$serverUrl$serverInstance".hashCode()).toString()
|
2020-06-13 19:04:31 +02:00
|
|
|
}
|
2018-06-23 22:18:08 +02:00
|
|
|
|
2020-06-13 19:04:31 +02:00
|
|
|
single {
|
2021-06-09 19:33:17 +02:00
|
|
|
val server = get<ActiveServerProvider>().getActiveServer()
|
|
|
|
|
2020-09-18 09:37:19 +02:00
|
|
|
return@single SubsonicClientConfiguration(
|
2021-06-09 19:33:17 +02:00
|
|
|
baseUrl = server.url,
|
|
|
|
username = server.userName,
|
|
|
|
password = server.password,
|
2020-09-18 09:37:19 +02:00
|
|
|
minimalProtocolVersion = SubsonicAPIVersions.getClosestKnownClientApiVersion(
|
2021-06-09 19:33:17 +02:00
|
|
|
server.minimumApiVersion
|
2020-10-13 21:41:01 +02:00
|
|
|
?: Constants.REST_PROTOCOL_VERSION
|
2020-09-18 09:37:19 +02:00
|
|
|
),
|
|
|
|
clientID = Constants.REST_CLIENT_ID,
|
2021-06-09 19:33:17 +02:00
|
|
|
allowSelfSignedCertificate = server.allowSelfSignedCertificate,
|
|
|
|
enableLdapUserSupport = server.ldapSupport,
|
|
|
|
debug = BuildConfig.DEBUG,
|
|
|
|
isRealProtocolVersion = server.minimumApiVersion != null
|
2020-06-13 19:04:31 +02:00
|
|
|
)
|
|
|
|
}
|
2018-06-23 22:18:08 +02:00
|
|
|
|
2020-09-30 18:17:57 +02:00
|
|
|
single<HttpLoggingInterceptor.Logger> { TimberOkHttpLogger() }
|
|
|
|
single { SubsonicAPIClient(get(), get()) }
|
2018-06-23 22:18:08 +02:00
|
|
|
|
2020-09-18 09:37:19 +02:00
|
|
|
single<MusicService>(named(ONLINE_MUSIC_SERVICE)) {
|
2021-06-20 16:31:08 +02:00
|
|
|
CachedMusicService(RESTMusicService(get(), get()))
|
2020-06-13 19:04:31 +02:00
|
|
|
}
|
2018-06-26 21:38:28 +02:00
|
|
|
|
2020-09-18 09:37:19 +02:00
|
|
|
single<MusicService>(named(OFFLINE_MUSIC_SERVICE)) {
|
2020-10-15 10:22:15 +02:00
|
|
|
OfflineMusicService()
|
2018-06-23 22:18:08 +02:00
|
|
|
}
|
2020-06-13 19:04:31 +02:00
|
|
|
|
2021-06-07 13:17:00 +02:00
|
|
|
single { ImageLoader(androidContext(), get(), ImageLoaderProvider.config) }
|
|
|
|
|
2021-02-04 20:15:58 +01:00
|
|
|
single { DownloadHandler(get(), get()) }
|
|
|
|
single { NetworkAndStorageChecker(androidContext()) }
|
|
|
|
single { ShareHandler(androidContext()) }
|
2020-06-13 19:04:31 +02:00
|
|
|
}
|