diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..3f25798e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,2 @@ +[*.{kt,kts}] +ktlint_code_style = android_studio \ No newline at end of file diff --git a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/Album.kt b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/Album.kt index 28af9da0..b581d6a9 100644 --- a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/Album.kt +++ b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/Album.kt @@ -31,7 +31,7 @@ data class Album( override var genre: String? = null, override var starred: Boolean = false, override var path: String? = null, - override var closeness: Int = 0, + override var closeness: Int = 0 ) : MusicDirectory.Child() { override var isDirectory = true override var isVideo = false diff --git a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/MusicDirectory.kt b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/MusicDirectory.kt index 23ba8663..852694e6 100644 --- a/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/MusicDirectory.kt +++ b/core/domain/src/main/kotlin/org/moire/ultrasonic/domain/MusicDirectory.kt @@ -13,10 +13,7 @@ class MusicDirectory : ArrayList() { var name: String? = null @JvmOverloads - fun getChildren( - includeDirs: Boolean = true, - includeFiles: Boolean = true - ): List { + fun getChildren(includeDirs: Boolean = true, includeFiles: Boolean = true): List { if (includeDirs && includeFiles) { return toList() } diff --git a/core/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIClientTest.kt b/core/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIClientTest.kt index 8fcacecb..8ec08853 100644 --- a/core/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIClientTest.kt +++ b/core/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIClientTest.kt @@ -8,7 +8,8 @@ import org.moire.ultrasonic.api.subsonic.rules.MockWebServerRule * Base class for integration tests for [SubsonicAPIClient] class. */ abstract class SubsonicAPIClientTest { - @JvmField @Rule val mockWebServerRule = MockWebServerRule() + @JvmField @Rule + val mockWebServerRule = MockWebServerRule() protected lateinit var config: SubsonicClientConfiguration protected lateinit var client: SubsonicAPIClient diff --git a/core/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/BaseInterceptorTest.kt b/core/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/BaseInterceptorTest.kt index 81cc2833..d1eef5cb 100644 --- a/core/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/BaseInterceptorTest.kt +++ b/core/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/BaseInterceptorTest.kt @@ -11,7 +11,8 @@ import org.moire.ultrasonic.api.subsonic.rules.MockWebServerRule * Base class for testing [okhttp3.Interceptor] implementations. */ abstract class BaseInterceptorTest { - @Rule @JvmField val mockWebServerRule = MockWebServerRule() + @Rule @JvmField + val mockWebServerRule = MockWebServerRule() lateinit var client: OkHttpClient diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt index 732de75d..8bd3488f 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/ApiVersionCheckWrapper.kt @@ -92,7 +92,13 @@ internal class ApiVersionCheckWrapper( checkVersion(V1_4_0) checkParamVersion(musicFolderId, V1_12_0) return api.search2( - query, artistCount, artistOffset, albumCount, albumOffset, songCount, musicFolderId + query, + artistCount, + artistOffset, + albumCount, + albumOffset, + songCount, + musicFolderId ) } @@ -108,7 +114,13 @@ internal class ApiVersionCheckWrapper( checkVersion(V1_8_0) checkParamVersion(musicFolderId, V1_12_0) return api.search3( - query, artistCount, artistOffset, albumCount, albumOffset, songCount, musicFolderId + query, + artistCount, + artistOffset, + albumCount, + albumOffset, + songCount, + musicFolderId ) } @@ -228,7 +240,13 @@ internal class ApiVersionCheckWrapper( checkParamVersion(estimateContentLength, V1_8_0) checkParamVersion(converted, V1_14_0) return api.stream( - id, maxBitRate, format, timeOffset, videoSize, estimateContentLength, converted + id, + maxBitRate, + format, + timeOffset, + videoSize, + estimateContentLength, + converted ) } @@ -335,8 +353,9 @@ internal class ApiVersionCheckWrapper( private fun checkVersion(expectedVersion: SubsonicAPIVersions) { // If it is true, it is probably the first call with this server if (!isRealProtocolVersion) return - if (currentApiVersion < expectedVersion) + if (currentApiVersion < expectedVersion) { throw ApiNotSupportedException(currentApiVersion) + } } private fun checkParamVersion(param: Any?, expectedVersion: SubsonicAPIVersions) { diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt index c6a7559a..15294079 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt @@ -90,10 +90,7 @@ interface SubsonicAPIDefinition { ): Call @GET("setRating.view") - fun setRating( - @Query("id") id: String, - @Query("rating") rating: Int - ): Call + fun setRating(@Query("id") id: String, @Query("rating") rating: Int): Call @GET("getArtist.view") fun getArtist(@Query("id") id: String): Call @@ -158,8 +155,7 @@ interface SubsonicAPIDefinition { @Query("public") public: Boolean? = null, @Query("songIdToAdd") songIdsToAdd: List? = null, @Query("songIndexToRemove") songIndexesToRemove: List? = null - ): - Call + ): Call @GET("getPodcasts.view") fun getPodcasts( @@ -227,10 +223,7 @@ interface SubsonicAPIDefinition { @Streaming @GET("getCoverArt.view") - fun getCoverArt( - @Query("id") id: String, - @Query("size") size: Long? = null - ): Call + fun getCoverArt(@Query("id") id: String, @Query("size") size: Long? = null): Call @Streaming @GET("stream.view") diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIVersions.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIVersions.kt index 1b7e6a66..a5e902e7 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIVersions.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIVersions.kt @@ -29,10 +29,12 @@ enum class SubsonicAPIVersions(val subsonicVersions: String, val restApiVersion: V1_13_0("5.3", "1.13.0"), V1_14_0("6.0", "1.14.0"), V1_15_0("6.1", "1.15.0"), - V1_16_0("6.1.2", "1.16.0"); + V1_16_0("6.1.2", "1.16.0") + ; companion object { - @JvmStatic @Throws(IllegalArgumentException::class) + @JvmStatic + @Throws(IllegalArgumentException::class) fun getClosestKnownClientApiVersion(apiVersion: String): SubsonicAPIVersions { val versionComponents = apiVersion.split(".") @@ -41,8 +43,11 @@ enum class SubsonicAPIVersions(val subsonicVersions: String, val restApiVersion: try { val majorVersion = versionComponents[0].toInt() val minorVersion = versionComponents[1].toInt() - val patchVersion = if (versionComponents.size > 2) versionComponents[2].toInt() - else 0 + val patchVersion = if (versionComponents.size > 2) { + versionComponents[2].toInt() + } else { + 0 + } when (majorVersion) { 1 -> when { diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/VersionAwareJacksonConverterFactory.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/VersionAwareJacksonConverterFactory.kt index b5c73e64..f68771b8 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/VersionAwareJacksonConverterFactory.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/VersionAwareJacksonConverterFactory.kt @@ -48,7 +48,10 @@ class VersionAwareJacksonConverterFactory( retrofit: Retrofit ): Converter<*, RequestBody>? { return jacksonConverterFactory?.requestBodyConverter( - type, parameterAnnotations, methodAnnotations, retrofit + type, + parameterAnnotations, + methodAnnotations, + retrofit ) } @@ -63,7 +66,7 @@ class VersionAwareJacksonConverterFactory( } } - class VersionAwareResponseBodyConverter ( + class VersionAwareResponseBodyConverter( private val notifier: (SubsonicAPIVersions) -> Unit = {}, private val adapter: ObjectReader ) : Converter { diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/RangeHeaderInterceptor.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/RangeHeaderInterceptor.kt index 1bdb0153..08311d04 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/RangeHeaderInterceptor.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/RangeHeaderInterceptor.kt @@ -6,6 +6,7 @@ import okhttp3.Interceptor.Chain import okhttp3.Response internal const val SOCKET_READ_TIMEOUT_DOWNLOAD = 30 * 1000 + // Allow 20 seconds extra timeout pear MB offset. internal const val TIMEOUT_MILLIS_PER_OFFSET_BYTE = 0.02 diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/AlbumListType.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/AlbumListType.kt index f30f389b..8d2b6069 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/AlbumListType.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/AlbumListType.kt @@ -23,7 +23,8 @@ enum class AlbumListType(val typeName: String) { SORTED_BY_ARTIST("alphabeticalByArtist"), STARRED("starred"), BY_YEAR("byYear"), - BY_GENRE("byGenre"); + BY_GENRE("byGenre") + ; override fun toString(): String { return typeName diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/JukeboxAction.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/JukeboxAction.kt index 19502d02..ae5415c2 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/JukeboxAction.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/models/JukeboxAction.kt @@ -16,7 +16,8 @@ enum class JukeboxAction(val action: String) { CLEAR("clear"), REMOVE("remove"), SHUFFLE("shuffle"), - SET_GAIN("setGain"); + SET_GAIN("setGain") + ; override fun toString(): String { return action diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/BookmarksResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/BookmarksResponse.kt index 5cbd8bbd..1aaaeecc 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/BookmarksResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/BookmarksResponse.kt @@ -10,7 +10,8 @@ class BookmarksResponse( version: SubsonicAPIVersions, error: SubsonicError? ) : SubsonicResponse(status, version, error) { - @JsonProperty("bookmarks") private val bookmarksWrapper = BookmarkWrapper() + @JsonProperty("bookmarks") + private val bookmarksWrapper = BookmarkWrapper() val bookmarkList: List get() = bookmarksWrapper.bookmarkList } diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/ChatMessagesResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/ChatMessagesResponse.kt index 71055616..bfdbce59 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/ChatMessagesResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/ChatMessagesResponse.kt @@ -10,7 +10,8 @@ class ChatMessagesResponse( version: SubsonicAPIVersions, error: SubsonicError? ) : SubsonicResponse(status, version, error) { - @JsonProperty("chatMessages") private val wrapper = ChatMessagesWrapper() + @JsonProperty("chatMessages") + private val wrapper = ChatMessagesWrapper() val chatMessages: List get() = wrapper.messagesList } diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GenresResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GenresResponse.kt index 85fbb35c..1108f2ec 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GenresResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GenresResponse.kt @@ -10,7 +10,8 @@ class GenresResponse( version: SubsonicAPIVersions, error: SubsonicError? ) : SubsonicResponse(status, version, error) { - @JsonProperty("genres") private val genresWrapper = GenresWrapper() + @JsonProperty("genres") + private val genresWrapper = GenresWrapper() val genresList: List get() = genresWrapper.genresList } diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetAlbumList2Response.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetAlbumList2Response.kt index 264ba727..3d6f23de 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetAlbumList2Response.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetAlbumList2Response.kt @@ -11,7 +11,8 @@ class GetAlbumList2Response( version: SubsonicAPIVersions, error: SubsonicError? ) : SubsonicResponse(status, version, error) { - @JsonProperty("albumList2") private val albumWrapper2 = AlbumWrapper2() + @JsonProperty("albumList2") + private val albumWrapper2 = AlbumWrapper2() val albumList: List get() = albumWrapper2.albumList diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetAlbumListResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetAlbumListResponse.kt index 81c6be5b..79212a4c 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetAlbumListResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetAlbumListResponse.kt @@ -10,7 +10,8 @@ class GetAlbumListResponse( version: SubsonicAPIVersions, error: SubsonicError? ) : SubsonicResponse(status, version, error) { - @JsonProperty("albumList") private val albumWrapper = AlbumWrapper() + @JsonProperty("albumList") + private val albumWrapper = AlbumWrapper() val albumList: List get() = albumWrapper.albumList diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetPodcastsResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetPodcastsResponse.kt index 3fa0fd1d..83a357f4 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetPodcastsResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetPodcastsResponse.kt @@ -10,7 +10,8 @@ class GetPodcastsResponse( version: SubsonicAPIVersions, error: SubsonicError? ) : SubsonicResponse(status, version, error) { - @JsonProperty("podcasts") private val channelsWrapper = PodcastChannelWrapper() + @JsonProperty("podcasts") + private val channelsWrapper = PodcastChannelWrapper() val podcastChannels: List get() = channelsWrapper.channelsList diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetRandomSongsResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetRandomSongsResponse.kt index c987db12..a5215a58 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetRandomSongsResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetRandomSongsResponse.kt @@ -10,7 +10,8 @@ class GetRandomSongsResponse( version: SubsonicAPIVersions, error: SubsonicError? ) : SubsonicResponse(status, version, error) { - @JsonProperty("randomSongs") private val songsWrapper = RandomSongsWrapper() + @JsonProperty("randomSongs") + private val songsWrapper = RandomSongsWrapper() val songsList get() = songsWrapper.songsList diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetSongsByGenreResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetSongsByGenreResponse.kt index 61b8274f..bc9d7e88 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetSongsByGenreResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/GetSongsByGenreResponse.kt @@ -10,7 +10,8 @@ class GetSongsByGenreResponse( version: SubsonicAPIVersions, error: SubsonicError? ) : SubsonicResponse(status, version, error) { - @JsonProperty("songsByGenre") private val songsByGenreList = SongsByGenreWrapper() + @JsonProperty("songsByGenre") + private val songsByGenreList = SongsByGenreWrapper() val songsList get() = songsByGenreList.songsList } diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/JukeboxResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/JukeboxResponse.kt index eb936ef5..6a909246 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/JukeboxResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/JukeboxResponse.kt @@ -11,11 +11,13 @@ class JukeboxResponse( error: SubsonicError?, var jukebox: JukeboxStatus = JukeboxStatus() ) : SubsonicResponse(status, version, error) { - @JsonSetter("jukeboxStatus") fun setJukeboxStatus(jukebox: JukeboxStatus) { + @JsonSetter("jukeboxStatus") + fun setJukeboxStatus(jukebox: JukeboxStatus) { this.jukebox = jukebox } - @JsonSetter("jukeboxPlaylist") fun setJukeboxPlaylist(jukebox: JukeboxStatus) { + @JsonSetter("jukeboxPlaylist") + fun setJukeboxPlaylist(jukebox: JukeboxStatus) { this.jukebox = jukebox } } diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/MusicFoldersResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/MusicFoldersResponse.kt index 1cd6edcc..d8989a7f 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/MusicFoldersResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/MusicFoldersResponse.kt @@ -10,7 +10,8 @@ class MusicFoldersResponse( version: SubsonicAPIVersions, error: SubsonicError? ) : SubsonicResponse(status, version, error) { - @JsonProperty("musicFolders") private val wrapper = MusicFoldersWrapper() + @JsonProperty("musicFolders") + private val wrapper = MusicFoldersWrapper() val musicFolders get() = wrapper.musicFolders } diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/SharesResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/SharesResponse.kt index a57d8b23..c457e8ed 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/SharesResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/SharesResponse.kt @@ -10,7 +10,8 @@ class SharesResponse( version: SubsonicAPIVersions, error: SubsonicError? ) : SubsonicResponse(status, version, error) { - @JsonProperty("shares") private val wrappedShares = SharesWrapper() + @JsonProperty("shares") + private val wrappedShares = SharesWrapper() val shares get() = wrappedShares.share } diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/SubsonicResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/SubsonicResponse.kt index abbe64b8..7fe6fa86 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/SubsonicResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/SubsonicResponse.kt @@ -20,7 +20,8 @@ open class SubsonicResponse( ) { @JsonDeserialize(using = Status.Companion.StatusJsonDeserializer::class) enum class Status(val jsonValue: String) { - OK("ok"), ERROR("failed"); + OK("ok"), + ERROR("failed"); companion object { fun getStatusFromJson(jsonValue: String) = diff --git a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/VideosResponse.kt b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/VideosResponse.kt index e6f8d0eb..f16d1dba 100644 --- a/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/VideosResponse.kt +++ b/core/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/response/VideosResponse.kt @@ -10,7 +10,8 @@ class VideosResponse( version: SubsonicAPIVersions, error: SubsonicError? ) : SubsonicResponse(status, version, error) { - @JsonProperty("videos") private val videosWrapper = VideosWrapper() + @JsonProperty("videos") + private val videosWrapper = VideosWrapper() val videosList: List get() = videosWrapper.videosList } diff --git a/core/subsonic-api/src/test/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/ProxyPasswordInterceptorTest.kt b/core/subsonic-api/src/test/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/ProxyPasswordInterceptorTest.kt index f9fde4b4..42f8e09d 100644 --- a/core/subsonic-api/src/test/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/ProxyPasswordInterceptorTest.kt +++ b/core/subsonic-api/src/test/kotlin/org/moire/ultrasonic/api/subsonic/interceptors/ProxyPasswordInterceptorTest.kt @@ -18,7 +18,9 @@ class ProxyPasswordInterceptorTest { private val proxyInterceptor = ProxyPasswordInterceptor( V1_12_0, - mockPasswordHexInterceptor, mockPasswordMd5Interceptor, false + mockPasswordHexInterceptor, + mockPasswordMd5Interceptor, + false ) @Test @@ -40,8 +42,10 @@ class ProxyPasswordInterceptorTest { @Test fun `Should use hex password if forceHex is true`() { val interceptor = ProxyPasswordInterceptor( - V1_16_0, mockPasswordHexInterceptor, - mockPasswordMd5Interceptor, true + V1_16_0, + mockPasswordHexInterceptor, + mockPasswordMd5Interceptor, + true ) interceptor.intercept(mockChain) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d2c9153a..e4499c93 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,8 +6,8 @@ navigation = "2.7.5" gradlePlugin = "8.2.0" androidxcar = "1.2.0" androidxcore = "1.12.0" -ktlint = "0.43.2" -ktlintGradle = "11.6.1" +ktlint = "1.0.1" +ktlintGradle = "12.0.2" detekt = "1.23.4" preferences = "1.2.1" media3 = "1.1.1" diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/activity/NavigationActivity.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/activity/NavigationActivity.kt index b6b6f8e4..862e9dda 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/activity/NavigationActivity.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/activity/NavigationActivity.kt @@ -204,10 +204,11 @@ class NavigationActivity : ScopeActivity() { } rxBusSubscription += RxBus.playerStateObservable.subscribe { - if (it.state == STATE_READY) + if (it.state == STATE_READY) { showNowPlaying() - else + } else { hideNowPlaying() + } } rxBusSubscription += RxBus.themeChangedEventObservable.subscribe { @@ -314,8 +315,11 @@ class NavigationActivity : ScopeActivity() { // Lifecycle support's constructor registers some event receivers so it should be created early lifecycleSupport.onCreate() - if (!nowPlayingHidden) showNowPlaying() - else hideNowPlaying() + if (!nowPlayingHidden) { + showNowPlaying() + } else { + hideNowPlaying() + } } /* @@ -334,21 +338,24 @@ class NavigationActivity : ScopeActivity() { val activeServer = activeServerProvider.getActiveServer() - if (cachedServerCount == 0) + if (cachedServerCount == 0) { selectServerButton?.text = getString(R.string.main_setup_server, activeServer.name) - else selectServerButton?.text = activeServer.name + } else { + selectServerButton?.text = activeServer.name + } val foregroundColor = ServerColor.getForegroundColor(this, activeServer.color, showVectorBackground) val backgroundColor = ServerColor.getBackgroundColor(this, activeServer.color) - if (activeServer.index == 0) + if (activeServer.index == 0) { selectServerButton?.icon = ContextCompat.getDrawable(this, R.drawable.ic_menu_screen_on_off) - else + } else { selectServerButton?.icon = ContextCompat.getDrawable(this, R.drawable.ic_menu_select_server) + } selectServerButton?.iconTint = ColorStateList.valueOf(foregroundColor) selectServerButton?.setTextColor(foregroundColor) @@ -406,8 +413,9 @@ class NavigationActivity : ScopeActivity() { navigationView?.getHeaderView(0)?.findViewById(R.id.edit_server_button) val onClick: (View) -> Unit = { - if (drawerLayout?.isDrawerVisible(GravityCompat.START) == true) + if (drawerLayout?.isDrawerVisible(GravityCompat.START) == true) { this.drawerLayout?.closeDrawer(GravityCompat.START) + } navController.navigate(R.id.serverSelectorFragment) } @@ -473,7 +481,8 @@ class NavigationActivity : ScopeActivity() { private fun handleSearchIntent(query: String?, autoPlay: Boolean) { val suggestions = SearchRecentSuggestions( this, - SearchSuggestionProvider.AUTHORITY, SearchSuggestionProvider.MODE + SearchSuggestionProvider.AUTHORITY, + SearchSuggestionProvider.MODE ) suggestions.saveRecentQuery(query, null) @@ -528,7 +537,6 @@ class NavigationActivity : ScopeActivity() { private fun showWelcomeDialog() { if (!UApp.instance!!.setupDialogDisplayed) { - Settings.firstInstalledVersion = Util.getVersionCode(UApp.applicationContext()) InfoDialog.Builder(this) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/AlbumRowDelegate.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/AlbumRowDelegate.kt index c54cb32a..e7d79cbb 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/AlbumRowDelegate.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/AlbumRowDelegate.kt @@ -32,7 +32,7 @@ import org.moire.ultrasonic.util.LayoutType */ open class AlbumRowDelegate( open val onItemClick: (Album) -> Unit, - open val onContextMenuClick: (MenuItem, Album) -> Boolean, + open val onContextMenuClick: (MenuItem, Album) -> Boolean ) : ItemViewDelegate(), KoinComponent { private val starDrawable: Int = R.drawable.ic_star_full @@ -61,8 +61,11 @@ open class AlbumRowDelegate( val imageLoaderProvider: ImageLoaderProvider by inject() imageLoaderProvider.executeOn { it.loadImage( - holder.coverArt, item, - false, 0, R.drawable.unknown_album + holder.coverArt, + item, + false, + 0, + R.drawable.unknown_album ) } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/DividerBinder.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/DividerBinder.kt index eae411dd..160e90b7 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/DividerBinder.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/adapters/DividerBinder.kt @@ -23,10 +23,7 @@ class DividerBinder : ItemViewBinder { + DownloadState.QUEUED + -> { showIndefiniteProgress() } else -> { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/audiofx/EqualizerController.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/audiofx/EqualizerController.kt index 80b25bbc..4727202b 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/audiofx/EqualizerController.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/audiofx/EqualizerController.kt @@ -50,7 +50,8 @@ class EqualizerController : CoroutineScope by CoroutineScope(Dispatchers.IO) { launch { try { val settings = deserialize( - UApp.applicationContext(), "equalizer.dat" + UApp.applicationContext(), + "equalizer.dat" ) settings?.apply(equalizer!!) } catch (all: Throwable) { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/ActiveServerProvider.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/ActiveServerProvider.kt index 0d1d51c1..b41f630d 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/ActiveServerProvider.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/ActiveServerProvider.kt @@ -51,7 +51,8 @@ class ActiveServerProvider( } Timber.d( "getActiveServer retrieved from DataBase, id: %s cachedServer: %s", - serverId, cachedServer + serverId, + cachedServer ) } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/AppDatabase.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/AppDatabase.kt index ef23f36f..ead1205a 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/AppDatabase.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/AppDatabase.kt @@ -1,3 +1,5 @@ +@file:Suppress("ktlint:standard:max-line-length") + package org.moire.ultrasonic.data import androidx.room.Database @@ -265,21 +267,27 @@ val MIGRATION_5_4: Migration = object : Migration(5, 4) { database.execSQL("ALTER TABLE `_new_ServerSetting` RENAME TO `ServerSetting`") } } -/* ktlint-disable max-line-length */ val MIGRATION_5_6: Migration = object : Migration(5, 6) { override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE IF NOT EXISTS `_new_ServerSetting` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `index` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, `color` INTEGER, `userName` TEXT NOT NULL, `password` TEXT NOT NULL, `jukeboxByDefault` INTEGER NOT NULL, `allowSelfSignedCertificate` INTEGER NOT NULL, `forcePlainTextPassword` INTEGER NOT NULL, `musicFolderId` TEXT, `minimumApiVersion` TEXT, `chatSupport` INTEGER, `bookmarkSupport` INTEGER, `shareSupport` INTEGER, `podcastSupport` INTEGER, `jukeboxSupport` INTEGER, `videoSupport` INTEGER)") - database.execSQL("INSERT INTO `_new_ServerSetting` (`musicFolderId`,`color`,`index`,`userName`,`minimumApiVersion`,`jukeboxByDefault`,`url`,`password`,`shareSupport`,`bookmarkSupport`,`name`,`podcastSupport`,`forcePlainTextPassword`,`id`,`allowSelfSignedCertificate`,`chatSupport`) SELECT `musicFolderId`,`color`,`index`,`userName`,`minimumApiVersion`,`jukeboxByDefault`,`url`,`password`,`shareSupport`,`bookmarkSupport`,`name`,`podcastSupport`,`ldapSupport`,`id`,`allowSelfSignedCertificate`,`chatSupport` FROM `ServerSetting`") + database.execSQL( + "CREATE TABLE IF NOT EXISTS `_new_ServerSetting` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `index` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, `color` INTEGER, `userName` TEXT NOT NULL, `password` TEXT NOT NULL, `jukeboxByDefault` INTEGER NOT NULL, `allowSelfSignedCertificate` INTEGER NOT NULL, `forcePlainTextPassword` INTEGER NOT NULL, `musicFolderId` TEXT, `minimumApiVersion` TEXT, `chatSupport` INTEGER, `bookmarkSupport` INTEGER, `shareSupport` INTEGER, `podcastSupport` INTEGER, `jukeboxSupport` INTEGER, `videoSupport` INTEGER)" + ) + database.execSQL( + "INSERT INTO `_new_ServerSetting` (`musicFolderId`,`color`,`index`,`userName`,`minimumApiVersion`,`jukeboxByDefault`,`url`,`password`,`shareSupport`,`bookmarkSupport`,`name`,`podcastSupport`,`forcePlainTextPassword`,`id`,`allowSelfSignedCertificate`,`chatSupport`) SELECT `musicFolderId`,`color`,`index`,`userName`,`minimumApiVersion`,`jukeboxByDefault`,`url`,`password`,`shareSupport`,`bookmarkSupport`,`name`,`podcastSupport`,`ldapSupport`,`id`,`allowSelfSignedCertificate`,`chatSupport` FROM `ServerSetting`" + ) database.execSQL("DROP TABLE `ServerSetting`") database.execSQL("ALTER TABLE `_new_ServerSetting` RENAME TO `ServerSetting`") } } val MIGRATION_6_5: Migration = object : Migration(6, 5) { override fun migrate(database: SupportSQLiteDatabase) { - database.execSQL("CREATE TABLE IF NOT EXISTS `_new_ServerSetting` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `index` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, `color` INTEGER, `userName` TEXT NOT NULL, `password` TEXT NOT NULL, `jukeboxByDefault` INTEGER NOT NULL, `allowSelfSignedCertificate` INTEGER NOT NULL, `ldapSupport` INTEGER NOT NULL, `musicFolderId` TEXT, `minimumApiVersion` TEXT, `chatSupport` INTEGER, `bookmarkSupport` INTEGER, `shareSupport` INTEGER, `podcastSupport` INTEGER)") - database.execSQL("INSERT INTO `_new_ServerSetting` (`musicFolderId`,`color`,`index`,`userName`,`minimumApiVersion`,`jukeboxByDefault`,`url`,`password`,`shareSupport`,`bookmarkSupport`,`name`,`podcastSupport`,`ldapSupport`,`id`,`allowSelfSignedCertificate`,`chatSupport`) SELECT `musicFolderId`,`color`,`index`,`userName`,`minimumApiVersion`,`jukeboxByDefault`,`url`,`password`,`shareSupport`,`bookmarkSupport`,`name`,`podcastSupport`,`forcePlainTextPassword`,`id`,`allowSelfSignedCertificate`,`chatSupport` FROM `ServerSetting`") + database.execSQL( + "CREATE TABLE IF NOT EXISTS `_new_ServerSetting` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `index` INTEGER NOT NULL, `name` TEXT NOT NULL, `url` TEXT NOT NULL, `color` INTEGER, `userName` TEXT NOT NULL, `password` TEXT NOT NULL, `jukeboxByDefault` INTEGER NOT NULL, `allowSelfSignedCertificate` INTEGER NOT NULL, `ldapSupport` INTEGER NOT NULL, `musicFolderId` TEXT, `minimumApiVersion` TEXT, `chatSupport` INTEGER, `bookmarkSupport` INTEGER, `shareSupport` INTEGER, `podcastSupport` INTEGER)" + ) + database.execSQL( + "INSERT INTO `_new_ServerSetting` (`musicFolderId`,`color`,`index`,`userName`,`minimumApiVersion`,`jukeboxByDefault`,`url`,`password`,`shareSupport`,`bookmarkSupport`,`name`,`podcastSupport`,`ldapSupport`,`id`,`allowSelfSignedCertificate`,`chatSupport`) SELECT `musicFolderId`,`color`,`index`,`userName`,`minimumApiVersion`,`jukeboxByDefault`,`url`,`password`,`shareSupport`,`bookmarkSupport`,`name`,`podcastSupport`,`forcePlainTextPassword`,`id`,`allowSelfSignedCertificate`,`chatSupport` FROM `ServerSetting`" + ) database.execSQL("DROP TABLE `ServerSetting`") database.execSQL("ALTER TABLE `_new_ServerSetting` RENAME TO `ServerSetting`") } } -/* ktlint-enable max-line-length */ diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/CachedDataSource.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/CachedDataSource.kt index 9f67f7f2..e0f833df 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/CachedDataSource.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/CachedDataSource.kt @@ -39,9 +39,7 @@ class CachedDataSource( ) } - private fun createDataSourceInternal( - upstreamDataSource: DataSource - ): CachedDataSource { + private fun createDataSourceInternal(upstreamDataSource: DataSource): CachedDataSource { return CachedDataSource( upstreamDataSource ) @@ -93,7 +91,9 @@ class CachedDataSource( readInternal(buffer, offset, length) } catch (e: IOException) { throw HttpDataSourceException.createForIOException( - e, Util.castNonNull(dataSpec), HttpDataSourceException.TYPE_READ + e, + Util.castNonNull(dataSpec), + HttpDataSourceException.TYPE_READ ) } } else { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/MetaDatabase.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/MetaDatabase.kt index 3ecbe54d..daf50d4c 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/MetaDatabase.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/data/MetaDatabase.kt @@ -5,6 +5,8 @@ * Distributed under terms of the GNU GPLv3 license. */ +@file:Suppress("ktlint:standard:max-line-length") + package org.moire.ultrasonic.data import androidx.room.AutoMigration @@ -37,7 +39,7 @@ import org.moire.ultrasonic.domain.Track AutoMigration( from = 1, to = 2 - ), + ) ], exportSchema = true, version = 3 @@ -67,7 +69,6 @@ class Converters { } } -/* ktlint-disable max-line-length */ val META_MIGRATION_2_3: Migration = object : Migration(2, 3) { override fun migrate(database: SupportSQLiteDatabase) { database.execSQL("DROP TABLE `albums`") @@ -75,11 +76,20 @@ val META_MIGRATION_2_3: Migration = object : Migration(2, 3) { database.execSQL("DROP TABLE `artists`") database.execSQL("DROP TABLE `tracks`") database.execSQL("DROP TABLE `music_folders`") - database.execSQL("CREATE TABLE IF NOT EXISTS `albums` (`id` TEXT NOT NULL, `serverId` INTEGER NOT NULL DEFAULT -1, `parent` TEXT, `album` TEXT, `title` TEXT, `name` TEXT, `discNumber` INTEGER, `coverArt` TEXT, `songCount` INTEGER, `created` INTEGER, `artist` TEXT, `artistId` TEXT, `duration` INTEGER, `year` INTEGER, `genre` TEXT, `starred` INTEGER NOT NULL, `path` TEXT, `closeness` INTEGER NOT NULL, `isDirectory` INTEGER NOT NULL, `isVideo` INTEGER NOT NULL, PRIMARY KEY(`id`, `serverId`))") - database.execSQL("CREATE TABLE IF NOT EXISTS `indexes` (`id` TEXT NOT NULL, `serverId` INTEGER NOT NULL DEFAULT -1, `name` TEXT, `index` TEXT, `coverArt` TEXT, `albumCount` INTEGER, `closeness` INTEGER NOT NULL, `musicFolderId` TEXT, PRIMARY KEY(`id`, `serverId`))") - database.execSQL("CREATE TABLE IF NOT EXISTS `artists` (`id` TEXT NOT NULL, `serverId` INTEGER NOT NULL DEFAULT -1, `name` TEXT, `index` TEXT, `coverArt` TEXT, `albumCount` INTEGER, `closeness` INTEGER NOT NULL, PRIMARY KEY(`id`, `serverId`))") - database.execSQL("CREATE TABLE IF NOT EXISTS `music_folders` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `serverId` INTEGER NOT NULL DEFAULT -1, PRIMARY KEY(`id`, `serverId`))") - database.execSQL("CREATE TABLE IF NOT EXISTS `tracks` (`id` TEXT NOT NULL, `serverId` INTEGER NOT NULL DEFAULT -1, `parent` TEXT, `isDirectory` INTEGER NOT NULL, `title` TEXT, `album` TEXT, `albumId` TEXT, `artist` TEXT, `artistId` TEXT, `track` INTEGER, `year` INTEGER, `genre` TEXT, `contentType` TEXT, `suffix` TEXT, `transcodedContentType` TEXT, `transcodedSuffix` TEXT, `coverArt` TEXT, `size` INTEGER, `songCount` INTEGER, `duration` INTEGER, `bitRate` INTEGER, `path` TEXT, `isVideo` INTEGER NOT NULL, `starred` INTEGER NOT NULL, `discNumber` INTEGER, `type` TEXT, `created` INTEGER, `closeness` INTEGER NOT NULL, `bookmarkPosition` INTEGER NOT NULL, `userRating` INTEGER, `averageRating` REAL, `name` TEXT, PRIMARY KEY(`id`, `serverId`))") + database.execSQL( + "CREATE TABLE IF NOT EXISTS `albums` (`id` TEXT NOT NULL, `serverId` INTEGER NOT NULL DEFAULT -1, `parent` TEXT, `album` TEXT, `title` TEXT, `name` TEXT, `discNumber` INTEGER, `coverArt` TEXT, `songCount` INTEGER, `created` INTEGER, `artist` TEXT, `artistId` TEXT, `duration` INTEGER, `year` INTEGER, `genre` TEXT, `starred` INTEGER NOT NULL, `path` TEXT, `closeness` INTEGER NOT NULL, `isDirectory` INTEGER NOT NULL, `isVideo` INTEGER NOT NULL, PRIMARY KEY(`id`, `serverId`))" + ) + database.execSQL( + "CREATE TABLE IF NOT EXISTS `indexes` (`id` TEXT NOT NULL, `serverId` INTEGER NOT NULL DEFAULT -1, `name` TEXT, `index` TEXT, `coverArt` TEXT, `albumCount` INTEGER, `closeness` INTEGER NOT NULL, `musicFolderId` TEXT, PRIMARY KEY(`id`, `serverId`))" + ) + database.execSQL( + "CREATE TABLE IF NOT EXISTS `artists` (`id` TEXT NOT NULL, `serverId` INTEGER NOT NULL DEFAULT -1, `name` TEXT, `index` TEXT, `coverArt` TEXT, `albumCount` INTEGER, `closeness` INTEGER NOT NULL, PRIMARY KEY(`id`, `serverId`))" + ) + database.execSQL( + "CREATE TABLE IF NOT EXISTS `music_folders` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `serverId` INTEGER NOT NULL DEFAULT -1, PRIMARY KEY(`id`, `serverId`))" + ) + database.execSQL( + "CREATE TABLE IF NOT EXISTS `tracks` (`id` TEXT NOT NULL, `serverId` INTEGER NOT NULL DEFAULT -1, `parent` TEXT, `isDirectory` INTEGER NOT NULL, `title` TEXT, `album` TEXT, `albumId` TEXT, `artist` TEXT, `artistId` TEXT, `track` INTEGER, `year` INTEGER, `genre` TEXT, `contentType` TEXT, `suffix` TEXT, `transcodedContentType` TEXT, `transcodedSuffix` TEXT, `coverArt` TEXT, `size` INTEGER, `songCount` INTEGER, `duration` INTEGER, `bitRate` INTEGER, `path` TEXT, `isVideo` INTEGER NOT NULL, `starred` INTEGER NOT NULL, `discNumber` INTEGER, `type` TEXT, `created` INTEGER, `closeness` INTEGER NOT NULL, `bookmarkPosition` INTEGER NOT NULL, `userRating` INTEGER, `averageRating` REAL, `name` TEXT, PRIMARY KEY(`id`, `serverId`))" + ) } } -/* ktlint-enable max-line-length */ diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/di/MusicServiceModule.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/di/MusicServiceModule.kt index 6f723c89..ce88f983 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/di/MusicServiceModule.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/di/MusicServiceModule.kt @@ -1,4 +1,5 @@ @file:JvmName("MusicServiceModule") + package org.moire.ultrasonic.di import kotlin.math.abs diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIAlbumConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIAlbumConverter.kt index a0754803..b22096a2 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIAlbumConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIAlbumConverter.kt @@ -8,6 +8,7 @@ // Converts Album entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient] // to app domain entities. @file:JvmName("APIAlbumConverter") + package org.moire.ultrasonic.domain import org.moire.ultrasonic.api.subsonic.models.Album diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIArtistConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIArtistConverter.kt index 497eae75..073a32f1 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIArtistConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIArtistConverter.kt @@ -8,6 +8,7 @@ // Converts Artist entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient] // to app domain entities. @file:JvmName("APIArtistConverter") + package org.moire.ultrasonic.domain import org.moire.ultrasonic.api.subsonic.models.Artist as APIArtist diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIChatMessageConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIChatMessageConverter.kt index edd8f51f..fa35cc02 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIChatMessageConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIChatMessageConverter.kt @@ -1,5 +1,6 @@ // Contains helper functions to convert from api ChatMessage entity to domain entity @file:JvmName("APIChatMessageConverter") + package org.moire.ultrasonic.domain import org.moire.ultrasonic.api.subsonic.models.ChatMessage as ApiChatMessage diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIGenreConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIGenreConverter.kt index 1cd23f60..968567bd 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIGenreConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIGenreConverter.kt @@ -1,5 +1,6 @@ // Collection of functions to convert api Genre entity to domain entity @file:JvmName("ApiGenreConverter") + package org.moire.ultrasonic.domain import org.moire.ultrasonic.api.subsonic.models.Genre as APIGenre diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIJukeboxCoverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIJukeboxCoverter.kt index 23f22a4f..0e8373b9 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIJukeboxCoverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIJukeboxCoverter.kt @@ -1,5 +1,6 @@ // Collection of function to convert subsonic api jukebox responses to app entities @file:JvmName("APIJukeboxConverter") + package org.moire.ultrasonic.domain import org.moire.ultrasonic.api.subsonic.models.JukeboxStatus as ApiJukeboxStatus diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APILyricsConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APILyricsConverter.kt index 2bebc6bb..4e449760 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APILyricsConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APILyricsConverter.kt @@ -1,6 +1,7 @@ // Converts Lyrics entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient] // to app domain entities. @file:JvmName("APILyricsConverter") + package org.moire.ultrasonic.domain import org.moire.ultrasonic.api.subsonic.models.Lyrics as APILyrics diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIMusicDirectoryConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIMusicDirectoryConverter.kt index 9d800369..0cafa7bf 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIMusicDirectoryConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIMusicDirectoryConverter.kt @@ -6,6 +6,7 @@ */ @file:JvmName("APIMusicDirectoryConverter") + package org.moire.ultrasonic.domain import java.text.DateFormat @@ -35,10 +36,7 @@ fun MusicDirectoryChild.toAlbumEntity(serverId: Int): Album = Album(id, serverId populateCommonProps(this, this@toAlbumEntity) } -private fun populateCommonProps( - entry: MusicDirectory.Child, - source: MusicDirectoryChild -) { +private fun populateCommonProps(entry: MusicDirectory.Child, source: MusicDirectoryChild) { entry.parent = source.parent entry.isDirectory = source.isDir entry.title = source.title @@ -63,10 +61,7 @@ private fun populateCommonProps( } } -private fun populateTrackProps( - track: Track, - source: MusicDirectoryChild -) { +private fun populateTrackProps(track: Track, source: MusicDirectoryChild) { track.size = source.size track.contentType = source.contentType track.suffix = source.suffix @@ -84,10 +79,11 @@ fun List.toDomainEntityList(serverId: Int): List = mutableListOf() forEach { - if (it.isDir) + if (it.isDir) { newList.add(it.toAlbumEntity(serverId)) - else + } else { newList.add(it.toTrackEntity(serverId)) + } } return newList diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIMusicFolderConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIMusicFolderConverter.kt index e0cbd6f9..39fb3e3d 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIMusicFolderConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIMusicFolderConverter.kt @@ -8,6 +8,7 @@ // Converts MusicFolder entity from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient] // to app domain entities. @file:JvmName("APIMusicFolderConverter") + package org.moire.ultrasonic.domain import org.moire.ultrasonic.api.subsonic.models.MusicFolder as APIMusicFolder @@ -18,9 +19,8 @@ fun APIMusicFolder.toDomainEntity(serverId: Int): MusicFolder = MusicFolder( name = this.name ) -fun List.toDomainEntityList(serverId: Int): List = - this.map { - val item = it.toDomainEntity(serverId) - item.serverId = serverId - item - } +fun List.toDomainEntityList(serverId: Int): List = this.map { + val item = it.toDomainEntity(serverId) + item.serverId = serverId + item +} diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIPlaylistConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIPlaylistConverter.kt index 3be0e3f1..d2c63f31 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIPlaylistConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIPlaylistConverter.kt @@ -31,8 +31,11 @@ fun APIPlaylist.toMusicDirectoryDomainEntity(serverId: Int): MusicDirectory = } fun APIPlaylist.toDomainEntity(): Playlist = Playlist( - this.id, this.name, this.owner, - this.comment, this.songCount.toString(), + this.id, + this.name, + this.owner, + this.comment, + this.songCount.toString(), this.created.ifNotNull { playlistDateFormat.format(it.time) } ?: "", public ) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIPodcastConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIPodcastConverter.kt index 3d7ee383..e0f9c2fa 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIPodcastConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIPodcastConverter.kt @@ -1,12 +1,17 @@ // Converts podcasts entities from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient] // to app domain entities. @file:JvmName("APIPodcastConverter") + package org.moire.ultrasonic.domain import org.moire.ultrasonic.api.subsonic.models.PodcastChannel fun PodcastChannel.toDomainEntity(): PodcastsChannel = PodcastsChannel( - this.id, this.title, this.url, this.description, this.status + this.id, + this.title, + this.url, + this.description, + this.status ) fun List.toDomainEntitiesList(): List = this diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APISearchConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APISearchConverter.kt index ed1af67d..1220642b 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APISearchConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APISearchConverter.kt @@ -8,6 +8,7 @@ // Converts SearchResult entities from [org.moire.ultrasonic.api.subsonic.SubsonicAPIClient] // to app domain entities. @file:JvmName("APISearchConverter") + package org.moire.ultrasonic.domain import org.moire.ultrasonic.api.subsonic.models.SearchResult as APISearchResult @@ -15,7 +16,8 @@ import org.moire.ultrasonic.api.subsonic.models.SearchThreeResult import org.moire.ultrasonic.api.subsonic.models.SearchTwoResult fun APISearchResult.toDomainEntity(serverId: Int): SearchResult = SearchResult( - emptyList(), emptyList(), + emptyList(), + emptyList(), this.matchList.map { it.toTrackEntity(serverId) } ) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIShareConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIShareConverter.kt index 7fb8a9a4..fa860231 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIShareConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIShareConverter.kt @@ -7,6 +7,7 @@ // Contains helper method to convert subsonic api share to domain model @file:JvmName("APIShareConverter") + package org.moire.ultrasonic.domain import java.text.SimpleDateFormat diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIUserConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIUserConverter.kt index 37dc53ad..7e341463 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIUserConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/domain/APIUserConverter.kt @@ -1,5 +1,6 @@ // Helper functions to convert User entity to domain entity @file:JvmName("APIUserConverter") + package org.moire.ultrasonic.domain import org.moire.ultrasonic.api.subsonic.models.User diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/AlbumListFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/AlbumListFragment.kt index 2a8c29c3..01b8348a 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/AlbumListFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/AlbumListFragment.kt @@ -65,10 +65,7 @@ class AlbumListFragment( /** * The central function to pass a query to the model and return a LiveData object */ - override fun getLiveData( - refresh: Boolean, - append: Boolean - ): LiveData> { + override fun getLiveData(refresh: Boolean, append: Boolean): LiveData> { fetchAlbums(refresh) return listModel.list diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/BookmarksFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/BookmarksFragment.kt index 7c235e5e..0a8f7180 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/BookmarksFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/BookmarksFragment.kt @@ -68,7 +68,6 @@ class BookmarksFragment : TrackCollectionFragment() { */ private fun playNow(songs: List) { if (songs.isNotEmpty()) { - mediaPlayerManager.addToPlaylist( songs = songs, autoPlay = false, diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EditServerFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EditServerFragment.kt index b50cfb67..13b700bd 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EditServerFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EditServerFragment.kt @@ -86,7 +86,8 @@ class EditServerFragment : Fragment() { override fun onAttach(context: Context) { requireActivity().onBackPressedDispatcher.addCallback( - this, confirmCloseCallback + this, + confirmCloseCallback ) super.onAttach(context) } @@ -186,7 +187,7 @@ class EditServerFragment : Fragment() { } ) .setNegativeButton(getString(R.string.common_cancel)) { - dialogInterface, _ -> + dialogInterface, _ -> dialogInterface.dismiss() } .setBottomSpace(DIALOG_PADDING) @@ -199,7 +200,8 @@ class EditServerFragment : Fragment() { } private val confirmCloseCallback = object : OnBackPressedCallback( - true // default to enabled + // default to enabled + true ) { override fun handleOnBackPressed() { finishActivity() @@ -231,35 +233,46 @@ class EditServerFragment : Fragment() { } override fun onSaveInstanceState(savedInstanceState: Bundle) { savedInstanceState.putString( - ::serverNameEditText.name, serverNameEditText!!.editText?.text.toString() + ::serverNameEditText.name, + serverNameEditText!!.editText?.text.toString() ) savedInstanceState.putString( - ::serverAddressEditText.name, serverAddressEditText!!.editText?.text.toString() + ::serverAddressEditText.name, + serverAddressEditText!!.editText?.text.toString() ) savedInstanceState.putString( - ::userNameEditText.name, userNameEditText!!.editText?.text.toString() + ::userNameEditText.name, + userNameEditText!!.editText?.text.toString() ) savedInstanceState.putString( - ::passwordEditText.name, passwordEditText!!.editText?.text.toString() + ::passwordEditText.name, + passwordEditText!!.editText?.text.toString() ) savedInstanceState.putBoolean( - ::selfSignedSwitch.name, selfSignedSwitch!!.isChecked + ::selfSignedSwitch.name, + selfSignedSwitch!!.isChecked ) savedInstanceState.putBoolean( - ::plaintextSwitch.name, plaintextSwitch!!.isChecked + ::plaintextSwitch.name, + plaintextSwitch!!.isChecked ) savedInstanceState.putBoolean( - ::jukeboxSwitch.name, jukeboxSwitch!!.isChecked + ::jukeboxSwitch.name, + jukeboxSwitch!!.isChecked ) savedInstanceState.putInt( - ::serverColorImageView.name, currentColor + ::serverColorImageView.name, + currentColor ) - if (selectedColor != null) + if (selectedColor != null) { savedInstanceState.putInt( - ::selectedColor.name, selectedColor!! + ::selectedColor.name, + selectedColor!! ) + } savedInstanceState.putBoolean( - ::isInstanceStateSaved.name, true + ::isInstanceStateSaved.name, + true ) super.onSaveInstanceState(savedInstanceState) @@ -286,8 +299,9 @@ class EditServerFragment : Fragment() { plaintextSwitch!!.isChecked = savedInstanceState.getBoolean(::plaintextSwitch.name) jukeboxSwitch!!.isChecked = savedInstanceState.getBoolean(::jukeboxSwitch.name) updateColor(savedInstanceState.getInt(::serverColorImageView.name)) - if (savedInstanceState.containsKey(::selectedColor.name)) + if (savedInstanceState.containsKey(::selectedColor.name)) { selectedColor = savedInstanceState.getInt(::selectedColor.name) + } isInstanceStateSaved = savedInstanceState.getBoolean(::isInstanceStateSaved.name) } @@ -434,7 +448,7 @@ class EditServerFragment : Fragment() { serverSetting.shareSupport, serverSetting.podcastSupport, serverSetting.videoSupport, - serverSetting.jukeboxSupport, + serverSetting.jukeboxSupport ).any { x -> x == false } var progressString = String.format( @@ -445,7 +459,7 @@ class EditServerFragment : Fragment() { |%s - ${resources.getString(R.string.button_bar_podcasts)} |%s - ${resources.getString(R.string.main_videos)} |%s - ${resources.getString(R.string.jukebox)} - """.trimMargin(), + """.trimMargin(), boolToMark(serverSetting.chatSupport), boolToMark(serverSetting.bookmarkSupport), boolToMark(serverSetting.shareSupport), @@ -453,15 +467,17 @@ class EditServerFragment : Fragment() { boolToMark(serverSetting.videoSupport), boolToMark(serverSetting.jukeboxSupport) ) - if (isAnyDisabled) + if (isAnyDisabled) { progressString += "\n\n" + resources.getString(R.string.server_editor_disabled_feature) + } return progressString } private fun boolToMark(value: Boolean?): String { - if (value == null) + if (value == null) { return "⌛" + } return if (value) "✔️" else "❌" } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EntryListFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EntryListFragment.kt index 4b1eed22..dc3ae5d2 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EntryListFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EntryListFragment.kt @@ -54,7 +54,7 @@ abstract class EntryListFragment : MultiListFragment(), Koi id = item.id, name = item.name, parentId = item.id, - isArtist = (item is Artist), + isArtist = (item is Artist) ) findNavController().navigate(action) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EqualizerFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EqualizerFragment.kt index 047ed65d..510adea2 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EqualizerFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/EqualizerFragment.kt @@ -92,7 +92,9 @@ class EqualizerFragment : Fragment() { } for (preset in 0 until equalizer!!.numberOfPresets) { val menuItem = menu.add( - MENU_GROUP_PRESET, preset, preset, + MENU_GROUP_PRESET, + preset, + preset, equalizer!!.getPresetName( preset.toShort() ) @@ -188,11 +190,7 @@ class EqualizerFragment : Fragment() { updateLevelText(levelTextView, bandLevel) bar.setOnSeekBarChangeListener(object : OnSeekBarChangeListener { - override fun onProgressChanged( - seekBar: SeekBar, - progress: Int, - fromUser: Boolean - ) { + override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { val level = (progress + minEQLevel).toShort() if (fromUser) { try { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/MainFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/MainFragment.kt index 6ef9e248..10509f70 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/MainFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/MainFragment.kt @@ -58,7 +58,6 @@ class MainFragment : ScopeFragment(), KoinScopeComponent { } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - FragmentTitle.setTitle(this, R.string.music_library_label) // Load last layout from settings @@ -133,10 +132,7 @@ class MainFragment : ScopeFragment(), KoinScopeComponent { return findFragmentAtPosition(childFragmentManager, viewPager.currentItem) } - private fun findFragmentAtPosition( - fragmentManager: FragmentManager, - position: Int - ): Fragment? { + private fun findFragmentAtPosition(fragmentManager: FragmentManager, position: Int): Fragment? { // If a fragment was recently created and never shown the fragment manager might not // hold a reference to it. Fallback on the WeakMap instead. return fragmentManager.findFragmentByTag("f$position") @@ -172,7 +168,6 @@ class MusicCollectionAdapter(fragment: Fragment, initialType: LayoutType = Layou } override fun createFragment(position: Int): Fragment { - Timber.i("Creating new fragment at position: $position") val action = when (position) { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/MultiListFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/MultiListFragment.kt index 43cc9b2a..505f1ffd 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/MultiListFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/MultiListFragment.kt @@ -96,9 +96,11 @@ abstract class MultiListFragment : ScopeFragment(), Refreshabl if (title == null) { FragmentTitle.setTitle( this, - if (listModel.isOffline()) + if (listModel.isOffline()) { R.string.music_library_label_offline - else R.string.music_library_label + } else { + R.string.music_library_label + } ) } else { FragmentTitle.setTitle(this, title) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/PlayerFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/PlayerFragment.kt index a7249b40..d9dada0a 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/PlayerFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/PlayerFragment.kt @@ -180,6 +180,7 @@ class PlayerFragment : private lateinit var fullStarDrawable: Drawable private var _binding: CurrentPlayingBinding? = null + // This property is only valid between onCreateView and // onDestroyView. private val binding get() = _binding!! @@ -333,8 +334,9 @@ class PlayerFragment : } playButton.setOnClickListener { - if (!mediaPlayerManager.isJukeboxEnabled) + if (!mediaPlayerManager.isJukeboxEnabled) { networkAndStorageChecker.warnIfNetworkOrStorageUnavailable() + } launch(CommunicationError.getHandler(context)) { mediaPlayerManager.play() @@ -637,10 +639,7 @@ class PlayerFragment : return popup } - private fun onContextMenuItemSelected( - menuItem: MenuItem, - item: MusicDirectory.Child - ): Boolean { + private fun onContextMenuItemSelected(menuItem: MenuItem, item: MusicDirectory.Child): Boolean { if (item !is Track) return false return menuItemSelected(menuItem.itemId, item) } @@ -707,8 +706,11 @@ class PlayerFragment : val jukeboxEnabled = !mediaPlayerManager.isJukeboxEnabled mediaPlayerManager.isJukeboxEnabled = jukeboxEnabled toast( - if (jukeboxEnabled) R.string.download_jukebox_on - else R.string.download_jukebox_off, + if (jukeboxEnabled) { + R.string.download_jukebox_on + } else { + R.string.download_jukebox_off + }, false ) return true @@ -783,7 +785,7 @@ class PlayerFragment : } shareHandler.createShare( this, - tracks = tracks, + tracks = tracks ) return true } @@ -792,7 +794,7 @@ class PlayerFragment : shareHandler.createShare( this, - listOf(track), + listOf(track) ) return true } @@ -876,7 +878,7 @@ class PlayerFragment : onContextMenuClick = { menu, id -> onContextMenuItemSelected(menu, id) }, checkable = false, draggable = true, - lifecycleOwner = viewLifecycleOwner, + lifecycleOwner = viewLifecycleOwner ) { view, track -> onCreateContextMenu(view, track) }.apply { this.startDrag = { holder -> dragTouchHelper.startDrag(holder) @@ -898,7 +900,6 @@ class PlayerFragment : viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder ): Boolean { - val from = viewHolder.bindingAdapterPosition val to = target.bindingAdapterPosition @@ -951,10 +952,7 @@ class PlayerFragment : mediaPlayerManager.removeFromPlaylist(pos) } - override fun onSelectedChanged( - viewHolder: RecyclerView.ViewHolder?, - actionState: Int - ) { + override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { super.onSelectedChanged(viewHolder, actionState) if (actionState == ACTION_STATE_DRAG) { @@ -1009,8 +1007,10 @@ class PlayerFragment : if (dX > 0) { canvas.clipRect( - itemView.left.toFloat(), itemView.top.toFloat(), - dX, itemView.bottom.toFloat() + itemView.left.toFloat(), + itemView.top.toFloat(), + dX, + itemView.bottom.toFloat() ) canvas.drawColor(backgroundColor) val left = itemView.left + Util.dpToPx(16, activity!!) @@ -1019,8 +1019,10 @@ class PlayerFragment : drawable?.draw(canvas) } else { canvas.clipRect( - itemView.right.toFloat() + dX, itemView.top.toFloat(), - itemView.right.toFloat(), itemView.bottom.toFloat(), + itemView.right.toFloat() + dX, + itemView.top.toFloat(), + itemView.right.toFloat(), + itemView.bottom.toFloat() ) canvas.drawColor(backgroundColor) val left = itemView.right - Util.dpToPx(16, activity!!) - iconSize @@ -1034,7 +1036,13 @@ class PlayerFragment : viewHolder.itemView.translationX = dX } else { super.onChildDraw( - canvas, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive + canvas, + recyclerView, + viewHolder, + dX, + dY, + actionState, + isCurrentlyActive ) } } @@ -1070,8 +1078,9 @@ class PlayerFragment : songTitleTextView.text = currentSong!!.title artistTextView.text = currentSong!!.artist albumTextView.text = currentSong!!.album - if (currentSong!!.year != null && Settings.showNowPlayingDetails) + if (currentSong!!.year != null && Settings.showNowPlayingDetails) { albumTextView.append(String.format(Locale.ROOT, " (%d)", currentSong!!.year)) + } if (Settings.showNowPlayingDetails) { genreTextView.text = currentSong!!.genre @@ -1079,11 +1088,12 @@ class PlayerFragment : (currentSong!!.genre != null && currentSong!!.genre!!.isNotBlank()) var bitRate = "" - if (currentSong!!.bitRate != null && currentSong!!.bitRate!! > 0) + if (currentSong!!.bitRate != null && currentSong!!.bitRate!! > 0) { bitRate = String.format( Util.appContext().getString(R.string.song_details_kbps), currentSong!!.bitRate ) + } bitrateFormatTextView.text = String.format( Locale.ROOT, "%s %s", bitRate, currentSong!!.suffix diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SearchFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SearchFragment.kt index 9074fe16..0d570ecd 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SearchFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SearchFragment.kt @@ -41,7 +41,6 @@ import org.moire.ultrasonic.subsonic.VideoPlayer.Companion.playVideo import org.moire.ultrasonic.util.ContextMenuUtil.handleContextMenu import org.moire.ultrasonic.util.ContextMenuUtil.handleContextMenuTracks import org.moire.ultrasonic.util.RefreshableFragment -import org.moire.ultrasonic.util.Settings import org.moire.ultrasonic.util.Util import org.moire.ultrasonic.util.Util.toast import org.moire.ultrasonic.util.toastingExceptionHandler @@ -143,7 +142,6 @@ class SearchFragment : MultiListFragment(), KoinScopeComponent, Re val artists = result.artists if (artists.isNotEmpty()) { - list.add(DividerBinder.Divider(R.string.search_artists)) list.addAll(artists) if (searchResult!!.artists.size > artists.size) { @@ -283,10 +281,4 @@ class SearchFragment : MultiListFragment(), KoinScopeComponent, Re ) } } - - companion object { - var DEFAULT_ARTISTS = Settings.defaultArtists - var DEFAULT_ALBUMS = Settings.defaultAlbums - var DEFAULT_SONGS = Settings.defaultSongs - } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SettingsFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SettingsFragment.kt index a67d1782..eb85b9dd 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SettingsFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/SettingsFragment.kt @@ -258,7 +258,8 @@ class SettingsFragment : val choice = intArrayOf(defaultChoice) ConfirmationDialog.Builder(requireContext()).setTitle(title) .setSingleChoiceItems( - R.array.bluetoothDeviceSettingNames, defaultChoice + R.array.bluetoothDeviceSettingNames, + defaultChoice ) { _: DialogInterface?, i: Int -> choice[0] = i } .setNegativeButton(R.string.common_cancel) { dialogInterface: DialogInterface, _: Int -> dialogInterface.cancel() diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/TrackCollectionFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/TrackCollectionFragment.kt index 7f7543f0..2e6d6bbd 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/TrackCollectionFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/TrackCollectionFragment.kt @@ -365,9 +365,7 @@ open class TrackCollectionFragment( ) } - private fun playSelectedOrAllTracks( - insertionMode: MediaPlayerManager.InsertionMode - ) { + private fun playSelectedOrAllTracks(insertionMode: MediaPlayerManager.InsertionMode) { mediaPlayerManager.playTracksAndToast( fragment = this, insertionMode = insertionMode, @@ -403,9 +401,7 @@ open class TrackCollectionFragment( listModel.calculateButtonState(selection, ::updateButtonState) } - private fun updateButtonState( - show: TrackCollectionModel.Companion.ButtonStates, - ) { + private fun updateButtonState(show: TrackCollectionModel.Companion.ButtonStates) { // We are coming back from unknown context // and need to ensure Main Thread in order to manipulate the UI // If view is null, our view was disposed in the meantime @@ -484,10 +480,11 @@ open class TrackCollectionFragment( internal fun getSelectedTracks(): List { // Walk through selected set and get the Entries based on the saved ids. return viewAdapter.getCurrentList().mapNotNull { - if (it is Track && viewAdapter.isSelected(it.longId)) + if (it is Track && viewAdapter.isSelected(it.longId)) { it - else + } else { null + } } } @@ -586,7 +583,6 @@ open class TrackCollectionFragment( menuItem: MenuItem, item: MusicDirectory.Child ): Boolean { - val tracks = getClickedSong(item) return ContextMenuUtil.handleContextMenuTracks( @@ -600,10 +596,11 @@ open class TrackCollectionFragment( private fun getClickedSong(item: MusicDirectory.Child): List { // This can probably be done better return viewAdapter.getCurrentList().mapNotNull { - if (it is Track && (it.id == item.id)) + if (it is Track && (it.id == item.id)) { it - else + } else { null + } } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/ChatFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/ChatFragment.kt index 9f7e4744..2245daa7 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/ChatFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/ChatFragment.kt @@ -112,9 +112,10 @@ class ChatFragment : Fragment(), KoinComponent, RefreshableFragment { }) messageEditText.setOnEditorActionListener( OnEditorActionListener { - _: TextView?, - actionId: Int, - event: KeyEvent -> + _: TextView?, + actionId: Int, + event: KeyEvent + -> if (actionId == EditorInfo.IME_ACTION_SEND || (actionId == EditorInfo.IME_NULL && event.action == KeyEvent.ACTION_DOWN) ) { @@ -170,7 +171,8 @@ class ChatFragment : Fragment(), KoinComponent, RefreshableFragment { requireActivity().runOnUiThread { load() } } }, - refreshInterval.toLong(), refreshInterval.toLong() + refreshInterval.toLong(), + refreshInterval.toLong() ) } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/PlaylistsFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/PlaylistsFragment.kt index d8a51c02..5e389308 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/PlaylistsFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/PlaylistsFragment.kt @@ -87,7 +87,7 @@ class PlaylistsFragment : ScopeFragment(), KoinScopeComponent, RefreshableFragme id = id, playlistId = id, name = name, - playlistName = name, + playlistName = name ) findNavController().navigate(action) } @@ -120,10 +120,14 @@ class PlaylistsFragment : ScopeFragment(), KoinScopeComponent, RefreshableFragme override fun onCreateContextMenu(menu: ContextMenu, view: View, menuInfo: ContextMenuInfo?) { super.onCreateContextMenu(menu, view, menuInfo) val inflater = requireActivity().menuInflater - if (isOffline()) inflater.inflate( - R.menu.select_playlist_context_offline, - menu - ) else inflater.inflate(R.menu.select_playlist_context, menu) + if (isOffline()) { + inflater.inflate( + R.menu.select_playlist_context_offline, + menu + ) + } else { + inflater.inflate(R.menu.select_playlist_context, menu) + } val downloadMenuItem = menu.findItem(R.id.playlist_menu_download) if (downloadMenuItem != null) { downloadMenuItem.isVisible = !isOffline() @@ -236,13 +240,17 @@ class PlaylistsFragment : ScopeFragment(), KoinScopeComponent, RefreshableFragme Comments: ${playlist.comment} Song Count: ${playlist.songCount} """.trimIndent() + - if (playlist.public == null) "" else """ + if (playlist.public == null) { + "" + } else { + """ Public: ${playlist.public} - """.trimIndent() + """ + """.trimIndent() + """ Creation Date: ${playlist.created.replace('T', ' ')} - """.trimIndent() + """.trimIndent() + } ) Linkify.addLinks(message, Linkify.WEB_URLS) textView.text = message diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/SelectGenreFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/SelectGenreFragment.kt index 879dafe2..8a9cf538 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/SelectGenreFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/SelectGenreFragment.kt @@ -53,8 +53,8 @@ class SelectGenreFragment : Fragment(), RefreshableFragment { swipeRefresh?.setOnRefreshListener { load(true) } genreListView?.setOnItemClickListener { - parent: AdapterView<*>, _: View?, - position: Int, _: Long + parent: AdapterView<*>, _: View?, + position: Int, _: Long -> val genre = parent.getItemAtPosition(position) as Genre diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/SharesFragment.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/SharesFragment.kt index a3336730..e9ceaec8 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/SharesFragment.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/fragment/legacy/SharesFragment.kt @@ -80,8 +80,9 @@ class SharesFragment : ScopeFragment(), KoinScopeComponent, RefreshableFragment swipeRefresh!!.setOnRefreshListener { load(true) } emptyTextView = view.findViewById(R.id.select_share_empty) sharesListView!!.onItemClickListener = AdapterView.OnItemClickListener { - parent, _, - position, _ -> + parent, _, + position, _ + -> val share = parent.getItemAtPosition(position) as Share val action = NavigationGraphDirections.toTrackCollection( @@ -171,7 +172,7 @@ class SharesFragment : ScopeFragment(), KoinScopeComponent, RefreshableFragment insertionMode = MediaPlayerManager.InsertionMode.CLEAR, id = share.id, name = share.name, - shuffle = true, + shuffle = true ) } R.id.share_menu_delete -> { @@ -235,21 +236,33 @@ class SharesFragment : ScopeFragment(), KoinScopeComponent, RefreshableFragment Visit Count: ${share.visitCount} """.trimIndent() + ( - if (share.created == null) "" else """ + if (share.created == null) { + "" + } else { + """ Creation Date: ${share.created!!.replace('T', ' ')} - """.trimIndent() + """.trimIndent() + } ) + ( - if (share.lastVisited == null) "" else """ + if (share.lastVisited == null) { + "" + } else { + """ Last Visited Date: ${share.lastVisited!!.replace('T', ' ')} - """.trimIndent() + """.trimIndent() + } ) + - if (share.expires == null) "" else """ + if (share.expires == null) { + "" + } else { + """ Expiration Date: ${share.expires!!.replace('T', ' ')} - """.trimIndent() + """.trimIndent() + } ) Linkify.addLinks(message, Linkify.WEB_URLS) textView.text = message @@ -289,11 +302,7 @@ class SharesFragment : ScopeFragment(), KoinScopeComponent, RefreshableFragment alertDialog.show() } - private fun updateShareOnServer( - millis: Long, - description: String, - share: Share - ) { + private fun updateShareOnServer(millis: Long, description: String, share: Share) { launchWithToast { withContext(Dispatchers.IO) { val musicService = MusicServiceFactory.getMusicService() diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/CoverArtRequestHandler.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/CoverArtRequestHandler.kt index c54f74b9..379d79f9 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/CoverArtRequestHandler.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/CoverArtRequestHandler.kt @@ -65,10 +65,7 @@ class CoverArtRequestHandler(private val client: SubsonicAPIClient) : RequestHan throw IOException("${response.apiError}") } - private fun getAlbumArtBitmapFromDisk( - filename: String, - size: Int? - ): Bitmap? { + private fun getAlbumArtBitmapFromDisk(filename: String, size: Int?): Bitmap? { val albumArtFile = FileUtil.getAlbumArtFile(filename) val bitmap: Bitmap? = null if (File(albumArtFile).exists()) { @@ -77,11 +74,7 @@ class CoverArtRequestHandler(private val client: SubsonicAPIClient) : RequestHan return null } - private fun getBitmapFromDisk( - path: String, - size: Int?, - bitmap: Bitmap? - ): Bitmap? { + private fun getBitmapFromDisk(path: String, size: Int?, bitmap: Bitmap?): Bitmap? { var bitmap1 = bitmap val opt = BitmapFactory.Options() if (size != null && size > 0) { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/ImageLoader.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/ImageLoader.kt index bb7a76c0..9c5e2566 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/ImageLoader.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/ImageLoader.kt @@ -38,7 +38,7 @@ import timber.log.Timber class ImageLoader( context: Context, apiClient: SubsonicAPIClient, - private val config: ImageLoaderConfig, + private val config: ImageLoaderConfig ) : CoroutineScope by CoroutineScope(Dispatchers.Main + SupervisorJob()) { private val cacheInProgress: ConcurrentHashMap = ConcurrentHashMap() @@ -112,7 +112,10 @@ class ImageLoader( val requestedSize = resolveSize(size, large) val request = ImageRequest.CoverArt( - id!!, cacheKey!!, null, requestedSize, + id!!, + cacheKey!!, + null, + requestedSize, placeHolderDrawableRes = defaultResourceId, errorDrawableRes = defaultResourceId ) @@ -157,7 +160,10 @@ class ImageLoader( if (id != null && key != null && id.isNotEmpty() && view is ImageView) { val request = ImageRequest.CoverArt( - id, key, view, requestedSize, + id, + key, + view, + requestedSize, placeHolderDrawableRes = defaultResourceId, errorDrawableRes = defaultResourceId ) @@ -170,13 +176,11 @@ class ImageLoader( /** * Load the avatar of a given user into an ImageView */ - fun loadAvatarImage( - view: ImageView, - username: String - ) { + fun loadAvatarImage(view: ImageView, username: String) { if (username.isNotEmpty()) { val request = ImageRequest.Avatar( - username, view, + username, + view, placeHolderDrawableRes = R.drawable.ic_contact_picture, errorDrawableRes = R.drawable.ic_contact_picture ) @@ -284,7 +288,7 @@ sealed class ImageRequest( imageView: ImageView?, val size: Int, placeHolderDrawableRes: Int? = null, - errorDrawableRes: Int? = null, + errorDrawableRes: Int? = null ) : ImageRequest( placeHolderDrawableRes, errorDrawableRes, diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/RequestCreator.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/RequestCreator.kt index 37a11f5a..d2657ef3 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/RequestCreator.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/imageloader/RequestCreator.kt @@ -13,17 +13,15 @@ internal const val QUERY_USERNAME = "username" * Picasso.load() only accepts an URI as parameter. Therefore we create a bogus URI, in which * we encode the data that we need in the RequestHandler. */ -internal fun createLoadCoverArtRequest(entityId: String, size: Long? = 0): Uri = - Uri.Builder() - .scheme(SCHEME) - .appendPath(COVER_ART_PATH) - .appendQueryParameter(QUERY_ID, entityId) - .appendQueryParameter(SIZE, size.toString()) - .build() +internal fun createLoadCoverArtRequest(entityId: String, size: Long? = 0): Uri = Uri.Builder() + .scheme(SCHEME) + .appendPath(COVER_ART_PATH) + .appendQueryParameter(QUERY_ID, entityId) + .appendQueryParameter(SIZE, size.toString()) + .build() -internal fun createLoadAvatarRequest(username: String): Uri = - Uri.Builder() - .scheme(SCHEME) - .appendPath(AVATAR_PATH) - .appendQueryParameter(QUERY_USERNAME, username) - .build() +internal fun createLoadAvatarRequest(username: String): Uri = Uri.Builder() + .scheme(SCHEME) + .appendPath(AVATAR_PATH) + .appendQueryParameter(QUERY_USERNAME, username) + .build() diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/AlbumListModel.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/AlbumListModel.kt index 4fda6e60..e281562f 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/AlbumListModel.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/AlbumListModel.kt @@ -22,11 +22,7 @@ class AlbumListModel(application: Application) : GenericListModel(application) { private var lastType: AlbumListType? = null private var loadedUntil: Int = 0 - suspend fun getAlbumsOfArtist( - refresh: Boolean, - id: String, - name: String? - ) { + suspend fun getAlbumsOfArtist(refresh: Boolean, id: String, name: String?) { withContext(Dispatchers.IO) { val service = MusicServiceFactory.getMusicService() list.postValue(service.getAlbumsOfArtist(id, name, refresh)) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/EditServerModel.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/EditServerModel.kt index 622f7b99..b89380f8 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/EditServerModel.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/EditServerModel.kt @@ -59,36 +59,33 @@ class EditServerModel(val app: Application) : AndroidViewModel(app), KoinCompone return (this.status === SubsonicResponse.Status.OK) } - private fun requestFlow( - type: ServerFeature, - api: SubsonicAPIDefinition, - userName: String - ) = flow { - when (type) { - ServerFeature.CHAT -> emit( - serverFunctionAvailable(type, api::getChatMessagesSuspend) - ) - ServerFeature.BOOKMARK -> emit( - serverFunctionAvailable(type, api::getBookmarksSuspend) - ) - ServerFeature.SHARE -> emit( - serverFunctionAvailable(type, api::getSharesSuspend) - ) - ServerFeature.PODCAST -> emit( - serverFunctionAvailable(type, api::getPodcastsSuspend) - ) - ServerFeature.JUKEBOX -> emit( - serverFunctionAvailable(type) { - val response = api.getUserSuspend(userName) - if (!response.user.jukeboxRole) throw IOException() - response - } - ) - ServerFeature.VIDEO -> emit( - serverFunctionAvailable(type, api::getVideosSuspend) - ) + private fun requestFlow(type: ServerFeature, api: SubsonicAPIDefinition, userName: String) = + flow { + when (type) { + ServerFeature.CHAT -> emit( + serverFunctionAvailable(type, api::getChatMessagesSuspend) + ) + ServerFeature.BOOKMARK -> emit( + serverFunctionAvailable(type, api::getBookmarksSuspend) + ) + ServerFeature.SHARE -> emit( + serverFunctionAvailable(type, api::getSharesSuspend) + ) + ServerFeature.PODCAST -> emit( + serverFunctionAvailable(type, api::getPodcastsSuspend) + ) + ServerFeature.JUKEBOX -> emit( + serverFunctionAvailable(type) { + val response = api.getUserSuspend(userName) + if (!response.user.jukeboxRole) throw IOException() + response + } + ) + ServerFeature.VIDEO -> emit( + serverFunctionAvailable(type, api::getVideosSuspend) + ) + } } - } @OptIn(ExperimentalCoroutinesApi::class) suspend fun queryFeatureSupport(currentServerSetting: ServerSetting): Flow { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/GenericListModel.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/GenericListModel.kt index b0ab5481..23551022 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/GenericListModel.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/GenericListModel.kt @@ -67,10 +67,7 @@ open class GenericListModel(application: Application) : /** * Trigger a load() and notify the UI that we are loading */ - fun backgroundLoadFromServer( - refresh: Boolean, - swipe: SwipeRefreshLayout - ) { + fun backgroundLoadFromServer(refresh: Boolean, swipe: SwipeRefreshLayout) { viewModelScope.launch { swipe.isRefreshing = true loadFromServer(refresh, swipe) @@ -81,10 +78,7 @@ open class GenericListModel(application: Application) : /** * Calls the load() function with error handling */ - private suspend fun loadFromServer( - refresh: Boolean, - swipe: SwipeRefreshLayout - ) { + private suspend fun loadFromServer(refresh: Boolean, swipe: SwipeRefreshLayout) { withContext(Dispatchers.IO) { val musicService = MusicServiceFactory.getMusicService() val isOffline = ActiveServerProvider.isOffline() diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/SearchListModel.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/SearchListModel.kt index b0492475..26c8a3ae 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/SearchListModel.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/SearchListModel.kt @@ -6,7 +6,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.moire.ultrasonic.domain.SearchCriteria import org.moire.ultrasonic.domain.SearchResult -import org.moire.ultrasonic.fragment.SearchFragment import org.moire.ultrasonic.service.MusicServiceFactory import org.moire.ultrasonic.util.Settings @@ -31,9 +30,9 @@ class SearchListModel(application: Application) : GenericListModel(application) fun trimResultLength( result: SearchResult, - maxArtists: Int = SearchFragment.DEFAULT_ARTISTS, - maxAlbums: Int = SearchFragment.DEFAULT_ALBUMS, - maxSongs: Int = SearchFragment.DEFAULT_SONGS + maxArtists: Int = Settings.defaultArtists, + maxAlbums: Int = Settings.defaultAlbums, + maxSongs: Int = Settings.defaultSongs ): SearchResult { return SearchResult( artists = result.artists.take(maxArtists), diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/TrackCollectionModel.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/TrackCollectionModel.kt index 22a92869..3cb5f7a5 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/TrackCollectionModel.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/model/TrackCollectionModel.kt @@ -30,13 +30,9 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat private var loadedUntil: Int = 0 /* - * Especially when dealing with indexes, this method can return Albums, Entries or a mix of both! - */ - suspend fun getMusicDirectory( - refresh: Boolean, - id: String, - name: String? - ) { + * Especially when dealing with indexes, this method can return Albums, Entries or a mix of both! + */ + suspend fun getMusicDirectory(refresh: Boolean, id: String, name: String?) { withContext(Dispatchers.IO) { val service = MusicServiceFactory.getMusicService() val musicDirectory = service.getMusicDirectory(id, name, refresh) @@ -46,9 +42,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat } suspend fun getAlbum(refresh: Boolean, id: String, name: String?) { - withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService() val musicDirectory: MusicDirectory = service.getAlbumAsDir(id, name, refresh) currentListIsSortable = true @@ -74,9 +68,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat } suspend fun getStarred() { - withContext(Dispatchers.IO) { - val service = MusicServiceFactory.getMusicService() val musicDirectory: MusicDirectory @@ -122,7 +114,6 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat } suspend fun getPodcastEpisodes(podcastChannelId: String) { - withContext(Dispatchers.IO) { val service = MusicServiceFactory.getMusicService() val musicDirectory = service.getPodcastEpisodes(podcastChannelId) @@ -134,7 +125,6 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat } suspend fun getShare(shareId: String) { - withContext(Dispatchers.IO) { val service = MusicServiceFactory.getMusicService() val musicDirectory = MusicDirectory() @@ -174,10 +164,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat } @Synchronized - fun calculateButtonState( - selection: List, - onComplete: (ButtonStates) -> Unit - ) { + fun calculateButtonState(selection: List, onComplete: (ButtonStates) -> Unit) { val enabled = selection.isNotEmpty() var unpinEnabled = false var deleteEnabled = false diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/provider/AlbumArtContentProvider.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/provider/AlbumArtContentProvider.kt index d55de716..f2d8606b 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/provider/AlbumArtContentProvider.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/provider/AlbumArtContentProvider.kt @@ -38,7 +38,9 @@ class AlbumArtContentProvider : ContentProvider(), KoinComponent { .path( String.format( Locale.ROOT, - "%s|%s", track!!.coverArt, FileUtil.getAlbumArtKey(track, true) + "%s|%s", + track!!.coverArt, + FileUtil.getAlbumArtKey(track, true) ) ) .build() diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/provider/UltrasonicAppWidgetProvider.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/provider/UltrasonicAppWidgetProvider.kt index 193bbe52..18f889f8 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/provider/UltrasonicAppWidgetProvider.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/provider/UltrasonicAppWidgetProvider.kt @@ -160,11 +160,7 @@ open class UltrasonicAppWidgetProvider : AppWidgetProvider() { /** * Update Track details in widgets */ - private fun updateTrack( - context: Context, - views: RemoteViews, - currentSong: Track? - ) { + private fun updateTrack(context: Context, views: RemoteViews, currentSong: Track?) { Timber.d("Updating Widget") val res = context.resources val title = currentSong?.title diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/receiver/BluetoothIntentReceiver.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/receiver/BluetoothIntentReceiver.kt index 54753ea9..4093f082 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/receiver/BluetoothIntentReceiver.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/receiver/BluetoothIntentReceiver.kt @@ -45,7 +45,8 @@ class BluetoothIntentReceiver : BroadcastReceiver() { connectionStatus = Constants.PREFERENCE_VALUE_ALL } BluetoothDevice.ACTION_ACL_DISCONNECTED, - BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED -> { + BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED + -> { disconnectionStatus = Constants.PREFERENCE_VALUE_ALL } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/CachedMusicService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/CachedMusicService.kt index 965f8b6b..54aa8b6b 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/CachedMusicService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/CachedMusicService.kt @@ -155,8 +155,7 @@ class CachedMusicService(private val musicService: MusicService) : MusicService, * Cached in the RoomDB */ @Throws(Exception::class) - override fun getAlbumsOfArtist(id: String, name: String?, refresh: Boolean): - List { + override fun getAlbumsOfArtist(id: String, name: String?, refresh: Boolean): List { checkSettingsChanged() var result: List @@ -481,11 +480,7 @@ class CachedMusicService(private val musicService: MusicService) : MusicService, } @Throws(Exception::class) - override fun createShare( - ids: List, - description: String?, - expires: Long? - ): List { + override fun createShare(ids: List, description: String?, expires: Long?): List { return musicService.createShare(ids, description, expires) } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadService.kt index f414ce05..429107ff 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadService.kt @@ -216,7 +216,6 @@ class DownloadService : Service(), KoinComponent { } private fun updateNotification() { - val notification = buildForegroundNotification() if (isInForeground) { @@ -344,10 +343,7 @@ class DownloadService : Service(), KoinComponent { updateLiveData() } - private fun setSaveFlagForTracks( - shouldPin: Boolean, - tracks: List - ): List { + private fun setSaveFlagForTracks(shouldPin: Boolean, tracks: List): List { // Walk through the tracks. If a track is pinned or complete and needs to be changed // to the other state, rename it, but don't return it, thereby excluding it from // further processing. diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadState.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadState.kt index 976184a1..c246046b 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadState.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadState.kt @@ -8,7 +8,15 @@ package org.moire.ultrasonic.service enum class DownloadState { - IDLE, QUEUED, DOWNLOADING, RETRYING, FAILED, CANCELLED, DONE, PINNED, UNKNOWN; + IDLE, + QUEUED, + DOWNLOADING, + RETRYING, + FAILED, + CANCELLED, + DONE, + PINNED, + UNKNOWN; companion object { fun DownloadState.isFinalState(): Boolean { @@ -17,7 +25,8 @@ enum class DownloadState { FAILED, CANCELLED, DONE, - PINNED -> true + PINNED + -> true else -> false } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadTask.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadTask.kt index 443defb5..961f9b97 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadTask.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/DownloadTask.kt @@ -91,7 +91,8 @@ class DownloadTask( // Attempt partial HTTP GET, appending to the file if it exists. val (inStream, isPartial) = musicService.getDownloadInputStream( - downloadTrack.track, fileLength, + downloadTrack.track, + fileLength, if (downloadTrack.pinned) Settings.maxBitRatePinning else Settings.maxBitRate, downloadTrack.pinned && Settings.pinWithHighestQuality ) @@ -228,8 +229,9 @@ class DownloadTask( } // Cache the artist - if (artistId != null) + if (artistId != null) { directArtist = cacheArtist(onlineDB, offlineDB, artistId) + } // Now cache the album if (albumId != null) { @@ -246,8 +248,9 @@ class DownloadTask( offlineDB.albumDao().insert(album) // If the album is a Compilation, also cache the Album artist - if (album.artistId != null && album.artistId != artistId) + if (album.artistId != null && album.artistId != artistId) { compilationArtist = cacheArtist(onlineDB, offlineDB, album.artistId!!) + } } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/JukeboxMediaPlayer.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/JukeboxMediaPlayer.kt index ebbd6cba..7cd8b922 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/JukeboxMediaPlayer.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/JukeboxMediaPlayer.kt @@ -109,8 +109,8 @@ class JukeboxMediaPlayer : JukeboxUnimplementedFunctions(), Player { stop() startProcessTasks() } - @Suppress("MagicNumber") + @Suppress("MagicNumber") override fun release() { tasks.clear() stop() @@ -210,7 +210,7 @@ class JukeboxMediaPlayer : JukeboxUnimplementedFunctions(), Player { Player.COMMAND_GET_TIMELINE, Player.COMMAND_GET_DEVICE_VOLUME, Player.COMMAND_ADJUST_DEVICE_VOLUME_WITH_FLAGS, - Player.COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS, + Player.COMMAND_SET_DEVICE_VOLUME_WITH_FLAGS ) if (isPlaying) commandsBuilder.add(Player.COMMAND_STOP) if (playlist.isNotEmpty()) { @@ -227,10 +227,12 @@ class JukeboxMediaPlayer : JukeboxUnimplementedFunctions(), Player { Player.COMMAND_SEEK_TO_PREVIOUS, Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM ) - if (currentIndex < playlist.size - 1) commandsBuilder.addAll( - Player.COMMAND_SEEK_TO_NEXT, - Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM, - ) + if (currentIndex < playlist.size - 1) { + commandsBuilder.addAll( + Player.COMMAND_SEEK_TO_NEXT, + Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM + ) + } } return commandsBuilder.build() } @@ -524,8 +526,11 @@ class JukeboxMediaPlayer : JukeboxUnimplementedFunctions(), Player { shouldUpdateCommands = true currentIndex = jukeboxStatus.currentPlayingIndex ?: 0 val currentMedia = - if (currentIndex > 0 && currentIndex < playlist.size) playlist[currentIndex] - else MediaItem.EMPTY + if (currentIndex > 0 && currentIndex < playlist.size) { + playlist[currentIndex] + } else { + MediaItem.EMPTY + } Handler(Looper.getMainLooper()).post { listeners.queueEvent(Player.EVENT_MEDIA_ITEM_TRANSITION) { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaLibrarySessionCallback.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaLibrarySessionCallback.kt index e2525785..c2011004 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaLibrarySessionCallback.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaLibrarySessionCallback.kt @@ -273,8 +273,9 @@ class MediaLibrarySessionCallback : var lastCarConnectionType = -1 CarConnection(UApp.applicationContext()).type.observeForever { - if (lastCarConnectionType == it) + if (lastCarConnectionType == it) { return@observeForever + } lastCarConnectionType = it @@ -296,8 +297,9 @@ class MediaLibrarySessionCallback : } } } - } else + } else { Timber.d("Car app library not available") + } } override fun onPostConnect(session: MediaSession, controller: MediaSession.ControllerInfo) { @@ -313,28 +315,29 @@ class MediaLibrarySessionCallback : private fun getHeartCommandButton(sessionCommand: SessionCommand, willHeart: Boolean) = CommandButton.Builder() .setDisplayName( - if (willHeart) + if (willHeart) { "Love" - else + } else { "Dislike" + } ) .setIconResId( - if (willHeart) + if (willHeart) { R.drawable.ic_star_hollow - else + } else { R.drawable.ic_star_full + } ) .setSessionCommand(sessionCommand) .setEnabled(true) .build() - private fun getShuffleCommandButton(sessionCommand: SessionCommand) = - CommandButton.Builder() - .setDisplayName("Shuffle") - .setIconResId(R.drawable.media_shuffle) - .setSessionCommand(sessionCommand) - .setEnabled(true) - .build() + private fun getShuffleCommandButton(sessionCommand: SessionCommand) = CommandButton.Builder() + .setDisplayName("Shuffle") + .setIconResId(R.drawable.media_shuffle) + .setSessionCommand(sessionCommand) + .setEnabled(true) + .build() private fun getPlaceholderButton() = CommandButton.Builder() .setDisplayName("Placeholder") @@ -514,22 +517,23 @@ class MediaLibrarySessionCallback : controller: MediaSession.ControllerInfo, mediaItems: MutableList ): ListenableFuture> { - Timber.i("onAddMediaItems") if (mediaItems.isEmpty()) return Futures.immediateFuture(mediaItems) // Return early if its a search - if (mediaItems[0].requestMetadata.searchQuery != null) + if (mediaItems[0].requestMetadata.searchQuery != null) { return playFromSearch(mediaItems[0].requestMetadata.searchQuery!!) + } val updatedMediaItems: List = mediaItems.mapNotNull { mediaItem -> - if (mediaItem.requestMetadata.mediaUri != null) + if (mediaItem.requestMetadata.mediaUri != null) { mediaItem.buildUpon() .setUri(mediaItem.requestMetadata.mediaUri) .build() - else + } else { null + } } return if (updatedMediaItems.isNotEmpty()) { @@ -552,12 +556,16 @@ class MediaLibrarySessionCallback : val tracks = when (mediaIdParts.first()) { MEDIA_PLAYLIST_ITEM -> playPlaylist(mediaIdParts[1], mediaIdParts[2]) MEDIA_PLAYLIST_SONG_ITEM -> playPlaylistSong( - mediaIdParts[1], mediaIdParts[2], mediaIdParts[3] + mediaIdParts[1], + mediaIdParts[2], + mediaIdParts[3] ) MEDIA_ALBUM_ITEM -> playAlbum(mediaIdParts[1], mediaIdParts[2]) MEDIA_ALBUM_SONG_ITEM -> playAlbumSong( - mediaIdParts[1], mediaIdParts[2], mediaIdParts[3] + mediaIdParts[1], + mediaIdParts[2], + mediaIdParts[3] ) MEDIA_SONG_STARRED_ID -> playStarredSongs() @@ -569,7 +577,8 @@ class MediaLibrarySessionCallback : MEDIA_BOOKMARK_ITEM -> playBookmark(mediaIdParts[1]) MEDIA_PODCAST_ITEM -> playPodcast(mediaIdParts[1]) MEDIA_PODCAST_EPISODE_ITEM -> playPodcastEpisode( - mediaIdParts[1], mediaIdParts[2] + mediaIdParts[1], + mediaIdParts[2] ) MEDIA_SEARCH_SONG_ITEM -> playSearch(mediaIdParts[1]) @@ -588,7 +597,7 @@ class MediaLibrarySessionCallback : @Suppress("ReturnCount", "ComplexMethod") private fun onLoadChildren( - parentId: String, + parentId: String ): ListenableFuture>> { Timber.d("AutoMediaBrowserService onLoadChildren called. ParentId: %s", parentId) @@ -601,7 +610,8 @@ class MediaLibrarySessionCallback : MEDIA_ARTIST_SECTION -> getArtists(parentIdParts[1]) MEDIA_ALBUM_ID -> getAlbums(AlbumListType.SORTED_BY_NAME) MEDIA_ALBUM_PAGE_ID -> getAlbums( - AlbumListType.fromName(parentIdParts[1]), parentIdParts[2].toInt() + AlbumListType.fromName(parentIdParts[1]), + parentIdParts[2].toInt() ) MEDIA_PLAYLIST_ID -> getPlaylists() @@ -617,7 +627,8 @@ class MediaLibrarySessionCallback : MEDIA_PODCAST_ID -> getPodcasts() MEDIA_PLAYLIST_ITEM -> getPlaylist(parentIdParts[1], parentIdParts[2]) MEDIA_ARTIST_ITEM -> getAlbumsForArtist( - parentIdParts[1], parentIdParts[2] + parentIdParts[1], + parentIdParts[2] ) MEDIA_ALBUM_ITEM -> getSongsForAlbum(parentIdParts[1], parentIdParts[2]) @@ -627,10 +638,7 @@ class MediaLibrarySessionCallback : } } - private fun playFromSearch( - query: String, - ): ListenableFuture> { - + private fun playFromSearch(query: String): ListenableFuture> { Timber.w("App state: %s", UApp.instance != null) Timber.i("AutoMediaBrowserService onSearch query: %s", query) @@ -651,7 +659,6 @@ class MediaLibrarySessionCallback : // TODO Add More... button to categories if (searchResult != null) { - searchResult.albums.map { album -> mediaItems.add( album.title ?: "", @@ -704,12 +711,16 @@ class MediaLibrarySessionCallback : return when (mediaIdParts.first()) { MEDIA_PLAYLIST_ITEM -> playPlaylist(mediaIdParts[1], mediaIdParts[2]) MEDIA_PLAYLIST_SONG_ITEM -> playPlaylistSong( - mediaIdParts[1], mediaIdParts[2], mediaIdParts[3] + mediaIdParts[1], + mediaIdParts[2], + mediaIdParts[3] ) MEDIA_ALBUM_ITEM -> playAlbum(mediaIdParts[1], mediaIdParts[2]) MEDIA_ALBUM_SONG_ITEM -> playAlbumSong( - mediaIdParts[1], mediaIdParts[2], mediaIdParts[3] + mediaIdParts[1], + mediaIdParts[2], + mediaIdParts[3] ) MEDIA_SONG_STARRED_ID -> playStarredSongs() @@ -721,7 +732,8 @@ class MediaLibrarySessionCallback : MEDIA_BOOKMARK_ITEM -> playBookmark(mediaIdParts[1]) MEDIA_PODCAST_ITEM -> playPodcast(mediaIdParts[1]) MEDIA_PODCAST_EPISODE_ITEM -> playPodcastEpisode( - mediaIdParts[1], mediaIdParts[2] + mediaIdParts[1], + mediaIdParts[2] ) MEDIA_SEARCH_SONG_ITEM -> playSearch(mediaIdParts[1]) @@ -743,7 +755,7 @@ class MediaLibrarySessionCallback : private fun getRootItems(): ListenableFuture>> { val mediaItems: MutableList = ArrayList() - if (!isOffline) + if (!isOffline) { mediaItems.add( R.string.music_library_label, MEDIA_LIBRARY_ID, @@ -752,6 +764,7 @@ class MediaLibrarySessionCallback : mediaType = MEDIA_TYPE_FOLDER_MIXED, icon = R.drawable.ic_library ) + } mediaItems.add( R.string.main_artists_title, @@ -762,7 +775,7 @@ class MediaLibrarySessionCallback : icon = R.drawable.ic_artist ) - if (!isOffline) + if (!isOffline) { mediaItems.add( R.string.main_albums_title, MEDIA_ALBUM_ID, @@ -771,6 +784,7 @@ class MediaLibrarySessionCallback : mediaType = MEDIA_TYPE_FOLDER_ALBUMS, icon = R.drawable.ic_menu_browse ) + } mediaItems.add( R.string.playlist_label, @@ -815,28 +829,28 @@ class MediaLibrarySessionCallback : R.string.main_albums_recent, MEDIA_ALBUM_RECENT_ID, R.string.main_albums_title, - mediaType = MEDIA_TYPE_FOLDER_ALBUMS, + mediaType = MEDIA_TYPE_FOLDER_ALBUMS ) mediaItems.add( R.string.main_albums_frequent, MEDIA_ALBUM_FREQUENT_ID, R.string.main_albums_title, - mediaType = MEDIA_TYPE_FOLDER_ALBUMS, + mediaType = MEDIA_TYPE_FOLDER_ALBUMS ) mediaItems.add( R.string.main_albums_random, MEDIA_ALBUM_RANDOM_ID, R.string.main_albums_title, - mediaType = MEDIA_TYPE_FOLDER_ALBUMS, + mediaType = MEDIA_TYPE_FOLDER_ALBUMS ) mediaItems.add( R.string.main_albums_starred, MEDIA_ALBUM_STARRED_ID, R.string.main_albums_title, - mediaType = MEDIA_TYPE_FOLDER_ALBUMS, + mediaType = MEDIA_TYPE_FOLDER_ALBUMS ) // Other @@ -869,10 +883,11 @@ class MediaLibrarySessionCallback : }.await() if (artists != null) { - if (section != null) + if (section != null) { artists = artists.filter { artist -> getSectionFromName(artist.name ?: "") == section } + } // If there are too many artists, create alphabetic index of them if (section == null && artists.count() > DISPLAY_LIMIT) { @@ -942,28 +957,30 @@ class MediaLibrarySessionCallback : if (songs != null) { if (songs.getChildren(includeDirs = true, includeFiles = false).isEmpty() && songs.getChildren(includeDirs = false, includeFiles = true).isNotEmpty() - ) + ) { mediaItems.addPlayAllItem(listOf(MEDIA_ALBUM_ITEM, id, name).joinToString("|")) + } // TODO: Paging is not implemented for songs, is it necessary at all? val items = songs.getChildren().take(DISPLAY_LIMIT).toMutableList() items.sortWith { o1, o2 -> - if (o1.isDirectory && o2.isDirectory) + if (o1.isDirectory && o2.isDirectory) { (o1.title ?: "").compareTo(o2.title ?: "") - else if (o1.isDirectory) + } else if (o1.isDirectory) { -1 - else + } else { 1 + } } items.map { item -> - if (item.isDirectory) + if (item.isDirectory) { mediaItems.add( item.title ?: "", listOf(MEDIA_ALBUM_ITEM, item.id, item.name).joinToString("|") ) - else if (item is Track) + } else if (item is Track) { mediaItems.add( item.toMediaItem( listOf( @@ -974,6 +991,7 @@ class MediaLibrarySessionCallback : ).joinToString("|") ) ) + } } } @@ -994,13 +1012,19 @@ class MediaLibrarySessionCallback : if (ActiveServerProvider.shouldUseId3Tags()) { callWithErrorHandling { musicService.getAlbumList2( - type, DISPLAY_LIMIT, offset, null + type, + DISPLAY_LIMIT, + offset, + null ) } } else { callWithErrorHandling { musicService.getAlbumList( - type, DISPLAY_LIMIT, offset, null + type, + DISPLAY_LIMIT, + offset, + null ) } } @@ -1014,12 +1038,13 @@ class MediaLibrarySessionCallback : ) } - if ((albums?.size ?: 0) >= DISPLAY_LIMIT) + if ((albums?.size ?: 0) >= DISPLAY_LIMIT) { mediaItems.add( R.string.search_more, listOf(MEDIA_ALBUM_PAGE_ID, type.typeName, (page ?: 0) + 1).joinToString("|"), null ) + } return@future LibraryResult.ofItemList(mediaItems, null) } @@ -1038,7 +1063,7 @@ class MediaLibrarySessionCallback : playlist.name, listOf(MEDIA_PLAYLIST_ITEM, playlist.id, playlist.name) .joinToString("|"), - mediaType = MEDIA_TYPE_PLAYLIST, + mediaType = MEDIA_TYPE_PLAYLIST ) } return@future LibraryResult.ofItemList(mediaItems, null) @@ -1047,7 +1072,7 @@ class MediaLibrarySessionCallback : private fun getPlaylist( id: String, - name: String, + name: String ): ListenableFuture>> { val mediaItems: MutableList = ArrayList() @@ -1057,10 +1082,11 @@ class MediaLibrarySessionCallback : }.await() if (content != null) { - if (content.size > 1) + if (content.size > 1) { mediaItems.addPlayAllItem( listOf(MEDIA_PLAYLIST_ITEM, id, name).joinToString("|") ) + } // Playlist should be cached as it may contain random elements playlistCache = content.getTracks() @@ -1132,7 +1158,7 @@ class MediaLibrarySessionCallback : mediaItems.add( podcast.title ?: "", listOf(MEDIA_PODCAST_ITEM, podcast.id).joinToString("|"), - mediaType = MEDIA_TYPE_FOLDER_MIXED, + mediaType = MEDIA_TYPE_FOLDER_MIXED ) } return@future LibraryResult.ofItemList(mediaItems, null) @@ -1149,8 +1175,9 @@ class MediaLibrarySessionCallback : }.await() if (episodes != null) { - if (episodes.getTracks().count() > 1) + if (episodes.getTracks().count() > 1) { mediaItems.addPlayAllItem(listOf(MEDIA_PODCAST_ITEM, id).joinToString("|")) + } episodes.getTracks().map { episode -> mediaItems.add( @@ -1235,7 +1262,7 @@ class MediaLibrarySessionCallback : share.name ?: "", listOf(MEDIA_SHARE_ITEM, share.id) .joinToString("|"), - mediaType = MEDIA_TYPE_FOLDER_MIXED, + mediaType = MEDIA_TYPE_FOLDER_MIXED ) } return@future LibraryResult.ofItemList(mediaItems, null) @@ -1254,9 +1281,9 @@ class MediaLibrarySessionCallback : val selectedShare = shares?.firstOrNull { share -> share.id == id } if (selectedShare != null) { - - if (selectedShare.getEntries().count() > 1) + if (selectedShare.getEntries().count() > 1) { mediaItems.addPlayAllItem(listOf(MEDIA_SHARE_ITEM, id).joinToString("|")) + } selectedShare.getEntries().map { song -> mediaItems.add( @@ -1302,8 +1329,9 @@ class MediaLibrarySessionCallback : }.await() if (songs != null) { - if (songs.songs.count() > 1) + if (songs.songs.count() > 1) { mediaItems.addPlayAllItem(listOf(MEDIA_SONG_STARRED_ID).joinToString("|")) + } // TODO: Paging is not implemented for songs, is it necessary at all? val items = songs.songs.take(DISPLAY_LIMIT) @@ -1350,8 +1378,9 @@ class MediaLibrarySessionCallback : }.await() if (songs != null) { - if (songs.size > 1) + if (songs.size > 1) { mediaItems.addPlayAllItem(listOf(MEDIA_SONG_RANDOM_ID).joinToString("|")) + } // TODO: Paging is not implemented for songs, is it necessary at all? val items = songs.getTracks() @@ -1416,7 +1445,6 @@ class MediaLibrarySessionCallback : mediaType: Int = MEDIA_TYPE_MIXED, isBrowsable: Boolean = false ) { - val mediaItem = buildMediaItem( title, mediaId, @@ -1446,19 +1474,21 @@ class MediaLibrarySessionCallback : isBrowsable = isBrowsable, imageUri = if (icon != null) { Util.getUriToDrawable(applicationContext, icon) - } else null, + } else { + null + }, group = if (groupNameId != null) { applicationContext.getString(groupNameId) - } else null, + } else { + null + }, mediaType = mediaType ) this.add(mediaItem) } - private fun MutableList.addPlayAllItem( - mediaId: String, - ) { + private fun MutableList.addPlayAllItem(mediaId: String) { this.add( R.string.select_album_play_all, mediaId, @@ -1513,8 +1543,7 @@ class MediaLibrarySessionCallback : } } - private fun MediaSession.canShuffle() = - player.mediaItemCount > 2 + private fun MediaSession.canShuffle() = player.mediaItemCount > 2 private fun MediaSession.buildCustomCommands( isHeart: Boolean = false, @@ -1531,22 +1560,25 @@ class MediaLibrarySessionCallback : if ( player.repeatMode != Player.REPEAT_MODE_ALL && player.currentMediaItemIndex == player.mediaItemCount - 1 - ) + ) { add(placeholderButton) + } // due to the previous placeholder this heart button will always appear to the left // of the default playback items add( - if (isHeart) + if (isHeart) { heartButtonToggleOff - else + } else { heartButtonToggleOn + } ) // both the shuffle and the active repeat mode button will end up in the overflow // menu if both are available at the same time - if (canShuffle) + if (canShuffle) { add(shuffleButton) + } add( when (player.repeatMode) { @@ -1564,8 +1596,9 @@ class MediaLibrarySessionCallback : // 3 was chosen because that leaves at least two other songs to be shuffled around @Suppress("MagicNumber") - if (player.mediaItemCount < 3) + if (player.mediaItemCount < 3) { return + } val mediaItemsToShuffle = mutableListOf() diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerLifecycleSupport.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerLifecycleSupport.kt index 939c51ee..af8cc1d3 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerLifecycleSupport.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerLifecycleSupport.kt @@ -58,7 +58,6 @@ class MediaPlayerLifecycleSupport( } private fun onCreate(autoPlay: Boolean, afterRestore: Runnable?) { - if (created) { afterRestore?.run() return @@ -87,7 +86,6 @@ class MediaPlayerLifecycleSupport( } private fun onDestroy() { - if (!created) return rxBusSubscription.dispose() @@ -100,7 +98,6 @@ class MediaPlayerLifecycleSupport( } fun receiveIntent(intent: Intent?) { - if (intent == null) return val intentAction = intent.action @@ -130,7 +127,6 @@ class MediaPlayerLifecycleSupport( * while Ultrasonic is running. */ private fun registerHeadsetReceiver() { - headsetEventReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val extras = intent.extras ?: return @@ -161,7 +157,6 @@ class MediaPlayerLifecycleSupport( @Suppress("MagicNumber", "ComplexMethod") private fun handleKeyEvent(event: KeyEvent) { - if (event.action != KeyEvent.ACTION_DOWN || event.repeatCount > 0) return val keyCode: Int = event.keyCode @@ -177,7 +172,8 @@ class MediaPlayerLifecycleSupport( onCreate(autoStart) { when (keyCode) { KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, - KeyEvent.KEYCODE_HEADSETHOOK -> mediaPlayerManager.togglePlayPause() + KeyEvent.KEYCODE_HEADSETHOOK + -> mediaPlayerManager.togglePlayPause() KeyEvent.KEYCODE_MEDIA_PREVIOUS -> mediaPlayerManager.seekToPrevious() KeyEvent.KEYCODE_MEDIA_NEXT -> mediaPlayerManager.seekToNext() KeyEvent.KEYCODE_MEDIA_STOP -> mediaPlayerManager.stop() @@ -200,12 +196,12 @@ class MediaPlayerLifecycleSupport( */ @Suppress("ComplexMethod") private fun handleUltrasonicIntent(action: String) { - val isRunning = created // If Ultrasonic is not running, do nothing to stop or pause - if (!isRunning && (action == Constants.CMD_PAUSE || action == Constants.CMD_STOP)) + if (!isRunning && (action == Constants.CMD_PAUSE || action == Constants.CMD_STOP)) { return + } val autoStart = action == Constants.CMD_PLAY || action == Constants.CMD_RESUME_OR_PLAY || diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerManager.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerManager.kt index 6671a0f3..41c2f817 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerManager.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MediaPlayerManager.kt @@ -325,10 +325,7 @@ class MediaPlayerManager( } @Synchronized - fun restore( - state: PlaybackState, - autoPlay: Boolean - ) { + fun restore(state: PlaybackState, autoPlay: Boolean) { val insertionMode = InsertionMode.APPEND addToPlaylist( @@ -398,7 +395,9 @@ class MediaPlayerManager( // This case would throw an exception in Media3. It can happen when an inconsistent state is saved. if (controller?.currentTimeline?.isEmpty != false || index >= controller!!.currentTimeline.windowCount - ) return + ) { + return + } Timber.i("SeekTo: %s %s", index, position) controller?.seekTo(index, position.toLong()) @@ -501,9 +500,7 @@ class MediaPlayerManager( shuffle: Boolean = false, isArtist: Boolean = false ) { - fragment.launchWithToast { - val list: List = tracks.ifEmpty { requireNotNull(id) @@ -514,7 +511,7 @@ class MediaPlayerManager( songs = list, insertionMode = insertionMode, autoPlay = (insertionMode == InsertionMode.CLEAR), - shuffle = shuffle, + shuffle = shuffle ) if (insertionMode == InsertionMode.CLEAR) { @@ -529,10 +526,11 @@ class MediaPlayerManager( quantize(R.plurals.n_songs_added_to_end, list) InsertionMode.CLEAR -> { - if (Settings.shouldTransitionOnPlayback) + if (Settings.shouldTransitionOnPlayback) { null - else + } else { quantize(R.plurals.n_songs_added_play_now, list) + } } } } @@ -585,12 +583,15 @@ class MediaPlayerManager( @Synchronized @JvmOverloads fun clear(serialize: Boolean = true) { - controller?.clearMediaItems() if (controller != null && serialize) { playbackStateSerializer.serializeAsync( - listOf(), -1, 0, isShufflePlayEnabled, repeatMode + listOf(), + -1, + 0, + isShufflePlayEnabled, + repeatMode ) } } @@ -731,8 +732,8 @@ class MediaPlayerManager( } /* - * Sets the rating of the current track - */ + * Sets the rating of the current track + */ private fun setRating(rating: Rating) { if (controller is MediaController) { (controller as MediaController).setRating(rating) @@ -740,9 +741,9 @@ class MediaPlayerManager( } /* - * This legacy function simply emits a rating update, - * which will then be processed by both the RatingManager as well as the controller - */ + * This legacy function simply emits a rating update, + * which will then be processed by both the RatingManager as well as the controller + */ fun legacyToggleStar() { if (currentMediaItem == null) return val track = currentMediaItem!!.toTrack() @@ -878,7 +879,9 @@ class MediaPlayerManager( } enum class InsertionMode { - CLEAR, APPEND, AFTER_CURRENT + CLEAR, + APPEND, + AFTER_CURRENT } enum class PlayerBackend { JUKEBOX, LOCAL } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MusicService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MusicService.kt index 73f292f0..0831a37a 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MusicService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/MusicService.kt @@ -27,7 +27,6 @@ import org.moire.ultrasonic.domain.Track import org.moire.ultrasonic.domain.UserInfo @Suppress("TooManyFunctions") - interface MusicService { @Throws(Exception::class) fun ping() diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/OfflineMusicService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/OfflineMusicService.kt index 504cf4a0..94a08c30 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/OfflineMusicService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/OfflineMusicService.kt @@ -113,13 +113,9 @@ class OfflineMusicService : MusicService, KoinComponent { } /* - * Especially when dealing with indexes, this method can return Albums, Entries or a mix of both! - */ - override fun getMusicDirectory( - id: String, - name: String?, - refresh: Boolean - ): MusicDirectory { + * Especially when dealing with indexes, this method can return Albums, Entries or a mix of both! + */ + override fun getMusicDirectory(id: String, name: String?, refresh: Boolean): MusicDirectory { val dir = Storage.getFromPath(id) val result = MusicDirectory() result.name = dir?.name ?: return result @@ -353,6 +349,7 @@ class OfflineMusicService : MusicService, KoinComponent { override fun stopJukebox(): JukeboxStatus { throw OfflineException("Jukebox not available in offline mode") } + @Throws(Exception::class) override fun clearJukebox(): JukeboxStatus { throw OfflineException("Jukebox not available in offline mode") @@ -394,11 +391,7 @@ class OfflineMusicService : MusicService, KoinComponent { } @Throws(Exception::class) - override fun createShare( - ids: List, - description: String?, - expires: Long? - ): List { + override fun createShare(ids: List, description: String?, expires: Long?): List { throw OfflineException("Creating shares not available in offline mode") } @@ -498,7 +491,6 @@ class OfflineMusicService : MusicService, KoinComponent { @Throws(OfflineException::class) override fun getAlbumAsDir(id: String, name: String?, refresh: Boolean): MusicDirectory { - Timber.i("Starting album query...") val list = cachedTracks @@ -637,10 +629,11 @@ class OfflineMusicService : MusicService, KoinComponent { val slashIndex = string.indexOf('/') - return if (slashIndex > 0) + return if (slashIndex > 0) { string.substring(0, slashIndex).toIntOrNull() - else + } else { string.toIntOrNull() + } } /* @@ -651,10 +644,11 @@ class OfflineMusicService : MusicService, KoinComponent { val duration: Long? = string.toLongOrNull() - return if (duration != null) + return if (duration != null) { TimeUnit.MILLISECONDS.toSeconds(duration).toInt() - else + } else { null + } } // TODO: Simplify this deeply nested and complicated function diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackService.kt index 34f6acc5..ed4dd5fb 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackService.kt @@ -240,8 +240,9 @@ class PlaybackService : // Create a renderer with HW rendering support val renderer = DefaultRenderersFactory(this) - if (Settings.useHwOffload) + if (Settings.useHwOffload) { renderer.setEnableAudioOffload(true) + } // Create the player val player = ExoPlayer.Builder(this) @@ -258,8 +259,9 @@ class PlaybackService : equalizer = EqualizerController.create(player.audioSessionId) // Enable audio offload - if (Settings.useHwOffload) + if (Settings.useHwOffload) { player.experimentalSetOffloadSchedulingEnabled(true) + } return player } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackState.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackState.kt index 3d81d21b..944fc20b 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackState.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackState.kt @@ -25,6 +25,6 @@ fun PlaybackState.toMediaItemsWithStartPosition(): MediaSession.MediaItemsWithSt return MediaSession.MediaItemsWithStartPosition( songs.map { it.toMediaItem() }, currentPlayingIndex, - currentPlayingPosition.toLong(), + currentPlayingPosition.toLong() ) } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackStateSerializer.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackStateSerializer.kt index c1a7fa85..337b3485 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackStateSerializer.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaybackStateSerializer.kt @@ -101,7 +101,6 @@ class PlaybackStateSerializer : KoinComponent { } fun deserializeNow(): PlaybackState? { - val state = FileUtil.deserialize( context, Constants.FILENAME_PLAYLIST_SER ) ?: return null diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaylistTimeline.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaylistTimeline.kt index a94ef1dc..0a0247a1 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaylistTimeline.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/PlaylistTimeline.kt @@ -59,11 +59,17 @@ class PlaylistTimeline @JvmOverloads constructor( return windowIndex } if (windowIndex == getLastWindowIndex(shuffleModeEnabled)) { - return if (repeatMode == Player.REPEAT_MODE_ALL) getFirstWindowIndex(shuffleModeEnabled) - else C.INDEX_UNSET + return if (repeatMode == Player.REPEAT_MODE_ALL) { + getFirstWindowIndex(shuffleModeEnabled) + } else { + C.INDEX_UNSET + } + } + return if (shuffleModeEnabled) { + shuffledIndices[indicesInShuffled[windowIndex] + 1] + } else { + windowIndex + 1 } - return if (shuffleModeEnabled) shuffledIndices[indicesInShuffled[windowIndex] + 1] - else windowIndex + 1 } override fun getPreviousWindowIndex( @@ -75,11 +81,17 @@ class PlaylistTimeline @JvmOverloads constructor( return windowIndex } if (windowIndex == getFirstWindowIndex(shuffleModeEnabled)) { - return if (repeatMode == Player.REPEAT_MODE_ALL) getLastWindowIndex(shuffleModeEnabled) - else C.INDEX_UNSET + return if (repeatMode == Player.REPEAT_MODE_ALL) { + getLastWindowIndex(shuffleModeEnabled) + } else { + C.INDEX_UNSET + } + } + return if (shuffleModeEnabled) { + shuffledIndices[indicesInShuffled[windowIndex] - 1] + } else { + windowIndex - 1 } - return if (shuffleModeEnabled) shuffledIndices[indicesInShuffled[windowIndex] - 1] - else windowIndex - 1 } override fun getLastWindowIndex(shuffleModeEnabled: Boolean): Int { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt index bdf9d5ef..15b5a24f 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RESTMusicService.kt @@ -72,9 +72,7 @@ open class RESTMusicService( } @Throws(Exception::class) - override fun getMusicFolders( - refresh: Boolean - ): List { + override fun getMusicFolders(refresh: Boolean): List { val response = API.getMusicFolders().execute().throwOnFailure() return response.body()!!.musicFolders.toDomainEntityList(activeServerId) @@ -84,10 +82,7 @@ open class RESTMusicService( * Retrieves the artists for a given music folder * */ @Throws(Exception::class) - override fun getIndexes( - musicFolderId: String?, - refresh: Boolean - ): List { + override fun getIndexes(musicFolderId: String?, refresh: Boolean): List { val response = API.getIndexes(musicFolderId, null).execute().throwOnFailure() return response.body()!!.indexes.toIndexList( @@ -97,88 +92,57 @@ open class RESTMusicService( } @Throws(Exception::class) - override fun getArtists( - refresh: Boolean - ): List { + override fun getArtists(refresh: Boolean): List { val response = API.getArtists(null).execute().throwOnFailure() return response.body()!!.indexes.toArtistList(activeServerId) } @Throws(Exception::class) - override fun star( - id: String?, - albumId: String?, - artistId: String? - ) { + override fun star(id: String?, albumId: String?, artistId: String?) { API.star(id, albumId, artistId).execute().throwOnFailure() } @Throws(Exception::class) - override fun unstar( - id: String?, - albumId: String?, - artistId: String? - ) { + override fun unstar(id: String?, albumId: String?, artistId: String?) { API.unstar(id, albumId, artistId).execute().throwOnFailure() } @Throws(Exception::class) - override fun setRating( - id: String, - rating: Int - ) { + override fun setRating(id: String, rating: Int) { API.setRating(id, rating).execute().throwOnFailure() } @Throws(Exception::class) - override fun getMusicDirectory( - id: String, - name: String?, - refresh: Boolean - ): MusicDirectory { + override fun getMusicDirectory(id: String, name: String?, refresh: Boolean): MusicDirectory { val response = API.getMusicDirectory(id).execute().throwOnFailure() return response.body()!!.musicDirectory.toDomainEntity(activeServerId) } @Throws(Exception::class) - override fun getAlbumsOfArtist( - id: String, - name: String?, - refresh: Boolean - ): List { + override fun getAlbumsOfArtist(id: String, name: String?, refresh: Boolean): List { val response = API.getArtist(id).execute().throwOnFailure() return response.body()!!.artist.toDomainEntityList(activeServerId) } @Throws(Exception::class) - override fun getAlbumAsDir( - id: String, - name: String?, - refresh: Boolean - ): MusicDirectory { + override fun getAlbumAsDir(id: String, name: String?, refresh: Boolean): MusicDirectory { val response = API.getAlbum(id).execute().throwOnFailure() return response.body()!!.album.toMusicDirectoryDomainEntity(activeServerId) } @Throws(Exception::class) - override fun getAlbum( - id: String, - name: String?, - refresh: Boolean - ): Album { + override fun getAlbum(id: String, name: String?, refresh: Boolean): Album { val response = API.getAlbum(id).execute().throwOnFailure() return response.body()!!.album.toDomainEntity(activeServerId) } @Throws(Exception::class) - override fun search( - criteria: SearchCriteria - ): SearchResult { + override fun search(criteria: SearchCriteria): SearchResult { return try { if (shouldUseId3Tags()) { search3(criteria) @@ -195,9 +159,7 @@ open class RESTMusicService( * Search using the "search" REST method. */ @Throws(Exception::class) - private fun searchOld( - criteria: SearchCriteria - ): SearchResult { + private fun searchOld(criteria: SearchCriteria): SearchResult { val response = API.search(null, null, null, criteria.query, criteria.songCount, null, null) .execute().throwOnFailure() @@ -209,36 +171,39 @@ open class RESTMusicService( * Search using the "search2" REST method, available in 1.4.0 and later. */ @Throws(Exception::class) - private fun search2( - criteria: SearchCriteria - ): SearchResult { + private fun search2(criteria: SearchCriteria): SearchResult { requireNotNull(criteria.query) { "Query param is null" } val response = API.search2( - criteria.query, criteria.artistCount, null, criteria.albumCount, null, - criteria.songCount, null + criteria.query, + criteria.artistCount, + null, + criteria.albumCount, + null, + criteria.songCount, + null ).execute().throwOnFailure() return response.body()!!.searchResult.toDomainEntity(activeServerId) } @Throws(Exception::class) - private fun search3( - criteria: SearchCriteria - ): SearchResult { + private fun search3(criteria: SearchCriteria): SearchResult { requireNotNull(criteria.query) { "Query param is null" } val response = API.search3( - criteria.query, criteria.artistCount, null, criteria.albumCount, null, - criteria.songCount, null + criteria.query, + criteria.artistCount, + null, + criteria.albumCount, + null, + criteria.songCount, + null ).execute().throwOnFailure() return response.body()!!.searchResult.toDomainEntity(activeServerId) } @Throws(Exception::class) - override fun getPlaylist( - id: String, - name: String - ): MusicDirectory { + override fun getPlaylist(id: String, name: String): MusicDirectory { val response = API.getPlaylist(id).execute().throwOnFailure() val playlist = response.body()!!.playlist.toMusicDirectoryDomainEntity(activeServerId) @@ -248,21 +213,17 @@ open class RESTMusicService( } @Throws(IOException::class) - private fun savePlaylist( - name: String, - playlist: MusicDirectory - ) { + private fun savePlaylist(name: String, playlist: MusicDirectory) { val playlistFile = FileUtil.getPlaylistFile( - activeServerProvider.getActiveServer().name, name + activeServerProvider.getActiveServer().name, + name ) FileUtil.savePlaylist(playlistFile, playlist, name) } @Throws(Exception::class) - override fun getPlaylists( - refresh: Boolean - ): List { + override fun getPlaylists(refresh: Boolean): List { val response = API.getPlaylists(null).execute().throwOnFailure() return response.body()!!.playlists.toDomainEntitiesList() @@ -274,11 +235,7 @@ open class RESTMusicService( * String is required when creating */ @Throws(Exception::class) - override fun createPlaylist( - id: String?, - name: String?, - tracks: List - ) { + override fun createPlaylist(id: String?, name: String?, tracks: List) { require(id != null || name != null) { "Either id or name is required." } val pSongIds: MutableList = ArrayList(tracks.size) @@ -290,36 +247,25 @@ open class RESTMusicService( } @Throws(Exception::class) - override fun deletePlaylist( - id: String - ) { + override fun deletePlaylist(id: String) { API.deletePlaylist(id).execute().throwOnFailure() } @Throws(Exception::class) - override fun updatePlaylist( - id: String, - name: String?, - comment: String?, - pub: Boolean - ) { + override fun updatePlaylist(id: String, name: String?, comment: String?, pub: Boolean) { API.updatePlaylist(id, name, comment, pub, null, null) .execute().throwOnFailure() } @Throws(Exception::class) - override fun getPodcastsChannels( - refresh: Boolean - ): List { + override fun getPodcastsChannels(refresh: Boolean): List { val response = API.getPodcasts(false, null).execute().throwOnFailure() return response.body()!!.podcastChannels.toDomainEntitiesList() } @Throws(Exception::class) - override fun getPodcastEpisodes( - podcastChannelId: String? - ): MusicDirectory { + override fun getPodcastEpisodes(podcastChannelId: String?): MusicDirectory { val response = API.getPodcasts(true, podcastChannelId).execute().throwOnFailure() val podcastEntries = response.body()!!.podcastChannels[0].episodeList @@ -340,20 +286,14 @@ open class RESTMusicService( } @Throws(Exception::class) - override fun getLyrics( - artist: String, - title: String - ): Lyrics { + override fun getLyrics(artist: String, title: String): Lyrics { val response = API.getLyrics(artist, title).execute().throwOnFailure() return response.body()!!.lyrics.toDomainEntity() } @Throws(Exception::class) - override fun scrobble( - id: String, - submission: Boolean - ) { + override fun scrobble(id: String, submission: Boolean) { API.scrobble(id, null, submission).execute().throwOnFailure() } @@ -398,9 +338,7 @@ open class RESTMusicService( } @Throws(Exception::class) - override fun getRandomSongs( - size: Int - ): MusicDirectory { + override fun getRandomSongs(size: Int): MusicDirectory { val response = API.getRandomSongs( size, null, @@ -464,11 +402,7 @@ open class RESTMusicService( * call because that could take a long time. */ @Throws(Exception::class) - override fun getStreamUrl( - id: String, - maxBitRate: Int?, - format: String? - ): String { + override fun getStreamUrl(id: String, maxBitRate: Int?, format: String?): String { Timber.i("Start") // Get the request from Retrofit, but don't execute it! @@ -510,9 +444,7 @@ open class RESTMusicService( } @Throws(Exception::class) - override fun updateJukeboxPlaylist( - ids: List - ): JukeboxStatus { + override fun updateJukeboxPlaylist(ids: List): JukeboxStatus { val response = API.jukeboxControl(JukeboxAction.SET, null, null, ids, null) .execute().throwOnFailure() @@ -520,10 +452,7 @@ open class RESTMusicService( } @Throws(Exception::class) - override fun skipJukebox( - index: Int, - offsetSeconds: Int - ): JukeboxStatus { + override fun skipJukebox(index: Int, offsetSeconds: Int): JukeboxStatus { val response = API.jukeboxControl(JukeboxAction.SKIP, index, offsetSeconds, null, null) .execute().throwOnFailure() @@ -563,9 +492,7 @@ open class RESTMusicService( } @Throws(Exception::class) - override fun setJukeboxGain( - gain: Float - ): JukeboxStatus { + override fun setJukeboxGain(gain: Float): JukeboxStatus { val response = API.jukeboxControl(JukeboxAction.SET_GAIN, null, null, null, gain) .execute().throwOnFailure() @@ -573,29 +500,21 @@ open class RESTMusicService( } @Throws(Exception::class) - override fun getShares( - refresh: Boolean - ): List { + override fun getShares(refresh: Boolean): List { val response = API.getShares().execute().throwOnFailure() return response.body()!!.shares.toDomainEntitiesList(activeServerId) } @Throws(Exception::class) - override fun getGenres( - refresh: Boolean - ): List { + override fun getGenres(refresh: Boolean): List { val response = API.getGenres().execute().throwOnFailure() return response.body()!!.genresList.toDomainEntityList() } @Throws(Exception::class) - override fun getSongsByGenre( - genre: String, - count: Int, - offset: Int - ): MusicDirectory { + override fun getSongsByGenre(genre: String, count: Int, offset: Int): MusicDirectory { val response = API.getSongsByGenre(genre, count, offset, null).execute().throwOnFailure() val result = MusicDirectory() @@ -605,27 +524,21 @@ open class RESTMusicService( } @Throws(Exception::class) - override fun getUser( - username: String - ): UserInfo { + override fun getUser(username: String): UserInfo { val response = API.getUser(username).execute().throwOnFailure() return response.body()!!.user.toDomainEntity() } @Throws(Exception::class) - override fun getChatMessages( - since: Long? - ): List { + override fun getChatMessages(since: Long?): List { val response = API.getChatMessages(since).execute().throwOnFailure() return response.body()!!.chatMessages.toDomainEntitiesList() } @Throws(Exception::class) - override fun addChatMessage( - message: String - ) { + override fun addChatMessage(message: String) { API.addChatMessage(message).execute().throwOnFailure() } @@ -637,24 +550,17 @@ open class RESTMusicService( } @Throws(Exception::class) - override fun createBookmark( - id: String, - position: Int - ) { + override fun createBookmark(id: String, position: Int) { API.createBookmark(id, position.toLong(), null).execute().throwOnFailure() } @Throws(Exception::class) - override fun deleteBookmark( - id: String - ) { + override fun deleteBookmark(id: String) { API.deleteBookmark(id).execute().throwOnFailure() } @Throws(Exception::class) - override fun getVideos( - refresh: Boolean - ): MusicDirectory { + override fun getVideos(refresh: Boolean): MusicDirectory { val response = API.getVideos().execute().throwOnFailure() val musicDirectory = MusicDirectory() @@ -664,29 +570,19 @@ open class RESTMusicService( } @Throws(Exception::class) - override fun createShare( - ids: List, - description: String?, - expires: Long? - ): List { + override fun createShare(ids: List, description: String?, expires: Long?): List { val response = API.createShare(ids, description, expires).execute().throwOnFailure() return response.body()!!.shares.toDomainEntitiesList(activeServerId) } @Throws(Exception::class) - override fun deleteShare( - id: String - ) { + override fun deleteShare(id: String) { API.deleteShare(id).execute().throwOnFailure() } @Throws(Exception::class) - override fun updateShare( - id: String, - description: String?, - expires: Long? - ) { + override fun updateShare(id: String, description: String?, expires: Long?) { var expiresValue: Long? = expires if (expires != null && expires == 0L) { expiresValue = null diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RatingManager.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RatingManager.kt index dd2bd38b..9b90e450 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RatingManager.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RatingManager.kt @@ -49,8 +49,11 @@ class RatingManager : CoroutineScope by CoroutineScope(Dispatchers.Default) { var success = false withContext(Dispatchers.IO) { try { - if (update.rating.isHeart) service.star(id) - else service.unstar(id) + if (update.rating.isHeart) { + service.star(id) + } else { + service.unstar(id) + } success = true } catch (all: Exception) { Timber.e(all) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RxBus.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RxBus.kt index ceadd14e..591b99a3 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RxBus.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/service/RxBus.kt @@ -29,6 +29,7 @@ class RxBus { var activeServerChangingPublisher: PublishSubject = PublishSubject.create() + // Subscribers should be called synchronously, not on another thread var activeServerChangingObservable: Observable = activeServerChangingPublisher diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/ImageLoaderProvider.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/ImageLoaderProvider.kt index b70852f1..29cc4c0d 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/ImageLoaderProvider.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/ImageLoaderProvider.kt @@ -68,7 +68,9 @@ class ImageLoaderProvider : val config by lazy { var defaultSize = 0 val fallbackImage = ResourcesCompat.getDrawable( - UApp.applicationContext().resources, R.drawable.unknown_album, null + UApp.applicationContext().resources, + R.drawable.unknown_album, + null ) // Determine the density-dependent image sizes by taking the fallback album diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/RestErrorMapper.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/RestErrorMapper.kt index 2f2e2304..3f28af71 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/RestErrorMapper.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/RestErrorMapper.kt @@ -1,4 +1,5 @@ @file:JvmName("RestErrorMapper") + package org.moire.ultrasonic.subsonic import android.content.Context @@ -18,28 +19,27 @@ import org.moire.ultrasonic.api.subsonic.SubsonicRESTException * Extension for [SubsonicRESTException] that returns localized error string, that can used to * display error reason for user. */ -fun SubsonicRESTException.getLocalizedErrorMessage(context: Context): String = - when (error) { - is Generic -> { - val message = (error as Generic).message - val errorMessage = if (message == "") { - context.getString(R.string.api_subsonic_generic_no_message) - } else { - message - } - context.getString(R.string.api_subsonic_generic, errorMessage) +fun SubsonicRESTException.getLocalizedErrorMessage(context: Context): String = when (error) { + is Generic -> { + val message = (error as Generic).message + val errorMessage = if (message == "") { + context.getString(R.string.api_subsonic_generic_no_message) + } else { + message } - RequiredParamMissing -> context.getString(R.string.api_subsonic_param_missing) - IncompatibleClientProtocolVersion -> - context.getString(R.string.api_subsonic_upgrade_client) - IncompatibleServerProtocolVersion -> - context.getString(R.string.api_subsonic_upgrade_server) - WrongUsernameOrPassword -> context.getString(R.string.api_subsonic_not_authenticated) - TokenAuthNotSupportedForLDAP -> - context.getString(R.string.api_subsonic_token_auth_not_supported_for_ldap) - UserNotAuthorizedForOperation -> - context.getString(R.string.api_subsonic_not_authorized) - TrialPeriodIsOver -> context.getString(R.string.api_subsonic_trial_period_is_over) - RequestedDataWasNotFound -> - context.getString(R.string.api_subsonic_requested_data_was_not_found) + context.getString(R.string.api_subsonic_generic, errorMessage) } + RequiredParamMissing -> context.getString(R.string.api_subsonic_param_missing) + IncompatibleClientProtocolVersion -> + context.getString(R.string.api_subsonic_upgrade_client) + IncompatibleServerProtocolVersion -> + context.getString(R.string.api_subsonic_upgrade_server) + WrongUsernameOrPassword -> context.getString(R.string.api_subsonic_not_authenticated) + TokenAuthNotSupportedForLDAP -> + context.getString(R.string.api_subsonic_token_auth_not_supported_for_ldap) + UserNotAuthorizedForOperation -> + context.getString(R.string.api_subsonic_not_authorized) + TrialPeriodIsOver -> context.getString(R.string.api_subsonic_trial_period_is_over) + RequestedDataWasNotFound -> + context.getString(R.string.api_subsonic_requested_data_was_not_found) +} 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 ce2f0eaa..7d0efa69 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/ShareHandler.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/subsonic/ShareHandler.kt @@ -47,11 +47,7 @@ class ShareHandler { private var textViewExpiration: TextView? = null private val pattern = Pattern.compile(":") - fun share( - fragment: Fragment, - shareDetails: ShareDetails, - additionalId: String? - ) { + fun share(fragment: Fragment, shareDetails: ShareDetails, additionalId: String?) { val scope = fragment.activity?.lifecycleScope ?: fragment.lifecycleScope scope.launch { val share = createShareOnServer(shareDetails, additionalId) @@ -65,11 +61,11 @@ class ShareHandler { ): Share? { return withContext(Dispatchers.IO) { return@withContext try { - val ids: MutableList = ArrayList() - if (!shareDetails.shareOnServer && shareDetails.entries.size == 1) + if (!shareDetails.shareOnServer && shareDetails.entries.size == 1) { return@withContext null + } if (shareDetails.entries.isEmpty()) { additionalId.ifNotNull { ids.add(it) @@ -94,10 +90,11 @@ class ShareHandler { ) // Return the share - if (shares.isNotEmpty()) + if (shares.isNotEmpty()) { shares[0] - else + } else { null + } } catch (ignored: Exception) { null } @@ -118,7 +115,10 @@ class ShareHandler { intent.putExtra( Intent.EXTRA_TEXT, String.format( - Locale.ROOT, "%s\n\n%s", Settings.shareGreeting, result.url + Locale.ROOT, + "%s\n\n%s", + Settings.shareGreeting, + result.url ) ) } else { @@ -126,15 +126,18 @@ class ShareHandler { val textBuilder = StringBuilder() textBuilder.appendLine(Settings.shareGreeting) - if (!shareDetails.entries[0].title.isNullOrEmpty()) + if (!shareDetails.entries[0].title.isNullOrEmpty()) { textBuilder.append(getString(R.string.common_title)) .append(": ").appendLine(shareDetails.entries[0].title) - if (!shareDetails.entries[0].artist.isNullOrEmpty()) + } + if (!shareDetails.entries[0].artist.isNullOrEmpty()) { textBuilder.append(getString(R.string.common_artist)) .append(": ").appendLine(shareDetails.entries[0].artist) - if (!shareDetails.entries[0].album.isNullOrEmpty()) + } + if (!shareDetails.entries[0].album.isNullOrEmpty()) { textBuilder.append(getString(R.string.common_album)) .append(": ").append(shareDetails.entries[0].album) + } intent.putExtra(Intent.EXTRA_TEXT, textBuilder.toString()) } @@ -148,11 +151,7 @@ class ShareHandler { } } - fun createShare( - fragment: Fragment, - tracks: List, - additionalId: String? = null - ) { + fun createShare(fragment: Fragment, tracks: List, additionalId: String? = null) { if (tracks.isEmpty()) return val askForDetails = Settings.shouldAskForShareDetails val shareDetails = ShareDetails(tracks) @@ -167,11 +166,7 @@ class ShareHandler { } @SuppressLint("InflateParams") - private fun showDialog( - fragment: Fragment, - shareDetails: ShareDetails, - additionalId: String? - ) { + private fun showDialog(fragment: Fragment, shareDetails: ShareDetails, additionalId: String?) { val layout = LayoutInflater.from(fragment.context).inflate(R.layout.share_details, null) if (layout != null) { @@ -258,8 +253,11 @@ class ShareHandler { val timeSpanType: String = timeSpanPicker!!.timeSpanType!! val timeSpanAmount: Int = timeSpanPicker!!.timeSpanAmount Settings.defaultShareExpiration = - if (!noExpirationCheckBox!!.isChecked && timeSpanAmount > 0) - String.format("%d:%s", timeSpanAmount, timeSpanType) else "" + if (!noExpirationCheckBox!!.isChecked && timeSpanAmount > 0) { + String.format("%d:%s", timeSpanAmount, timeSpanType) + } else { + "" + } Settings.defaultShareDescription = shareDetails.description!! Settings.shareOnServer = shareDetails.shareOnServer diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/CommunicationError.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/CommunicationError.kt index acdd03da..f3d7995f 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/CommunicationError.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/CommunicationError.kt @@ -29,8 +29,10 @@ import timber.log.Timber * thrown during the communication with a Subsonic server */ object CommunicationError { - fun getHandler(context: Context?, handler: ((CoroutineContext, Throwable) -> Unit)? = null): - CoroutineExceptionHandler { + fun getHandler( + context: Context?, + handler: ((CoroutineContext, Throwable) -> Unit)? = null + ): CoroutineExceptionHandler { return CoroutineExceptionHandler { coroutineContext, exception -> Handler(Looper.getMainLooper()).post { handleError(exception, context) @@ -68,14 +70,16 @@ object CommunicationError { ) { context.resources .getString( - R.string.background_task_ssl_cert_error, error.cause?.cause?.message + R.string.background_task_ssl_cert_error, + error.cause?.cause?.message ) } else { context.resources.getString(R.string.background_task_ssl_error) } } else if (error is ApiNotSupportedException) { return context.resources.getString( - R.string.background_task_unsupported_api, error.serverApiVersion + R.string.background_task_unsupported_api, + error.serverApiVersion ) } else if (error is IOException) { return context.resources.getString(R.string.background_task_network_error) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/CoroutinePatterns.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/CoroutinePatterns.kt index dad0ae39..4b04994a 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/CoroutinePatterns.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/CoroutinePatterns.kt @@ -31,9 +31,7 @@ object CoroutinePatterns { } } -fun Fragment.toastingExceptionHandler( - prefix: String = "" -): CoroutineExceptionHandler { +fun Fragment.toastingExceptionHandler(prefix: String = ""): CoroutineExceptionHandler { return CoroutineExceptionHandler { _, exception -> // Stop the spinner if applicable if (this is RefreshableFragment) { @@ -48,9 +46,7 @@ fun Fragment.toastingExceptionHandler( * This extension can be only started from a fragment * because it needs the fragments scope to create the toast */ -fun Fragment.launchWithToast( - block: suspend CoroutineScope.() -> String? -) { +fun Fragment.launchWithToast(block: suspend CoroutineScope.() -> String?) { // Get the scope val scope = activity?.lifecycleScope ?: lifecycleScope diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/DownloadUtil.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/DownloadUtil.kt index 00ce9acd..4a3c576a 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/DownloadUtil.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/DownloadUtil.kt @@ -34,7 +34,6 @@ object DownloadUtil { isArtist: Boolean = false, tracks: List? = null ) { - // Launch the Job fragment.launchWithToast { val tracksToDownload: List = tracks @@ -87,10 +86,11 @@ object DownloadUtil { return getSongsForArtist(id) } else { if (isDirectory) { - root = if (ActiveServerProvider.shouldUseId3Tags()) + root = if (ActiveServerProvider.shouldUseId3Tags()) { musicService.getAlbumAsDir(id, name, false) - else + } else { musicService.getMusicDirectory(id, name, false) + } } else if (isShare) { root = MusicDirectory() val shares = musicService.getShares(true) @@ -107,10 +107,7 @@ object DownloadUtil { @Suppress("DestructuringDeclarationWithTooManyEntries") @Throws(Exception::class) - private fun getSongsRecursively( - parent: MusicDirectory, - songs: MutableList - ) { + private fun getSongsRecursively(parent: MusicDirectory, songs: MutableList) { if (songs.size > Constants.MAX_SONGS_RECURSIVE) { return } @@ -121,18 +118,17 @@ object DownloadUtil { } val musicService = MusicServiceFactory.getMusicService() for ((id1, _, _, title) in parent.getAlbums()) { - val root: MusicDirectory = if (ActiveServerProvider.shouldUseId3Tags()) + val root: MusicDirectory = if (ActiveServerProvider.shouldUseId3Tags()) { musicService.getAlbumAsDir(id1, title, false) - else + } else { musicService.getMusicDirectory(id1, title, false) + } getSongsRecursively(root, songs) } } @Throws(Exception::class) - private fun getSongsForArtist( - id: String - ): MutableList { + private fun getSongsForArtist(id: String): MutableList { val songs: MutableList = LinkedList() val musicService = MusicServiceFactory.getMusicService() val artist = musicService.getAlbumsOfArtist(id, "", false) @@ -191,5 +187,8 @@ object DownloadUtil { } enum class DownloadAction { - DOWNLOAD, PIN, UNPIN, DELETE + DOWNLOAD, + PIN, + UNPIN, + DELETE } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/EntryByDiscAndTrackComparator.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/EntryByDiscAndTrackComparator.kt index 099eeb66..b2c1f6f4 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/EntryByDiscAndTrackComparator.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/EntryByDiscAndTrackComparator.kt @@ -25,10 +25,12 @@ class EntryByDiscAndTrackComparator : Comparator { val trackComparison = compare(trackX ?: 0, trackY ?: 0) return if (trackComparison != 0) { trackComparison - } else compare( - pathX ?: "", - pathY ?: "" - ) + } else { + compare( + pathX ?: "", + pathY ?: "" + ) + } } companion object { @@ -45,7 +47,9 @@ class EntryByDiscAndTrackComparator : Comparator { } return if (b == null) { 1 - } else a.compareTo(b) + } else { + a.compareTo(b) + } } } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/FileUtil.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/FileUtil.kt index 24db2753..8f08ed03 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/FileUtil.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/FileUtil.kt @@ -261,10 +261,14 @@ object FileUtil { if (cachedUltrasonicDirectory != null) return cachedUltrasonicDirectory!! @Suppress("DEPRECATION") - cachedUltrasonicDirectory = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) File( - Environment.getExternalStorageDirectory(), - "Android/data/org.moire.ultrasonic" - ) else UApp.applicationContext().getExternalFilesDir(null)!! + cachedUltrasonicDirectory = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + File( + Environment.getExternalStorageDirectory(), + "Android/data/org.moire.ultrasonic" + ) + } else { + UApp.applicationContext().getExternalFilesDir(null)!! + } return cachedUltrasonicDirectory!! } @@ -489,11 +493,7 @@ object FileUtil { } } - fun savePlaylist( - playlistFile: File?, - playlist: MusicDirectory, - name: String - ) { + fun savePlaylist(playlistFile: File?, playlist: MusicDirectory, name: String) { val fw = FileWriter(playlistFile) val bw = BufferedWriter(fw) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/LayoutType.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/LayoutType.kt index 46fa11c7..b930a9bd 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/LayoutType.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/LayoutType.kt @@ -9,7 +9,8 @@ package org.moire.ultrasonic.util enum class LayoutType(val value: Int) { LIST(0), - COVER(1); + COVER(1) + ; companion object { private val map = values().associateBy { it.value } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/MediaItemConverter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/MediaItemConverter.kt index e05957ed..bf03e09e 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/MediaItemConverter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/MediaItemConverter.kt @@ -58,10 +58,7 @@ object MediaItemConverter { * Extension function to convert a Track to an MediaItem, using the cache if possible */ @Suppress("LongMethod") -fun Track.toMediaItem( - mediaId: String = id, -): MediaItem { - +fun Track.toMediaItem(mediaId: String = id): MediaItem { // Check Cache val cachedItem = MediaItemConverter.mediaItemCache[mediaId]?.get() if (cachedItem != null) return cachedItem @@ -85,8 +82,11 @@ fun Track.toMediaItem( imageUri = artworkUri, starred = starred, group = null, - mediaType = if (isDirectory) MEDIA_TYPE_FOLDER_MIXED - else MEDIA_TYPE_MUSIC + mediaType = if (isDirectory) { + MEDIA_TYPE_FOLDER_MIXED + } else { + MEDIA_TYPE_MUSIC + } ) val metadataBuilder = mediaItem.mediaMetadata.buildUpon() @@ -111,9 +111,12 @@ fun Track.toMediaItem( mediaItem.mediaMetadata.extras?.putBoolean("isVideo", isVideo) mediaItem.mediaMetadata.extras?.putBoolean("starred", starred) mediaItem.mediaMetadata.extras?.putString("type", type) - if (created != null) mediaItem.mediaMetadata.extras?.putString( - "created", DateFormat.getDateInstance().format(created!!) - ) + if (created != null) { + mediaItem.mediaMetadata.extras?.putString( + "created", + DateFormat.getDateInstance().format(created!!) + ) + } mediaItem.mediaMetadata.extras?.putInt("closeness", closeness) mediaItem.mediaMetadata.extras?.putInt("bookmarkPosition", bookmarkPosition) mediaItem.mediaMetadata.extras?.putString("name", name) @@ -141,7 +144,6 @@ fun Track.toMediaItem( */ @Suppress("ComplexMethod") fun MediaItem.toTrack(): Track { - // Check Cache val cachedTrack = MediaItemConverter.trackCache[mediaId]?.get() if (cachedTrack != null) return cachedTrack @@ -168,13 +170,22 @@ fun MediaItem.toTrack(): Track { mediaMetadata.extras?.getString("transcodedContentType"), mediaMetadata.extras?.getString("transcodedSuffix"), mediaMetadata.extras?.getString("coverArt"), - if (mediaMetadata.extras?.containsKey("size") == true) - mediaMetadata.extras?.getLong("size") else null, + if (mediaMetadata.extras?.containsKey("size") == true) { + mediaMetadata.extras?.getLong("size") + } else { + null + }, mediaMetadata.totalTrackCount?.toLong(), - if (mediaMetadata.extras?.containsKey("duration") == true) - mediaMetadata.extras?.getInt("duration") else null, - if (mediaMetadata.extras?.containsKey("bitRate") == true) - mediaMetadata.extras?.getInt("bitRate") else null, + if (mediaMetadata.extras?.containsKey("duration") == true) { + mediaMetadata.extras?.getInt("duration") + } else { + null + }, + if (mediaMetadata.extras?.containsKey("bitRate") == true) { + mediaMetadata.extras?.getInt("bitRate") + } else { + null + }, mediaMetadata.extras?.getString("path"), mediaMetadata.extras?.getBoolean("isVideo") ?: false, mediaMetadata.extras?.getBoolean("starred", false) ?: false, @@ -185,7 +196,7 @@ fun MediaItem.toTrack(): Track { mediaMetadata.extras?.getInt("bookmarkPosition", 0) ?: 0, mediaMetadata.extras?.getInt("userRating", 0) ?: 0, mediaMetadata.extras?.getFloat("averageRating", 0F) ?: 0F, - mediaMetadata.extras?.getString("name"), + mediaMetadata.extras?.getString("name") ) if (mediaMetadata.userRating is HeartRating) { track.starred = (mediaMetadata.userRating as HeartRating).isHeart @@ -199,11 +210,15 @@ fun MediaItem.toTrack(): Track { } private fun safeParseDate(created: String?): Date? { - return if (created != null) try { - DateFormat.getDateInstance().parse(created) - } catch (_: ParseException) { + return if (created != null) { + try { + DateFormat.getDateInstance().parse(created) + } catch (_: ParseException) { + null + } + } else { null - } else null + } } /** @@ -224,9 +239,8 @@ fun buildMediaItem( imageUri: Uri? = null, starred: Boolean = false, group: String? = null, - mediaType: @MediaMetadata.MediaType Int? = null, + mediaType: @MediaMetadata.MediaType Int? = null ): MediaItem { - val metadataBuilder = MediaMetadata.Builder() .setAlbumTitle(album) .setTitle(title) @@ -255,7 +269,9 @@ fun buildMediaItem( ) } ) - } else metadataBuilder.setExtras(Bundle()) + } else { + metadataBuilder.setExtras(Bundle()) + } val metadata = metadataBuilder.build() diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/SettableAsyncListDiffer.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/SettableAsyncListDiffer.kt index 9e0dc12f..f16b504d 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/SettableAsyncListDiffer.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/SettableAsyncListDiffer.kt @@ -116,7 +116,7 @@ class SettableAsyncListDiffer { private var mReadOnlyList = emptyList() // Max generation of currently scheduled runnable - private var mMaxScheduledGeneration/* synthetic access */ = 0 + private var mMaxScheduledGeneration = 0 /** * Get the current List - any diffing to present this list has already been computed and @@ -176,10 +176,7 @@ class SettableAsyncListDiffer { * @param commitCallback Optional runnable that is executed when the List is committed, if * it is committed. */ - fun submitList( - newList: List?, - commitCallback: Runnable? - ) { + fun submitList(newList: List?, commitCallback: Runnable?) { // incrementing generation means any currently-running diffs are discarded when they finish val runGeneration = ++mMaxScheduledGeneration if (newList === mList) { @@ -220,15 +217,14 @@ class SettableAsyncListDiffer { return newList.size } - override fun areItemsTheSame( - oldItemPosition: Int, - newItemPosition: Int - ): Boolean { + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { val oldItem: T? = oldList[oldItemPosition] val newItem: T? = newList[newItemPosition] return if (oldItem != null && newItem != null) { mConfig!!.diffCallback.areItemsTheSame(oldItem, newItem) - } else oldItem == null && newItem == null + } else { + oldItem == null && newItem == null + } // If both items are null we consider them the same. } @@ -264,11 +260,7 @@ class SettableAsyncListDiffer { } } - private fun latchList( - newList: List, - diffResult: DiffResult, - commitCallback: Runnable? - ) { + private fun latchList(newList: List, diffResult: DiffResult, commitCallback: Runnable?) { val previousList = mReadOnlyList mList = newList // notify last, after list is updated @@ -277,10 +269,7 @@ class SettableAsyncListDiffer { onCurrentListChanged(previousList, commitCallback) } - private fun onCurrentListChanged( - previousList: List, - commitCallback: Runnable? - ) { + private fun onCurrentListChanged(previousList: List, commitCallback: Runnable?) { // current list is always mReadOnlyList for (listener in mListeners) { listener.onCurrentListChanged(previousList, mReadOnlyList) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Settings.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Settings.kt index c6e69c8f..c184b916 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Settings.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Settings.kt @@ -79,7 +79,8 @@ object Settings { @JvmStatic var cacheLocationUri by StringSetting( - getKey(R.string.setting_key_cache_location), "" + getKey(R.string.setting_key_cache_location), + "" ) @JvmStatic diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/SettingsDelegate.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/SettingsDelegate.kt index 88356bff..b9f6c523 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/SettingsDelegate.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/SettingsDelegate.kt @@ -78,6 +78,7 @@ class BooleanSetting(private val key: String, private val defaultValue: Boolean sharedPreferences.edit { putBoolean(key, value) } constructor(stringId: Int, defaultValue: Boolean = false) : this( - Util.appContext().getString(stringId), defaultValue + Util.appContext().getString(stringId), + defaultValue ) } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/StorageFile.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/StorageFile.kt index 5d1eb983..0acababf 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/StorageFile.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/StorageFile.kt @@ -107,8 +107,9 @@ class StorageFile( @Synchronized override fun getOrCreateFileFromPath(path: String): AbstractFile { - if (storageFilePathDictionary.containsKey(path)) + if (storageFilePathDictionary.containsKey(path)) { return storageFilePathDictionary[path]!! + } val parent = getStorageFileForParentDirectory(path) ?: throw IOException("Parent directory doesn't exist") @@ -126,8 +127,9 @@ class StorageFile( } override fun getFromPath(path: String): StorageFile? { - if (storageFilePathDictionary.containsKey(path)) + if (storageFilePathDictionary.containsKey(path)) { return storageFilePathDictionary[path]!! + } if (notExistingPathDictionary.contains(path)) return null val parent = getStorageFileForParentDirectory(path) @@ -274,8 +276,9 @@ class StorageFile( private fun getStorageFileForParentDirectory(path: String): StorageFile? { val parentPath = FileUtil.getParentPath(path) ?: return null - if (storageFilePathDictionary.containsKey(parentPath)) + if (storageFilePathDictionary.containsKey(parentPath)) { return storageFilePathDictionary[parentPath]!! + } if (notExistingPathDictionary.contains(parentPath)) return null val parent = findStorageFileForParentDirectory(parentPath) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/TimeSpanPicker.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/TimeSpanPicker.kt index 33b66540..79008e67 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/TimeSpanPicker.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/TimeSpanPicker.kt @@ -26,7 +26,9 @@ import timber.log.Timber */ class TimeSpanPicker(private var mContext: Context, attrs: AttributeSet?, defStyle: Int) : LinearLayout( - mContext, attrs, defStyle + mContext, + attrs, + defStyle ), AdapterView.OnItemSelectedListener { private val timeSpanEditText: EditText @@ -72,9 +74,14 @@ class TimeSpanPicker(private var mContext: Context, attrs: AttributeSet?, defSty } fun getTimeSpan(): Long { - return if (!timeSpanDisableCheckbox.isChecked) getTimeSpanFromDialog( - mContext, dialog - ) else -1L + return if (!timeSpanDisableCheckbox.isChecked) { + getTimeSpanFromDialog( + mContext, + dialog + ) + } else { + -1L + } } val timeSpanEnabled: Boolean @@ -142,11 +149,7 @@ class TimeSpanPicker(private var mContext: Context, attrs: AttributeSet?, defSty return calculateTimeSpan(context, timeSpanType, timeSpanAmount) } - fun calculateTimeSpan( - context: Context, - timeSpanType: String, - timeSpanAmount: Long - ): Long { + fun calculateTimeSpan(context: Context, timeSpanType: String, timeSpanAmount: Long): Long { val resources = context.resources return when (timeSpanType) { diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/TimeSpanPreference.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/TimeSpanPreference.kt index cbb55ddd..a9fc37cb 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/TimeSpanPreference.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/TimeSpanPreference.kt @@ -9,7 +9,8 @@ import org.moire.ultrasonic.R * Created by Joshua Bahnsen on 12/22/13. */ class TimeSpanPreference(mContext: Context, attrs: AttributeSet?) : DialogPreference( - mContext, attrs + mContext, + attrs ) { init { setPositiveButtonText(android.R.string.ok) @@ -22,6 +23,8 @@ class TimeSpanPreference(mContext: Context, attrs: AttributeSet?) : DialogPrefer val persisted = getPersistedString("") return if ("" != persisted) { persisted.replace(':', ' ') - } else context.resources.getString(R.string.time_span_disabled) + } else { + context.resources.getString(R.string.time_span_disabled) + } } } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/UncaughtExceptionHandler.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/UncaughtExceptionHandler.kt index b6315d5e..64d8714c 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/UncaughtExceptionHandler.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/UncaughtExceptionHandler.kt @@ -26,7 +26,9 @@ class UncaughtExceptionHandler( val logMessage = String.format( "Android API level: %s\nUltrasonic version name: %s\n" + "Ultrasonic version code: %s\n\n", - Build.VERSION.SDK_INT, Util.getVersionName(context), Util.getVersionCode(context) + Build.VERSION.SDK_INT, + Util.getVersionName(context), + Util.getVersionCode(context) ) printWriter.println(logMessage) throwable.printStackTrace(printWriter) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Util.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Util.kt index c0d24af8..a8c04b49 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Util.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/util/Util.kt @@ -78,10 +78,6 @@ object Util { private val GIGA_BYTE_FORMAT = DecimalFormat("0.00 GB") private val MEGA_BYTE_FORMAT = DecimalFormat("0.00 MB") private val KILO_BYTE_FORMAT = DecimalFormat("0 KB") - private var GIGA_BYTE_LOCALIZED_FORMAT: DecimalFormat? = null - private var MEGA_BYTE_LOCALIZED_FORMAT: DecimalFormat? = null - private var KILO_BYTE_LOCALIZED_FORMAT: DecimalFormat? = null - private var BYTE_LOCALIZED_FORMAT: DecimalFormat? = null // Used by hexEncode() private val HEX_DIGITS = @@ -137,10 +133,10 @@ object Util { toast(message, true, context) } - @JvmStatic // Toast needs a real context or it will throw a IllegalAccessException // We wrap it in a try-catch block, because if called after doing // some background processing, our context might have expired! + @JvmStatic fun toast(message: CharSequence, shortDuration: Boolean, context: Context?) { try { Toast.makeText( @@ -186,7 +182,6 @@ object Util { @JvmStatic @Synchronized fun formatBytes(byteCount: Long): String { - // More than 1 GB? if (byteCount >= KBYTE * KBYTE * KBYTE) { return GIGA_BYTE_FORMAT.format(byteCount.toDouble() / (KBYTE * KBYTE * KBYTE)) @@ -200,60 +195,9 @@ object Util { // More than 1 KB? return if (byteCount >= KBYTE) { KILO_BYTE_FORMAT.format(byteCount.toDouble() / KBYTE) - } else "$byteCount B" - } - - /** - * Converts a byte-count to a formatted string suitable for display to the user. - * For instance: - * - * * `format(918)` returns *"918 B"*. - * * `format(98765)` returns *"96 KB"*. - * * `format(1238476)` returns *"1.2 MB"*. - * - * This method assumes that 1 KB is 1024 bytes. - * This version of the method returns a localized string. - * - * @param byteCount The number of bytes. - * @return The formatted string. - */ - @Synchronized - @Suppress("ReturnCount") - fun formatLocalizedBytes(byteCount: Long, context: Context): String { - - // More than 1 GB? - if (byteCount >= KBYTE * KBYTE * KBYTE) { - if (GIGA_BYTE_LOCALIZED_FORMAT == null) { - GIGA_BYTE_LOCALIZED_FORMAT = - DecimalFormat(context.resources.getString(R.string.util_bytes_format_gigabyte)) - } - return GIGA_BYTE_LOCALIZED_FORMAT!! - .format(byteCount.toDouble() / (KBYTE * KBYTE * KBYTE)) + } else { + "$byteCount B" } - - // More than 1 MB? - if (byteCount >= KBYTE * KBYTE) { - if (MEGA_BYTE_LOCALIZED_FORMAT == null) { - MEGA_BYTE_LOCALIZED_FORMAT = - DecimalFormat(context.resources.getString(R.string.util_bytes_format_megabyte)) - } - return MEGA_BYTE_LOCALIZED_FORMAT!! - .format(byteCount.toDouble() / (KBYTE * KBYTE)) - } - - // More than 1 KB? - if (byteCount >= KBYTE) { - if (KILO_BYTE_LOCALIZED_FORMAT == null) { - KILO_BYTE_LOCALIZED_FORMAT = - DecimalFormat(context.resources.getString(R.string.util_bytes_format_kilobyte)) - } - return KILO_BYTE_LOCALIZED_FORMAT!!.format(byteCount.toDouble() / KBYTE) - } - if (BYTE_LOCALIZED_FORMAT == null) { - BYTE_LOCALIZED_FORMAT = - DecimalFormat(context.resources.getString(R.string.util_bytes_format_byte)) - } - return BYTE_LOCALIZED_FORMAT!!.format(byteCount.toDouble()) } @Suppress("SuspiciousEqualsCombination") @@ -314,12 +258,14 @@ object Util { fun md5Hex(s: String?): String? { return if (s == null) { null - } else try { - val md5 = MessageDigest.getInstance("MD5") - hexEncode(md5.digest(s.toByteArray(charset(Constants.UTF_8)))) - } catch (all: Exception) { - // TODO: Why is it needed to change the exception type here? - throw RuntimeException(all.message, all) + } else { + try { + val md5 = MessageDigest.getInstance("MD5") + hexEncode(md5.digest(s.toByteArray(charset(Constants.UTF_8)))) + } catch (all: Exception) { + // TODO: Why is it needed to change the exception type here? + throw RuntimeException(all.message, all) + } } } @@ -485,7 +431,6 @@ object Util { val width = options.outWidth var inSampleSize = 1 if (height > reqHeight || width > reqWidth) { - // Calculate ratios of height and width to requested height and // width val heightRatio = (height.toFloat() / reqHeight.toFloat()).roundToInt() @@ -554,7 +499,6 @@ object Util { notificationManager: NotificationManagerCompat ) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - // The suggested importance of a startForeground service notification is IMPORTANCE_LOW val channel = NotificationChannel( id, @@ -576,11 +520,10 @@ object Util { ) { if (ContextCompat.checkSelfPermission( applicationContext(), - POST_NOTIFICATIONS, + POST_NOTIFICATIONS ) != PackageManager.PERMISSION_GRANTED && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ) { - val requestPermissionLauncher = fragment.registerForActivityResult(ActivityResultContracts.RequestPermission()) { if (!it) { @@ -604,7 +547,7 @@ object Util { ) { if (ContextCompat.checkSelfPermission( applicationContext(), - POST_NOTIFICATIONS, + POST_NOTIFICATIONS ) == PackageManager.PERMISSION_GRANTED && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU ) { @@ -644,8 +587,10 @@ object Util { fun scanMedia(file: String?) { // TODO this doesn't work for URIs MediaScannerConnection.scanFile( - applicationContext(), arrayOf(file), - null, null + applicationContext(), + arrayOf(file), + null, + null ) } @@ -683,7 +628,7 @@ object Util { val trackNumber: String, val duration: String, var bitrate: String?, - var fileFormat: String?, + var fileFormat: String? ) @Suppress("ComplexMethod", "LongMethod") @@ -694,10 +639,11 @@ object Util { val duration = song.duration - if (song.bitRate != null && song.bitRate!! > 0) + if (song.bitRate != null && song.bitRate!! > 0) { bitRate = String.format( appContext().getString(R.string.song_details_kbps), song.bitRate ) + } val fileFormat: String? val suffix = song.suffix @@ -705,20 +651,27 @@ object Util { fileFormat = if ( TextUtils.isEmpty(transcodedSuffix) || transcodedSuffix == suffix || song.isVideo - ) suffix else String.format(Locale.ROOT, "%s > %s", suffix, transcodedSuffix) + ) { + suffix + } else { + String.format(Locale.ROOT, "%s > %s", suffix, transcodedSuffix) + } val artistName = song.artist if (artistName != null) { if (Settings.shouldDisplayBitrateWithArtist && ( - !bitRate.isNullOrBlank() || !fileFormat.isNullOrBlank() - ) + !bitRate.isNullOrBlank() || !fileFormat.isNullOrBlank() + ) ) { artist.append(artistName).append(" (").append( String.format( appContext().getString(R.string.song_details_all), - if (bitRate == null) "" - else String.format(Locale.ROOT, "%s ", bitRate), + if (bitRate == null) { + "" + } else { + String.format(Locale.ROOT, "%s ", bitRate) + }, fileFormat ) ).append(')') @@ -740,8 +693,11 @@ object Util { title.append(" (").append( String.format( appContext().getString(R.string.song_details_all), - if (bitRate == null) "" - else String.format(Locale.ROOT, "%s ", bitRate), + if (bitRate == null) { + "" + } else { + String.format(Locale.ROOT, "%s ", bitRate) + }, fileFormat ) ).append(')') @@ -753,7 +709,7 @@ object Util { trackNumber = trackText, duration = formatTotalDuration(duration?.toLong()), bitrate = bitRate, - fileFormat = fileFormat, + fileFormat = fileFormat ) } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/AutoRepeatButton.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/AutoRepeatButton.kt index 0f50f12c..2e04e7a9 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/AutoRepeatButton.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/AutoRepeatButton.kt @@ -56,13 +56,16 @@ class AutoRepeatButton : MaterialButton { } constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super( - context!!, attrs, defStyle + context!!, + attrs, + defStyle ) { commonConstructorCode() } constructor(context: Context?, attrs: AttributeSet?) : super( - context!!, attrs + context!!, + attrs ) { commonConstructorCode() } diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/ChatAdapter.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/ChatAdapter.kt index cb2db531..5413f877 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/ChatAdapter.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/ChatAdapter.kt @@ -26,7 +26,9 @@ import org.moire.ultrasonic.subsonic.ImageLoaderProvider class ChatAdapter(private val context: Context, private val messages: List) : ArrayAdapter( - context, R.layout.chat_item, messages + context, + R.layout.chat_item, + messages ), KoinComponent { @@ -90,10 +92,7 @@ class ChatAdapter(private val context: Context, private val messages: List) : ArrayAdapter( - context, R.layout.share_list_item, shares + context, + R.layout.share_list_item, + shares ) { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { val entry = getItem(position) diff --git a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/SortOrder.kt b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/SortOrder.kt index 5c372198..e646f152 100644 --- a/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/SortOrder.kt +++ b/ultrasonic/src/main/kotlin/org/moire/ultrasonic/view/SortOrder.kt @@ -19,5 +19,5 @@ enum class SortOrder(val typeName: String) { BY_NAME("alphabeticalByName"), BY_ARTIST("alphabeticalByArtist"), STARRED("starred"), - BY_YEAR("byYear"); + BY_YEAR("byYear") } diff --git a/ultrasonic/src/main/res/values-cs/strings.xml b/ultrasonic/src/main/res/values-cs/strings.xml index 3cf8675c..3be9153f 100644 --- a/ultrasonic/src/main/res/values-cs/strings.xml +++ b/ultrasonic/src/main/res/values-cs/strings.xml @@ -254,10 +254,6 @@ Zobrazí obrázek umělce v náhledu umělců pokud je dostupný Video %d kbps - 0 B - 0.00 GB - 0 KB - 0.00 MB -:-- 0:00 Ťuknutím vybrat hudbu diff --git a/ultrasonic/src/main/res/values-de/strings.xml b/ultrasonic/src/main/res/values-de/strings.xml index 46aa76fc..a94a15e0 100644 --- a/ultrasonic/src/main/res/values-de/strings.xml +++ b/ultrasonic/src/main/res/values-de/strings.xml @@ -308,10 +308,6 @@ Medien nur über gebührenfreie Verbindungen herunterladen Nur über WLAN herunterladen %d kbps - 0 B - 0.00 GB - 0 KB - 0.00 MB -:-- 0:00 Berühren, um Musik auszuwählen diff --git a/ultrasonic/src/main/res/values-es/strings.xml b/ultrasonic/src/main/res/values-es/strings.xml index b6014e4b..100b01c7 100644 --- a/ultrasonic/src/main/res/values-es/strings.xml +++ b/ultrasonic/src/main/res/values-es/strings.xml @@ -312,10 +312,6 @@ Solo descargar medios en conexiones sin medir Descargar solo por Wi-Fi %d kbps - 0 B - 0.00 GB - 0 KB - 0.00 MB -:-- 0:00 Toca para seleccionar música diff --git a/ultrasonic/src/main/res/values-fr/strings.xml b/ultrasonic/src/main/res/values-fr/strings.xml index f2578bef..31914406 100644 --- a/ultrasonic/src/main/res/values-fr/strings.xml +++ b/ultrasonic/src/main/res/values-fr/strings.xml @@ -298,10 +298,6 @@ Télécharger des médias uniquement sur des connexions non mesurées Téléchargement en Wifi uniquement %d kbits/s - 0 o - 0,00 Go - 0 ko - 0,00 Mo —:—— 0:00 Touchez pour sélectionner un titre diff --git a/ultrasonic/src/main/res/values-hu/strings.xml b/ultrasonic/src/main/res/values-hu/strings.xml index 0bfd09f0..28efc2c8 100644 --- a/ultrasonic/src/main/res/values-hu/strings.xml +++ b/ultrasonic/src/main/res/values-hu/strings.xml @@ -262,10 +262,6 @@ Az előadó listában megjeleníti a képeket, amennyiben elérhetőek Videó %d kbps - 0 B - 0.00 GB - 0 KB - 0.00 MB -:-- 0:00 Érintse meg a zene kiválasztásához diff --git a/ultrasonic/src/main/res/values-it/strings.xml b/ultrasonic/src/main/res/values-it/strings.xml index 77fed0ee..2b7c99b0 100644 --- a/ultrasonic/src/main/res/values-it/strings.xml +++ b/ultrasonic/src/main/res/values-it/strings.xml @@ -241,10 +241,6 @@ Usa metodi tag ID3 invece dei metodi basati sul filesystem Video %d kbps - 0 B - 0.00 GB - 0 KB - 0.00 MB -:-- 0:00 Tocca per selezionare musica diff --git a/ultrasonic/src/main/res/values-ja/strings.xml b/ultrasonic/src/main/res/values-ja/strings.xml index 8641b570..abb4cc52 100644 --- a/ultrasonic/src/main/res/values-ja/strings.xml +++ b/ultrasonic/src/main/res/values-ja/strings.xml @@ -243,10 +243,7 @@ 定額制接続でのみメディアをダウンロードします Wi-Fi接続時のみダウンロード %d kbps - 0 B - 0.00 GB プレイリストを消去 - 0.00 MB -:-- 0:00 タップして音楽を選択 @@ -413,7 +410,6 @@ テーマ この設定を有効にすると、Ultrasonic 4.0以降でダウンロードした音楽のみが表示されます。それ以前のバージョンでダウンロードしたファイルには、必要なメタデータが含まれていません。固定モードと保存モードを切り替えることで、不足メタデータのダウンロードができます。 再生中に詳細を表示 - 0 KB SDカード利用不可 常に詳細を確認 デフォルトの有効期限 diff --git a/ultrasonic/src/main/res/values-nb-rNO/strings.xml b/ultrasonic/src/main/res/values-nb-rNO/strings.xml index 81719af4..0bd99046 100644 --- a/ultrasonic/src/main/res/values-nb-rNO/strings.xml +++ b/ultrasonic/src/main/res/values-nb-rNO/strings.xml @@ -399,14 +399,10 @@ Vis mer sporinfo i «Spilles nå» (sjanger, år, bitrate) Dette tvinger programmet til å alltid sende passordet ukryptert. Nyttig hvis Subsonic-tjeneren ikke støtter det nye identitetbekreftelses-API-et for brukere. Antaat toppnivåmappen er navnet på albumsartisten - 0 B Vis artistbilde i artistliste Forvalgt utløpstid Bruk ID3-etikettmetoder istedenfor filsystemsbaserte metoder Bruk ID3-metode også når frakoblet - 0,00 GB - 0 KB - 0,00 MB Deling Slettet %s-deling Viser kun musikken som er lastet ned med Ultrasonic 4.0 eller senere. Tidligere nedlastinger har ikke nødvendig metadata nedlastet. Du kan veksle mellom festingsmodus og lagringsmodus for å utløse nedlasting av manglende metadata. diff --git a/ultrasonic/src/main/res/values-nl/strings.xml b/ultrasonic/src/main/res/values-nl/strings.xml index 5f34a530..ca71f450 100644 --- a/ultrasonic/src/main/res/values-nl/strings.xml +++ b/ultrasonic/src/main/res/values-nl/strings.xml @@ -312,10 +312,6 @@ Haal media alleen op bij gebruik van onbeperkte dataverbindingen Alleen ophalen via wifi %d kbps - 0 B - 0,00 GB - 0 KB - 0,00 MB -:-- 0:00 Druk om muziek te selecteren diff --git a/ultrasonic/src/main/res/values-pl/strings.xml b/ultrasonic/src/main/res/values-pl/strings.xml index 6610ad1c..f7392c5c 100644 --- a/ultrasonic/src/main/res/values-pl/strings.xml +++ b/ultrasonic/src/main/res/values-pl/strings.xml @@ -250,10 +250,6 @@ Używa metod z tagów ID3 zamiast metod opartych na systemie plików Wideo %d kbps - 0 B - 0.00 GB - 0 KB - 0.00 MB -:-- 0:00 Dotknij, aby wybrać muzykę diff --git a/ultrasonic/src/main/res/values-pt-rBR/strings.xml b/ultrasonic/src/main/res/values-pt-rBR/strings.xml index 43c96885..55afaf4c 100644 --- a/ultrasonic/src/main/res/values-pt-rBR/strings.xml +++ b/ultrasonic/src/main/res/values-pt-rBR/strings.xml @@ -310,10 +310,6 @@ Baixar mídia somente em conexões não medidas Download somente via Wi-Fi %d kbps - 0 B - 0.00 GB - 0 KB - 0.00 MB -:-- 0:00 Toque para selecionar a música diff --git a/ultrasonic/src/main/res/values-pt/strings.xml b/ultrasonic/src/main/res/values-pt/strings.xml index ad5cd34f..bc63daad 100644 --- a/ultrasonic/src/main/res/values-pt/strings.xml +++ b/ultrasonic/src/main/res/values-pt/strings.xml @@ -250,10 +250,6 @@ Usa as etiquetas ID3 ao invés do sistema de ficheiros Vídeo %d kbps - 0 B - 0.00 GB - 0 KB - 0.00 MB —:—— 0:00 Toque para selecionar a música diff --git a/ultrasonic/src/main/res/values-ru/strings.xml b/ultrasonic/src/main/res/values-ru/strings.xml index 38756d33..da167d66 100644 --- a/ultrasonic/src/main/res/values-ru/strings.xml +++ b/ultrasonic/src/main/res/values-ru/strings.xml @@ -280,10 +280,6 @@ Отображает изображение исполнителя в списке исполнителей, если доступно Видео %d kbps - 0 B - 0.00 GB - 0 KB - 0.00 MB -:-- 0:00 Нажмите, чтобы выбрать музыку diff --git a/ultrasonic/src/main/res/values-zh-rCN/strings.xml b/ultrasonic/src/main/res/values-zh-rCN/strings.xml index 625d81fb..0e0ecbb0 100644 --- a/ultrasonic/src/main/res/values-zh-rCN/strings.xml +++ b/ultrasonic/src/main/res/values-zh-rCN/strings.xml @@ -289,10 +289,6 @@ 仅未计量的网络用于下载媒体 仅使用 Wi-Fi 进行下载 %d kbps - 0 B - 0.00 GB - 0 KB - 0.00 MB -:-- 0:00 轻触选择音乐 diff --git a/ultrasonic/src/main/res/values-zh-rTW/strings.xml b/ultrasonic/src/main/res/values-zh-rTW/strings.xml index 6645fc95..c3c7ead6 100644 --- a/ultrasonic/src/main/res/values-zh-rTW/strings.xml +++ b/ultrasonic/src/main/res/values-zh-rTW/strings.xml @@ -255,7 +255,6 @@ 100 首歌 明色 96 Kbps - 0 KB 覆寫當前語言 5 首歌 250 @@ -283,12 +282,9 @@ 其他設定 15 伺服器顏色 - 0 B - 0.00 GB 用戶名 暗色 -:-- - 0.00 MB 1000 首歌 密碼 diff --git a/ultrasonic/src/main/res/values/strings.xml b/ultrasonic/src/main/res/values/strings.xml index 98c0263f..a4e457a7 100644 --- a/ultrasonic/src/main/res/values/strings.xml +++ b/ultrasonic/src/main/res/values/strings.xml @@ -319,10 +319,6 @@ Download on Wi-Fi only %1$s%2$s %d kbps - 0 B - 0.00 GB - 0 KB - 0.00 MB -:-- 0:00 Touch to select music diff --git a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIArtistConverterTest.kt b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIArtistConverterTest.kt index 5920744e..983d7c20 100644 --- a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIArtistConverterTest.kt +++ b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIArtistConverterTest.kt @@ -27,7 +27,9 @@ class APIArtistConverterTest : BaseTest() { @Test fun `Should convert Artist entity to domain MusicDirectory entity`() { val entity = Artist( - id = "101", name = "artist-name", coverArt = "some-art", + id = "101", + name = "artist-name", + coverArt = "some-art", albumCount = 10, albumsList = listOf( Album( diff --git a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIBookmarkConverterTest.kt b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIBookmarkConverterTest.kt index fe03805c..81386b10 100644 --- a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIBookmarkConverterTest.kt +++ b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIBookmarkConverterTest.kt @@ -16,8 +16,12 @@ class APIBookmarkConverterTest : BaseTest() { @Test fun `Should convert to domain entity`() { val entity = Bookmark( - 412313L, "Awesemo", "Nice", Calendar.getInstance(), - Calendar.getInstance(), MusicDirectoryChild(id = "12333") + 412313L, + "Awesemo", + "Nice", + Calendar.getInstance(), + Calendar.getInstance(), + MusicDirectoryChild(id = "12333") ) val domainEntity = entity.toDomainEntity(serverId) diff --git a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIIndexConverterTest.kt b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIIndexConverterTest.kt index a785a9ce..40bea4ae 100644 --- a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIIndexConverterTest.kt +++ b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIIndexConverterTest.kt @@ -23,7 +23,8 @@ class APIIndexConverterTest : BaseTest() { Artist(id = "12", name = "Teebee") ) val entity = Indexes( - lastModified = 154, ignoredArticles = "Le Tre Ze", + lastModified = 154, + ignoredArticles = "Le Tre Ze", indexList = listOf( Index(name = "A", artists = artistsA), Index(name = "T", artists = artistsT) diff --git a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIMusicDirectoryConverterTest.kt b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIMusicDirectoryConverterTest.kt index 55bb07b1..8707eb9f 100644 --- a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIMusicDirectoryConverterTest.kt +++ b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIMusicDirectoryConverterTest.kt @@ -15,8 +15,13 @@ class APIMusicDirectoryConverterTest : BaseTest() { @Test fun `Should convert MusicDirectory entity`() { val entity = MusicDirectory( - id = "1982", parent = "345", name = "some-name", userRating = 3, - averageRating = 3.4f, starred = Calendar.getInstance(), playCount = 10, + id = "1982", + parent = "345", + name = "some-name", + userRating = 3, + averageRating = 3.4f, + starred = Calendar.getInstance(), + playCount = 10, childList = listOf(MusicDirectoryChild("1"), MusicDirectoryChild("2")) ) @@ -80,8 +85,10 @@ class APIMusicDirectoryConverterTest : BaseTest() { @Test fun `Should convert MusicDirectoryChild podcast entity`() { val entity = MusicDirectoryChild( - id = "584", streamId = "394", - artist = "some-artist", publishDate = Calendar.getInstance() + id = "584", + streamId = "394", + artist = "some-artist", + publishDate = Calendar.getInstance() ) val convertedEntity = entity.toTrackEntity(serverId) diff --git a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIPodcastConverterTest.kt b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIPodcastConverterTest.kt index 040a272e..ec997c43 100644 --- a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIPodcastConverterTest.kt +++ b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIPodcastConverterTest.kt @@ -13,9 +13,14 @@ class APIPodcastConverterTest { @Test fun `Should convert podcast channel entity to domain entity`() { val entity = PodcastChannel( - id = "452", url = "some-url", title = "some-title", - description = "some-description", coverArt = "cA", originalImageUrl = "image-url", - status = "podcast-status", errorMessage = "some-error-message" + id = "452", + url = "some-url", + title = "some-title", + description = "some-description", + coverArt = "cA", + originalImageUrl = "image-url", + status = "podcast-status", + errorMessage = "some-error-message" ) val converterEntity = entity.toDomainEntity() diff --git a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIUserConverterTest.kt b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIUserConverterTest.kt index 101bf160..30562758 100644 --- a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIUserConverterTest.kt +++ b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/domain/APIUserConverterTest.kt @@ -13,8 +13,11 @@ class APIUserConverterTest { @Test fun `Should convert to domain entity`() { val entity = User( - username = "Awsemo", email = "none@none.net", scrobblingEnabled = false, - shareRole = true, streamRole = true + username = "Awsemo", + email = "none@none.net", + scrobblingEnabled = false, + shareRole = true, + streamRole = true ) val domainEntity = entity.toDomainEntity() diff --git a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/imageloader/AvatarRequestHandlerTest.kt b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/imageloader/AvatarRequestHandlerTest.kt index ddf283bb..424012b0 100644 --- a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/imageloader/AvatarRequestHandlerTest.kt +++ b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/imageloader/AvatarRequestHandlerTest.kt @@ -67,7 +67,8 @@ class AvatarRequestHandlerTest { ).thenReturn(streamResponse) val response = handler.load( - createLoadAvatarRequest("some-username").buildRequest(), 0 + createLoadAvatarRequest("some-username").buildRequest(), + 0 ) response.loadedFrom `should be equal to` Picasso.LoadedFrom.NETWORK diff --git a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/imageloader/CoverArtRequestHandlerTest.kt b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/imageloader/CoverArtRequestHandlerTest.kt index fdef0b0c..4434b7bc 100644 --- a/ultrasonic/src/test/kotlin/org/moire/ultrasonic/imageloader/CoverArtRequestHandlerTest.kt +++ b/ultrasonic/src/test/kotlin/org/moire/ultrasonic/imageloader/CoverArtRequestHandlerTest.kt @@ -80,7 +80,8 @@ class CoverArtRequestHandlerTest { ).thenReturn(streamResponse) val response = handler.load( - createLoadCoverArtRequest("some").buildRequest(), 0 + createLoadCoverArtRequest("some").buildRequest(), + 0 ) response.loadedFrom `should be equal to` Picasso.LoadedFrom.NETWORK