@ -3,16 +3,14 @@ package com.github.apognu.otter
import android.app.Application
import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.AppCompatDelegate
import com.github.apognu.otter.playback.QueueManager
import com.github.apognu.otter.playback.QueueManager
import com.github.apognu.otter.utils.Cache
import com.github.apognu.otter.utils.*
import com.github.apognu.otter.utils.Command
import com.github.apognu.otter.utils.Event
import com.github.apognu.otter.utils.Request
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.DefaultDownloadIndex
import com.google.android.exoplayer2.offline.DefaultDownloaderFactory
import com.google.android.exoplayer2.offline.DefaultDownloaderFactory
import com.google.android.exoplayer2.offline.DownloadManager
import com.google.android.exoplayer2.offline.DownloadManager
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper
import com.google.android.exoplayer2.offline.DownloaderConstructorHelper
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.SimpleCache
import com.google.android.exoplayer2.upstream.cache.SimpleCache
import com.preference.PowerPreference
import com.preference.PowerPreference
import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.channels.BroadcastChannel
@ -36,6 +34,7 @@ class Otter : Application() {
val progressBus : BroadcastChannel < Triple < Int , Int , Int > > = ConflatedBroadcastChannel ( )
val progressBus : BroadcastChannel < Triple < Int , Int , Int > > = ConflatedBroadcastChannel ( )
private val exoDatabase : ExoDatabaseProvider by lazy { ExoDatabaseProvider ( this ) }
private val exoDatabase : ExoDatabaseProvider by lazy { ExoDatabaseProvider ( this ) }
val exoCache : SimpleCache by lazy {
val exoCache : SimpleCache by lazy {
PowerPreference . getDefaultFile ( ) . getInt ( " media_cache_size " , 1 ) . toLong ( ) . let {
PowerPreference . getDefaultFile ( ) . getInt ( " media_cache_size " , 1 ) . toLong ( ) . let {
SimpleCache (
SimpleCache (
@ -45,8 +44,17 @@ class Otter : Application() {
)
)
}
}
}
}
val exoDownloadCache : SimpleCache by lazy {
SimpleCache (
cacheDir . resolve ( " downloads " ) ,
NoOpCacheEvictor ( ) ,
exoDatabase
)
}
val exoDownloadManager : DownloadManager by lazy {
val exoDownloadManager : DownloadManager by lazy {
DownloaderConstructorHelper ( exoCache , QueueManager . factory ( this ) ) . run {
DownloaderConstructorHelper ( exoDownload Cache , QueueManager . factory ( this ) ) . run {
DownloadManager ( this @Otter , DefaultDownloadIndex ( exoDatabase ) , DefaultDownloaderFactory ( this ) )
DownloadManager ( this @Otter , DefaultDownloadIndex ( exoDatabase ) , DefaultDownloaderFactory ( this ) )
}
}
}
}