mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-05-14 06:16:36 +03:00
commit
7dcc5bbf13
@ -93,7 +93,6 @@ class SelectAlbumFragment : Fragment() {
|
|||||||
private var cancellationToken: CancellationToken? = null
|
private var cancellationToken: CancellationToken? = null
|
||||||
private val activeServerProvider: ActiveServerProvider by inject()
|
private val activeServerProvider: ActiveServerProvider by inject()
|
||||||
|
|
||||||
private val serverSettingsModel: ServerSettingsModel by viewModel()
|
|
||||||
private val model: SelectAlbumModel by viewModels()
|
private val model: SelectAlbumModel by viewModels()
|
||||||
|
|
||||||
private val random: Random = SecureRandom()
|
private val random: Random = SecureRandom()
|
||||||
@ -133,6 +132,7 @@ class SelectAlbumFragment : Fragment() {
|
|||||||
requireContext(), view as ViewGroup
|
requireContext(), view as ViewGroup
|
||||||
) { selectedFolderId ->
|
) { selectedFolderId ->
|
||||||
if (!isOffline(context)) {
|
if (!isOffline(context)) {
|
||||||
|
val serverSettingsModel: ServerSettingsModel by viewModel()
|
||||||
val currentSetting = activeServerProvider.getActiveServer()
|
val currentSetting = activeServerProvider.getActiveServer()
|
||||||
currentSetting.musicFolderId = selectedFolderId
|
currentSetting.musicFolderId = selectedFolderId
|
||||||
serverSettingsModel.updateItem(currentSetting)
|
serverSettingsModel.updateItem(currentSetting)
|
||||||
@ -230,31 +230,32 @@ class SelectAlbumFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateDisplay(refresh: Boolean) {
|
private fun updateDisplay(refresh: Boolean) {
|
||||||
val id = requireArguments().getString(Constants.INTENT_EXTRA_NAME_ID)
|
val args = requireArguments()
|
||||||
val isAlbum = requireArguments().getBoolean(Constants.INTENT_EXTRA_NAME_IS_ALBUM, false)
|
val id = args.getString(Constants.INTENT_EXTRA_NAME_ID)
|
||||||
val name = requireArguments().getString(Constants.INTENT_EXTRA_NAME_NAME)
|
val isAlbum = args.getBoolean(Constants.INTENT_EXTRA_NAME_IS_ALBUM, false)
|
||||||
val parentId = requireArguments().getString(Constants.INTENT_EXTRA_NAME_PARENT_ID)
|
val name = args.getString(Constants.INTENT_EXTRA_NAME_NAME)
|
||||||
val playlistId = requireArguments().getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID)
|
val parentId = args.getString(Constants.INTENT_EXTRA_NAME_PARENT_ID)
|
||||||
val podcastChannelId = requireArguments().getString(
|
val playlistId = args.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID)
|
||||||
|
val podcastChannelId = args.getString(
|
||||||
Constants.INTENT_EXTRA_NAME_PODCAST_CHANNEL_ID
|
Constants.INTENT_EXTRA_NAME_PODCAST_CHANNEL_ID
|
||||||
)
|
)
|
||||||
val playlistName = requireArguments().getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME)
|
val playlistName = args.getString(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME)
|
||||||
val shareId = requireArguments().getString(Constants.INTENT_EXTRA_NAME_SHARE_ID)
|
val shareId = args.getString(Constants.INTENT_EXTRA_NAME_SHARE_ID)
|
||||||
val shareName = requireArguments().getString(Constants.INTENT_EXTRA_NAME_SHARE_NAME)
|
val shareName = args.getString(Constants.INTENT_EXTRA_NAME_SHARE_NAME)
|
||||||
val albumListType = requireArguments().getString(
|
val albumListType = args.getString(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE
|
||||||
)
|
)
|
||||||
val genreName = requireArguments().getString(Constants.INTENT_EXTRA_NAME_GENRE_NAME)
|
val genreName = args.getString(Constants.INTENT_EXTRA_NAME_GENRE_NAME)
|
||||||
val albumListTitle = requireArguments().getInt(
|
val albumListTitle = args.getInt(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, 0
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, 0
|
||||||
)
|
)
|
||||||
val getStarredTracks = requireArguments().getInt(Constants.INTENT_EXTRA_NAME_STARRED, 0)
|
val getStarredTracks = args.getInt(Constants.INTENT_EXTRA_NAME_STARRED, 0)
|
||||||
val getVideos = requireArguments().getInt(Constants.INTENT_EXTRA_NAME_VIDEOS, 0)
|
val getVideos = args.getInt(Constants.INTENT_EXTRA_NAME_VIDEOS, 0)
|
||||||
val getRandomTracks = requireArguments().getInt(Constants.INTENT_EXTRA_NAME_RANDOM, 0)
|
val getRandomTracks = args.getInt(Constants.INTENT_EXTRA_NAME_RANDOM, 0)
|
||||||
val albumListSize = requireArguments().getInt(
|
val albumListSize = args.getInt(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0
|
||||||
)
|
)
|
||||||
val albumListOffset = requireArguments().getInt(
|
val albumListOffset = args.getInt(
|
||||||
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0
|
Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,50 +54,49 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
|||||||
parentId: String?
|
parentId: String?
|
||||||
) {
|
) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (!ActiveServerProvider.isOffline(context)) {
|
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
|
||||||
|
|
||||||
var root = MusicDirectory()
|
val service = MusicServiceFactory.getMusicService(context)
|
||||||
|
|
||||||
if (allSongsId == id) {
|
var root = MusicDirectory()
|
||||||
val musicDirectory = service.getMusicDirectory(
|
|
||||||
parentId, name, refresh, context
|
|
||||||
)
|
|
||||||
|
|
||||||
val songs: MutableList<MusicDirectory.Entry> = LinkedList()
|
if (allSongsId == id) {
|
||||||
getSongsRecursively(musicDirectory, songs)
|
val musicDirectory = service.getMusicDirectory(
|
||||||
|
parentId, name, refresh, context
|
||||||
|
)
|
||||||
|
|
||||||
for (song in songs) {
|
val songs: MutableList<MusicDirectory.Entry> = LinkedList()
|
||||||
if (!song.isDirectory) {
|
getSongsRecursively(musicDirectory, songs)
|
||||||
root.addChild(song)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val musicDirectory = service.getMusicDirectory(id, name, refresh, context)
|
|
||||||
|
|
||||||
if (Util.getShouldShowAllSongsByArtist(context) &&
|
for (song in songs) {
|
||||||
musicDirectory.findChild(allSongsId) == null &&
|
if (!song.isDirectory) {
|
||||||
hasOnlyFolders(musicDirectory)
|
root.addChild(song)
|
||||||
) {
|
|
||||||
val allSongs = MusicDirectory.Entry()
|
|
||||||
|
|
||||||
allSongs.isDirectory = true
|
|
||||||
allSongs.artist = name
|
|
||||||
allSongs.parent = id
|
|
||||||
allSongs.id = allSongsId
|
|
||||||
allSongs.title = String.format(
|
|
||||||
context.resources.getString(R.string.select_album_all_songs), name
|
|
||||||
)
|
|
||||||
|
|
||||||
root.addChild(allSongs)
|
|
||||||
root.addAll(musicDirectory.getChildren())
|
|
||||||
} else {
|
|
||||||
root = musicDirectory
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
val musicDirectory = service.getMusicDirectory(id, name, refresh, context)
|
||||||
|
|
||||||
currentDirectory.postValue(root)
|
if (Util.getShouldShowAllSongsByArtist(context) &&
|
||||||
|
musicDirectory.findChild(allSongsId) == null &&
|
||||||
|
hasOnlyFolders(musicDirectory)
|
||||||
|
) {
|
||||||
|
val allSongs = MusicDirectory.Entry()
|
||||||
|
|
||||||
|
allSongs.isDirectory = true
|
||||||
|
allSongs.artist = name
|
||||||
|
allSongs.parent = id
|
||||||
|
allSongs.id = allSongsId
|
||||||
|
allSongs.title = String.format(
|
||||||
|
context.resources.getString(R.string.select_album_all_songs), name
|
||||||
|
)
|
||||||
|
|
||||||
|
root.addChild(allSongs)
|
||||||
|
root.addAll(musicDirectory.getChildren())
|
||||||
|
} else {
|
||||||
|
root = musicDirectory
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentDirectory.postValue(root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,107 +127,99 @@ 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) {
|
||||||
if (!ActiveServerProvider.isOffline(context)) {
|
val service = MusicServiceFactory.getMusicService(context)
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
|
||||||
|
|
||||||
var root = MusicDirectory()
|
var root = MusicDirectory()
|
||||||
|
|
||||||
val musicDirectory = service.getArtist(id, name, refresh, context)
|
val musicDirectory = service.getArtist(id, name, refresh, context)
|
||||||
|
|
||||||
if (Util.getShouldShowAllSongsByArtist(context) &&
|
if (Util.getShouldShowAllSongsByArtist(context) &&
|
||||||
musicDirectory.findChild(allSongsId) == null &&
|
musicDirectory.findChild(allSongsId) == null &&
|
||||||
hasOnlyFolders(musicDirectory)
|
hasOnlyFolders(musicDirectory)
|
||||||
) {
|
) {
|
||||||
val allSongs = MusicDirectory.Entry()
|
val allSongs = MusicDirectory.Entry()
|
||||||
|
|
||||||
allSongs.isDirectory = true
|
allSongs.isDirectory = true
|
||||||
allSongs.artist = name
|
allSongs.artist = name
|
||||||
allSongs.parent = id
|
allSongs.parent = id
|
||||||
allSongs.id = allSongsId
|
allSongs.id = allSongsId
|
||||||
allSongs.title = String.format(
|
allSongs.title = String.format(
|
||||||
context.resources.getString(R.string.select_album_all_songs), name
|
context.resources.getString(R.string.select_album_all_songs), name
|
||||||
)
|
)
|
||||||
|
|
||||||
root.addFirst(allSongs)
|
root.addFirst(allSongs)
|
||||||
root.addAll(musicDirectory.getChildren())
|
root.addAll(musicDirectory.getChildren())
|
||||||
} else {
|
} else {
|
||||||
root = musicDirectory
|
root = musicDirectory
|
||||||
}
|
|
||||||
currentDirectory.postValue(root)
|
|
||||||
}
|
}
|
||||||
|
currentDirectory.postValue(root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getAlbum(refresh: Boolean, id: String?, name: String?, parentId: String?) {
|
suspend fun getAlbum(refresh: Boolean, id: String?, name: String?, parentId: String?) {
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (!ActiveServerProvider.isOffline(context)) {
|
|
||||||
|
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService(context)
|
||||||
|
|
||||||
val musicDirectory: MusicDirectory
|
val musicDirectory: MusicDirectory
|
||||||
|
|
||||||
musicDirectory = if (allSongsId == id) {
|
musicDirectory = if (allSongsId == id) {
|
||||||
val root = MusicDirectory()
|
val root = MusicDirectory()
|
||||||
|
|
||||||
val songs: MutableCollection<MusicDirectory.Entry> = LinkedList()
|
val songs: MutableCollection<MusicDirectory.Entry> = LinkedList()
|
||||||
val artist = service.getArtist(parentId, "", false, context)
|
val artist = service.getArtist(parentId, "", false, context)
|
||||||
|
|
||||||
for ((id1) in artist.getChildren()) {
|
for ((id1) in artist.getChildren()) {
|
||||||
if (allSongsId != id1) {
|
if (allSongsId != id1) {
|
||||||
val albumDirectory = service.getAlbum(
|
val albumDirectory = service.getAlbum(
|
||||||
id1, "", false, context
|
id1, "", false, context
|
||||||
)
|
)
|
||||||
|
|
||||||
for (song in albumDirectory.getChildren()) {
|
for (song in albumDirectory.getChildren()) {
|
||||||
if (!song.isVideo) {
|
if (!song.isVideo) {
|
||||||
songs.add(song)
|
songs.add(song)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (song in songs) {
|
|
||||||
if (!song.isDirectory) {
|
|
||||||
root.addChild(song)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
root
|
|
||||||
} else {
|
|
||||||
service.getAlbum(id, name, refresh, context)
|
|
||||||
}
|
}
|
||||||
currentDirectory.postValue(musicDirectory)
|
|
||||||
|
for (song in songs) {
|
||||||
|
if (!song.isDirectory) {
|
||||||
|
root.addChild(song)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
root
|
||||||
|
} else {
|
||||||
|
service.getAlbum(id, name, refresh, context)
|
||||||
}
|
}
|
||||||
|
currentDirectory.postValue(musicDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getSongsForGenre(genre: String, count: Int, offset: Int) {
|
suspend fun getSongsForGenre(genre: String, count: Int, offset: Int) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (!ActiveServerProvider.isOffline(context)) {
|
val service = MusicServiceFactory.getMusicService(context)
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val musicDirectory = service.getSongsByGenre(genre, count, offset, context)
|
||||||
val musicDirectory = service.getSongsByGenre(genre, count, offset, context)
|
songsForGenre.postValue(musicDirectory)
|
||||||
songsForGenre.postValue(musicDirectory)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getStarred() {
|
suspend fun getStarred() {
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (!ActiveServerProvider.isOffline(context)) {
|
|
||||||
|
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val service = MusicServiceFactory.getMusicService(context)
|
||||||
val musicDirectory: MusicDirectory
|
val musicDirectory: MusicDirectory
|
||||||
val context = context
|
val context = context
|
||||||
|
|
||||||
if (Util.getShouldUseId3Tags(context)) {
|
if (Util.getShouldUseId3Tags(context)) {
|
||||||
musicDirectory = Util.getSongsFromSearchResult(service.getStarred2(context))
|
musicDirectory = Util.getSongsFromSearchResult(service.getStarred2(context))
|
||||||
} else {
|
} else {
|
||||||
musicDirectory = Util.getSongsFromSearchResult(service.getStarred(context))
|
musicDirectory = Util.getSongsFromSearchResult(service.getStarred(context))
|
||||||
}
|
|
||||||
|
|
||||||
currentDirectory.postValue(musicDirectory)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentDirectory.postValue(musicDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,68 +227,58 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
|||||||
showHeader = false
|
showHeader = false
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (!ActiveServerProvider.isOffline(context)) {
|
val service = MusicServiceFactory.getMusicService(context)
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
currentDirectory.postValue(service.getVideos(refresh, context))
|
||||||
currentDirectory.postValue(service.getVideos(refresh, context))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getRandom(size: Int) {
|
suspend fun getRandom(size: Int) {
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (!ActiveServerProvider.isOffline(context)) {
|
val service = MusicServiceFactory.getMusicService(context)
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val musicDirectory = service.getRandomSongs(size, context)
|
||||||
val musicDirectory = service.getRandomSongs(size, context)
|
|
||||||
|
|
||||||
currentDirectoryIsSortable = false
|
currentDirectoryIsSortable = false
|
||||||
currentDirectory.postValue(musicDirectory)
|
currentDirectory.postValue(musicDirectory)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getPlaylist(playlistId: String, playlistName: String?) {
|
suspend fun getPlaylist(playlistId: String, playlistName: String?) {
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (!ActiveServerProvider.isOffline(context)) {
|
val service = MusicServiceFactory.getMusicService(context)
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val musicDirectory = service.getPlaylist(playlistId, playlistName, context)
|
||||||
val musicDirectory = service.getPlaylist(playlistId, playlistName, context)
|
|
||||||
|
|
||||||
currentDirectory.postValue(musicDirectory)
|
currentDirectory.postValue(musicDirectory)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getPodcastEpisodes(podcastChannelId: String) {
|
suspend fun getPodcastEpisodes(podcastChannelId: String) {
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (!ActiveServerProvider.isOffline(context)) {
|
val service = MusicServiceFactory.getMusicService(context)
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val musicDirectory = service.getPodcastEpisodes(podcastChannelId, context)
|
||||||
val musicDirectory = service.getPodcastEpisodes(podcastChannelId, context)
|
currentDirectory.postValue(musicDirectory)
|
||||||
currentDirectory.postValue(musicDirectory)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getShare(shareId: String) {
|
suspend fun getShare(shareId: String) {
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (!ActiveServerProvider.isOffline(context)) {
|
val service = MusicServiceFactory.getMusicService(context)
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val musicDirectory = MusicDirectory()
|
||||||
val musicDirectory = MusicDirectory()
|
|
||||||
|
|
||||||
val shares = service.getShares(true, context)
|
val shares = service.getShares(true, context)
|
||||||
|
|
||||||
for (share in shares) {
|
for (share in shares) {
|
||||||
if (share.id == shareId) {
|
if (share.id == shareId) {
|
||||||
for (entry in share.getEntries()) {
|
for (entry in share.getEntries()) {
|
||||||
musicDirectory.addChild(entry)
|
musicDirectory.addChild(entry)
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
currentDirectory.postValue(musicDirectory)
|
|
||||||
}
|
}
|
||||||
|
currentDirectory.postValue(musicDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,30 +292,28 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
|
|||||||
)
|
)
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
if (!ActiveServerProvider.isOffline(context)) {
|
val service = MusicServiceFactory.getMusicService(context)
|
||||||
val service = MusicServiceFactory.getMusicService(context)
|
val musicDirectory: MusicDirectory
|
||||||
val musicDirectory: MusicDirectory
|
val musicFolderId = if (showSelectFolderHeader) {
|
||||||
val musicFolderId = if (showSelectFolderHeader) {
|
activeServerProvider.getActiveServer().musicFolderId
|
||||||
activeServerProvider.getActiveServer().musicFolderId
|
} else {
|
||||||
} else {
|
null
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Util.getShouldUseId3Tags(context)) {
|
|
||||||
musicDirectory = service.getAlbumList2(
|
|
||||||
albumListType, size,
|
|
||||||
offset, musicFolderId, context
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
musicDirectory = service.getAlbumList(
|
|
||||||
albumListType, size,
|
|
||||||
offset, musicFolderId, context
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
currentDirectoryIsSortable = sortableCollection(albumListType)
|
|
||||||
albumList.postValue(musicDirectory)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Util.getShouldUseId3Tags(context)) {
|
||||||
|
musicDirectory = service.getAlbumList2(
|
||||||
|
albumListType, size,
|
||||||
|
offset, musicFolderId, context
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
musicDirectory = service.getAlbumList(
|
||||||
|
albumListType, size,
|
||||||
|
offset, musicFolderId, context
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
currentDirectoryIsSortable = sortableCollection(albumListType)
|
||||||
|
albumList.postValue(musicDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user