Remove unused context references in MusicServiceFactory
This commit is contained in:
parent
1fa9e604b5
commit
f2b1ba0e94
|
@ -381,7 +381,7 @@ public class BookmarksFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
protected Pair<MusicDirectory, Boolean> doInBackground() throws Throwable
|
protected Pair<MusicDirectory, Boolean> doInBackground() throws Throwable
|
||||||
{
|
{
|
||||||
MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
MusicDirectory dir = load(musicService);
|
MusicDirectory dir = load(musicService);
|
||||||
boolean valid = musicService.isLicenseValid();
|
boolean valid = musicService.isLicenseValid();
|
||||||
return new Pair<>(dir, valid);
|
return new Pair<>(dir, valid);
|
||||||
|
|
|
@ -249,7 +249,7 @@ public class ChatFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground() throws Throwable
|
protected Void doInBackground() throws Throwable
|
||||||
{
|
{
|
||||||
MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
musicService.addChatMessage(message, getContext());
|
musicService.addChatMessage(message, getContext());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,7 @@ public class ChatFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
protected List<ChatMessage> doInBackground() throws Throwable
|
protected List<ChatMessage> doInBackground() throws Throwable
|
||||||
{
|
{
|
||||||
MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
return musicService.getChatMessages(lastChatMessageTime, getContext());
|
return musicService.getChatMessages(lastChatMessageTime, getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class LyricsFragment extends Fragment {
|
||||||
if (arguments == null) return null;
|
if (arguments == null) return null;
|
||||||
String artist = arguments.getString(Constants.INTENT_EXTRA_NAME_ARTIST);
|
String artist = arguments.getString(Constants.INTENT_EXTRA_NAME_ARTIST);
|
||||||
String title = arguments.getString(Constants.INTENT_EXTRA_NAME_TITLE);
|
String title = arguments.getString(Constants.INTENT_EXTRA_NAME_TITLE);
|
||||||
MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
return musicService.getLyrics(artist, title, getContext());
|
return musicService.getLyrics(artist, title, getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -994,7 +994,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
final MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (isStarred) {
|
if (isStarred) {
|
||||||
|
@ -1024,7 +1024,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
final MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
musicService.createBookmark(songId, playerPosition, getContext());
|
musicService.createBookmark(songId, playerPosition, getContext());
|
||||||
|
@ -1050,7 +1050,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
final MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
final MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
musicService.deleteBookmark(bookmarkSongId, getContext());
|
musicService.deleteBookmark(bookmarkSongId, getContext());
|
||||||
|
@ -1127,7 +1127,7 @@ public class PlayerFragment extends Fragment implements GestureDetector.OnGestur
|
||||||
{
|
{
|
||||||
entries.add(downloadFile.getSong());
|
entries.add(downloadFile.getSong());
|
||||||
}
|
}
|
||||||
final MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
final MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
musicService.createPlaylist(null, playlistName, entries, getContext());
|
musicService.createPlaylist(null, playlistName, entries, getContext());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,7 @@ public class PlaylistsFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
protected List<Playlist> doInBackground() throws Throwable
|
protected List<Playlist> doInBackground() throws Throwable
|
||||||
{
|
{
|
||||||
MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
List<Playlist> playlists = musicService.getPlaylists(refresh, getContext());
|
List<Playlist> playlists = musicService.getPlaylists(refresh, getContext());
|
||||||
|
|
||||||
if (!ActiveServerProvider.Companion.isOffline())
|
if (!ActiveServerProvider.Companion.isOffline())
|
||||||
|
@ -222,7 +222,7 @@ public class PlaylistsFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground() throws Throwable
|
protected Void doInBackground() throws Throwable
|
||||||
{
|
{
|
||||||
MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
musicService.deletePlaylist(playlist.getId(), getContext());
|
musicService.deletePlaylist(playlist.getId(), getContext());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ public class PlaylistsFragment extends Fragment {
|
||||||
String name = nameBoxText != null ? nameBoxText.toString() : null;
|
String name = nameBoxText != null ? nameBoxText.toString() : null;
|
||||||
String comment = commentBoxText != null ? commentBoxText.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());
|
musicService.updatePlaylist(playlist.getId(), name, comment, publicBox.isChecked(), getContext());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class PodcastFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
protected List<PodcastsChannel> doInBackground() throws Throwable
|
protected List<PodcastsChannel> doInBackground() throws Throwable
|
||||||
{
|
{
|
||||||
MusicService musicService = MusicServiceFactory.getMusicService(context);
|
MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
return musicService.getPodcastsChannels(refresh, context);
|
return musicService.getPodcastsChannels(refresh, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -420,7 +420,7 @@ public class SearchFragment extends Fragment {
|
||||||
protected SearchResult doInBackground() throws Throwable
|
protected SearchResult doInBackground() throws Throwable
|
||||||
{
|
{
|
||||||
SearchCriteria criteria = new SearchCriteria(query, maxArtists, maxAlbums, maxSongs);
|
SearchCriteria criteria = new SearchCriteria(query, maxArtists, maxAlbums, maxSongs);
|
||||||
MusicService service = MusicServiceFactory.getMusicService(getContext());
|
MusicService service = MusicServiceFactory.getMusicService();
|
||||||
return service.search(criteria, getContext());
|
return service.search(criteria, getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,7 +102,7 @@ public class SelectGenreFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
protected List<Genre> doInBackground()
|
protected List<Genre> doInBackground()
|
||||||
{
|
{
|
||||||
MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
|
|
||||||
List<Genre> genres = new ArrayList<>();
|
List<Genre> genres = new ArrayList<>();
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class SharesFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
protected List<Share> doInBackground() throws Throwable
|
protected List<Share> doInBackground() throws Throwable
|
||||||
{
|
{
|
||||||
MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
return musicService.getShares(refresh, getContext());
|
return musicService.getShares(refresh, getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ public class SharesFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground() throws Throwable
|
protected Void doInBackground() throws Throwable
|
||||||
{
|
{
|
||||||
MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
musicService.deleteShare(share.getId(), getContext());
|
musicService.deleteShare(share.getId(), getContext());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ public class SharesFragment extends Fragment {
|
||||||
Editable shareDescriptionText = shareDescription.getText();
|
Editable shareDescriptionText = shareDescription.getText();
|
||||||
String description = shareDescriptionText != null ? shareDescriptionText.toString() : null;
|
String description = shareDescriptionText != null ? shareDescriptionText.toString() : null;
|
||||||
|
|
||||||
MusicService musicService = MusicServiceFactory.getMusicService(getContext());
|
MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
musicService.updateShare(share.getId(), description, millis, getContext());
|
musicService.updateShare(share.getId(), description, millis, getContext());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,7 +300,7 @@ public class JukeboxMediaPlayer
|
||||||
|
|
||||||
private MusicService getMusicService()
|
private MusicService getMusicService()
|
||||||
{
|
{
|
||||||
return MusicServiceFactory.getMusicService(context);
|
return MusicServiceFactory.getMusicService();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPositionSeconds()
|
public int getPositionSeconds()
|
||||||
|
|
|
@ -527,7 +527,7 @@ public class MediaPlayerControllerImpl implements MediaPlayerController
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String username = activeServerProvider.getValue().getActiveServer().getUserName();
|
String username = activeServerProvider.getValue().getActiveServer().getUserName();
|
||||||
UserInfo user = MusicServiceFactory.getMusicService(context).getUser(username, context);
|
UserInfo user = MusicServiceFactory.getMusicService().getUser(username, context);
|
||||||
return user.getJukeboxRole();
|
return user.getJukeboxRole();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -608,7 +608,7 @@ public class MediaPlayerControllerImpl implements MediaPlayerController
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MusicServiceFactory.getMusicService(context).setRating(song.getId(), rating);
|
MusicServiceFactory.getMusicService().setRating(song.getId(), rating);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class Scrobbler
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
MusicService service = MusicServiceFactory.getMusicService(context);
|
MusicService service = MusicServiceFactory.getMusicService();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
service.scrobble(id, submission, context);
|
service.scrobble(id, submission, context);
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class ShufflePlayBuffer
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MusicService service = MusicServiceFactory.getMusicService(context);
|
MusicService service = MusicServiceFactory.getMusicService();
|
||||||
int n = CAPACITY - buffer.size();
|
int n = CAPACITY - buffer.size();
|
||||||
MusicDirectory songs = service.getRandomSongs(n, context);
|
MusicDirectory songs = service.getRandomSongs(n, context);
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ public enum VideoPlayerType
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.setPackage(installedPro ? PACKAGE_NAME_MX_PRO : PACKAGE_NAME_MX_AD);
|
intent.setPackage(installedPro ? PACKAGE_NAME_MX_PRO : PACKAGE_NAME_MX_AD);
|
||||||
intent.putExtra("title", entry.getTitle());
|
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);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ public enum VideoPlayerType
|
||||||
public void playVideo(Context context, MusicDirectory.Entry entry) throws Exception
|
public void playVideo(Context context, MusicDirectory.Entry entry) throws Exception
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
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);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -102,7 +102,7 @@ public enum VideoPlayerType
|
||||||
public void playVideo(Context context, MusicDirectory.Entry entry) throws Exception
|
public void playVideo(Context context, MusicDirectory.Entry entry) throws Exception
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
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);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -146,7 +146,7 @@ public class AlbumView extends UpdateView
|
||||||
album.setStarred(false);
|
album.setStarred(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
final MusicService musicService = MusicServiceFactory.getMusicService(view.getContext());
|
final MusicService musicService = MusicServiceFactory.getMusicService();
|
||||||
new Thread(new Runnable()
|
new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -78,7 +78,7 @@ class ArtistListModel(
|
||||||
|
|
||||||
private suspend fun loadFromServer(refresh: Boolean, swipe: SwipeRefreshLayout) =
|
private suspend fun loadFromServer(refresh: Boolean, swipe: SwipeRefreshLayout) =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val musicService = MusicServiceFactory.getMusicService(context)
|
val musicService = MusicServiceFactory.getMusicService()
|
||||||
val isOffline = ActiveServerProvider.isOffline()
|
val isOffline = ActiveServerProvider.isOffline()
|
||||||
val useId3Tags = Util.getShouldUseId3Tags()
|
val useId3Tags = Util.getShouldUseId3Tags()
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
suspend fun getMusicFolders(refresh: Boolean) {
|
suspend fun getMusicFolders(refresh: Boolean) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (!ActiveServerProvider.isOffline()) {
|
if (!ActiveServerProvider.isOffline()) {
|
||||||
val musicService = MusicServiceFactory.getMusicService(context)
|
val musicService = MusicServiceFactory.getMusicService()
|
||||||
musicFolders.postValue(musicService.getMusicFolders(refresh))
|
musicFolders.postValue(musicService.getMusicFolders(refresh))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
) {
|
) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
|
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService()
|
||||||
|
|
||||||
var root = MusicDirectory()
|
var root = MusicDirectory()
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
parent: MusicDirectory,
|
parent: MusicDirectory,
|
||||||
songs: MutableList<MusicDirectory.Entry>
|
songs: MutableList<MusicDirectory.Entry>
|
||||||
) {
|
) {
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService()
|
||||||
|
|
||||||
for (song in parent.getChildren(includeDirs = false, includeFiles = true)) {
|
for (song in parent.getChildren(includeDirs = false, includeFiles = true)) {
|
||||||
if (!song.isVideo && !song.isDirectory) {
|
if (!song.isVideo && !song.isDirectory) {
|
||||||
|
@ -127,7 +127,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
suspend fun getArtist(refresh: Boolean, id: String?, name: String?) {
|
suspend fun getArtist(refresh: Boolean, id: String?, name: String?) {
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService()
|
||||||
|
|
||||||
var root = MusicDirectory()
|
var root = MusicDirectory()
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
|
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService()
|
||||||
|
|
||||||
val musicDirectory: MusicDirectory
|
val musicDirectory: MusicDirectory
|
||||||
|
|
||||||
|
@ -199,7 +199,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
|
|
||||||
suspend fun getSongsForGenre(genre: String, count: Int, offset: Int) {
|
suspend fun getSongsForGenre(genre: String, count: Int, offset: Int) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val musicDirectory = service.getSongsByGenre(genre, count, offset, context)
|
val musicDirectory = service.getSongsByGenre(genre, count, offset, context)
|
||||||
songsForGenre.postValue(musicDirectory)
|
songsForGenre.postValue(musicDirectory)
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
|
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val musicDirectory: MusicDirectory
|
val musicDirectory: MusicDirectory
|
||||||
|
|
||||||
if (Util.getShouldUseId3Tags()) {
|
if (Util.getShouldUseId3Tags()) {
|
||||||
|
@ -226,7 +226,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
showHeader = false
|
showHeader = false
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService()
|
||||||
currentDirectory.postValue(service.getVideos(refresh, context))
|
currentDirectory.postValue(service.getVideos(refresh, context))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
suspend fun getRandom(size: Int) {
|
suspend fun getRandom(size: Int) {
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val musicDirectory = service.getRandomSongs(size, context)
|
val musicDirectory = service.getRandomSongs(size, context)
|
||||||
|
|
||||||
currentDirectoryIsSortable = false
|
currentDirectoryIsSortable = false
|
||||||
|
@ -245,7 +245,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
suspend fun getPlaylist(playlistId: String, playlistName: String?) {
|
suspend fun getPlaylist(playlistId: String, playlistName: String?) {
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val musicDirectory = service.getPlaylist(playlistId, playlistName, context)
|
val musicDirectory = service.getPlaylist(playlistId, playlistName, context)
|
||||||
|
|
||||||
currentDirectory.postValue(musicDirectory)
|
currentDirectory.postValue(musicDirectory)
|
||||||
|
@ -255,7 +255,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
suspend fun getPodcastEpisodes(podcastChannelId: String) {
|
suspend fun getPodcastEpisodes(podcastChannelId: String) {
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val musicDirectory = service.getPodcastEpisodes(podcastChannelId, context)
|
val musicDirectory = service.getPodcastEpisodes(podcastChannelId, context)
|
||||||
currentDirectory.postValue(musicDirectory)
|
currentDirectory.postValue(musicDirectory)
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
suspend fun getShare(shareId: String) {
|
suspend fun getShare(shareId: String) {
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val musicDirectory = MusicDirectory()
|
val musicDirectory = MusicDirectory()
|
||||||
|
|
||||||
val shares = service.getShares(true, context)
|
val shares = service.getShares(true, context)
|
||||||
|
@ -291,7 +291,7 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
||||||
)
|
)
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val musicDirectory: MusicDirectory
|
val musicDirectory: MusicDirectory
|
||||||
val musicFolderId = if (showSelectFolderHeader) {
|
val musicFolderId = if (showSelectFolderHeader) {
|
||||||
activeServerProvider.getActiveServer().musicFolderId
|
activeServerProvider.getActiveServer().musicFolderId
|
||||||
|
|
|
@ -228,7 +228,7 @@ class DownloadFile(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val musicService = getMusicService(context)
|
val musicService = getMusicService()
|
||||||
|
|
||||||
// Some devices seem to throw error on partial file which doesn't exist
|
// Some devices seem to throw error on partial file which doesn't exist
|
||||||
val needsDownloading: Boolean
|
val needsDownloading: Boolean
|
||||||
|
|
|
@ -422,7 +422,7 @@ class MediaPlayerService : Service() {
|
||||||
if (currentPlaying != null) {
|
if (currentPlaying != null) {
|
||||||
val song = currentPlaying.song
|
val song = currentPlaying.song
|
||||||
if (song.bookmarkPosition > 0 && Util.getShouldClearBookmark()) {
|
if (song.bookmarkPosition > 0 && Util.getShouldClearBookmark()) {
|
||||||
val musicService = getMusicService(context)
|
val musicService = getMusicService()
|
||||||
try {
|
try {
|
||||||
musicService.deleteBookmark(song.id, context)
|
musicService.deleteBookmark(song.id, context)
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.moire.ultrasonic.service
|
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.KoinComponent
|
||||||
import org.koin.core.component.get
|
import org.koin.core.component.get
|
||||||
import org.koin.core.context.loadKoinModules
|
import org.koin.core.context.loadKoinModules
|
||||||
|
@ -30,9 +30,10 @@ import org.moire.ultrasonic.di.ONLINE_MUSIC_SERVICE
|
||||||
import org.moire.ultrasonic.di.musicServiceModule
|
import org.moire.ultrasonic.di.musicServiceModule
|
||||||
|
|
||||||
// TODO Refactor everywhere to use DI way to get MusicService, and then remove this class
|
// TODO Refactor everywhere to use DI way to get MusicService, and then remove this class
|
||||||
|
@KoinApiExtension
|
||||||
object MusicServiceFactory : KoinComponent {
|
object MusicServiceFactory : KoinComponent {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getMusicService(context: Context): MusicService {
|
fun getMusicService(): MusicService {
|
||||||
return if (ActiveServerProvider.isOffline()) {
|
return if (ActiveServerProvider.isOffline()) {
|
||||||
get(named(OFFLINE_MUSIC_SERVICE))
|
get(named(OFFLINE_MUSIC_SERVICE))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.moire.ultrasonic.subsonic
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.navigation.fragment.findNavController
|
import androidx.navigation.fragment.findNavController
|
||||||
|
import org.koin.core.component.KoinApiExtension
|
||||||
import java.util.Collections
|
import java.util.Collections
|
||||||
import java.util.LinkedList
|
import java.util.LinkedList
|
||||||
import org.moire.ultrasonic.R
|
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
|
* Retrieves a list of songs and adds them to the now playing list
|
||||||
*/
|
*/
|
||||||
|
@KoinApiExtension
|
||||||
class DownloadHandler(
|
class DownloadHandler(
|
||||||
val mediaPlayerController: MediaPlayerController,
|
val mediaPlayerController: MediaPlayerController,
|
||||||
val networkAndStorageChecker: NetworkAndStorageChecker
|
val networkAndStorageChecker: NetworkAndStorageChecker
|
||||||
|
@ -200,7 +202,7 @@ class DownloadHandler(
|
||||||
|
|
||||||
@Throws(Throwable::class)
|
@Throws(Throwable::class)
|
||||||
override fun doInBackground(): List<MusicDirectory.Entry> {
|
override fun doInBackground(): List<MusicDirectory.Entry> {
|
||||||
val musicService = getMusicService(activity)
|
val musicService = getMusicService()
|
||||||
val songs: MutableList<MusicDirectory.Entry> = LinkedList()
|
val songs: MutableList<MusicDirectory.Entry> = LinkedList()
|
||||||
val root: MusicDirectory
|
val root: MusicDirectory
|
||||||
if (!isOffline() && isArtist && Util.getShouldUseId3Tags()) {
|
if (!isOffline() && isArtist && Util.getShouldUseId3Tags()) {
|
||||||
|
@ -243,7 +245,7 @@ class DownloadHandler(
|
||||||
songs.add(song)
|
songs.add(song)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val musicService = getMusicService(activity)
|
val musicService = getMusicService()
|
||||||
for (
|
for (
|
||||||
(id1, _, _, title) in parent.getChildren(
|
(id1, _, _, title) in parent.getChildren(
|
||||||
includeDirs = true,
|
includeDirs = true,
|
||||||
|
@ -267,7 +269,7 @@ class DownloadHandler(
|
||||||
if (songs.size > maxSongs) {
|
if (songs.size > maxSongs) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val musicService = getMusicService(activity)
|
val musicService = getMusicService()
|
||||||
val artist = musicService.getArtist(id, "", false)
|
val artist = musicService.getArtist(id, "", false)
|
||||||
for ((id1) in artist.getChildren()) {
|
for ((id1) in artist.getChildren()) {
|
||||||
val albumDirectory = musicService.getAlbum(
|
val albumDirectory = musicService.getAlbum(
|
||||||
|
|
|
@ -76,7 +76,7 @@ class ShareHandler(val context: Context) {
|
||||||
ids.add(id)
|
ids.add(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val musicService = getMusicService(context)
|
val musicService = getMusicService()
|
||||||
var timeInMillis: Long = 0
|
var timeInMillis: Long = 0
|
||||||
if (shareDetails.Expiration != 0L) {
|
if (shareDetails.Expiration != 0L) {
|
||||||
timeInMillis = shareDetails.Expiration
|
timeInMillis = shareDetails.Expiration
|
||||||
|
|
|
@ -201,7 +201,7 @@ class SongView(context: Context) : UpdateView(context), Checkable {
|
||||||
song.starred = false
|
song.starred = false
|
||||||
}
|
}
|
||||||
Thread {
|
Thread {
|
||||||
val musicService = getMusicService(this@SongView.context)
|
val musicService = getMusicService()
|
||||||
try {
|
try {
|
||||||
if (!isStarred) {
|
if (!isStarred) {
|
||||||
musicService.star(id, null, null)
|
musicService.star(id, null, null)
|
||||||
|
|
Loading…
Reference in New Issue