The ordering preferences of "Your sites" left menu list on the app is saved as a number (the order that you have) concatenated with the name of the site, for example "1_meta", "0_stackoverflow" or "12_meta.gaming". The lowest order number is 0.
To order, that string is simply ordered, without taking in account that it should be ordered as numbers. When you order like that (and ignoring the site name part), for 13 items, instead of having an ordered list of "0 1 2 3 4 5 6 7 8 9 10 11 12" you get "0 10 11 12 1 2 3 4 5 6 7 8 9". That's because 0 < 10 < 11 < .. < 19 < 1 < 20 < 2
, I mean, 10 is after 0, but before 1 and 20 would be before 2.
The problem only happens when you have more than 10 sites.
The answer was posted in a different question on this site “Your Sites” in Android left sidebar shown in unpredictable order, in this answer and it's a bug. Here's the full answer:
This will be fixed in 1.0.84.
Andrew's description was right on the nose. When preferences are
saved, they are stored in a HashSet<String>
(who knows why?) which
would look something like this:
1_meta
9_hermeneutics
8_patents
10_coffee
2_math
11_photo
0_stackoverflow
4_bricks
12_meta.gaming
5_ja.stackoverflow
7_pt.stackoverflow
3_cooking
6_meta.ja.stackoverflow
A naïve Collections.sort
was applied which gets us the incorrect
ordering:
0_stackoverflow 10_coffee 11_photo
12_meta.gaming 1_meta 2_math 3_cooking 4_bricks
5_ja.stackoverflow 6_meta.ja.stackoverflow 7_pt.stackoverflow
8_patents 9_hermeneutics
Now instead I'm breaking the list into (int, String)
pair, sorting
by the index, and returning the name:
return Bite.from(siteNamesAndIndexes)
.map(SiteIndexPair::new)
.sortBy(SiteIndexPair::getIndex)
.map(SiteIndexPair::getName).toArrayList();