Skip to content

fix(sorting): accent-aware library sorting with COLLATE LOCALIZED#2467

Open
AmrEldeeb5 wants to merge 1 commit into
PixelPlayerHQ:masterfrom
AmrEldeeb5:fix/2164-accent-aware-sorting
Open

fix(sorting): accent-aware library sorting with COLLATE LOCALIZED#2467
AmrEldeeb5 wants to merge 1 commit into
PixelPlayerHQ:masterfrom
AmrEldeeb5:fix/2164-accent-aware-sorting

Conversation

@AmrEldeeb5

Copy link
Copy Markdown
Contributor

Fixes #2164

Problem

Titles starting with accented letters (e.g. "Águas De Março") sort after Z instead of under A.

Cause

All library ORDER BY clauses in MusicDao order text with COLLATE NOCASE. NOCASE only case-folds ASCII A–Z; everything else falls back to code-point order, and accented Latin letters sit above z in Unicode (Á = U+00C1 > z = U+007A).

Fix

Use COLLATE LOCALIZED for the text orderings (title / artist / album / name) across the songs, albums, artists, liked, and folder queries. LOCALIZED is registered by Android's framework SQLite — which this app already uses via the default Room open-helper, so there's no new dependency — and it orders accented characters in their expected position, locale-aware.

  • No schema migration: only @Query text changes; Room's schema/identity hash is unaffected.
  • Scope is ordering only. The LIKE … COLLATE NOCASE search filter in MediaStoreSongRepository (case-insensitive matching, not sorting) is intentionally left as-is.

Alternatives considered

  • COLLATE UNICODE — locale-independent/deterministic across locales. Happy to switch to this if preferred.
  • A precomputed diacritic-stripped sort-key column — more robust but needs a schema migration + backfill; overkill for this.

Testing

  • Project compiles; Room's annotation processor validates every modified query.
  • Installs and runs with no regression to existing sorting.
  • Recommend a quick on-device check: a title beginning with Á/É/Ñ now sorts within its base-letter group rather than after Z.

Note: COLLATE LOCALIZED resolves only at runtime on-device/emulator (framework SQLite), so this is validated at runtime rather than in a JVM unit test.

Library sort queries ordered text with COLLATE NOCASE, which only
case-folds ASCII A-Z and otherwise sorts by Unicode code point. Accented
Latin letters (e.g. "A" with acute, U+00C1) sort after "Z", so titles
like "Aguas De Marco" landed at the bottom of the list instead of under
"A".

Switch the title/artist/album/name ORDER BY clauses to COLLATE LOCALIZED,
which is registered by Android's framework SQLite (used here via the
default Room open-helper, so no new dependency) and orders accented
characters in their expected position, locale-aware. Only query text
changes, so no schema migration is required. The case-insensitive search
filter in MediaStoreSongRepository is left untouched.

Fixes PixelPlayerHQ#2164

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Alphabetical sorting fails with accented characters (Unicode/ASCII sorting issue)

1 participant