#7: Restructure koin modules
This commit is contained in:
parent
709d678565
commit
79f047015a
|
@ -3,7 +3,8 @@ package audio.funkwhale.ffa
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import audio.funkwhale.ffa.koin.ffaModule
|
import audio.funkwhale.ffa.koin.authModule
|
||||||
|
import audio.funkwhale.ffa.koin.exoplayerModule
|
||||||
import audio.funkwhale.ffa.utils.*
|
import audio.funkwhale.ffa.utils.*
|
||||||
import com.preference.PowerPreference
|
import com.preference.PowerPreference
|
||||||
import kotlinx.coroutines.channels.BroadcastChannel
|
import kotlinx.coroutines.channels.BroadcastChannel
|
||||||
|
@ -31,7 +32,10 @@ class FFA : Application() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
startKoin {
|
startKoin {
|
||||||
modules(ffaModule(this@FFA))
|
modules(
|
||||||
|
authModule(),
|
||||||
|
exoplayerModule(this@FFA)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
|
defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler()
|
||||||
|
|
|
@ -8,10 +8,6 @@ import audio.funkwhale.ffa.utils.DefaultOAuth
|
||||||
import audio.funkwhale.ffa.utils.OAuth
|
import audio.funkwhale.ffa.utils.OAuth
|
||||||
import com.google.android.exoplayer2.database.DatabaseProvider
|
import com.google.android.exoplayer2.database.DatabaseProvider
|
||||||
import com.google.android.exoplayer2.database.ExoDatabaseProvider
|
import com.google.android.exoplayer2.database.ExoDatabaseProvider
|
||||||
import com.google.android.exoplayer2.offline.DefaultDownloadIndex
|
|
||||||
import com.google.android.exoplayer2.offline.DefaultDownloaderFactory
|
|
||||||
import com.google.android.exoplayer2.offline.DownloadManager
|
|
||||||
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper
|
|
||||||
import com.google.android.exoplayer2.upstream.cache.Cache
|
import com.google.android.exoplayer2.upstream.cache.Cache
|
||||||
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor
|
import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor
|
||||||
import com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor
|
import com.google.android.exoplayer2.upstream.cache.NoOpCacheEvictor
|
||||||
|
@ -20,23 +16,10 @@ import com.preference.PowerPreference
|
||||||
import org.koin.core.qualifier.named
|
import org.koin.core.qualifier.named
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
|
||||||
fun ffaModule(context: Context) = module {
|
fun exoplayerModule(context: Context) = module {
|
||||||
|
|
||||||
single<OAuth> { DefaultOAuth(get()) }
|
single<DatabaseProvider>(named("exoDatabase")) {
|
||||||
|
ExoDatabaseProvider(context)
|
||||||
single { AuthorizationServiceFactory() }
|
|
||||||
|
|
||||||
single {
|
|
||||||
val cacheDataSourceFactoryProvider = get<CacheDataSourceFactoryProvider>()
|
|
||||||
DownloaderConstructorHelper(
|
|
||||||
get(named("exoDownloadCache")), cacheDataSourceFactoryProvider.create(context)
|
|
||||||
).run {
|
|
||||||
DownloadManager(
|
|
||||||
context,
|
|
||||||
DefaultDownloadIndex(get(named("exoDatabase"))),
|
|
||||||
DefaultDownloaderFactory(this)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
single {
|
single {
|
||||||
|
@ -47,8 +30,6 @@ fun ffaModule(context: Context) = module {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
single<DatabaseProvider>(named("exoDatabase")) { ExoDatabaseProvider(context) }
|
|
||||||
|
|
||||||
single<Cache>(named("exoDownloadCache")) {
|
single<Cache>(named("exoDownloadCache")) {
|
||||||
SimpleCache(
|
SimpleCache(
|
||||||
context.cacheDir.resolve("downloads"),
|
context.cacheDir.resolve("downloads"),
|
||||||
|
@ -69,3 +50,9 @@ fun ffaModule(context: Context) = module {
|
||||||
|
|
||||||
single { MediaSession(context) }
|
single { MediaSession(context) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun authModule() = module {
|
||||||
|
single<OAuth> { DefaultOAuth(get()) }
|
||||||
|
|
||||||
|
single { AuthorizationServiceFactory() }
|
||||||
|
}
|
|
@ -13,6 +13,7 @@ import com.google.android.exoplayer2.Player
|
||||||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
|
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
|
||||||
|
|
||||||
class MediaSession(private val context: Context) {
|
class MediaSession(private val context: Context) {
|
||||||
|
|
||||||
var active = false
|
var active = false
|
||||||
|
|
||||||
private val playbackStateBuilder = PlaybackStateCompat.Builder().apply {
|
private val playbackStateBuilder = PlaybackStateCompat.Builder().apply {
|
||||||
|
|
Loading…
Reference in New Issue