Adopt changes from stricter nullabilities

This commit is contained in:
tzugen 2021-05-26 23:21:56 +02:00
parent b30584f99c
commit e059d737bc
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
6 changed files with 30 additions and 48 deletions

View File

@ -258,7 +258,7 @@ class TrackCollectionFragment : Fragment() {
model.getMusicFolders(refresh) model.getMusicFolders(refresh)
if (playlistId != null) { if (playlistId != null) {
setTitle(playlistName) setTitle(playlistName!!)
model.getPlaylist(playlistId, playlistName) model.getPlaylist(playlistId, playlistName)
} else if (podcastChannelId != null) { } else if (podcastChannelId != null) {
setTitle(getString(R.string.podcasts_label)) setTitle(getString(R.string.podcasts_label))
@ -282,12 +282,12 @@ class TrackCollectionFragment : Fragment() {
setTitle(name) setTitle(name)
if (!isOffline() && Util.getShouldUseId3Tags()) { if (!isOffline() && Util.getShouldUseId3Tags()) {
if (isAlbum) { if (isAlbum) {
model.getAlbum(refresh, id, name, parentId) model.getAlbum(refresh, id!!, name, parentId!!)
} else { } else {
model.getArtist(refresh, id, name) model.getArtist(refresh, id!!, name)
} }
} else { } else {
model.getMusicDirectory(refresh, id, name, parentId) model.getMusicDirectory(refresh, id!!, name, parentId!!)
} }
} }

View File

@ -43,9 +43,9 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
suspend fun getMusicDirectory( suspend fun getMusicDirectory(
refresh: Boolean, refresh: Boolean,
id: String?, id: String,
name: String?, name: String?,
parentId: String? parentId: String
) { ) {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
@ -121,7 +121,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
* TODO: This method should be moved to AlbumListModel, * TODO: This method should be moved to AlbumListModel,
* since it displays a list of albums by a specified artist. * since it displays a list of albums by a specified artist.
*/ */
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() val service = MusicServiceFactory.getMusicService()
@ -152,7 +152,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
} }
} }
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) {
@ -210,9 +210,9 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
val musicDirectory: MusicDirectory val musicDirectory: MusicDirectory
if (Util.getShouldUseId3Tags()) { if (Util.getShouldUseId3Tags()) {
musicDirectory = Util.getSongsFromSearchResult(service.starred2) musicDirectory = Util.getSongsFromSearchResult(service.getStarred2())
} else { } else {
musicDirectory = Util.getSongsFromSearchResult(service.starred) musicDirectory = Util.getSongsFromSearchResult(service.getStarred())
} }
currentDirectory.postValue(musicDirectory) currentDirectory.postValue(musicDirectory)
@ -239,7 +239,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
} }
} }
suspend fun getPlaylist(playlistId: String, playlistName: String?) { suspend fun getPlaylist(playlistId: String, playlistName: String) {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
val service = MusicServiceFactory.getMusicService() val service = MusicServiceFactory.getMusicService()

View File

@ -429,10 +429,7 @@ class MediaPlayerController(
get() { get() {
try { try {
val username = activeServerProvider.getActiveServer().userName val username = activeServerProvider.getActiveServer().userName
val (_, _, _, _, _, _, _, _, _, _, _, _, jukeboxRole) = getMusicService().getUser( return getMusicService().getUser(username).jukeboxRole
username
)
return jukeboxRole
} catch (e: Exception) { } catch (e: Exception) {
Timber.w(e, "Error getting user information") Timber.w(e, "Error getting user information")
} }

View File

@ -1,20 +1,8 @@
/* /*
This file is part of Subsonic. * RestMusicService.kt
* Copyright (C) 2009-2021 Ultrasonic developers
Subsonic is free software: you can redistribute it and/or modify *
it under the terms of the GNU General Public License as published by * Distributed under terms of the GNU GPLv3 license.
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Subsonic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2009 (C) Sindre Mehus
*/ */
package org.moire.ultrasonic.service package org.moire.ultrasonic.service
@ -64,7 +52,6 @@ import timber.log.Timber
/** /**
* This Music Service implementation connects to a server using the Subsonic REST API * This Music Service implementation connects to a server using the Subsonic REST API
* @author Sindre Mehus
*/ */
open class RESTMusicService( open class RESTMusicService(
private val subsonicAPIClient: SubsonicAPIClient, private val subsonicAPIClient: SubsonicAPIClient,
@ -109,7 +96,7 @@ open class RESTMusicService(
override fun getIndexes( override fun getIndexes(
musicFolderId: String?, musicFolderId: String?,
refresh: Boolean refresh: Boolean
): Indexes? { ): Indexes {
val indexName = INDEXES_STORAGE_NAME + (musicFolderId ?: "") val indexName = INDEXES_STORAGE_NAME + (musicFolderId ?: "")
val cachedIndexes = fileStorage.load(indexName, getIndexesSerializer()) val cachedIndexes = fileStorage.load(indexName, getIndexesSerializer())
@ -171,7 +158,7 @@ open class RESTMusicService(
id: String, id: String,
name: String?, name: String?,
refresh: Boolean refresh: Boolean
): MusicDirectory? { ): MusicDirectory {
val response = responseChecker.callWithResponseCheck { api -> val response = responseChecker.callWithResponseCheck { api ->
api.getMusicDirectory(id).execute() api.getMusicDirectory(id).execute()
} }
@ -268,7 +255,7 @@ open class RESTMusicService(
@Throws(Exception::class) @Throws(Exception::class)
override fun getPlaylist( override fun getPlaylist(
id: String, id: String,
name: String? name: String
): MusicDirectory { ): MusicDirectory {
val response = responseChecker.callWithResponseCheck { api -> val response = responseChecker.callWithResponseCheck { api ->
api.getPlaylist(id).execute() api.getPlaylist(id).execute()
@ -282,7 +269,7 @@ open class RESTMusicService(
@Throws(IOException::class) @Throws(IOException::class)
private fun savePlaylist( private fun savePlaylist(
name: String?, name: String,
playlist: MusicDirectory playlist: MusicDirectory
) { ) {
val playlistFile = FileUtil.getPlaylistFile( val playlistFile = FileUtil.getPlaylistFile(
@ -326,16 +313,14 @@ open class RESTMusicService(
@Throws(Exception::class) @Throws(Exception::class)
override fun createPlaylist( override fun createPlaylist(
id: String?, id: String,
name: String?, name: String,
entries: List<MusicDirectory.Entry> entries: List<MusicDirectory.Entry>
) { ) {
val pSongIds: MutableList<String> = ArrayList(entries.size) val pSongIds: MutableList<String> = ArrayList(entries.size)
for ((id1) in entries) { for ((id1) in entries) {
if (id1 != null) { pSongIds.add(id1)
pSongIds.add(id1)
}
} }
responseChecker.callWithResponseCheck { api -> responseChecker.callWithResponseCheck { api ->
api.createPlaylist(id, name, pSongIds.toList()).execute() api.createPlaylist(id, name, pSongIds.toList()).execute()
@ -400,8 +385,8 @@ open class RESTMusicService(
@Throws(Exception::class) @Throws(Exception::class)
override fun getLyrics( override fun getLyrics(
artist: String?, artist: String,
title: String? title: String
): Lyrics { ): Lyrics {
val response = responseChecker.callWithResponseCheck { api -> val response = responseChecker.callWithResponseCheck { api ->
api.getLyrics(artist, title).execute() api.getLyrics(artist, title).execute()
@ -587,7 +572,7 @@ open class RESTMusicService(
): Pair<InputStream, Boolean> { ): Pair<InputStream, Boolean> {
val songOffset = if (offset < 0) 0 else offset val songOffset = if (offset < 0) 0 else offset
val response = subsonicAPIClient.stream(song.id!!, maxBitrate, songOffset) val response = subsonicAPIClient.stream(song.id, maxBitrate, songOffset)
checkStreamResponseError(response) checkStreamResponseError(response)
if (response.stream == null) { if (response.stream == null) {
@ -704,7 +689,7 @@ open class RESTMusicService(
@Throws(Exception::class) @Throws(Exception::class)
override fun getGenres( override fun getGenres(
refresh: Boolean refresh: Boolean
): List<Genre> { ): List<Genre>? {
val response = responseChecker.callWithResponseCheck { api -> api.getGenres().execute() } val response = responseChecker.callWithResponseCheck { api -> api.getGenres().execute() }
return response.body()!!.genresList.toDomainEntityList() return response.body()!!.genresList.toDomainEntityList()

View File

@ -226,7 +226,7 @@ class DownloadHandler(
} }
} }
} else { } else {
root = musicService.getPlaylist(id, name) root = musicService.getPlaylist(id, name!!)
} }
getSongsRecursively(root, songs) getSongsRecursively(root, songs)
} }

View File

@ -68,9 +68,9 @@ class ShareHandler(val context: Context) {
) { ) {
@Throws(Throwable::class) @Throws(Throwable::class)
override fun doInBackground(): Share { override fun doInBackground(): Share {
val ids: MutableList<String?> = ArrayList() val ids: MutableList<String> = ArrayList()
if (shareDetails.Entries.isEmpty()) { if (shareDetails.Entries.isEmpty()) {
ids.add(fragment.arguments?.getString(Constants.INTENT_EXTRA_NAME_ID)) fragment.arguments?.getString(Constants.INTENT_EXTRA_NAME_ID)?.let { ids.add(it) }
} else { } else {
for ((id) in shareDetails.Entries) { for ((id) in shareDetails.Entries) {
ids.add(id) ids.add(id)