forked from Read-Write/Submariner
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Navidrome at least has an [Unknown] index with an [Unknown Artist] artist entry below it, but the Foundation sorting puts it in a clumsy place with the index and artist flipped. Provide a custom sort order that deals with it. Ugly and Navidrome specific, but does work. I'm considering preserving the order the server gives us, but that has its own problems (is it actually desirable?). Might need to rethink the schema with index vs. artist a little.
- Loading branch information
1 parent
8674038
commit b6d1c4a
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// NSString+Comparison.swift | ||
// Submariner | ||
// | ||
// Created by Calvin Buckley on 2024-05-14. | ||
// | ||
// Copyright (c) 2024 Calvin Buckley | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
|
||
import Foundation | ||
|
||
extension NSString { | ||
private func isUnknownValue(_ string: String) -> Bool { | ||
return string.starts(with: "[Unknown") && string.last == "]" | ||
} | ||
|
||
@objc func artistListCompare(_ rhs: String) -> ComparisonResult { | ||
let lhs = self as String | ||
// Our goal with this is to kick the special unknown values to the bottom. | ||
// For example in Navidrome, there is the [Unknown] index group as well as | ||
// [Unknown Artist] and [Unknown Album]. The default sorting behaviours from | ||
// Foundation are unpleasant and put the group after the artist, or put them | ||
// in the middle of the list. | ||
// This is Navidrome specific unfortunately. | ||
// In the future other comparison changes could be made. | ||
let lhsUnknown = isUnknownValue(lhs) | ||
let rhsUnknown = isUnknownValue(rhs) | ||
if lhsUnknown && !rhsUnknown { | ||
return .orderedDescending | ||
} else if !lhsUnknown && rhsUnknown { | ||
return .orderedAscending | ||
} else if lhsUnknown && rhsUnknown { | ||
// we won't see special items of the same length | ||
return lhs.count < rhs.count ? .orderedAscending : .orderedDescending | ||
} | ||
|
||
return self.caseInsensitiveCompare(rhs) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters