mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-17 18:12:01 +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 )
|
public static int countGames( Context context )
|
||||||
{
|
{
|
||||||
int result = 0;
|
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.jni.CommsAddrRec.CommsConnType;
|
||||||
import org.eehouse.android.xw4.DBUtils.GameGroupInfo;
|
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 Context m_context;
|
||||||
private ListView m_list;
|
private ListView m_list;
|
||||||
private int m_fieldID;
|
private int m_fieldID;
|
||||||
|
@ -52,8 +54,7 @@ public class GameListAdapter extends XWListAdapter {
|
||||||
Handler handler, SelectableItem cb,
|
Handler handler, SelectableItem cb,
|
||||||
long[] positions, String fieldName )
|
long[] positions, String fieldName )
|
||||||
{
|
{
|
||||||
super( DBUtils.getGroups( context ).size()
|
super( 0 );
|
||||||
+ DBUtils.countGames( context ) );
|
|
||||||
m_context = context;
|
m_context = context;
|
||||||
m_list = list;
|
m_list = list;
|
||||||
m_handler = handler;
|
m_handler = handler;
|
||||||
|
@ -63,6 +64,16 @@ public class GameListAdapter extends XWListAdapter {
|
||||||
m_fieldID = fieldToID( fieldName );
|
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()
|
public long[] getGroupPositions()
|
||||||
{
|
{
|
||||||
Set<Long> keys = gameInfo().keySet(); // do not modify!!!!
|
Set<Long> keys = gameInfo().keySet(); // do not modify!!!!
|
||||||
|
@ -161,11 +172,24 @@ public class GameListAdapter extends XWListAdapter {
|
||||||
deselectGroups( groupIDs );
|
deselectGroups( groupIDs );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// GroupStateListener interface
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
public void onGroupExpandedChanged( int groupPosition, boolean expanded )
|
||||||
|
{
|
||||||
|
if ( expanded ) {
|
||||||
|
onGroupExpanded( groupPosition );
|
||||||
|
} else {
|
||||||
|
onGroupCollapsed( groupPosition );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// ListAdapter interface
|
// ListAdapter interface
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
public View getView( final int position, View convertView, ViewGroup parent )
|
public View getView( final int position, View convertView, ViewGroup parent )
|
||||||
{
|
{
|
||||||
|
DbgUtils.logf( "getView(convertView=%H)", convertView );
|
||||||
View result = null;
|
View result = null;
|
||||||
HashMap<Long,GameGroupInfo> info = gameInfo();
|
HashMap<Long,GameGroupInfo> info = gameInfo();
|
||||||
Set<Long> posns = info.keySet();
|
Set<Long> posns = info.keySet();
|
||||||
|
@ -173,10 +197,12 @@ public class GameListAdapter extends XWListAdapter {
|
||||||
int indx = position;
|
int indx = position;
|
||||||
for ( Iterator<Long>iter = posns.iterator(); iter.hasNext(); ) {
|
for ( Iterator<Long>iter = posns.iterator(); iter.hasNext(); ) {
|
||||||
long groupID = iter.next();
|
long groupID = iter.next();
|
||||||
|
GameGroupInfo groupInfo = info.get( groupID );
|
||||||
if ( indx == 0 ) {
|
if ( indx == 0 ) {
|
||||||
GameListGroup group =
|
GameListGroup group =
|
||||||
GameListGroup.makeForPosition( m_context, groupPosition,
|
GameListGroup.makeForPosition( m_context, groupPosition,
|
||||||
groupID, m_cb );
|
groupID, groupInfo.m_expanded,
|
||||||
|
m_cb, this );
|
||||||
|
|
||||||
int nKids = getChildrenCount( groupPosition );
|
int nKids = getChildrenCount( groupPosition );
|
||||||
String name = m_context.getString( R.string.group_namef,
|
String name = m_context.getString( R.string.group_namef,
|
||||||
|
@ -186,21 +212,25 @@ public class GameListAdapter extends XWListAdapter {
|
||||||
result = group;
|
result = group;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
GameGroupInfo group = info.get( groupID );
|
int count = groupInfo.m_expanded ? groupInfo.m_count : 0;
|
||||||
DbgUtils.logf( "group[%d] count: %d", groupPosition, group.m_count );
|
// int count = groupInfo.m_count;
|
||||||
if ( indx <= group.m_count ) {
|
DbgUtils.logf( "group[%d] visible count: %d", groupPosition, count );
|
||||||
|
if ( indx <= count ) {
|
||||||
long[] rows = DBUtils.getGroupGames( m_context, groupID );
|
long[] rows = DBUtils.getGroupGames( m_context, groupID );
|
||||||
long rowid = rows[indx - 1];
|
long rowid = rows[indx - 1];
|
||||||
result = GameListItem.makeForRow( m_context, rowid, m_handler,
|
result =
|
||||||
groupPosition, m_fieldID, m_cb );
|
GameListItem.makeForRow( m_context, rowid, m_handler,
|
||||||
|
groupPosition, m_fieldID, m_cb );
|
||||||
|
result.setVisibility( groupInfo.m_expanded ?
|
||||||
|
View.VISIBLE : View.GONE );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
indx -= 1 + group.m_count;
|
indx -= 1 + count;
|
||||||
++groupPosition;
|
++groupPosition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DbgUtils.logf( "GameListAdapter.getView(pos=%d, group=%d)=>%s",
|
DbgUtils.logf( "GameListAdapter.getView(pos=%d, group=%d)=>%H",
|
||||||
position, groupPosition, result.getClass().getName() );
|
position, groupPosition, result );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,20 +255,25 @@ public class GameListAdapter extends XWListAdapter {
|
||||||
|
|
||||||
// public boolean isEmpty() { return false; }
|
// 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 );
|
private void onGroupCollapsed( int groupPosition )
|
||||||
// deselectGames( rowids );
|
{
|
||||||
// }
|
long groupid = getGroupIDFor( groupPosition );
|
||||||
|
DBUtils.setGroupExpanded( m_context, groupid, false );
|
||||||
|
|
||||||
// public void onGroupExpanded( int groupPosition )
|
long[] rowids = DBUtils.getGroupGames( m_context, groupid );
|
||||||
// {
|
deselectGames( rowids );
|
||||||
// long groupid = getGroupIDFor( groupPosition );
|
|
||||||
// DBUtils.setGroupExpanded( m_context, groupid, true );
|
notifyDataSetChanged();
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
private void onGroupExpanded( int groupPosition )
|
||||||
|
{
|
||||||
|
long groupid = getGroupIDFor( groupPosition );
|
||||||
|
DBUtils.setGroupExpanded( m_context, groupid, true );
|
||||||
|
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
// public boolean areAllItemsEnabled() { return true; }
|
// public boolean areAllItemsEnabled() { return true; }
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,16 @@ public class GameListGroup extends LinearLayout
|
||||||
View.OnClickListener,
|
View.OnClickListener,
|
||||||
View.OnLongClickListener
|
View.OnLongClickListener
|
||||||
{
|
{
|
||||||
|
// Find me a home....
|
||||||
|
interface GroupStateListener {
|
||||||
|
void onGroupExpandedChanged( int groupPosition, boolean expanded );
|
||||||
|
}
|
||||||
|
|
||||||
private int m_groupPosition;
|
private int m_groupPosition;
|
||||||
private long m_groupID;
|
private long m_groupID;
|
||||||
private boolean m_expanded;
|
private boolean m_expanded;
|
||||||
private SelectableItem m_cb;
|
private SelectableItem m_cb;
|
||||||
|
private GroupStateListener m_gcb;
|
||||||
private ExpiringTextView m_etv;
|
private ExpiringTextView m_etv;
|
||||||
private boolean m_selected;
|
private boolean m_selected;
|
||||||
private DrawSelDelegate m_dsdel;
|
private DrawSelDelegate m_dsdel;
|
||||||
|
@ -46,13 +52,18 @@ public class GameListGroup extends LinearLayout
|
||||||
public static GameListGroup makeForPosition( Context context,
|
public static GameListGroup makeForPosition( Context context,
|
||||||
int groupPosition,
|
int groupPosition,
|
||||||
long groupID,
|
long groupID,
|
||||||
SelectableItem cb )
|
boolean expanded,
|
||||||
|
SelectableItem cb,
|
||||||
|
GroupStateListener gcb )
|
||||||
{
|
{
|
||||||
GameListGroup result =
|
GameListGroup result =
|
||||||
(GameListGroup)Utils.inflate( context, R.layout.game_list_group );
|
(GameListGroup)Utils.inflate( context, R.layout.game_list_group );
|
||||||
result.m_cb = cb;
|
result.m_cb = cb;
|
||||||
|
result.m_gcb = gcb;
|
||||||
result.m_groupPosition = groupPosition;
|
result.m_groupPosition = groupPosition;
|
||||||
result.m_groupID = groupID;
|
result.m_groupID = groupID;
|
||||||
|
result.m_expanded = expanded;
|
||||||
|
result.setButton();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,15 +146,17 @@ public class GameListGroup extends LinearLayout
|
||||||
public void onClick( View view )
|
public void onClick( View view )
|
||||||
{
|
{
|
||||||
m_expanded = !m_expanded;
|
m_expanded = !m_expanded;
|
||||||
DBUtils.setGroupExpanded( getContext(), m_groupID, m_expanded );
|
m_gcb.onGroupExpandedChanged( m_groupPosition, m_expanded );
|
||||||
setButton();
|
setButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setButton()
|
private void setButton()
|
||||||
{
|
{
|
||||||
m_expandButton.setImageResource( m_expanded ?
|
if ( null != m_expandButton ) {
|
||||||
R.drawable.expander_ic_maximized :
|
m_expandButton.setImageResource( m_expanded ?
|
||||||
R.drawable.expander_ic_minimized);
|
R.drawable.expander_ic_maximized :
|
||||||
|
R.drawable.expander_ic_minimized);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,13 @@ import android.app.ListActivity;
|
||||||
import android.widget.ListAdapter;
|
import android.widget.ListAdapter;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.DataSetObserver;
|
import android.database.DataSetObserver;
|
||||||
|
import android.widget.BaseAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Let's see if we can implement a few of these methods just once.
|
* 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;
|
private int m_count;
|
||||||
|
|
||||||
public XWListAdapter( ) {
|
public XWListAdapter( ) {
|
||||||
|
@ -49,6 +51,6 @@ public abstract class XWListAdapter implements ListAdapter {
|
||||||
public int getViewTypeCount() { return 1; }
|
public int getViewTypeCount() { return 1; }
|
||||||
public boolean hasStableIds() { return true; }
|
public boolean hasStableIds() { return true; }
|
||||||
public boolean isEmpty() { return getCount() == 0; }
|
public boolean isEmpty() { return getCount() == 0; }
|
||||||
public void registerDataSetObserver( DataSetObserver observer ) {}
|
// public void registerDataSetObserver( DataSetObserver observer ) {}
|
||||||
public void unregisterDataSetObserver( DataSetObserver observer ) {}
|
// public void unregisterDataSetObserver( DataSetObserver observer ) {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue