make game sort order clearer and easier to modify

For the ORDER BY clause that governs how games are displayed within a
group, use a static string built from a list of clauses that are then
easy to move up and down. Add clause that moves games with unread chat
to the top. Another commit will modify the display so it's clear why
it's there.
This commit is contained in:
Eric House 2017-09-02 11:26:10 -07:00
parent 5ed9d2c6aa
commit a10dd6a314

View file

@ -1616,25 +1616,34 @@ public class DBUtils {
return result;
}
// ORDER BY clause that governs display of games in main GamesList view
private static final String s_getGroupGamesOrderBy =
TextUtils.join(",", new String[] {
// Ended games at bottom
DBHelper.GAME_OVER,
// games with unread chat messages at top
"(" + DBHelper.HASMSGS + " & " + GameSummary.MSG_FLAGS_CHAT + ") IS NOT 0 DESC",
// Games not yet connected at top
DBHelper.TURN + " is -1 DESC",
// Games where it's a local player's turn at top
DBHelper.TURN_LOCAL + " DESC",
// finally, sort by timestamp of last-made move
DBHelper.LASTMOVE,
});
public static long[] getGroupGames( Context context, long groupID )
{
long[] result = null;
initDB( context );
String[] columns = { ROW_ID };
String[] columns = { ROW_ID, DBHelper.HASMSGS };
String selection = String.format( "%s=%d", DBHelper.GROUPID, groupID );
// Sort unconnected games at top (turn==-1), games that are finished
// at the bottom, then games at the top by how long it's been the
// device owner's turn.
String orderBy = String.format( "%s is -1 DESC,%s,%s DESC,%s", DBHelper.TURN,
DBHelper.GAME_OVER, DBHelper.TURN_LOCAL,
DBHelper.LASTMOVE );
synchronized( s_dbHelper ) {
Cursor cursor = s_db.query( DBHelper.TABLE_NAME_SUM, columns,
selection, // selection
null, // args
null, // groupBy
null, // having
orderBy
s_getGroupGamesOrderBy
);
int index = cursor.getColumnIndex( ROW_ID );
result = new long[ cursor.getCount() ];