mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-29 15:11:34 +03:00
Remove Context from Downloader & DownloadFile
This commit is contained in:
parent
9b2e54b94e
commit
b8fbbd8c49
@ -25,7 +25,7 @@
|
|||||||
<ID>ImplicitDefaultLocale:LocalMediaPlayer.kt$LocalMediaPlayer.BufferTask$String.format("BufferTask (%s)", downloadFile)</ID>
|
<ID>ImplicitDefaultLocale:LocalMediaPlayer.kt$LocalMediaPlayer.BufferTask$String.format("BufferTask (%s)", downloadFile)</ID>
|
||||||
<ID>ImplicitDefaultLocale:LocalMediaPlayer.kt$LocalMediaPlayer.CheckCompletionTask$String.format("CheckCompletionTask (%s)", downloadFile)</ID>
|
<ID>ImplicitDefaultLocale:LocalMediaPlayer.kt$LocalMediaPlayer.CheckCompletionTask$String.format("CheckCompletionTask (%s)", downloadFile)</ID>
|
||||||
<ID>ImplicitDefaultLocale:ShareHandler.kt$ShareHandler$String.format("%d:%s", timeSpanAmount, timeSpanType)</ID>
|
<ID>ImplicitDefaultLocale:ShareHandler.kt$ShareHandler$String.format("%d:%s", timeSpanAmount, timeSpanType)</ID>
|
||||||
<ID>ImplicitDefaultLocale:ShareHandler.kt$ShareHandler.<no name provided>$String.format("%s\n\n%s", Util.getShareGreeting(context), result.url)</ID>
|
<ID>ImplicitDefaultLocale:ShareHandler.kt$ShareHandler.<no name provided>$String.format("%s\n\n%s", Util.getShareGreeting(), result.url)</ID>
|
||||||
<ID>ImplicitDefaultLocale:SongView.kt$SongView$String.format("%02d.", trackNumber)</ID>
|
<ID>ImplicitDefaultLocale:SongView.kt$SongView$String.format("%02d.", trackNumber)</ID>
|
||||||
<ID>ImplicitDefaultLocale:SongView.kt$SongView$String.format("%s ", bitRate)</ID>
|
<ID>ImplicitDefaultLocale:SongView.kt$SongView$String.format("%s ", bitRate)</ID>
|
||||||
<ID>ImplicitDefaultLocale:SongView.kt$SongView$String.format("%s > %s", suffix, transcodedSuffix)</ID>
|
<ID>ImplicitDefaultLocale:SongView.kt$SongView$String.format("%s > %s", suffix, transcodedSuffix)</ID>
|
||||||
|
@ -139,7 +139,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
|||||||
showArtistPicture = findPreference(Constants.PREFERENCES_KEY_SHOW_ARTIST_PICTURE);
|
showArtistPicture = findPreference(Constants.PREFERENCES_KEY_SHOW_ARTIST_PICTURE);
|
||||||
|
|
||||||
setupServersCategory();
|
setupServersCategory();
|
||||||
sharingDefaultGreeting.setText(Util.getShareGreeting(getActivity()));
|
sharingDefaultGreeting.setText(Util.getShareGreeting());
|
||||||
setupClearSearchPreference();
|
setupClearSearchPreference();
|
||||||
setupGaplessControlSettingsV14();
|
setupGaplessControlSettingsV14();
|
||||||
setupFeatureFlagsPreferences();
|
setupFeatureFlagsPreferences();
|
||||||
|
@ -35,7 +35,6 @@ public class Downloader
|
|||||||
private final ShufflePlayBuffer shufflePlayBuffer;
|
private final ShufflePlayBuffer shufflePlayBuffer;
|
||||||
private final ExternalStorageMonitor externalStorageMonitor;
|
private final ExternalStorageMonitor externalStorageMonitor;
|
||||||
private final LocalMediaPlayer localMediaPlayer;
|
private final LocalMediaPlayer localMediaPlayer;
|
||||||
private final Context context;
|
|
||||||
|
|
||||||
// TODO: This is a circular reference, try to remove
|
// TODO: This is a circular reference, try to remove
|
||||||
private Lazy<JukeboxMediaPlayer> jukeboxMediaPlayer = inject(JukeboxMediaPlayer.class);
|
private Lazy<JukeboxMediaPlayer> jukeboxMediaPlayer = inject(JukeboxMediaPlayer.class);
|
||||||
@ -45,10 +44,9 @@ public class Downloader
|
|||||||
private ScheduledExecutorService executorService;
|
private ScheduledExecutorService executorService;
|
||||||
private long revision;
|
private long revision;
|
||||||
|
|
||||||
public Downloader(Context context, ShufflePlayBuffer shufflePlayBuffer, ExternalStorageMonitor externalStorageMonitor,
|
public Downloader(ShufflePlayBuffer shufflePlayBuffer, ExternalStorageMonitor externalStorageMonitor,
|
||||||
LocalMediaPlayer localMediaPlayer)
|
LocalMediaPlayer localMediaPlayer)
|
||||||
{
|
{
|
||||||
this.context = context;
|
|
||||||
this.shufflePlayBuffer = shufflePlayBuffer;
|
this.shufflePlayBuffer = shufflePlayBuffer;
|
||||||
this.externalStorageMonitor = externalStorageMonitor;
|
this.externalStorageMonitor = externalStorageMonitor;
|
||||||
this.localMediaPlayer = localMediaPlayer;
|
this.localMediaPlayer = localMediaPlayer;
|
||||||
@ -100,10 +98,10 @@ public class Downloader
|
|||||||
|
|
||||||
if (shufflePlayBuffer.isEnabled)
|
if (shufflePlayBuffer.isEnabled)
|
||||||
{
|
{
|
||||||
checkShufflePlay(context);
|
checkShufflePlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jukeboxMediaPlayer.getValue().isEnabled() || !Util.isNetworkConnected(context))
|
if (jukeboxMediaPlayer.getValue().isEnabled() || !Util.isNetworkConnected())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -188,7 +186,7 @@ public class Downloader
|
|||||||
DownloadFile downloadFile = backgroundDownloadList.get(i);
|
DownloadFile downloadFile = backgroundDownloadList.get(i);
|
||||||
if (downloadFile.isWorkDone() && (!downloadFile.shouldSave() || downloadFile.isSaved()))
|
if (downloadFile.isWorkDone() && (!downloadFile.shouldSave() || downloadFile.isSaved()))
|
||||||
{
|
{
|
||||||
Util.scanMedia(context, downloadFile.getCompleteFile());
|
Util.scanMedia(downloadFile.getCompleteFile());
|
||||||
|
|
||||||
// Don't need to keep list like active song list
|
// Don't need to keep list like active song list
|
||||||
backgroundDownloadList.remove(i);
|
backgroundDownloadList.remove(i);
|
||||||
@ -316,7 +314,7 @@ public class Downloader
|
|||||||
|
|
||||||
for (MusicDirectory.Entry song : songs)
|
for (MusicDirectory.Entry song : songs)
|
||||||
{
|
{
|
||||||
DownloadFile downloadFile = new DownloadFile(context, song, save);
|
DownloadFile downloadFile = new DownloadFile(song, save);
|
||||||
downloadList.add(getCurrentPlayingIndex() + offset, downloadFile);
|
downloadList.add(getCurrentPlayingIndex() + offset, downloadFile);
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
@ -325,7 +323,7 @@ public class Downloader
|
|||||||
{
|
{
|
||||||
for (MusicDirectory.Entry song : songs)
|
for (MusicDirectory.Entry song : songs)
|
||||||
{
|
{
|
||||||
DownloadFile downloadFile = new DownloadFile(context, song, save);
|
DownloadFile downloadFile = new DownloadFile(song, save);
|
||||||
downloadList.add(downloadFile);
|
downloadList.add(downloadFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,7 +334,7 @@ public class Downloader
|
|||||||
{
|
{
|
||||||
for (MusicDirectory.Entry song : songs)
|
for (MusicDirectory.Entry song : songs)
|
||||||
{
|
{
|
||||||
DownloadFile downloadFile = new DownloadFile(context, song, save);
|
DownloadFile downloadFile = new DownloadFile(song, save);
|
||||||
backgroundDownloadList.add(downloadFile);
|
backgroundDownloadList.add(downloadFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,7 +374,7 @@ public class Downloader
|
|||||||
DownloadFile downloadFile = downloadFileCache.get(song);
|
DownloadFile downloadFile = downloadFileCache.get(song);
|
||||||
if (downloadFile == null)
|
if (downloadFile == null)
|
||||||
{
|
{
|
||||||
downloadFile = new DownloadFile(context, song, false);
|
downloadFile = new DownloadFile(song, false);
|
||||||
downloadFileCache.put(song, downloadFile);
|
downloadFileCache.put(song, downloadFile);
|
||||||
}
|
}
|
||||||
return downloadFile;
|
return downloadFile;
|
||||||
@ -398,7 +396,7 @@ public class Downloader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void checkShufflePlay(Context context)
|
private synchronized void checkShufflePlay()
|
||||||
{
|
{
|
||||||
// Get users desired random playlist size
|
// Get users desired random playlist size
|
||||||
int listSize = Util.getMaxSongs();
|
int listSize = Util.getMaxSongs();
|
||||||
@ -412,7 +410,7 @@ public class Downloader
|
|||||||
{
|
{
|
||||||
for (MusicDirectory.Entry song : shufflePlayBuffer.get(listSize - size))
|
for (MusicDirectory.Entry song : shufflePlayBuffer.get(listSize - size))
|
||||||
{
|
{
|
||||||
DownloadFile downloadFile = new DownloadFile(context, song, false);
|
DownloadFile downloadFile = new DownloadFile(song, false);
|
||||||
downloadList.add(downloadFile);
|
downloadList.add(downloadFile);
|
||||||
revision++;
|
revision++;
|
||||||
}
|
}
|
||||||
@ -426,7 +424,7 @@ public class Downloader
|
|||||||
int songsToShift = currIndex - 2;
|
int songsToShift = currIndex - 2;
|
||||||
for (MusicDirectory.Entry song : shufflePlayBuffer.get(songsToShift))
|
for (MusicDirectory.Entry song : shufflePlayBuffer.get(songsToShift))
|
||||||
{
|
{
|
||||||
downloadList.add(new DownloadFile(context, song, false));
|
downloadList.add(new DownloadFile(song, false));
|
||||||
downloadList.get(0).cancelDownload();
|
downloadList.get(0).cancelDownload();
|
||||||
downloadList.remove(0);
|
downloadList.remove(0);
|
||||||
revision++;
|
revision++;
|
||||||
|
@ -79,7 +79,7 @@ public class LegacyImageLoader implements Runnable, ImageLoader {
|
|||||||
imageSizeDefault = drawable.getIntrinsicHeight();
|
imageSizeDefault = drawable.getIntrinsicHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
imageSizeLarge = Util.getMaxDisplayMetric(context);
|
imageSizeLarge = Util.getMaxDisplayMetric();
|
||||||
createLargeUnknownImage(context);
|
createLargeUnknownImage(context);
|
||||||
createUnknownAvatarImage(context);
|
createUnknownAvatarImage(context);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ public class ShufflePlayBuffer
|
|||||||
// Check if active server has changed.
|
// Check if active server has changed.
|
||||||
clearBufferIfNecessary();
|
clearBufferIfNecessary();
|
||||||
|
|
||||||
if (buffer.size() > REFILL_THRESHOLD || (!Util.isNetworkConnected(context) && !ActiveServerProvider.Companion.isOffline()))
|
if (buffer.size() > REFILL_THRESHOLD || (!Util.isNetworkConnected() && !ActiveServerProvider.Companion.isOffline()))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -167,10 +167,14 @@ public class Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxBitRate(Context context)
|
public static ConnectivityManager getConnectivityManager() {
|
||||||
{
|
Context context = appContext();
|
||||||
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getMaxBitRate()
|
||||||
|
{
|
||||||
|
ConnectivityManager manager = getConnectivityManager();
|
||||||
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
|
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
|
||||||
|
|
||||||
if (networkInfo == null)
|
if (networkInfo == null)
|
||||||
@ -548,9 +552,9 @@ public class Util
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNetworkConnected(Context context)
|
public static boolean isNetworkConnected()
|
||||||
{
|
{
|
||||||
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
ConnectivityManager manager = getConnectivityManager();
|
||||||
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
|
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
|
||||||
boolean connected = networkInfo != null && networkInfo.isConnected();
|
boolean connected = networkInfo != null && networkInfo.isConnected();
|
||||||
|
|
||||||
@ -648,9 +652,9 @@ public class Util
|
|||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WifiManager.WifiLock createWifiLock(Context context, String tag)
|
public static WifiManager.WifiLock createWifiLock(String tag)
|
||||||
{
|
{
|
||||||
WifiManager wm = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
WifiManager wm = (WifiManager) appContext().getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||||
return wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, tag);
|
return wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -945,15 +949,15 @@ public class Util
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMinDisplayMetric(Context context)
|
public static int getMinDisplayMetric()
|
||||||
{
|
{
|
||||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
DisplayMetrics metrics = appContext().getResources().getDisplayMetrics();
|
||||||
return Math.min(metrics.widthPixels, metrics.heightPixels);
|
return Math.min(metrics.widthPixels, metrics.heightPixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getMaxDisplayMetric(Context context)
|
public static int getMaxDisplayMetric()
|
||||||
{
|
{
|
||||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
DisplayMetrics metrics = appContext().getResources().getDisplayMetrics();
|
||||||
return Math.max(metrics.widthPixels, metrics.heightPixels);
|
return Math.max(metrics.widthPixels, metrics.heightPixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1251,10 +1255,12 @@ public class Util
|
|||||||
return preferences.getString(Constants.PREFERENCES_KEY_DEFAULT_SHARE_DESCRIPTION, "");
|
return preferences.getString(Constants.PREFERENCES_KEY_DEFAULT_SHARE_DESCRIPTION, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getShareGreeting(Context context)
|
public static String getShareGreeting()
|
||||||
{
|
{
|
||||||
SharedPreferences preferences = getPreferences();
|
SharedPreferences preferences = getPreferences();
|
||||||
return preferences.getString(Constants.PREFERENCES_KEY_DEFAULT_SHARE_GREETING, String.format(context.getResources().getString(R.string.share_default_greeting), context.getResources().getString(R.string.common_appname)));
|
Context context = appContext();
|
||||||
|
String defaultVal = String.format(context.getResources().getString(R.string.share_default_greeting), context.getResources().getString(R.string.common_appname));
|
||||||
|
return preferences.getString(Constants.PREFERENCES_KEY_DEFAULT_SHARE_GREETING, defaultVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDefaultShareExpiration()
|
public static String getDefaultShareExpiration()
|
||||||
@ -1313,11 +1319,11 @@ public class Util
|
|||||||
return preferences.getBoolean(Constants.PREFERENCES_KEY_SHOW_ALL_SONGS_BY_ARTIST, false);
|
return preferences.getBoolean(Constants.PREFERENCES_KEY_SHOW_ALL_SONGS_BY_ARTIST, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void scanMedia(Context context, File file)
|
public static void scanMedia(File file)
|
||||||
{
|
{
|
||||||
Uri uri = Uri.fromFile(file);
|
Uri uri = Uri.fromFile(file);
|
||||||
Intent scanFileIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
|
Intent scanFileIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
|
||||||
context.sendBroadcast(scanFileIntent);
|
appContext().sendBroadcast(scanFileIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getImageLoaderConcurrency()
|
public static int getImageLoaderConcurrency()
|
||||||
|
@ -21,7 +21,7 @@ val mediaPlayerModule = module {
|
|||||||
single { DownloadQueueSerializer(androidContext()) }
|
single { DownloadQueueSerializer(androidContext()) }
|
||||||
single { ExternalStorageMonitor() }
|
single { ExternalStorageMonitor() }
|
||||||
single { ShufflePlayBuffer(androidContext()) }
|
single { ShufflePlayBuffer(androidContext()) }
|
||||||
single { Downloader(androidContext(), get(), get(), get()) }
|
single { Downloader(get(), get(), get()) }
|
||||||
single { LocalMediaPlayer(get(), androidContext()) }
|
single { LocalMediaPlayer(get(), androidContext()) }
|
||||||
single { AudioFocusHandler(get()) }
|
single { AudioFocusHandler(get()) }
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class CommunicationErrorHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getErrorMessage(error: Throwable, context: Context): String {
|
fun getErrorMessage(error: Throwable, context: Context): String {
|
||||||
if (error is IOException && !Util.isNetworkConnected(context)) {
|
if (error is IOException && !Util.isNetworkConnected()) {
|
||||||
return context.resources.getString(R.string.background_task_no_network)
|
return context.resources.getString(R.string.background_task_no_network)
|
||||||
} else if (error is FileNotFoundException) {
|
} else if (error is FileNotFoundException) {
|
||||||
return context.resources.getString(R.string.background_task_not_found)
|
return context.resources.getString(R.string.background_task_not_found)
|
||||||
|
@ -21,6 +21,7 @@ import java.io.OutputStream
|
|||||||
import java.io.RandomAccessFile
|
import java.io.RandomAccessFile
|
||||||
import org.koin.core.component.KoinApiExtension
|
import org.koin.core.component.KoinApiExtension
|
||||||
import org.koin.java.KoinJavaComponent.inject
|
import org.koin.java.KoinJavaComponent.inject
|
||||||
|
import org.moire.ultrasonic.app.UApp
|
||||||
import org.moire.ultrasonic.domain.MusicDirectory
|
import org.moire.ultrasonic.domain.MusicDirectory
|
||||||
import org.moire.ultrasonic.service.MusicServiceFactory.getMusicService
|
import org.moire.ultrasonic.service.MusicServiceFactory.getMusicService
|
||||||
import org.moire.ultrasonic.util.CacheCleaner
|
import org.moire.ultrasonic.util.CacheCleaner
|
||||||
@ -37,7 +38,6 @@ import timber.log.Timber
|
|||||||
*/
|
*/
|
||||||
@KoinApiExtension
|
@KoinApiExtension
|
||||||
class DownloadFile(
|
class DownloadFile(
|
||||||
private val context: Context,
|
|
||||||
val song: MusicDirectory.Entry,
|
val song: MusicDirectory.Entry,
|
||||||
private val save: Boolean
|
private val save: Boolean
|
||||||
) {
|
) {
|
||||||
@ -48,7 +48,7 @@ class DownloadFile(
|
|||||||
var isFailed = false
|
var isFailed = false
|
||||||
private var retryCount = MAX_RETRIES
|
private var retryCount = MAX_RETRIES
|
||||||
|
|
||||||
private val desiredBitRate: Int = Util.getMaxBitRate(context)
|
private val desiredBitRate: Int = Util.getMaxBitRate()
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
private var isPlaying = false
|
private var isPlaying = false
|
||||||
@ -138,7 +138,7 @@ class DownloadFile(
|
|||||||
Util.delete(completeFile)
|
Util.delete(completeFile)
|
||||||
Util.delete(saveFile)
|
Util.delete(saveFile)
|
||||||
|
|
||||||
Util.scanMedia(context, saveFile)
|
Util.scanMedia(saveFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unpin() {
|
fun unpin() {
|
||||||
@ -186,7 +186,7 @@ class DownloadFile(
|
|||||||
} else if (completeWhenDone) {
|
} else if (completeWhenDone) {
|
||||||
if (save) {
|
if (save) {
|
||||||
Util.renameFile(partialFile, saveFile)
|
Util.renameFile(partialFile, saveFile)
|
||||||
Util.scanMedia(context, saveFile)
|
Util.scanMedia(saveFile)
|
||||||
} else {
|
} else {
|
||||||
Util.renameFile(partialFile, completeFile)
|
Util.renameFile(partialFile, completeFile)
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ class DownloadFile(
|
|||||||
var wifiLock: WifiLock? = null
|
var wifiLock: WifiLock? = null
|
||||||
try {
|
try {
|
||||||
wakeLock = acquireWakeLock(wakeLock)
|
wakeLock = acquireWakeLock(wakeLock)
|
||||||
wifiLock = Util.createWifiLock(context, toString())
|
wifiLock = Util.createWifiLock(toString())
|
||||||
wifiLock.acquire()
|
wifiLock.acquire()
|
||||||
|
|
||||||
if (saveFile.exists()) {
|
if (saveFile.exists()) {
|
||||||
@ -285,7 +285,7 @@ class DownloadFile(
|
|||||||
} else {
|
} else {
|
||||||
if (save) {
|
if (save) {
|
||||||
Util.renameFile(partialFile, saveFile)
|
Util.renameFile(partialFile, saveFile)
|
||||||
Util.scanMedia(context, saveFile)
|
Util.scanMedia(saveFile)
|
||||||
} else {
|
} else {
|
||||||
Util.renameFile(partialFile, completeFile)
|
Util.renameFile(partialFile, completeFile)
|
||||||
}
|
}
|
||||||
@ -317,6 +317,7 @@ class DownloadFile(
|
|||||||
private fun acquireWakeLock(wakeLock: WakeLock?): WakeLock? {
|
private fun acquireWakeLock(wakeLock: WakeLock?): WakeLock? {
|
||||||
var wakeLock1 = wakeLock
|
var wakeLock1 = wakeLock
|
||||||
if (Util.isScreenLitOnDownload()) {
|
if (Util.isScreenLitOnDownload()) {
|
||||||
|
val context = UApp.applicationContext()
|
||||||
val pm = context.getSystemService(Context.POWER_SERVICE) as PowerManager
|
val pm = context.getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||||
val flags = PowerManager.SCREEN_DIM_WAKE_LOCK or PowerManager.ON_AFTER_RELEASE
|
val flags = PowerManager.SCREEN_DIM_WAKE_LOCK or PowerManager.ON_AFTER_RELEASE
|
||||||
wakeLock1 = pm.newWakeLock(flags, toString())
|
wakeLock1 = pm.newWakeLock(flags, toString())
|
||||||
@ -333,7 +334,7 @@ class DownloadFile(
|
|||||||
private fun downloadAndSaveCoverArt(musicService: MusicService) {
|
private fun downloadAndSaveCoverArt(musicService: MusicService) {
|
||||||
try {
|
try {
|
||||||
if (!TextUtils.isEmpty(song.coverArt)) {
|
if (!TextUtils.isEmpty(song.coverArt)) {
|
||||||
val size = Util.getMinDisplayMetric(context)
|
val size = Util.getMinDisplayMetric()
|
||||||
musicService.getCoverArt(song, size, true, true)
|
musicService.getCoverArt(song, size, true, true)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -397,7 +397,7 @@ class LocalMediaPlayer(
|
|||||||
|
|
||||||
secondaryProgress = (percent.toDouble() / 100.toDouble() * progressBar.max).toInt()
|
secondaryProgress = (percent.toDouble() / 100.toDouble() * progressBar.max).toInt()
|
||||||
|
|
||||||
if (song.transcodedContentType == null && Util.getMaxBitRate(context) == 0) {
|
if (song.transcodedContentType == null && Util.getMaxBitRate() == 0) {
|
||||||
progressBar?.secondaryProgress = secondaryProgress
|
progressBar?.secondaryProgress = secondaryProgress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -478,12 +478,11 @@ class MediaPlayerService : Service() {
|
|||||||
|
|
||||||
// Set Metadata
|
// Set Metadata
|
||||||
val metadata = MediaMetadataCompat.Builder()
|
val metadata = MediaMetadataCompat.Builder()
|
||||||
val context = applicationContext
|
|
||||||
if (currentPlaying != null) {
|
if (currentPlaying != null) {
|
||||||
try {
|
try {
|
||||||
val song = currentPlaying.song
|
val song = currentPlaying.song
|
||||||
val cover = FileUtil.getAlbumArtBitmap(
|
val cover = FileUtil.getAlbumArtBitmap(
|
||||||
song, Util.getMinDisplayMetric(context),
|
song, Util.getMinDisplayMetric(),
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
metadata.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, -1L)
|
metadata.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, -1L)
|
||||||
|
@ -12,7 +12,7 @@ class NetworkAndStorageChecker(val context: Context) {
|
|||||||
fun warnIfNetworkOrStorageUnavailable() {
|
fun warnIfNetworkOrStorageUnavailable() {
|
||||||
if (!Util.isExternalStoragePresent()) {
|
if (!Util.isExternalStoragePresent()) {
|
||||||
Util.toast(context, R.string.select_album_no_sdcard)
|
Util.toast(context, R.string.select_album_no_sdcard)
|
||||||
} else if (!isOffline() && !Util.isNetworkConnected(context)) {
|
} else if (!isOffline() && !Util.isNetworkConnected()) {
|
||||||
Util.toast(context, R.string.select_album_no_network)
|
Util.toast(context, R.string.select_album_no_network)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ class ShareHandler(val context: Context) {
|
|||||||
intent.type = "text/plain"
|
intent.type = "text/plain"
|
||||||
intent.putExtra(
|
intent.putExtra(
|
||||||
Intent.EXTRA_TEXT,
|
Intent.EXTRA_TEXT,
|
||||||
String.format("%s\n\n%s", Util.getShareGreeting(context), result.url)
|
String.format("%s\n\n%s", Util.getShareGreeting(), result.url)
|
||||||
)
|
)
|
||||||
fragment.activity?.startActivity(
|
fragment.activity?.startActivity(
|
||||||
Intent.createChooser(
|
Intent.createChooser(
|
||||||
|
@ -10,7 +10,7 @@ import org.moire.ultrasonic.util.Util
|
|||||||
*/
|
*/
|
||||||
class VideoPlayer() {
|
class VideoPlayer() {
|
||||||
fun playVideo(context: Context, entry: MusicDirectory.Entry?) {
|
fun playVideo(context: Context, entry: MusicDirectory.Entry?) {
|
||||||
if (!Util.isNetworkConnected(context)) {
|
if (!Util.isNetworkConnected()) {
|
||||||
Util.toast(context, R.string.select_album_no_network)
|
Util.toast(context, R.string.select_album_no_network)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user