mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
implement expand/contract of groups. Still skanky, but works.
This commit is contained in:
parent
64d0e0c867
commit
3f3e9f5389
4 changed files with 104 additions and 33 deletions
|
@ -1149,6 +1149,27 @@ public class DBUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static int countVisibleGames( Context context )
|
||||
{
|
||||
int result = 0;
|
||||
String[] columns = { ROW_ID };
|
||||
|
||||
String query = "SELECT %s FROM %s WHERE %s IN (SELECT %s FROM %s WHERE NOT %s = 0)";
|
||||
query = String.format( query, ROW_ID, DBHelper.TABLE_NAME_SUM, DBHelper.GROUPID,
|
||||
ROW_ID, DBHelper.TABLE_NAME_GROUPS, DBHelper.EXPANDED );
|
||||
// DbgUtils.logf( "countVisibleGames: query=%s", query );
|
||||
|
||||
initDB( context );
|
||||
synchronized( s_dbHelper ) {
|
||||
SQLiteDatabase db = s_dbHelper.getReadableDatabase();
|
||||
Cursor cursor = db.rawQuery( query, null );
|
||||
result = cursor.getCount();
|
||||
cursor.close();
|
||||
db.close();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int countGames( Context context )
|
||||
{
|
||||
int result = 0;
|
||||
|
|
|
@ -40,7 +40,9 @@ import org.eehouse.android.xw4.jni.CurGameInfo.DeviceRole;
|
|||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
||||
import org.eehouse.android.xw4.DBUtils.GameGroupInfo;
|
||||
|
||||
public class GameListAdapter extends XWListAdapter {
|
||||
public class GameListAdapter extends XWListAdapter
|
||||
implements GameListGroup.GroupStateListener {
|
||||
|
||||
private Context m_context;
|
||||
private ListView m_list;
|
||||
private int m_fieldID;
|
||||
|
@ -52,8 +54,7 @@ public class GameListAdapter extends XWListAdapter {
|
|||
Handler handler, SelectableItem cb,
|
||||
long[] positions, String fieldName )
|
||||
{
|
||||
super( DBUtils.getGroups( context ).size()
|
||||
+ DBUtils.countGames( context ) );
|
||||
super( 0 );
|
||||
m_context = context;
|
||||
m_list = list;
|
||||
m_handler = handler;
|
||||
|
@ -63,6 +64,16 @@ public class GameListAdapter extends XWListAdapter {
|
|||
m_fieldID = fieldToID( fieldName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount()
|
||||
{
|
||||
return DBUtils.getGroups( m_context ).size()
|
||||
+ DBUtils.countVisibleGames( m_context );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() { return 2; }
|
||||
|
||||
public long[] getGroupPositions()
|
||||
{
|
||||
Set<Long> keys = gameInfo().keySet(); // do not modify!!!!
|
||||
|
@ -161,11 +172,24 @@ public class GameListAdapter extends XWListAdapter {
|
|||
deselectGroups( groupIDs );
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// GroupStateListener interface
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public void onGroupExpandedChanged( int groupPosition, boolean expanded )
|
||||
{
|
||||
if ( expanded ) {
|
||||
onGroupExpanded( groupPosition );
|
||||
} else {
|
||||
onGroupCollapsed( groupPosition );
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// ListAdapter interface
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
public View getView( final int position, View convertView, ViewGroup parent )
|
||||
{
|
||||
DbgUtils.logf( "getView(convertView=%H)", convertView );
|
||||
View result = null;
|
||||
HashMap<Long,GameGroupInfo> info = gameInfo();
|
||||
Set<Long> posns = info.keySet();
|
||||
|
@ -173,10 +197,12 @@ public class GameListAdapter extends XWListAdapter {
|
|||
int indx = position;
|
||||
for ( Iterator<Long>iter = posns.iterator(); iter.hasNext(); ) {
|
||||
long groupID = iter.next();
|
||||
GameGroupInfo groupInfo = info.get( groupID );
|
||||
if ( indx == 0 ) {
|
||||
GameListGroup group =
|
||||
GameListGroup.makeForPosition( m_context, groupPosition,
|
||||
groupID, m_cb );
|
||||
groupID, groupInfo.m_expanded,
|
||||
m_cb, this );
|
||||
|
||||
int nKids = getChildrenCount( groupPosition );
|
||||
String name = m_context.getString( R.string.group_namef,
|
||||
|
@ -186,21 +212,25 @@ public class GameListAdapter extends XWListAdapter {
|
|||
result = group;
|
||||
break;
|
||||
} else {
|
||||
GameGroupInfo group = info.get( groupID );
|
||||
DbgUtils.logf( "group[%d] count: %d", groupPosition, group.m_count );
|
||||
if ( indx <= group.m_count ) {
|
||||
int count = groupInfo.m_expanded ? groupInfo.m_count : 0;
|
||||
// int count = groupInfo.m_count;
|
||||
DbgUtils.logf( "group[%d] visible count: %d", groupPosition, count );
|
||||
if ( indx <= count ) {
|
||||
long[] rows = DBUtils.getGroupGames( m_context, groupID );
|
||||
long rowid = rows[indx - 1];
|
||||
result = GameListItem.makeForRow( m_context, rowid, m_handler,
|
||||
groupPosition, m_fieldID, m_cb );
|
||||
result =
|
||||
GameListItem.makeForRow( m_context, rowid, m_handler,
|
||||
groupPosition, m_fieldID, m_cb );
|
||||
result.setVisibility( groupInfo.m_expanded ?
|
||||
View.VISIBLE : View.GONE );
|
||||
break;
|
||||
}
|
||||
indx -= 1 + group.m_count;
|
||||
indx -= 1 + count;
|
||||
++groupPosition;
|
||||
}
|
||||
}
|
||||
DbgUtils.logf( "GameListAdapter.getView(pos=%d, group=%d)=>%s",
|
||||
position, groupPosition, result.getClass().getName() );
|
||||
DbgUtils.logf( "GameListAdapter.getView(pos=%d, group=%d)=>%H",
|
||||
position, groupPosition, result );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -225,20 +255,25 @@ public class GameListAdapter extends XWListAdapter {
|
|||
|
||||
// public boolean isEmpty() { return false; }
|
||||
|
||||
// public void onGroupCollapsed( int groupPosition )
|
||||
// {
|
||||
// long groupid = getGroupIDFor( groupPosition );
|
||||
// DBUtils.setGroupExpanded( m_context, groupid, false );
|
||||
|
||||
// long[] rowids = DBUtils.getGroupGames( m_context, groupid );
|
||||
// deselectGames( rowids );
|
||||
// }
|
||||
private void onGroupCollapsed( int groupPosition )
|
||||
{
|
||||
long groupid = getGroupIDFor( groupPosition );
|
||||
DBUtils.setGroupExpanded( m_context, groupid, false );
|
||||
|
||||
// public void onGroupExpanded( int groupPosition )
|
||||
// {
|
||||
// long groupid = getGroupIDFor( groupPosition );
|
||||
// DBUtils.setGroupExpanded( m_context, groupid, true );
|
||||
// }
|
||||
long[] rowids = DBUtils.getGroupGames( m_context, groupid );
|
||||
deselectGames( rowids );
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void onGroupExpanded( int groupPosition )
|
||||
{
|
||||
long groupid = getGroupIDFor( groupPosition );
|
||||
DBUtils.setGroupExpanded( m_context, groupid, true );
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
// public boolean areAllItemsEnabled() { return true; }
|
||||
|
||||
|
|
|
@ -34,10 +34,16 @@ public class GameListGroup extends LinearLayout
|
|||
View.OnClickListener,
|
||||
View.OnLongClickListener
|
||||
{
|
||||
// Find me a home....
|
||||
interface GroupStateListener {
|
||||
void onGroupExpandedChanged( int groupPosition, boolean expanded );
|
||||
}
|
||||
|
||||
private int m_groupPosition;
|
||||
private long m_groupID;
|
||||
private boolean m_expanded;
|
||||
private SelectableItem m_cb;
|
||||
private GroupStateListener m_gcb;
|
||||
private ExpiringTextView m_etv;
|
||||
private boolean m_selected;
|
||||
private DrawSelDelegate m_dsdel;
|
||||
|
@ -46,13 +52,18 @@ public class GameListGroup extends LinearLayout
|
|||
public static GameListGroup makeForPosition( Context context,
|
||||
int groupPosition,
|
||||
long groupID,
|
||||
SelectableItem cb )
|
||||
boolean expanded,
|
||||
SelectableItem cb,
|
||||
GroupStateListener gcb )
|
||||
{
|
||||
GameListGroup result =
|
||||
(GameListGroup)Utils.inflate( context, R.layout.game_list_group );
|
||||
result.m_cb = cb;
|
||||
result.m_gcb = gcb;
|
||||
result.m_groupPosition = groupPosition;
|
||||
result.m_groupID = groupID;
|
||||
result.m_expanded = expanded;
|
||||
result.setButton();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -135,15 +146,17 @@ public class GameListGroup extends LinearLayout
|
|||
public void onClick( View view )
|
||||
{
|
||||
m_expanded = !m_expanded;
|
||||
DBUtils.setGroupExpanded( getContext(), m_groupID, m_expanded );
|
||||
m_gcb.onGroupExpandedChanged( m_groupPosition, m_expanded );
|
||||
setButton();
|
||||
}
|
||||
|
||||
private void setButton()
|
||||
{
|
||||
m_expandButton.setImageResource( m_expanded ?
|
||||
R.drawable.expander_ic_maximized :
|
||||
R.drawable.expander_ic_minimized);
|
||||
if ( null != m_expandButton ) {
|
||||
m_expandButton.setImageResource( m_expanded ?
|
||||
R.drawable.expander_ic_maximized :
|
||||
R.drawable.expander_ic_minimized);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,11 +24,13 @@ import android.app.ListActivity;
|
|||
import android.widget.ListAdapter;
|
||||
import android.content.Context;
|
||||
import android.database.DataSetObserver;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
/**
|
||||
* Let's see if we can implement a few of these methods just once.
|
||||
*/
|
||||
public abstract class XWListAdapter implements ListAdapter {
|
||||
public abstract class XWListAdapter extends BaseAdapter
|
||||
implements ListAdapter {
|
||||
private int m_count;
|
||||
|
||||
public XWListAdapter( ) {
|
||||
|
@ -49,6 +51,6 @@ public abstract class XWListAdapter implements ListAdapter {
|
|||
public int getViewTypeCount() { return 1; }
|
||||
public boolean hasStableIds() { return true; }
|
||||
public boolean isEmpty() { return getCount() == 0; }
|
||||
public void registerDataSetObserver( DataSetObserver observer ) {}
|
||||
public void unregisterDataSetObserver( DataSetObserver observer ) {}
|
||||
}
|
||||
// public void registerDataSetObserver( DataSetObserver observer ) {}
|
||||
// public void unregisterDataSetObserver( DataSetObserver observer ) {}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue