From 79f047015ace30f626a9c618d6fb45fa3f2f5a71 Mon Sep 17 00:00:00 2001 From: Ryan Harg Date: Mon, 9 Aug 2021 07:03:20 +0200 Subject: [PATCH] #7: Restructure koin modules --- app/src/main/java/audio/funkwhale/ffa/FFA.kt | 8 +++-- .../java/audio/funkwhale/ffa/koin/Modules.kt | 31 ++++++------------- .../funkwhale/ffa/playback/MediaSession.kt | 1 + 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/audio/funkwhale/ffa/FFA.kt b/app/src/main/java/audio/funkwhale/ffa/FFA.kt index 4aef877..e0002a6 100644 --- a/app/src/main/java/audio/funkwhale/ffa/FFA.kt +++ b/app/src/main/java/audio/funkwhale/ffa/FFA.kt @@ -3,7 +3,8 @@ package audio.funkwhale.ffa import android.app.Application import android.content.Context 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 com.preference.PowerPreference import kotlinx.coroutines.channels.BroadcastChannel @@ -31,7 +32,10 @@ class FFA : Application() { super.onCreate() startKoin { - modules(ffaModule(this@FFA)) + modules( + authModule(), + exoplayerModule(this@FFA) + ) } defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler() diff --git a/app/src/main/java/audio/funkwhale/ffa/koin/Modules.kt b/app/src/main/java/audio/funkwhale/ffa/koin/Modules.kt index 1974fc1..936019c 100644 --- a/app/src/main/java/audio/funkwhale/ffa/koin/Modules.kt +++ b/app/src/main/java/audio/funkwhale/ffa/koin/Modules.kt @@ -8,10 +8,6 @@ import audio.funkwhale.ffa.utils.DefaultOAuth import audio.funkwhale.ffa.utils.OAuth import com.google.android.exoplayer2.database.DatabaseProvider 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.LeastRecentlyUsedCacheEvictor 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.dsl.module -fun ffaModule(context: Context) = module { +fun exoplayerModule(context: Context) = module { - single { DefaultOAuth(get()) } - - single { AuthorizationServiceFactory() } - - single { - val cacheDataSourceFactoryProvider = get() - DownloaderConstructorHelper( - get(named("exoDownloadCache")), cacheDataSourceFactoryProvider.create(context) - ).run { - DownloadManager( - context, - DefaultDownloadIndex(get(named("exoDatabase"))), - DefaultDownloaderFactory(this) - ) - } + single(named("exoDatabase")) { + ExoDatabaseProvider(context) } single { @@ -47,8 +30,6 @@ fun ffaModule(context: Context) = module { ) } - single(named("exoDatabase")) { ExoDatabaseProvider(context) } - single(named("exoDownloadCache")) { SimpleCache( context.cacheDir.resolve("downloads"), @@ -68,4 +49,10 @@ fun ffaModule(context: Context) = module { } single { MediaSession(context) } +} + +fun authModule() = module { + single { DefaultOAuth(get()) } + + single { AuthorizationServiceFactory() } } \ No newline at end of file diff --git a/app/src/main/java/audio/funkwhale/ffa/playback/MediaSession.kt b/app/src/main/java/audio/funkwhale/ffa/playback/MediaSession.kt index 35d6daf..2e39bd3 100644 --- a/app/src/main/java/audio/funkwhale/ffa/playback/MediaSession.kt +++ b/app/src/main/java/audio/funkwhale/ffa/playback/MediaSession.kt @@ -13,6 +13,7 @@ import com.google.android.exoplayer2.Player import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector class MediaSession(private val context: Context) { + var active = false private val playbackStateBuilder = PlaybackStateCompat.Builder().apply {