mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-01-29 16:39:20 +01:00
Upgrade Koin to 3.0.2
This commit is contained in:
parent
f9401ba1fa
commit
71068fe635
@ -29,7 +29,7 @@ ext.versions = [
|
||||
jackson : "2.9.5",
|
||||
okhttp : "3.12.13",
|
||||
twitterSerial : "0.1.6",
|
||||
koin : "2.2.2",
|
||||
koin : "3.0.2",
|
||||
picasso : "2.71828",
|
||||
sortListView : "1.0.1",
|
||||
|
||||
|
@ -56,7 +56,6 @@ android {
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs += "-Xopt-in=org.koin.core.component.KoinApiExtension"
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
@ -94,7 +93,6 @@ dependencies {
|
||||
implementation other.kotlinStdlib
|
||||
implementation other.kotlinxCoroutines
|
||||
implementation other.koinAndroid
|
||||
implementation other.koinViewModel
|
||||
implementation other.okhttpLogging
|
||||
implementation other.fastScroll
|
||||
implementation other.sortListView
|
||||
|
@ -162,7 +162,8 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
useFiveStarRating = KoinJavaComponent.get(FeatureStorage.class).isFeatureEnabled(Feature.FIVE_STAR_RATING);
|
||||
FeatureStorage features = KoinJavaComponent.get(FeatureStorage.class);
|
||||
useFiveStarRating = features.isFeatureEnabled(Feature.FIVE_STAR_RATING);
|
||||
|
||||
swipeDistance = (width + height) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
|
||||
swipeVelocity = swipeDistance;
|
||||
|
@ -23,7 +23,7 @@ import kotlin.Lazy;
|
||||
import static org.koin.java.KoinJavaComponent.inject;
|
||||
|
||||
/**
|
||||
* Responsible for cleaning up files from the offline download cache on the filesystem
|
||||
* Responsible for cleaning up files from the offline download cache on the filesystem.
|
||||
*/
|
||||
public class CacheCleaner
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ import androidx.navigation.ui.setupWithNavController
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.google.android.material.navigation.NavigationView
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.android.viewmodel.ext.android.viewModel
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline
|
||||
import org.moire.ultrasonic.domain.PlayerState
|
||||
|
@ -2,7 +2,7 @@ package org.moire.ultrasonic.di
|
||||
|
||||
import androidx.room.Room
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.android.viewmodel.dsl.viewModel
|
||||
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||
import org.koin.core.qualifier.named
|
||||
import org.koin.dsl.module
|
||||
import org.moire.ultrasonic.data.AppDatabase
|
||||
|
@ -6,7 +6,6 @@ import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.domain.MusicDirectory
|
||||
import org.moire.ultrasonic.util.Constants
|
||||
@ -15,7 +14,6 @@ import org.moire.ultrasonic.util.Constants
|
||||
* Displays a list of Albums from the media library
|
||||
* TODO: Check refresh is working
|
||||
*/
|
||||
@KoinApiExtension
|
||||
class AlbumListFragment : GenericListFragment<MusicDirectory.Entry, AlbumRowAdapter>() {
|
||||
|
||||
/**
|
||||
|
@ -5,14 +5,12 @@ import android.os.Bundle
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.moire.ultrasonic.api.subsonic.models.AlbumListType
|
||||
import org.moire.ultrasonic.domain.MusicDirectory
|
||||
import org.moire.ultrasonic.service.MusicService
|
||||
import org.moire.ultrasonic.util.Constants
|
||||
import org.moire.ultrasonic.util.Util
|
||||
|
||||
@KoinApiExtension
|
||||
class AlbumListModel(application: Application) : GenericListModel(application) {
|
||||
|
||||
val albumList: MutableLiveData<List<MusicDirectory.Entry>> = MutableLiveData()
|
||||
|
@ -3,7 +3,6 @@ package org.moire.ultrasonic.fragment
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.LiveData
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.domain.Artist
|
||||
import org.moire.ultrasonic.util.Constants
|
||||
@ -11,7 +10,6 @@ import org.moire.ultrasonic.util.Constants
|
||||
/**
|
||||
* Displays the list of Artists from the media library
|
||||
*/
|
||||
@KoinApiExtension
|
||||
class ArtistListFragment : GenericListFragment<Artist, ArtistRowAdapter>() {
|
||||
|
||||
/**
|
||||
|
@ -23,14 +23,12 @@ import android.os.Bundle
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.moire.ultrasonic.domain.Artist
|
||||
import org.moire.ultrasonic.service.MusicService
|
||||
|
||||
/**
|
||||
* Provides ViewModel which contains the list of available Artists
|
||||
*/
|
||||
@KoinApiExtension
|
||||
class ArtistListModel(application: Application) : GenericListModel(application) {
|
||||
private val artists: MutableLiveData<List<Artist>> = MutableLiveData()
|
||||
|
||||
|
@ -14,7 +14,7 @@ import com.google.android.material.textfield.TextInputLayout
|
||||
import java.net.MalformedURLException
|
||||
import java.net.URL
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.android.viewmodel.ext.android.viewModel
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.moire.ultrasonic.BuildConfig
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient
|
||||
|
@ -13,8 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.android.viewmodel.ext.android.viewModel
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||
import org.moire.ultrasonic.domain.Artist
|
||||
@ -31,7 +30,6 @@ import org.moire.ultrasonic.view.SelectMusicFolderView
|
||||
* @param T: The type of data which will be used (must extend GenericEntry)
|
||||
* @param TA: The Adapter to use (must extend GenericRowAdapter)
|
||||
*/
|
||||
@KoinApiExtension
|
||||
abstract class GenericListFragment<T : GenericEntry, TA : GenericRowAdapter<T>> : Fragment() {
|
||||
internal val activeServerProvider: ActiveServerProvider by inject()
|
||||
internal val serverSettingsModel: ServerSettingsModel by viewModel()
|
||||
|
@ -15,7 +15,6 @@ import java.net.UnknownHostException
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||
@ -29,7 +28,6 @@ import org.moire.ultrasonic.util.Util
|
||||
/**
|
||||
* An abstract Model, which can be extended to retrieve a list of items from the API
|
||||
*/
|
||||
@KoinApiExtension
|
||||
open class GenericListModel(application: Application) :
|
||||
AndroidViewModel(application), KoinComponent {
|
||||
|
||||
|
@ -15,7 +15,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.android.viewmodel.ext.android.viewModel
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||
import org.moire.ultrasonic.fragment.EditServerFragment.Companion.EDIT_SERVER_INTENT_INDEX
|
||||
|
@ -33,7 +33,6 @@ import java.util.Random
|
||||
import kotlinx.coroutines.CoroutineExceptionHandler
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.android.ext.android.inject
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline
|
||||
import org.moire.ultrasonic.domain.MusicDirectory
|
||||
@ -60,7 +59,6 @@ import timber.log.Timber
|
||||
* Displays a group of tracks, eg. the songs of an album, of a playlist etc.
|
||||
* TODO: Refactor this fragment and model to extend the GenericListFragment
|
||||
*/
|
||||
@KoinApiExtension
|
||||
class TrackCollectionFragment : Fragment() {
|
||||
|
||||
private var refreshAlbumListView: SwipeRefreshLayout? = null
|
||||
|
@ -13,7 +13,6 @@ import androidx.lifecycle.MutableLiveData
|
||||
import java.util.LinkedList
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.domain.MusicDirectory
|
||||
import org.moire.ultrasonic.service.MusicService
|
||||
@ -24,7 +23,6 @@ import org.moire.ultrasonic.util.Util
|
||||
* Model for retrieving different collections of tracks from the API
|
||||
* TODO: Refactor this model to extend the GenericListModel
|
||||
*/
|
||||
@KoinApiExtension
|
||||
class TrackCollectionModel(application: Application) : GenericListModel(application) {
|
||||
|
||||
private val allSongsId = "-1"
|
||||
|
@ -18,7 +18,8 @@ import timber.log.Timber
|
||||
class AudioFocusHandler(private val context: Context) {
|
||||
// TODO: This is a circular reference, try to remove it
|
||||
// This should be doable by using the native MediaController framework
|
||||
private val mediaPlayerControllerLazy = inject(MediaPlayerController::class.java)
|
||||
private val mediaPlayerControllerLazy =
|
||||
inject<MediaPlayerController>(MediaPlayerController::class.java)
|
||||
|
||||
private val audioManager by lazy {
|
||||
context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
|
@ -9,7 +9,8 @@ package org.moire.ultrasonic.service
|
||||
import android.graphics.Bitmap
|
||||
import java.io.InputStream
|
||||
import java.util.concurrent.TimeUnit
|
||||
import org.koin.java.KoinJavaComponent.inject
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||
import org.moire.ultrasonic.domain.Bookmark
|
||||
import org.moire.ultrasonic.domain.ChatMessage
|
||||
@ -31,10 +32,9 @@ import org.moire.ultrasonic.util.TimeLimitedCache
|
||||
import org.moire.ultrasonic.util.Util
|
||||
|
||||
@Suppress("TooManyFunctions")
|
||||
class CachedMusicService(private val musicService: MusicService) : MusicService {
|
||||
private val activeServerProvider = inject(
|
||||
ActiveServerProvider::class.java
|
||||
)
|
||||
class CachedMusicService(private val musicService: MusicService) : MusicService, KoinComponent {
|
||||
private val activeServerProvider: ActiveServerProvider by inject()
|
||||
|
||||
private val cachedMusicDirectories: LRUCache<String?, TimeLimitedCache<MusicDirectory?>>
|
||||
private val cachedArtist: LRUCache<String?, TimeLimitedCache<MusicDirectory?>>
|
||||
private val cachedAlbum: LRUCache<String?, TimeLimitedCache<MusicDirectory?>>
|
||||
@ -308,8 +308,8 @@ class CachedMusicService(private val musicService: MusicService) : MusicService
|
||||
}
|
||||
|
||||
private fun checkSettingsChanged() {
|
||||
val newUrl = activeServerProvider.value.getRestUrl(null)
|
||||
val newFolderId = activeServerProvider.value.getActiveServer().musicFolderId
|
||||
val newUrl = activeServerProvider.getRestUrl(null)
|
||||
val newFolderId = activeServerProvider.getActiveServer().musicFolderId
|
||||
if (!Util.equals(newUrl, restUrl) || !Util.equals(cachedMusicFolderId, newFolderId)) {
|
||||
cachedMusicFolders.clear()
|
||||
cachedMusicDirectories.clear()
|
||||
|
@ -19,8 +19,8 @@ import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.io.RandomAccessFile
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.koin.java.KoinJavaComponent.inject
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import org.moire.ultrasonic.app.UApp
|
||||
import org.moire.ultrasonic.domain.MusicDirectory
|
||||
import org.moire.ultrasonic.service.MusicServiceFactory.getMusicService
|
||||
@ -36,11 +36,10 @@ import timber.log.Timber
|
||||
* @author Sindre Mehus
|
||||
* @version $Id$
|
||||
*/
|
||||
@KoinApiExtension
|
||||
class DownloadFile(
|
||||
val song: MusicDirectory.Entry,
|
||||
private val save: Boolean
|
||||
) {
|
||||
) : KoinComponent {
|
||||
val partialFile: File
|
||||
val completeFile: File
|
||||
private val saveFile: File = FileUtil.getSongFile(song)
|
||||
@ -59,7 +58,7 @@ class DownloadFile(
|
||||
@Volatile
|
||||
private var completeWhenDone = false
|
||||
|
||||
private val downloader = inject(Downloader::class.java)
|
||||
private val downloader: Downloader by inject()
|
||||
|
||||
val progress: MutableLiveData<Int> = MutableLiveData(0)
|
||||
|
||||
@ -201,7 +200,6 @@ class DownloadFile(
|
||||
return String.format("DownloadFile (%s)", song)
|
||||
}
|
||||
|
||||
@KoinApiExtension
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
private inner class DownloadTask : CancellableTask() {
|
||||
override fun execute() {
|
||||
@ -310,7 +308,7 @@ class DownloadFile(
|
||||
}
|
||||
wifiLock?.release()
|
||||
CacheCleaner().cleanSpace()
|
||||
downloader.value.checkDownloads()
|
||||
downloader.checkDownloads()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ import java.net.URLEncoder
|
||||
import java.util.Locale
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.moire.ultrasonic.audiofx.EqualizerController
|
||||
import org.moire.ultrasonic.audiofx.VisualizerController
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline
|
||||
@ -40,7 +39,6 @@ import timber.log.Timber
|
||||
/**
|
||||
* Represents a Media Player which uses the mobile's resources for playback
|
||||
*/
|
||||
@KoinApiExtension
|
||||
class LocalMediaPlayer(
|
||||
private val audioFocusHandler: AudioFocusHandler,
|
||||
private val context: Context
|
||||
|
@ -7,9 +7,9 @@
|
||||
package org.moire.ultrasonic.service
|
||||
|
||||
import android.content.Intent
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.koin.java.KoinJavaComponent.get
|
||||
import org.koin.java.KoinJavaComponent.inject
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.get
|
||||
import org.koin.core.component.inject
|
||||
import org.moire.ultrasonic.app.UApp
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||
import org.moire.ultrasonic.domain.MusicDirectory
|
||||
@ -30,7 +30,6 @@ import timber.log.Timber
|
||||
* This class contains everything that is necessary for the Application UI
|
||||
* to control the Media Player implementation.
|
||||
*/
|
||||
@KoinApiExtension
|
||||
@Suppress("TooManyFunctions")
|
||||
class MediaPlayerController(
|
||||
private val downloadQueueSerializer: DownloadQueueSerializer,
|
||||
@ -38,7 +37,7 @@ class MediaPlayerController(
|
||||
private val downloader: Downloader,
|
||||
private val shufflePlayBuffer: ShufflePlayBuffer,
|
||||
private val localMediaPlayer: LocalMediaPlayer
|
||||
) {
|
||||
) : KoinComponent {
|
||||
|
||||
private var created = false
|
||||
var suggestedPlaylistName: String? = null
|
||||
@ -46,8 +45,8 @@ class MediaPlayerController(
|
||||
var showVisualization = false
|
||||
private var autoPlayStart = false
|
||||
|
||||
private val jukeboxMediaPlayer = inject(JukeboxMediaPlayer::class.java).value
|
||||
private val activeServerProvider = inject(ActiveServerProvider::class.java).value
|
||||
private val jukeboxMediaPlayer: JukeboxMediaPlayer by inject()
|
||||
private val activeServerProvider: ActiveServerProvider by inject()
|
||||
|
||||
fun onCreate() {
|
||||
if (created) return
|
||||
@ -462,7 +461,8 @@ class MediaPlayerController(
|
||||
|
||||
@Suppress("TooGenericExceptionCaught") // The interface throws only generic exceptions
|
||||
fun setSongRating(rating: Int) {
|
||||
if (!get(FeatureStorage::class.java).isFeatureEnabled(Feature.FIVE_STAR_RATING)) return
|
||||
val features: FeatureStorage = get()
|
||||
if (!features.isFeatureEnabled(Feature.FIVE_STAR_RATING)) return
|
||||
if (localMediaPlayer.currentPlaying == null) return
|
||||
val song = localMediaPlayer.currentPlaying!!.song
|
||||
song.userRating = rating
|
||||
|
@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.moire.ultrasonic.service
|
||||
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.get
|
||||
import org.koin.core.context.loadKoinModules
|
||||
@ -30,7 +29,6 @@ import org.moire.ultrasonic.di.ONLINE_MUSIC_SERVICE
|
||||
import org.moire.ultrasonic.di.musicServiceModule
|
||||
|
||||
// TODO Refactor everywhere to use DI way to get MusicService, and then remove this class
|
||||
@KoinApiExtension
|
||||
object MusicServiceFactory : KoinComponent {
|
||||
@JvmStatic
|
||||
fun getMusicService(): MusicService {
|
||||
|
@ -22,7 +22,8 @@ import java.util.Locale
|
||||
import java.util.Random
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.regex.Pattern
|
||||
import org.koin.java.KoinJavaComponent.inject
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider
|
||||
import org.moire.ultrasonic.domain.Artist
|
||||
import org.moire.ultrasonic.domain.Bookmark
|
||||
@ -47,10 +48,8 @@ import timber.log.Timber
|
||||
// TODO: There are quite a number of deeply nested and complicated functions in this class..
|
||||
// Simplify them :)
|
||||
@Suppress("TooManyFunctions")
|
||||
class OfflineMusicService : MusicService {
|
||||
private val activeServerProvider = inject(
|
||||
ActiveServerProvider::class.java
|
||||
)
|
||||
class OfflineMusicService : MusicService, KoinComponent {
|
||||
private val activeServerProvider: ActiveServerProvider by inject()
|
||||
|
||||
override fun getIndexes(musicFolderId: String?, refresh: Boolean): Indexes {
|
||||
val artists: MutableList<Artist> = ArrayList()
|
||||
@ -85,7 +84,7 @@ class OfflineMusicService : MusicService {
|
||||
lhs = lhs.substring(article.length + 1)
|
||||
}
|
||||
index = rhs.indexOf(
|
||||
String.format(Locale.ROOT, "%s ", article.toLowerCase(Locale.ROOT))
|
||||
String.format(Locale.ROOT, "%s ", article.lowercase(Locale.ROOT))
|
||||
)
|
||||
if (index == 0) {
|
||||
rhs = rhs.substring(article.length + 1)
|
||||
@ -253,7 +252,7 @@ class OfflineMusicService : MusicService {
|
||||
@Throws(Exception::class)
|
||||
override fun createPlaylist(id: String, name: String, entries: List<MusicDirectory.Entry>) {
|
||||
val playlistFile =
|
||||
FileUtil.getPlaylistFile(activeServerProvider.value.getActiveServer().name, name)
|
||||
FileUtil.getPlaylistFile(activeServerProvider.getActiveServer().name, name)
|
||||
val fw = FileWriter(playlistFile)
|
||||
val bw = BufferedWriter(fw)
|
||||
try {
|
||||
|
@ -5,7 +5,6 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import java.util.Collections
|
||||
import java.util.LinkedList
|
||||
import org.koin.core.component.KoinApiExtension
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline
|
||||
import org.moire.ultrasonic.domain.MusicDirectory
|
||||
@ -20,7 +19,6 @@ import org.moire.ultrasonic.util.Util
|
||||
* Retrieves a list of songs and adds them to the now playing list
|
||||
*/
|
||||
@Suppress("LongParameterList")
|
||||
@KoinApiExtension
|
||||
class DownloadHandler(
|
||||
val mediaPlayerController: MediaPlayerController,
|
||||
val networkAndStorageChecker: NetworkAndStorageChecker
|
||||
|
@ -1,10 +1,10 @@
|
||||
package org.moire.ultrasonic.subsonic
|
||||
|
||||
import android.content.Context
|
||||
import org.koin.java.KoinJavaComponent.get
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.get
|
||||
import org.moire.ultrasonic.featureflags.Feature
|
||||
import org.moire.ultrasonic.featureflags.FeatureStorage
|
||||
import org.moire.ultrasonic.subsonic.loader.image.SubsonicImageLoader
|
||||
import org.moire.ultrasonic.util.ImageLoader
|
||||
import org.moire.ultrasonic.util.LegacyImageLoader
|
||||
import org.moire.ultrasonic.util.Util
|
||||
@ -12,7 +12,7 @@ import org.moire.ultrasonic.util.Util
|
||||
/**
|
||||
* Handles the lifetime of the Image Loader
|
||||
*/
|
||||
class ImageLoaderProvider(val context: Context) {
|
||||
class ImageLoaderProvider(val context: Context) : KoinComponent {
|
||||
private var imageLoader: ImageLoader? = null
|
||||
|
||||
@Synchronized
|
||||
@ -33,12 +33,12 @@ class ImageLoaderProvider(val context: Context) {
|
||||
context,
|
||||
Util.getImageLoaderConcurrency()
|
||||
)
|
||||
val isNewImageLoaderEnabled = get(FeatureStorage::class.java)
|
||||
.isFeatureEnabled(Feature.NEW_IMAGE_DOWNLOADER)
|
||||
val features: FeatureStorage = get()
|
||||
val isNewImageLoaderEnabled = features.isFeatureEnabled(Feature.NEW_IMAGE_DOWNLOADER)
|
||||
imageLoader = if (isNewImageLoaderEnabled) {
|
||||
SubsonicImageLoaderProxy(
|
||||
legacyImageLoader,
|
||||
get(SubsonicImageLoader::class.java)
|
||||
get()
|
||||
)
|
||||
} else {
|
||||
legacyImageLoader
|
||||
|
@ -24,8 +24,9 @@ import android.graphics.drawable.Drawable
|
||||
import android.text.TextUtils
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.Checkable
|
||||
import org.koin.java.KoinJavaComponent.get
|
||||
import org.koin.java.KoinJavaComponent.inject
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.get
|
||||
import org.koin.core.component.inject
|
||||
import org.moire.ultrasonic.R
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider.Companion.isOffline
|
||||
import org.moire.ultrasonic.domain.MusicDirectory
|
||||
@ -42,7 +43,7 @@ import timber.log.Timber
|
||||
/**
|
||||
* Used to display songs and videos in a `ListView`.
|
||||
*/
|
||||
class SongView(context: Context) : UpdateView(context), Checkable {
|
||||
class SongView(context: Context) : UpdateView(context), Checkable, KoinComponent {
|
||||
|
||||
var entry: MusicDirectory.Entry? = null
|
||||
private set
|
||||
@ -55,10 +56,9 @@ class SongView(context: Context) : UpdateView(context), Checkable {
|
||||
private var downloadFile: DownloadFile? = null
|
||||
private var playing = false
|
||||
private var viewHolder: SongViewHolder? = null
|
||||
|
||||
private val useFiveStarRating: Boolean =
|
||||
get(FeatureStorage::class.java).isFeatureEnabled(Feature.FIVE_STAR_RATING)
|
||||
private val mediaPlayerControllerLazy = inject(MediaPlayerController::class.java)
|
||||
private val features: FeatureStorage = get()
|
||||
private val useFiveStarRating: Boolean = features.isFeatureEnabled(Feature.FIVE_STAR_RATING)
|
||||
private val mediaPlayerController: MediaPlayerController by inject()
|
||||
|
||||
fun setLayout(song: MusicDirectory.Entry) {
|
||||
|
||||
@ -96,7 +96,7 @@ class SongView(context: Context) : UpdateView(context), Checkable {
|
||||
updateBackground()
|
||||
|
||||
entry = song
|
||||
downloadFile = mediaPlayerControllerLazy.value.getDownloadFileForSong(song)
|
||||
downloadFile = mediaPlayerController.getDownloadFileForSong(song)
|
||||
|
||||
val artist = StringBuilder(60)
|
||||
var bitRate: String? = null
|
||||
@ -223,7 +223,7 @@ class SongView(context: Context) : UpdateView(context), Checkable {
|
||||
public override fun update() {
|
||||
updateBackground()
|
||||
|
||||
downloadFile = mediaPlayerControllerLazy.value.getDownloadFileForSong(entry)
|
||||
downloadFile = mediaPlayerController.getDownloadFileForSong(entry)
|
||||
|
||||
updateDownloadStatus(downloadFile!!)
|
||||
|
||||
@ -254,7 +254,7 @@ class SongView(context: Context) : UpdateView(context), Checkable {
|
||||
if (rating > 4) starDrawable else starHollowDrawable
|
||||
)
|
||||
|
||||
val playing = mediaPlayerControllerLazy.value.currentPlaying === downloadFile
|
||||
val playing = mediaPlayerController.currentPlaying === downloadFile
|
||||
|
||||
if (playing) {
|
||||
if (!this.playing) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user