minimum to get game list group headers reflecting the most urgent move

expiry info of a contained game: local if there is one, otherwise
remote.  Still need to hide it when expanded, update, etc.
This commit is contained in:
Eric House 2012-12-19 20:45:58 -08:00
parent 7e302aae69
commit ed0bb5b31e
4 changed files with 100 additions and 7 deletions

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<org.eehouse.android.xw4.ExpiringTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/game_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
/>

View file

@ -869,8 +869,13 @@ public class DBUtils {
public static class GameGroupInfo {
public long m_id;
public boolean m_expanded;
public long m_lastMoveTime;
public boolean m_hasTurn;
public boolean m_turnLocal;
public GameGroupInfo( long id, boolean expanded ) {
m_id = id; m_expanded = expanded;
m_lastMoveTime = 0;
}
}
@ -912,6 +917,13 @@ public class DBUtils {
result.put( name, new GameGroupInfo( id, expanded ) );
}
cursor.close();
Iterator<GameGroupInfo> iter = result.values().iterator();
while ( iter.hasNext() ) {
GameGroupInfo ggi = iter.next();
readTurnInfo( db, ggi );
}
db.close();
}
s_groupsCache = result;
@ -919,6 +931,58 @@ public class DBUtils {
return s_groupsCache;
} // getGroups
private static void readTurnInfo( SQLiteDatabase db, GameGroupInfo ggi )
{
String[] columns = { DBHelper.LASTMOVE, DBHelper.GIFLAGS,
DBHelper.TURN };
String orderBy = DBHelper.LASTMOVE;
String selection = String.format( "%s=%d", DBHelper.GROUPID, ggi.m_id );
Cursor cursor = db.query( DBHelper.TABLE_NAME_SUM, columns,
selection,
null, // args
null, // groupBy,
null, // having
orderBy
);
// We want the earliest LASTPLAY_TIME (i.e. the first we see
// since they're in order) that's a local turn, if any,
// otherwise a non-local turn.
long lastPlayTimeLocal = 0;
long lastPlayTimeRemote = 0;
int indexLPT = cursor.getColumnIndex( DBHelper.LASTMOVE );
int indexFlags = cursor.getColumnIndex( DBHelper.GIFLAGS );
int turnFlags = cursor.getColumnIndex( DBHelper.TURN );
while ( cursor.moveToNext() && 0 == lastPlayTimeLocal ) {
int flags = cursor.getInt( indexFlags );
int turn = cursor.getInt( turnFlags );
Boolean isLocal = GameSummary.localTurnNext( flags, turn );
if ( null != isLocal ) {
long lpt = cursor.getLong( indexLPT );
if ( isLocal ) {
lastPlayTimeLocal = lpt;
} else if ( 0 == lastPlayTimeRemote ) {
lastPlayTimeRemote = lpt;
}
}
}
cursor.close();
ggi.m_hasTurn = 0 != lastPlayTimeLocal || 0 != lastPlayTimeRemote;
if ( ggi.m_hasTurn ) {
ggi.m_turnLocal = 0 != lastPlayTimeLocal;
if ( ggi.m_turnLocal ) {
ggi.m_lastMoveTime = lastPlayTimeLocal;
} else {
ggi.m_lastMoveTime = lastPlayTimeRemote;
}
// DateFormat df = DateFormat.getDateTimeInstance( DateFormat.SHORT,
// DateFormat.SHORT );
// DbgUtils.logf( "using last play time %s for",
// df.format( new Date( 1000 * ggi.m_lastMoveTime ) ) );
}
}
public static long[] getGroupGames( Context context, long groupID )
{
long[] result = null;

View file

@ -189,12 +189,15 @@ public class GameListAdapter implements ExpandableListAdapter {
if ( null != convertView ) {
DbgUtils.logf( "getGroupView gave non-null convertView" );
}
View row =
Utils.inflate(m_context,
android.R.layout.simple_expandable_list_item_1 );
TextView view = (TextView)row.findViewById( android.R.id.text1 );
ExpiringTextView view = (ExpiringTextView)
Utils.inflate(m_context, R.layout.game_list_group );
String name = groupNames()[groupPosition];
GameGroupInfo ggi = gameInfo().get( name );
view.setPct( m_handler, ggi.m_hasTurn, ggi.m_turnLocal,
ggi.m_lastMoveTime );
int nKids = getChildrenCount( groupPosition );
name = m_context.getString( R.string.group_namef, name, nKids );
view.setText( name );

View file

@ -224,9 +224,9 @@ public class GameSummary {
&& serverRole != DeviceRole.SERVER_STANDALONE );
}
private boolean isLocal( int indx ) {
int flag = 2 << (indx * 2);
return 0 == (m_giFlags & flag);
private boolean isLocal( int indx )
{
return localTurnNextImpl( m_giFlags, indx );
}
private boolean isRobot( int indx ) {
@ -328,4 +328,19 @@ public class GameSummary {
return String.format( "%s%s%s", separator, list, separator );
}
private static boolean localTurnNextImpl( int flags, int turn )
{
int flag = 2 << (turn * 2);
return 0 == (flags & flag);
}
public static Boolean localTurnNext( int flags, int turn )
{
Boolean result = null;
if ( 0 <= turn ) {
result = new Boolean( localTurnNextImpl( flags, turn ) );
}
return result;
}
}