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