mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-17 04:00:39 +01:00
Remove context from JukeboxMediaPlayer and Scrobbler
This commit is contained in:
parent
00e64cdddc
commit
9b2e54b94e
@ -30,6 +30,7 @@ import android.widget.Toast;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.moire.ultrasonic.R;
|
||||
import org.moire.ultrasonic.api.subsonic.ApiNotSupportedException;
|
||||
import org.moire.ultrasonic.app.UApp;
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider;
|
||||
import org.moire.ultrasonic.domain.JukeboxStatus;
|
||||
import org.moire.ultrasonic.domain.PlayerState;
|
||||
@ -70,7 +71,6 @@ public class JukeboxMediaPlayer
|
||||
private final AtomicBoolean running = new AtomicBoolean();
|
||||
private Thread serviceThread;
|
||||
private boolean enabled = false;
|
||||
private final Context context;
|
||||
|
||||
// TODO: These create circular references, try to refactor
|
||||
private final Lazy<MediaPlayerController> mediaPlayerControllerLazy = inject(MediaPlayerController.class);
|
||||
@ -82,9 +82,8 @@ public class JukeboxMediaPlayer
|
||||
// TODO: Persist RC state?
|
||||
// TODO: Minimize status updates.
|
||||
|
||||
public JukeboxMediaPlayer(Context context, Downloader downloader)
|
||||
public JukeboxMediaPlayer(Downloader downloader)
|
||||
{
|
||||
this.context = context;
|
||||
this.downloader = downloader;
|
||||
}
|
||||
|
||||
@ -217,15 +216,8 @@ public class JukeboxMediaPlayer
|
||||
private void disableJukeboxOnError(Throwable x, final int resourceId)
|
||||
{
|
||||
Timber.w(x.toString());
|
||||
|
||||
new Handler().post(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Util.toast(context, resourceId, false);
|
||||
}
|
||||
});
|
||||
Context context = UApp.Companion.applicationContext();
|
||||
new Handler().post(() -> Util.toast(context, resourceId, false));
|
||||
|
||||
mediaPlayerControllerLazy.getValue().setJukeboxEnabled(false);
|
||||
}
|
||||
@ -293,6 +285,7 @@ public class JukeboxMediaPlayer
|
||||
tasks.remove(SetGain.class);
|
||||
tasks.add(new SetGain(gain));
|
||||
|
||||
Context context = UApp.Companion.applicationContext();
|
||||
if (volumeToast == null) volumeToast = new VolumeToast(context);
|
||||
|
||||
volumeToast.setVolume(gain);
|
||||
|
@ -1,8 +1,6 @@
|
||||
package org.moire.ultrasonic.service;
|
||||
|
||||
import android.content.Context;
|
||||
import timber.log.Timber;
|
||||
|
||||
import org.moire.ultrasonic.data.ActiveServerProvider;
|
||||
|
||||
/**
|
||||
@ -16,7 +14,7 @@ public class Scrobbler
|
||||
private String lastSubmission;
|
||||
private String lastNowPlaying;
|
||||
|
||||
public void scrobble(final Context context, final DownloadFile song, final boolean submission)
|
||||
public void scrobble(final DownloadFile song, final boolean submission)
|
||||
{
|
||||
if (song == null || !ActiveServerProvider.Companion.isScrobblingEnabled()) return;
|
||||
|
||||
|
@ -16,7 +16,7 @@ import org.moire.ultrasonic.util.ShufflePlayBuffer
|
||||
* This Koin module contains the registration of classes related to the media player
|
||||
*/
|
||||
val mediaPlayerModule = module {
|
||||
single { JukeboxMediaPlayer(androidContext(), get()) }
|
||||
single { JukeboxMediaPlayer(get()) }
|
||||
single { MediaPlayerLifecycleSupport(get(), get(), get()) }
|
||||
single { DownloadQueueSerializer(androidContext()) }
|
||||
single { ExternalStorageMonitor() }
|
||||
|
@ -409,9 +409,9 @@ class MediaPlayerService : Service() {
|
||||
}
|
||||
|
||||
if (playerState === PlayerState.STARTED) {
|
||||
scrobbler.scrobble(context, currentPlaying, false)
|
||||
scrobbler.scrobble(currentPlaying, false)
|
||||
} else if (playerState === PlayerState.COMPLETED) {
|
||||
scrobbler.scrobble(context, currentPlaying, true)
|
||||
scrobbler.scrobble(currentPlaying, true)
|
||||
}
|
||||
|
||||
null
|
||||
|
Loading…
x
Reference in New Issue
Block a user