util: fix horrible numeric function naming
"nonZeroOrNull" is actuallly more apt as "positiveOrNull".
This commit is contained in:
parent
7adf7f7beb
commit
b4394c3a4a
6 changed files with 11 additions and 15 deletions
|
@ -45,7 +45,7 @@ import org.oxycblt.auxio.music.Song
|
|||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.playback.formatDurationMs
|
||||
import org.oxycblt.auxio.util.collectImmediately
|
||||
import org.oxycblt.auxio.util.nonZeroOrNull
|
||||
import org.oxycblt.auxio.util.positiveOrNull
|
||||
|
||||
/**
|
||||
* A [ListFragment] that shows a list of [Artist]s.
|
||||
|
@ -104,7 +104,7 @@ class ArtistListFragment :
|
|||
is Sort.Mode.ByDuration -> artist.durationMs?.formatDurationMs(false)
|
||||
|
||||
// Count -> Use song count
|
||||
is Sort.Mode.ByCount -> artist.songs.size.nonZeroOrNull()?.toString()
|
||||
is Sort.Mode.ByCount -> artist.songs.size.positiveOrNull()?.toString()
|
||||
|
||||
// Unsupported sort, error gracefully
|
||||
else -> null
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.oxycblt.auxio.music.info.ReleaseType
|
|||
import org.oxycblt.auxio.music.metadata.parseId3GenreNames
|
||||
import org.oxycblt.auxio.music.metadata.parseMultiValue
|
||||
import org.oxycblt.auxio.playback.replaygain.ReplayGainAdjustment
|
||||
import org.oxycblt.auxio.util.nonZeroOrNull
|
||||
import org.oxycblt.auxio.util.positiveOrNull
|
||||
import org.oxycblt.auxio.util.toUuidOrNull
|
||||
import org.oxycblt.auxio.util.unlikelyToBeNull
|
||||
import org.oxycblt.auxio.util.update
|
||||
|
@ -407,7 +407,7 @@ class ArtistImpl(grouping: Grouping<RawArtist, Music>, musicSettings: MusicSetti
|
|||
albums = albumMap.keys
|
||||
explicitAlbums = albums.filterTo(mutableSetOf()) { albumMap[it] == true }
|
||||
implicitAlbums = albums.filterNotTo(mutableSetOf()) { albumMap[it] == true }
|
||||
durationMs = songs.sumOf { it.durationMs }.nonZeroOrNull()
|
||||
durationMs = songs.sumOf { it.durationMs }.positiveOrNull()
|
||||
|
||||
hashCode = 31 * hashCode + rawArtist.hashCode()
|
||||
hashCode = 31 * hashCode + songs.hashCode()
|
||||
|
|
|
@ -25,7 +25,7 @@ import kotlin.math.max
|
|||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.util.inRangeOrNull
|
||||
import org.oxycblt.auxio.util.logE
|
||||
import org.oxycblt.auxio.util.nonZeroOrNull
|
||||
import org.oxycblt.auxio.util.positiveOrNull
|
||||
|
||||
/**
|
||||
* An ISO-8601/RFC 3339 Date.
|
||||
|
@ -247,7 +247,7 @@ class Date private constructor(private val tokens: List<Int>) : Comparable<Date>
|
|||
* @param dst The destination list to add valid tokens to.
|
||||
*/
|
||||
private fun transformTokens(src: List<Int>, dst: MutableList<Int>) {
|
||||
dst.add(src.getOrNull(0)?.nonZeroOrNull() ?: return)
|
||||
dst.add(src.getOrNull(0)?.positiveOrNull() ?: return)
|
||||
dst.add(src.getOrNull(1)?.inRangeOrNull(1..12) ?: return)
|
||||
dst.add(src.getOrNull(2)?.inRangeOrNull(1..31) ?: return)
|
||||
dst.add(src.getOrNull(3)?.inRangeOrNull(0..23) ?: return)
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
package org.oxycblt.auxio.music.metadata
|
||||
|
||||
import org.oxycblt.auxio.music.MusicSettings
|
||||
import org.oxycblt.auxio.util.nonZeroOrNull
|
||||
import org.oxycblt.auxio.util.positiveOrNull
|
||||
|
||||
/// --- GENERIC PARSING ---
|
||||
|
||||
|
@ -154,7 +154,7 @@ fun parseVorbisPositionField(pos: String?, total: String?) =
|
|||
* - The position was zeroed AND the total value was not present/zeroed
|
||||
*/
|
||||
fun transformPositionField(pos: Int?, total: Int?) =
|
||||
if (pos != null && (pos > 0 || (total?.nonZeroOrNull() != null))) {
|
||||
if (pos != null && (pos > 0 || (total?.positiveOrNull() != null))) {
|
||||
pos
|
||||
} else {
|
||||
null
|
||||
|
|
|
@ -314,11 +314,7 @@ private class TagWorkerImpl(
|
|||
* @return A parsed adjustment float, or null if the adjustment had invalid formatting.
|
||||
*/
|
||||
private fun List<String>.parseReplayGainAdjustment() =
|
||||
first()
|
||||
.replace(REPLAYGAIN_ADJUSTMENT_FILTER_REGEX, "")
|
||||
.toFloatOrNull()
|
||||
?.nonZeroOrNull()
|
||||
.also { logD(it) }
|
||||
first().replace(REPLAYGAIN_ADJUSTMENT_FILTER_REGEX, "").toFloatOrNull()?.nonZeroOrNull()
|
||||
|
||||
private companion object {
|
||||
val COMPILATION_ALBUM_ARTISTS = listOf("Various Artists")
|
||||
|
|
|
@ -41,14 +41,14 @@ fun <T> unlikelyToBeNull(value: T?) =
|
|||
*
|
||||
* @return The given number if it's non-zero, null otherwise.
|
||||
*/
|
||||
fun Int.nonZeroOrNull() = if (this > 0) this else null
|
||||
fun Int.positiveOrNull() = if (this > 0) this else null
|
||||
|
||||
/**
|
||||
* Aliases a check to ensure that the given number is non-zero.
|
||||
*
|
||||
* @return The same number if it's non-zero, null otherwise.
|
||||
*/
|
||||
fun Long.nonZeroOrNull() = if (this > 0) this else null
|
||||
fun Long.positiveOrNull() = if (this > 0) this else null
|
||||
|
||||
/**
|
||||
* Aliases a check to ensure that the given number is non-zero.
|
||||
|
|
Loading…
Reference in a new issue