Make ExternalStorageMonitor context-free
This commit is contained in:
parent
df047dd463
commit
1b5db9da1f
|
@ -4,6 +4,9 @@ import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
|
||||||
|
import org.moire.ultrasonic.app.UApp;
|
||||||
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,15 +14,9 @@ import timber.log.Timber;
|
||||||
*/
|
*/
|
||||||
public class ExternalStorageMonitor
|
public class ExternalStorageMonitor
|
||||||
{
|
{
|
||||||
private Context context;
|
|
||||||
private BroadcastReceiver ejectEventReceiver;
|
private BroadcastReceiver ejectEventReceiver;
|
||||||
private boolean externalStorageAvailable = true;
|
private boolean externalStorageAvailable = true;
|
||||||
|
|
||||||
public ExternalStorageMonitor(Context context)
|
|
||||||
{
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onCreate(final Runnable ejectedCallback)
|
public void onCreate(final Runnable ejectedCallback)
|
||||||
{
|
{
|
||||||
// Stop when SD card is ejected.
|
// Stop when SD card is ejected.
|
||||||
|
@ -44,12 +41,12 @@ public class ExternalStorageMonitor
|
||||||
IntentFilter ejectFilter = new IntentFilter(Intent.ACTION_MEDIA_EJECT);
|
IntentFilter ejectFilter = new IntentFilter(Intent.ACTION_MEDIA_EJECT);
|
||||||
ejectFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
|
ejectFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
|
||||||
ejectFilter.addDataScheme("file");
|
ejectFilter.addDataScheme("file");
|
||||||
context.registerReceiver(ejectEventReceiver, ejectFilter);
|
UApp.Companion.applicationContext().registerReceiver(ejectEventReceiver, ejectFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDestroy()
|
public void onDestroy()
|
||||||
{
|
{
|
||||||
context.unregisterReceiver(ejectEventReceiver);
|
UApp.Companion.applicationContext().unregisterReceiver(ejectEventReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExternalStorageAvailable() { return externalStorageAvailable; }
|
public boolean isExternalStorageAvailable() { return externalStorageAvailable; }
|
||||||
|
|
|
@ -19,7 +19,7 @@ val mediaPlayerModule = module {
|
||||||
single { JukeboxMediaPlayer(androidContext(), get()) }
|
single { JukeboxMediaPlayer(androidContext(), get()) }
|
||||||
single { MediaPlayerLifecycleSupport(get(), get(), get()) }
|
single { MediaPlayerLifecycleSupport(get(), get(), get()) }
|
||||||
single { DownloadQueueSerializer(androidContext()) }
|
single { DownloadQueueSerializer(androidContext()) }
|
||||||
single { ExternalStorageMonitor(androidContext()) }
|
single { ExternalStorageMonitor() }
|
||||||
single { ShufflePlayBuffer(androidContext()) }
|
single { ShufflePlayBuffer(androidContext()) }
|
||||||
single { Downloader(androidContext(), get(), get(), get()) }
|
single { Downloader(androidContext(), get(), get(), get()) }
|
||||||
single { LocalMediaPlayer(get(), androidContext()) }
|
single { LocalMediaPlayer(get(), androidContext()) }
|
||||||
|
|
Loading…
Reference in New Issue