music: move sort name number handling to setting
Make the numeric sort name handling added prior dependent on a new "Intelligent Sorting" setting that also controls the article checks. This kind of behavior might not be desirable in all cases, and it makes the setting more consistent anyway.
This commit is contained in:
@@ -85,7 +85,7 @@ sealed interface Music : Item {
|
||||
* A unique identifier for a piece of music.
|
||||
*
|
||||
* [UID] enables a much cheaper and more reliable form of differentiating music, derived from
|
||||
* either a hash of meaningful metadata or the MusicBrainz ID spec. Using this enables several
|
||||
* either internal app information or the MusicBrainz ID spec. Using this enables several
|
||||
* improvements to music management in this app, including:
|
||||
* - Proper differentiation of identical music. It's common for large, well-tagged libraries to
|
||||
* have functionally duplicate items that are differentiated with MusicBrainz IDs, and so
|
||||
@@ -355,7 +355,7 @@ class SortName(name: String, musicSettings: MusicSettings) : Comparable<SortName
|
||||
|
||||
init {
|
||||
var sortName = name
|
||||
if (musicSettings.automaticSortNames) {
|
||||
if (musicSettings.intelligentSorting) {
|
||||
sortName =
|
||||
sortName.run {
|
||||
when {
|
||||
@@ -365,23 +365,24 @@ class SortName(name: String, musicSettings: MusicSettings) : Comparable<SortName
|
||||
else -> this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parse out numeric portions of the title and use those for sorting, if applicable.
|
||||
val numericEnd = sortName.indexOfFirst { !it.isDigit() }
|
||||
when (numericEnd) {
|
||||
// No numeric component.
|
||||
0 -> number = null
|
||||
// Whole title is numeric.
|
||||
-1 -> {
|
||||
number = sortName.toIntOrNull()
|
||||
sortName = ""
|
||||
}
|
||||
// Part of the title is numeric.
|
||||
else -> {
|
||||
number = sortName.slice(0 until numericEnd).toIntOrNull()
|
||||
sortName = sortName.slice(numericEnd until sortName.length)
|
||||
// Parse out numeric portions of the title and use those for sorting, if applicable.
|
||||
when (val numericEnd = sortName.indexOfFirst { !it.isDigit() }) {
|
||||
// No numeric component.
|
||||
0 -> number = null
|
||||
// Whole title is numeric.
|
||||
-1 -> {
|
||||
number = sortName.toIntOrNull()
|
||||
sortName = ""
|
||||
}
|
||||
// Part of the title is numeric.
|
||||
else -> {
|
||||
number = sortName.slice(0 until numericEnd).toIntOrNull()
|
||||
sortName = sortName.slice(numericEnd until sortName.length)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
number = null
|
||||
}
|
||||
|
||||
collationKey = COLLATOR.getCollationKey(sortName)
|
||||
|
||||
@@ -44,8 +44,8 @@ interface MusicSettings : Settings<MusicSettings.Listener> {
|
||||
val shouldBeObserving: Boolean
|
||||
/** A [String] of characters representing the desired characters to denote multi-value tags. */
|
||||
var multiValueSeparators: String
|
||||
/** Whether to trim english articles with song sort names. */
|
||||
val automaticSortNames: Boolean
|
||||
/** Whether to enable more advanced sorting by articles and numbers. */
|
||||
val intelligentSorting: Boolean
|
||||
// TODO: Move sort settings to list module
|
||||
/** The [Sort] mode used in [Song] lists. */
|
||||
var songSort: Sort
|
||||
@@ -115,7 +115,7 @@ class MusicSettingsImpl @Inject constructor(@ApplicationContext context: Context
|
||||
}
|
||||
}
|
||||
|
||||
override val automaticSortNames: Boolean
|
||||
override val intelligentSorting: Boolean
|
||||
get() = sharedPreferences.getBoolean(getString(R.string.set_key_auto_sort_names), true)
|
||||
|
||||
override var songSort: Sort
|
||||
|
||||
@@ -483,6 +483,7 @@ class GenreImpl(
|
||||
* @return A new [Music.UID] of Auxio format whose [UUID] was derived from the SHA-256 hash of the
|
||||
* metadata given.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
fun createHashedUid(mode: MusicMode, updates: MessageDigest.() -> Unit): Music.UID {
|
||||
val digest =
|
||||
MessageDigest.getInstance("SHA-256").run {
|
||||
|
||||
Reference in New Issue
Block a user