Open c33s opened 4 years ago
I have two solutions to this issue at hacky-filesort and database-filesort.
The reasons for not making (one of) them a pull request are:
The hacky one is ... well hacky in the sense that the ordering is computed (in java) on the fly every time it is needed. It works actually quite well (on my own phone) and touches not too much existing code -- but it is only a workaround, or "symptomatic treatment" ...
(Ideally, the sorting would be done by the database backend, but as far as i can see, this is not easily possible: SQLite does not support this natively, and sqlite3_create_collation does not seem to be exposed in the java/android classes ...)
The other one is not thoroughly tested.
It works by adding an additional column to the database table for audio files, called sort_index
. Each Synchronize
of the database will (if necessary) trigger recomputation of the album's file order according to natural sort. Later, the database query can simply ORDER BY
the new column.
It seems to work fine, but i only quickly tested it in the emulator on a couple of files ... However, this approach is a lot cleaner and i don't see a reason why it shouldn't be merged in principle.
Warning: If you want to try this, make a backup of your database first (Export database
...), because the database will be upgraded automatically (and then be incompatible with the official app) and there is no downgrade implemented.
(After the automatic database upgrade, a manual Synchronize
is necessary to populate the sort_index
.)
Additional notes:
android.icu.text.RuleBasedCollator
for natural sort. While i would always prefer not to re-invent the wheel, the minimum API version could probably be preserved by using one of the available ad-hoc java classes for natural sort (e.g. as mentioned by OP) ...Synchronizer::updateAudioFileTable
quite a bit (to include the sort_index
generation), while i tried to preserve the semantics of the previous code ...
currently items are not sorted by natural sort which leads to:
i assume that #5 was already released, i am currently on version 2.2 but i also asume that the
CAST
fix only work for numbers at the beginning and the end (or do i miss something?).maybe helpful:
maybe a fix: