From f2b1ba0e948b99a64f0a800cf6192365cac5d784 Mon Sep 17 00:00:00 2001 From: tzugen Date: Sun, 9 May 2021 10:38:03 +0200 Subject: [PATCH] Remove unused context references in MusicServiceFactory --- .../fragment/BookmarksFragment.java | 2 +- .../ultrasonic/fragment/ChatFragment.java | 4 +-- .../ultrasonic/fragment/LyricsFragment.java | 2 +- .../ultrasonic/fragment/PlayerFragment.java | 8 +++--- .../fragment/PlaylistsFragment.java | 6 ++--- .../ultrasonic/fragment/PodcastFragment.java | 2 +- .../ultrasonic/fragment/SearchFragment.java | 2 +- .../fragment/SelectGenreFragment.java | 2 +- .../ultrasonic/fragment/SharesFragment.java | 6 ++--- .../service/JukeboxMediaPlayer.java | 2 +- .../service/MediaPlayerControllerImpl.java | 4 +-- .../moire/ultrasonic/service/Scrobbler.java | 2 +- .../ultrasonic/util/ShufflePlayBuffer.java | 2 +- .../ultrasonic/util/VideoPlayerType.java | 6 ++--- .../org/moire/ultrasonic/view/AlbumView.java | 2 +- .../ultrasonic/fragment/ArtistListModel.kt | 2 +- .../ultrasonic/fragment/SelectAlbumModel.kt | 26 +++++++++---------- .../moire/ultrasonic/service/DownloadFile.kt | 2 +- .../ultrasonic/service/MediaPlayerService.kt | 2 +- .../ultrasonic/service/MusicServiceFactory.kt | 5 ++-- .../ultrasonic/subsonic/DownloadHandler.kt | 8 +++--- .../moire/ultrasonic/subsonic/ShareHandler.kt | 2 +- .../org/moire/ultrasonic/view/SongView.kt | 2 +- 23 files changed, 52 insertions(+), 49 deletions(-) diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/BookmarksFragment.java b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/BookmarksFragment.java index 61a677c6..de1d1e94 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/BookmarksFragment.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/BookmarksFragment.java @@ -381,7 +381,7 @@ public class BookmarksFragment extends Fragment { @Override protected Pair doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + MusicService musicService = MusicServiceFactory.getMusicService(); MusicDirectory dir = load(musicService); boolean valid = musicService.isLicenseValid(); return new Pair<>(dir, valid); diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/ChatFragment.java b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/ChatFragment.java index 776de4d2..19689f14 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/ChatFragment.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/ChatFragment.java @@ -249,7 +249,7 @@ public class ChatFragment extends Fragment { @Override protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + MusicService musicService = MusicServiceFactory.getMusicService(); musicService.addChatMessage(message, getContext()); return null; } @@ -273,7 +273,7 @@ public class ChatFragment extends Fragment { @Override protected List doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + MusicService musicService = MusicServiceFactory.getMusicService(); return musicService.getChatMessages(lastChatMessageTime, getContext()); } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/LyricsFragment.java b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/LyricsFragment.java index 50692866..a0491972 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/LyricsFragment.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/LyricsFragment.java @@ -78,7 +78,7 @@ public class LyricsFragment extends Fragment { if (arguments == null) return null; String artist = arguments.getString(Constants.INTENT_EXTRA_NAME_ARTIST); String title = arguments.getString(Constants.INTENT_EXTRA_NAME_TITLE); - MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + MusicService musicService = MusicServiceFactory.getMusicService(); return musicService.getLyrics(artist, title, getContext()); } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/PlayerFragment.java b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/PlayerFragment.java index 627021f8..5c78237f 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/PlayerFragment.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/PlayerFragment.java @@ -994,7 +994,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur new Thread(new Runnable() { @Override public void run() { - final MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + final MusicService musicService = MusicServiceFactory.getMusicService(); try { if (isStarred) { @@ -1024,7 +1024,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur new Thread(new Runnable() { @Override public void run() { - final MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + final MusicService musicService = MusicServiceFactory.getMusicService(); try { musicService.createBookmark(songId, playerPosition, getContext()); @@ -1050,7 +1050,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur new Thread(new Runnable() { @Override public void run() { - final MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + final MusicService musicService = MusicServiceFactory.getMusicService(); try { musicService.deleteBookmark(bookmarkSongId, getContext()); @@ -1127,7 +1127,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur { entries.add(downloadFile.getSong()); } - final MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + final MusicService musicService = MusicServiceFactory.getMusicService(); musicService.createPlaylist(null, playlistName, entries, getContext()); return null; } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/PlaylistsFragment.java b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/PlaylistsFragment.java index ee00b273..068158e5 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/PlaylistsFragment.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/PlaylistsFragment.java @@ -127,7 +127,7 @@ public class PlaylistsFragment extends Fragment { @Override protected List doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + MusicService musicService = MusicServiceFactory.getMusicService(); List playlists = musicService.getPlaylists(refresh, getContext()); if (!ActiveServerProvider.Companion.isOffline()) @@ -222,7 +222,7 @@ public class PlaylistsFragment extends Fragment { @Override protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + MusicService musicService = MusicServiceFactory.getMusicService(); musicService.deletePlaylist(playlist.getId(), getContext()); return null; } @@ -312,7 +312,7 @@ public class PlaylistsFragment extends Fragment { String name = nameBoxText != null ? nameBoxText.toString() : null; String comment = commentBoxText != null ? commentBoxText.toString() : null; - MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + MusicService musicService = MusicServiceFactory.getMusicService(); musicService.updatePlaylist(playlist.getId(), name, comment, publicBox.isChecked(), getContext()); return null; } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/PodcastFragment.java b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/PodcastFragment.java index 701ac9d7..1f2f34fe 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/PodcastFragment.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/PodcastFragment.java @@ -96,7 +96,7 @@ public class PodcastFragment extends Fragment { @Override protected List doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(context); + MusicService musicService = MusicServiceFactory.getMusicService(); return musicService.getPodcastsChannels(refresh, context); } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/SearchFragment.java b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/SearchFragment.java index ad77f069..f01777b3 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/SearchFragment.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/SearchFragment.java @@ -420,7 +420,7 @@ public class SearchFragment extends Fragment { protected SearchResult doInBackground() throws Throwable { SearchCriteria criteria = new SearchCriteria(query, maxArtists, maxAlbums, maxSongs); - MusicService service = MusicServiceFactory.getMusicService(getContext()); + MusicService service = MusicServiceFactory.getMusicService(); return service.search(criteria, getContext()); } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/SelectGenreFragment.java b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/SelectGenreFragment.java index abbcc9ec..171f039e 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/SelectGenreFragment.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/SelectGenreFragment.java @@ -102,7 +102,7 @@ public class SelectGenreFragment extends Fragment { @Override protected List doInBackground() { - MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + MusicService musicService = MusicServiceFactory.getMusicService(); List genres = new ArrayList<>(); diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/SharesFragment.java b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/SharesFragment.java index 9db90eec..ce1ef153 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/SharesFragment.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/fragment/SharesFragment.java @@ -128,7 +128,7 @@ public class SharesFragment extends Fragment { @Override protected List doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + MusicService musicService = MusicServiceFactory.getMusicService(); return musicService.getShares(refresh, getContext()); } @@ -195,7 +195,7 @@ public class SharesFragment extends Fragment { @Override protected Void doInBackground() throws Throwable { - MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + MusicService musicService = MusicServiceFactory.getMusicService(); musicService.deleteShare(share.getId(), getContext()); return null; } @@ -301,7 +301,7 @@ public class SharesFragment extends Fragment { Editable shareDescriptionText = shareDescription.getText(); String description = shareDescriptionText != null ? shareDescriptionText.toString() : null; - MusicService musicService = MusicServiceFactory.getMusicService(getContext()); + MusicService musicService = MusicServiceFactory.getMusicService(); musicService.updateShare(share.getId(), description, millis, getContext()); return null; } diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/service/JukeboxMediaPlayer.java b/ultrasonic/src/main/java/org/moire/ultrasonic/service/JukeboxMediaPlayer.java index 22e6c07a..3f5316f8 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/service/JukeboxMediaPlayer.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/service/JukeboxMediaPlayer.java @@ -300,7 +300,7 @@ public class JukeboxMediaPlayer private MusicService getMusicService() { - return MusicServiceFactory.getMusicService(context); + return MusicServiceFactory.getMusicService(); } public int getPositionSeconds() diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/service/MediaPlayerControllerImpl.java b/ultrasonic/src/main/java/org/moire/ultrasonic/service/MediaPlayerControllerImpl.java index 7df14f24..87ff1b14 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/service/MediaPlayerControllerImpl.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/service/MediaPlayerControllerImpl.java @@ -527,7 +527,7 @@ public class MediaPlayerControllerImpl implements MediaPlayerController try { String username = activeServerProvider.getValue().getActiveServer().getUserName(); - UserInfo user = MusicServiceFactory.getMusicService(context).getUser(username, context); + UserInfo user = MusicServiceFactory.getMusicService().getUser(username, context); return user.getJukeboxRole(); } catch (Exception e) @@ -608,7 +608,7 @@ public class MediaPlayerControllerImpl implements MediaPlayerController new Thread(() -> { try { - MusicServiceFactory.getMusicService(context).setRating(song.getId(), rating); + MusicServiceFactory.getMusicService().setRating(song.getId(), rating); } catch (Exception e) { diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/service/Scrobbler.java b/ultrasonic/src/main/java/org/moire/ultrasonic/service/Scrobbler.java index 18b09971..47b7ff49 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/service/Scrobbler.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/service/Scrobbler.java @@ -36,7 +36,7 @@ public class Scrobbler @Override public void run() { - MusicService service = MusicServiceFactory.getMusicService(context); + MusicService service = MusicServiceFactory.getMusicService(); try { service.scrobble(id, submission, context); diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/util/ShufflePlayBuffer.java b/ultrasonic/src/main/java/org/moire/ultrasonic/util/ShufflePlayBuffer.java index 2d8bd2eb..43d21106 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/util/ShufflePlayBuffer.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/util/ShufflePlayBuffer.java @@ -104,7 +104,7 @@ public class ShufflePlayBuffer try { - MusicService service = MusicServiceFactory.getMusicService(context); + MusicService service = MusicServiceFactory.getMusicService(); int n = CAPACITY - buffer.size(); MusicDirectory songs = service.getRandomSongs(n, context); diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/util/VideoPlayerType.java b/ultrasonic/src/main/java/org/moire/ultrasonic/util/VideoPlayerType.java index 53c87163..fc4dadc5 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/util/VideoPlayerType.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/util/VideoPlayerType.java @@ -79,7 +79,7 @@ public enum VideoPlayerType Intent intent = new Intent(Intent.ACTION_VIEW); intent.setPackage(installedPro ? PACKAGE_NAME_MX_PRO : PACKAGE_NAME_MX_AD); intent.putExtra("title", entry.getTitle()); - intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoUrl(context, entry.getId(), false)), "video/*"); + intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService().getVideoUrl(context, entry.getId(), false)), "video/*"); context.startActivity(intent); } } @@ -91,7 +91,7 @@ public enum VideoPlayerType public void playVideo(Context context, MusicDirectory.Entry entry) throws Exception { Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoUrl(context, entry.getId(), true))); + intent.setData(Uri.parse(MusicServiceFactory.getMusicService().getVideoUrl(context, entry.getId(), true))); context.startActivity(intent); } }, @@ -102,7 +102,7 @@ public enum VideoPlayerType public void playVideo(Context context, MusicDirectory.Entry entry) throws Exception { Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService(context).getVideoUrl(context, entry.getId(), false)), "video/*"); + intent.setDataAndType(Uri.parse(MusicServiceFactory.getMusicService().getVideoUrl(context, entry.getId(), false)), "video/*"); context.startActivity(intent); } }; diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/view/AlbumView.java b/ultrasonic/src/main/java/org/moire/ultrasonic/view/AlbumView.java index 40e2d027..0b7fba7c 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/view/AlbumView.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/view/AlbumView.java @@ -146,7 +146,7 @@ public class AlbumView extends UpdateView album.setStarred(false); } - final MusicService musicService = MusicServiceFactory.getMusicService(view.getContext()); + final MusicService musicService = MusicServiceFactory.getMusicService(); new Thread(new Runnable() { @Override diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/ArtistListModel.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/ArtistListModel.kt index 24498684..ece73e14 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/ArtistListModel.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/ArtistListModel.kt @@ -78,7 +78,7 @@ class ArtistListModel( private suspend fun loadFromServer(refresh: Boolean, swipe: SwipeRefreshLayout) = withContext(Dispatchers.IO) { - val musicService = MusicServiceFactory.getMusicService(context) + val musicService = MusicServiceFactory.getMusicService() val isOffline = ActiveServerProvider.isOffline() val useId3Tags = Util.getShouldUseId3Tags() diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SelectAlbumModel.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SelectAlbumModel.kt index 63391ea4..5650c419 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SelectAlbumModel.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SelectAlbumModel.kt @@ -41,7 +41,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) suspend fun getMusicFolders(refresh: Boolean) { withContext(Dispatchers.IO) { if (!ActiveServerProvider.isOffline()) { - val musicService = MusicServiceFactory.getMusicService(context) + val musicService = MusicServiceFactory.getMusicService() musicFolders.postValue(musicService.getMusicFolders(refresh)) } } @@ -55,7 +55,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) ) { withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService(context) + val service = MusicServiceFactory.getMusicService() var root = MusicDirectory() @@ -105,7 +105,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) parent: MusicDirectory, songs: MutableList ) { - val service = MusicServiceFactory.getMusicService(context) + val service = MusicServiceFactory.getMusicService() for (song in parent.getChildren(includeDirs = false, includeFiles = true)) { if (!song.isVideo && !song.isDirectory) { @@ -127,7 +127,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) suspend fun getArtist(refresh: Boolean, id: String?, name: String?) { withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService(context) + val service = MusicServiceFactory.getMusicService() var root = MusicDirectory() @@ -160,7 +160,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService(context) + val service = MusicServiceFactory.getMusicService() val musicDirectory: MusicDirectory @@ -199,7 +199,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) suspend fun getSongsForGenre(genre: String, count: Int, offset: Int) { withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService(context) + val service = MusicServiceFactory.getMusicService() val musicDirectory = service.getSongsByGenre(genre, count, offset, context) songsForGenre.postValue(musicDirectory) } @@ -209,7 +209,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService(context) + val service = MusicServiceFactory.getMusicService() val musicDirectory: MusicDirectory if (Util.getShouldUseId3Tags()) { @@ -226,7 +226,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) showHeader = false withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService(context) + val service = MusicServiceFactory.getMusicService() currentDirectory.postValue(service.getVideos(refresh, context)) } } @@ -234,7 +234,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) suspend fun getRandom(size: Int) { withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService(context) + val service = MusicServiceFactory.getMusicService() val musicDirectory = service.getRandomSongs(size, context) currentDirectoryIsSortable = false @@ -245,7 +245,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) suspend fun getPlaylist(playlistId: String, playlistName: String?) { withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService(context) + val service = MusicServiceFactory.getMusicService() val musicDirectory = service.getPlaylist(playlistId, playlistName, context) currentDirectory.postValue(musicDirectory) @@ -255,7 +255,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) suspend fun getPodcastEpisodes(podcastChannelId: String) { withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService(context) + val service = MusicServiceFactory.getMusicService() val musicDirectory = service.getPodcastEpisodes(podcastChannelId, context) currentDirectory.postValue(musicDirectory) } @@ -264,7 +264,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) suspend fun getShare(shareId: String) { withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService(context) + val service = MusicServiceFactory.getMusicService() val musicDirectory = MusicDirectory() val shares = service.getShares(true, context) @@ -291,7 +291,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application) ) withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService(context) + val service = MusicServiceFactory.getMusicService() val musicDirectory: MusicDirectory val musicFolderId = if (showSelectFolderHeader) { activeServerProvider.getActiveServer().musicFolderId diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt index ba599659..0454e755 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadFile.kt @@ -228,7 +228,7 @@ class DownloadFile( return } - val musicService = getMusicService(context) + val musicService = getMusicService() // Some devices seem to throw error on partial file which doesn't exist val needsDownloading: Boolean diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt index f2dfaca4..778ea623 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerService.kt @@ -422,7 +422,7 @@ class MediaPlayerService : Service() { if (currentPlaying != null) { val song = currentPlaying.song if (song.bookmarkPosition > 0 && Util.getShouldClearBookmark()) { - val musicService = getMusicService(context) + val musicService = getMusicService() try { musicService.deleteBookmark(song.id, context) } catch (ignored: Exception) { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MusicServiceFactory.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MusicServiceFactory.kt index 59d4ec6c..0f3f33df 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MusicServiceFactory.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MusicServiceFactory.kt @@ -18,7 +18,7 @@ */ package org.moire.ultrasonic.service -import android.content.Context +import org.koin.core.component.KoinApiExtension import org.koin.core.component.KoinComponent import org.koin.core.component.get import org.koin.core.context.loadKoinModules @@ -30,9 +30,10 @@ import org.moire.ultrasonic.di.ONLINE_MUSIC_SERVICE import org.moire.ultrasonic.di.musicServiceModule // TODO Refactor everywhere to use DI way to get MusicService, and then remove this class +@KoinApiExtension object MusicServiceFactory : KoinComponent { @JvmStatic - fun getMusicService(context: Context): MusicService { + fun getMusicService(): MusicService { return if (ActiveServerProvider.isOffline()) { get(named(OFFLINE_MUSIC_SERVICE)) } else { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/DownloadHandler.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/DownloadHandler.kt index e9869d32..dd9e16f9 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/DownloadHandler.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/DownloadHandler.kt @@ -3,6 +3,7 @@ package org.moire.ultrasonic.subsonic import android.app.Activity import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController +import org.koin.core.component.KoinApiExtension import java.util.Collections import java.util.LinkedList import org.moire.ultrasonic.R @@ -18,6 +19,7 @@ import org.moire.ultrasonic.util.Util /** * Retrieves a list of songs and adds them to the now playing list */ +@KoinApiExtension class DownloadHandler( val mediaPlayerController: MediaPlayerController, val networkAndStorageChecker: NetworkAndStorageChecker @@ -200,7 +202,7 @@ class DownloadHandler( @Throws(Throwable::class) override fun doInBackground(): List { - val musicService = getMusicService(activity) + val musicService = getMusicService() val songs: MutableList = LinkedList() val root: MusicDirectory if (!isOffline() && isArtist && Util.getShouldUseId3Tags()) { @@ -243,7 +245,7 @@ class DownloadHandler( songs.add(song) } } - val musicService = getMusicService(activity) + val musicService = getMusicService() for ( (id1, _, _, title) in parent.getChildren( includeDirs = true, @@ -267,7 +269,7 @@ class DownloadHandler( if (songs.size > maxSongs) { return } - val musicService = getMusicService(activity) + val musicService = getMusicService() val artist = musicService.getArtist(id, "", false) for ((id1) in artist.getChildren()) { val albumDirectory = musicService.getAlbum( diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/ShareHandler.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/ShareHandler.kt index 0a7e53b3..5b6fa873 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/ShareHandler.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/ShareHandler.kt @@ -76,7 +76,7 @@ class ShareHandler(val context: Context) { ids.add(id) } } - val musicService = getMusicService(context) + val musicService = getMusicService() var timeInMillis: Long = 0 if (shareDetails.Expiration != 0L) { timeInMillis = shareDetails.Expiration diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/SongView.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/SongView.kt index 0682d241..165f4ab1 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/SongView.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/SongView.kt @@ -201,7 +201,7 @@ class SongView(context: Context) : UpdateView(context), Checkable { song.starred = false } Thread { - val musicService = getMusicService(this@SongView.context) + val musicService = getMusicService() try { if (!isStarred) { musicService.star(id, null, null)