Merge pull request #455 from tzugen/patch-further

Followup #437
This commit is contained in:
Nite 2021-05-07 09:36:30 +02:00 committed by GitHub
commit 7dcc5bbf13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 151 additions and 171 deletions

View File

@ -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
) )

View File

@ -54,7 +54,7 @@ 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) val service = MusicServiceFactory.getMusicService(context)
var root = MusicDirectory() var root = MusicDirectory()
@ -99,7 +99,6 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
currentDirectory.postValue(root) currentDirectory.postValue(root)
} }
} }
}
// Given a Music directory "songs" it recursively adds all children to "songs" // Given a Music directory "songs" it recursively adds all children to "songs"
private fun getSongsRecursively( private fun getSongsRecursively(
@ -128,7 +127,6 @@ 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()
@ -157,12 +155,10 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
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)
@ -200,22 +196,18 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
currentDirectory.postValue(musicDirectory) 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
@ -230,23 +222,19 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
currentDirectory.postValue(musicDirectory) currentDirectory.postValue(musicDirectory)
} }
} }
}
suspend fun getVideos(refresh: Boolean) { suspend fun getVideos(refresh: Boolean) {
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)
@ -254,35 +242,29 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
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()
@ -299,7 +281,6 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
currentDirectory.postValue(musicDirectory) currentDirectory.postValue(musicDirectory)
} }
} }
}
suspend fun getAlbumList(albumListType: String, size: Int, offset: Int) { suspend fun getAlbumList(albumListType: String, size: Int, offset: Int) {
@ -311,7 +292,6 @@ 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) {
@ -336,7 +316,6 @@ class SelectAlbumModel(application: Application) : AndroidViewModel(application)
albumList.postValue(musicDirectory) albumList.postValue(musicDirectory)
} }
} }
}
private fun sortableCollection(albumListType: String): Boolean { private fun sortableCollection(albumListType: String): Boolean {
return albumListType != "newest" && albumListType != "random" && return albumListType != "newest" && albumListType != "random" &&