Glue together old ImageLoader impl and new one.
Currently it is working in a pretty limited way. Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
74591571bf
commit
77eb257d84
|
@ -39,11 +39,13 @@ import android.widget.*;
|
|||
import net.simonvt.menudrawer.MenuDrawer;
|
||||
import net.simonvt.menudrawer.Position;
|
||||
import org.moire.ultrasonic.R;
|
||||
import org.moire.ultrasonic.app.UApp;
|
||||
import org.moire.ultrasonic.domain.MusicDirectory;
|
||||
import org.moire.ultrasonic.domain.MusicDirectory.Entry;
|
||||
import org.moire.ultrasonic.domain.PlayerState;
|
||||
import org.moire.ultrasonic.domain.Share;
|
||||
import org.moire.ultrasonic.service.*;
|
||||
import org.moire.ultrasonic.subsonic.SubsonicImageLoaderProxy;
|
||||
import org.moire.ultrasonic.util.*;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -793,11 +795,17 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
|||
if (IMAGE_LOADER != null && IMAGE_LOADER.isRunning()) IMAGE_LOADER.clear();
|
||||
}
|
||||
|
||||
public synchronized ImageLoader getImageLoader()
|
||||
{
|
||||
if (IMAGE_LOADER == null || !IMAGE_LOADER.isRunning())
|
||||
{
|
||||
IMAGE_LOADER = new LegacyImageLoader(this, Util.getImageLoaderConcurrency(this));
|
||||
public synchronized ImageLoader getImageLoader() {
|
||||
if (IMAGE_LOADER == null ||
|
||||
!IMAGE_LOADER.isRunning()) {
|
||||
LegacyImageLoader legacyImageLoader = new LegacyImageLoader(
|
||||
this,
|
||||
Util.getImageLoaderConcurrency(this)
|
||||
);
|
||||
IMAGE_LOADER = new SubsonicImageLoaderProxy(
|
||||
legacyImageLoader,
|
||||
((UApp) getApplication()).getSubsonicImageLoader()
|
||||
);
|
||||
IMAGE_LOADER.startImageLoader();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package org.moire.ultrasonic.app
|
||||
|
||||
import android.app.Application
|
||||
import org.koin.android.ext.android.get
|
||||
import org.koin.android.ext.android.startKoin
|
||||
import org.moire.ultrasonic.di.baseNetworkModule
|
||||
import org.moire.ultrasonic.di.directoriesModule
|
||||
import org.moire.ultrasonic.di.musicServiceModule
|
||||
import org.moire.ultrasonic.subsonic.loader.image.SubsonicImageLoader
|
||||
import org.moire.ultrasonic.util.Util
|
||||
|
||||
class UApp : Application() {
|
||||
|
@ -15,7 +17,14 @@ class UApp : Application() {
|
|||
startKoin(this, listOf(
|
||||
directoriesModule,
|
||||
baseNetworkModule,
|
||||
musicServiceModule(sharedPreferences)
|
||||
musicServiceModule(sharedPreferences, this)
|
||||
))
|
||||
}
|
||||
|
||||
/**
|
||||
* Temporary method to get subsonic image loader from java code.
|
||||
*/
|
||||
fun getSubsonicImageLoader(): SubsonicImageLoader {
|
||||
return get()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
@file:JvmName("MusicServiceModule")
|
||||
package org.moire.ultrasonic.di
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import org.koin.dsl.module.applicationContext
|
||||
|
@ -14,6 +15,7 @@ import org.moire.ultrasonic.service.CachedMusicService
|
|||
import org.moire.ultrasonic.service.MusicService
|
||||
import org.moire.ultrasonic.service.OfflineMusicService
|
||||
import org.moire.ultrasonic.service.RESTMusicService
|
||||
import org.moire.ultrasonic.subsonic.loader.image.SubsonicImageLoader
|
||||
import org.moire.ultrasonic.util.Constants
|
||||
import kotlin.math.abs
|
||||
|
||||
|
@ -24,7 +26,10 @@ private const val DEFAULT_SERVER_INSTANCE = 1
|
|||
private const val UNKNOWN_SERVER_URL = "not-exists"
|
||||
private const val LOG_TAG = "MusicServiceModule"
|
||||
|
||||
fun musicServiceModule(sp: SharedPreferences) = applicationContext {
|
||||
fun musicServiceModule(
|
||||
sp: SharedPreferences,
|
||||
context: Context
|
||||
) = applicationContext {
|
||||
context(MUSIC_SERVICE_CONTEXT) {
|
||||
subsonicApiModule()
|
||||
|
||||
|
@ -109,5 +114,7 @@ fun musicServiceModule(sp: SharedPreferences) = applicationContext {
|
|||
bean<MusicService>(name = OFFLINE_MUSIC_SERVICE) {
|
||||
return@bean OfflineMusicService(get(), get())
|
||||
}
|
||||
|
||||
bean { return@bean SubsonicImageLoader(context, get()) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package org.moire.ultrasonic.subsonic
|
||||
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import org.moire.ultrasonic.domain.MusicDirectory
|
||||
import org.moire.ultrasonic.subsonic.loader.image.SubsonicImageLoader
|
||||
import org.moire.ultrasonic.util.ImageLoader
|
||||
import org.moire.ultrasonic.util.LegacyImageLoader
|
||||
|
||||
/**
|
||||
* Temporary proxy between new [SubsonicImageLoader] and [ImageLoader] interface and old
|
||||
* [LegacyImageLoader] implementation.
|
||||
*
|
||||
* Should be removed on [LegacyImageLoader] removal.
|
||||
*/
|
||||
class SubsonicImageLoaderProxy(
|
||||
legacyImageLoader: LegacyImageLoader,
|
||||
private val subsonicImageLoader: SubsonicImageLoader
|
||||
) : ImageLoader by legacyImageLoader {
|
||||
override fun loadImage(
|
||||
view: View?,
|
||||
entry: MusicDirectory.Entry?,
|
||||
large: Boolean,
|
||||
size: Int,
|
||||
crossFade: Boolean,
|
||||
highQuality: Boolean
|
||||
) {
|
||||
val id = entry?.coverArt
|
||||
|
||||
if (id != null &&
|
||||
view != null &&
|
||||
view is ImageView) {
|
||||
subsonicImageLoader.loadCoverArt(
|
||||
entityId = id,
|
||||
view = view
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue