Fix remaining warnings

This commit is contained in:
tzugen 2021-05-27 11:18:29 +02:00
parent ac77d9557c
commit cc7e273d50
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
4 changed files with 35 additions and 51 deletions

View File

@ -69,6 +69,8 @@ style:
ignorePropertyDeclaration: true ignorePropertyDeclaration: true
UnnecessaryAbstractClass: UnnecessaryAbstractClass:
active: false active: false
ReturnCount:
max: 3
comments: comments:
active: true active: true

View File

@ -23,6 +23,7 @@ import org.moire.ultrasonic.domain.SearchResult
import org.moire.ultrasonic.domain.Share import org.moire.ultrasonic.domain.Share
import org.moire.ultrasonic.domain.UserInfo import org.moire.ultrasonic.domain.UserInfo
@Suppress("TooManyFunctions")
interface MusicService { interface MusicService {
@Throws(Exception::class) @Throws(Exception::class)
fun ping() fun ping()

View File

@ -45,6 +45,10 @@ import org.moire.ultrasonic.util.FileUtil
import org.moire.ultrasonic.util.Util import org.moire.ultrasonic.util.Util
import timber.log.Timber import timber.log.Timber
// TODO: There are quite a number of deeply nested and complicated functions in this class..
// Simplify them :)
@Suppress("TooManyFunctions")
class OfflineMusicService : MusicService { class OfflineMusicService : MusicService {
private val activeServerProvider = inject( private val activeServerProvider = inject(
ActiveServerProvider::class.java ActiveServerProvider::class.java
@ -76,11 +80,15 @@ class OfflineMusicService : MusicService {
return@sortWith -1 return@sortWith -1
} }
for (article in ignoredArticles) { for (article in ignoredArticles) {
var index = lhs.indexOf(String.format("%s ", article.toLowerCase(Locale.ROOT))) var index = lhs.indexOf(
String.format(Locale.ROOT, "%s ", article.toLowerCase(Locale.ROOT))
)
if (index == 0) { if (index == 0) {
lhs = lhs.substring(article.length + 1) lhs = lhs.substring(article.length + 1)
} }
index = rhs.indexOf(String.format("%s ", article.toLowerCase(Locale.ROOT))) index = rhs.indexOf(
String.format(Locale.ROOT, "%s ", article.toLowerCase(Locale.ROOT))
)
if (index == 0) { if (index == 0) {
rhs = rhs.substring(article.length + 1) rhs = rhs.substring(article.length + 1)
} }
@ -122,7 +130,7 @@ class OfflineMusicService : MusicService {
return try { return try {
val bitmap = FileUtil.getAvatarBitmap(username, size, highQuality) val bitmap = FileUtil.getAvatarBitmap(username, size, highQuality)
Util.scaleBitmap(bitmap, size) Util.scaleBitmap(bitmap, size)
} catch (e: Exception) { } catch (ignored: Exception) {
null null
} }
} }
@ -136,7 +144,7 @@ class OfflineMusicService : MusicService {
return try { return try {
val bitmap = FileUtil.getAlbumArtBitmap(entry, size, highQuality) val bitmap = FileUtil.getAlbumArtBitmap(entry, size, highQuality)
Util.scaleBitmap(bitmap, size) Util.scaleBitmap(bitmap, size)
} catch (e: Exception) { } catch (ignored: Exception) {
null null
} }
} }
@ -162,51 +170,14 @@ class OfflineMusicService : MusicService {
} }
} }
artists.sortWith { lhs, rhs -> artists.sort()
when { albums.sort()
lhs.closeness == rhs.closeness -> { songs.sort()
return@sortWith 0
}
lhs.closeness > rhs.closeness -> {
return@sortWith -1
}
else -> {
return@sortWith 1
}
}
}
albums.sortWith { lhs, rhs ->
when {
lhs.closeness == rhs.closeness -> {
return@sortWith 0
}
lhs.closeness > rhs.closeness -> {
return@sortWith -1
}
else -> {
return@sortWith 1
}
}
}
songs.sortWith { lhs, rhs ->
when {
lhs.closeness == rhs.closeness -> {
return@sortWith 0
}
lhs.closeness > rhs.closeness -> {
return@sortWith -1
}
else -> {
return@sortWith 1
}
}
}
return SearchResult(artists, albums, songs) return SearchResult(artists, albums, songs)
} }
@Suppress("NestedBlockDepth", "TooGenericExceptionCaught")
override fun getPlaylists(refresh: Boolean): List<Playlist> { override fun getPlaylists(refresh: Boolean): List<Playlist> {
val playlists: MutableList<Playlist> = ArrayList() val playlists: MutableList<Playlist> = ArrayList()
val root = FileUtil.getPlaylistDirectory() val root = FileUtil.getPlaylistDirectory()
@ -280,6 +251,7 @@ class OfflineMusicService : MusicService {
} }
} }
@Suppress("TooGenericExceptionCaught")
@Throws(Exception::class) @Throws(Exception::class)
override fun createPlaylist(id: String, name: String, entries: List<MusicDirectory.Entry>) { override fun createPlaylist(id: String, name: String, entries: List<MusicDirectory.Entry>) {
val playlistFile = val playlistFile =
@ -302,7 +274,7 @@ class OfflineMusicService : MusicService {
""".trimIndent() """.trimIndent()
) )
} }
} catch (e: Exception) { } catch (ignored: Exception) {
Timber.w("Failed to save playlist: %s", name) Timber.w("Failed to save playlist: %s", name)
} finally { } finally {
bw.close() bw.close()
@ -495,7 +467,9 @@ class OfflineMusicService : MusicService {
throw OfflineException("getStarred2 isn't available in offline mode") throw OfflineException("getStarred2 isn't available in offline mode")
} }
override fun ping() {} override fun ping() {
// Void
}
override fun isLicenseValid(): Boolean = true override fun isLicenseValid(): Boolean = true
@ -545,21 +519,25 @@ class OfflineMusicService : MusicService {
if (file.isDirectory) { if (file.isDirectory) {
return name return name
} }
if (name.endsWith(".partial") || name.contains(".partial.") if (name.endsWith(".partial") || name.contains(".partial.") ||
|| name == Constants.ALBUM_ART_FILE) { name == Constants.ALBUM_ART_FILE
) {
return null return null
} }
name = name.replace(".complete", "") name = name.replace(".complete", "")
return FileUtil.getBaseName(name) return FileUtil.getBaseName(name)
} }
@Suppress("TooGenericExceptionCaught", "ComplexMethod", "LongMethod", "NestedBlockDepth")
private fun createEntry(file: File, name: String?): MusicDirectory.Entry { private fun createEntry(file: File, name: String?): MusicDirectory.Entry {
val entry = MusicDirectory.Entry(file.path) val entry = MusicDirectory.Entry(file.path)
entry.isDirectory = file.isDirectory entry.isDirectory = file.isDirectory
entry.parent = file.parent entry.parent = file.parent
entry.size = file.length() entry.size = file.length()
val root = FileUtil.getMusicDirectory().path val root = FileUtil.getMusicDirectory().path
entry.path = file.path.replaceFirst(String.format("^%s/", root).toRegex(), "") entry.path = file.path.replaceFirst(
String.format(Locale.ROOT, "^%s/", root).toRegex(), ""
)
entry.title = name entry.title = name
if (file.isFile) { if (file.isFile) {
var artist: String? = null var artist: String? = null
@ -648,6 +626,7 @@ class OfflineMusicService : MusicService {
return entry return entry
} }
@Suppress("NestedBlockDepth")
private fun recursiveAlbumSearch( private fun recursiveAlbumSearch(
artistName: String, artistName: String,
file: File, file: File,

View File

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