move interfaces out of GameListAdapter and into own file; should be no

change beyond renaming.
This commit is contained in:
Eric House 2013-10-30 06:29:31 -07:00
parent 1d7a443c8d
commit dbf76287a8
5 changed files with 55 additions and 30 deletions

View file

@ -45,24 +45,12 @@ public class GameListAdapter implements ExpandableListAdapter {
private ExpandableListView m_list; private ExpandableListView m_list;
private int m_fieldID; private int m_fieldID;
private Handler m_handler; private Handler m_handler;
private LoadItemCB m_cb; private SelectableItem m_cb;
private long[] m_positions; private long[] m_positions;
public interface LoadItemCB {
public void itemClicked( GameListAdapter.ClickHandler clicked,
GameSummary summary );
public void itemToggled( GameListAdapter.ClickHandler toggled,
boolean selected );
public boolean getSelected( GameListAdapter.ClickHandler obj );
}
public interface ClickHandler {
public void longClicked();
}
public GameListAdapter( Context context, ExpandableListView list, public GameListAdapter( Context context, ExpandableListView list,
Handler handler, LoadItemCB cb, long[] positions, Handler handler, SelectableItem cb,
String fieldName ) long[] positions, String fieldName )
{ {
m_context = context; m_context = context;
m_list = list; m_list = list;

View file

@ -28,17 +28,17 @@ import android.view.View;
import org.eehouse.android.xw4.DBUtils.GameGroupInfo; import org.eehouse.android.xw4.DBUtils.GameGroupInfo;
public class GameListGroup extends ExpiringTextView public class GameListGroup extends ExpiringTextView
implements GameListAdapter.ClickHandler implements SelectableItem.LongClickHandler
{ {
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 GameListAdapter.LoadItemCB m_cb; private SelectableItem m_cb;
public static GameListGroup makeForPosition( Context context, public static GameListGroup makeForPosition( Context context,
int groupPosition, int groupPosition,
long groupID, long groupID,
GameListAdapter.LoadItemCB cb ) SelectableItem cb )
{ {
GameListGroup result = GameListGroup result =
(GameListGroup)Utils.inflate( context, R.layout.game_list_group ); (GameListGroup)Utils.inflate( context, R.layout.game_list_group );

View file

@ -43,7 +43,7 @@ import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.GameSummary; import org.eehouse.android.xw4.jni.GameSummary;
public class GameListItem extends LinearLayout public class GameListItem extends LinearLayout
implements View.OnClickListener, GameListAdapter.ClickHandler { implements View.OnClickListener, SelectableItem.LongClickHandler {
private static HashSet<Long> s_invalRows = new HashSet<Long>(); private static HashSet<Long> s_invalRows = new HashSet<Long>();
@ -57,7 +57,7 @@ public class GameListItem extends LinearLayout
private ImageButton m_expandButton; private ImageButton m_expandButton;
private Handler m_handler; private Handler m_handler;
private GameSummary m_summary; private GameSummary m_summary;
private GameListAdapter.LoadItemCB m_cb; private SelectableItem m_cb;
private int m_fieldID; private int m_fieldID;
private int m_loadingCount; private int m_loadingCount;
private int m_groupPosition; private int m_groupPosition;
@ -87,7 +87,7 @@ public class GameListItem extends LinearLayout
} }
private void init( Handler handler, long rowid, int groupPosition, private void init( Handler handler, long rowid, int groupPosition,
int fieldID, GameListAdapter.LoadItemCB cb ) int fieldID, SelectableItem cb )
{ {
m_handler = handler; m_handler = handler;
m_rowid = rowid; m_rowid = rowid;
@ -343,7 +343,7 @@ public class GameListItem extends LinearLayout
public static GameListItem makeForRow( Context context, long rowid, public static GameListItem makeForRow( Context context, long rowid,
Handler handler, int groupPosition, Handler handler, int groupPosition,
int fieldID, int fieldID,
GameListAdapter.LoadItemCB cb ) SelectableItem cb )
{ {
GameListItem result = GameListItem result =
(GameListItem)Utils.inflate( context, R.layout.game_list_item ); (GameListItem)Utils.inflate( context, R.layout.game_list_item );

View file

@ -58,8 +58,7 @@ import org.eehouse.android.xw4.jni.*;
public class GamesList extends XWExpandableListActivity public class GamesList extends XWExpandableListActivity
implements OnItemLongClickListener, implements OnItemLongClickListener,
DBUtils.DBChangeListener, DBUtils.DBChangeListener, SelectableItem,
GameListAdapter.LoadItemCB,
DictImportActivity.DownloadFinishedListener { DictImportActivity.DownloadFinishedListener {
private static final int WARN_NODICT = DlgDelegate.DIALOG_LAST + 1; private static final int WARN_NODICT = DlgDelegate.DIALOG_LAST + 1;
@ -473,9 +472,9 @@ public class GamesList extends XWExpandableListActivity
// OnItemLongClickListener interface // OnItemLongClickListener interface
public boolean onItemLongClick( AdapterView<?> parent, View view, public boolean onItemLongClick( AdapterView<?> parent, View view,
int position, long id ) { int position, long id ) {
boolean success = view instanceof GameListAdapter.ClickHandler; boolean success = view instanceof SelectableItem.LongClickHandler;
if ( success ) { if ( success ) {
((GameListAdapter.ClickHandler)view).longClicked(); ((SelectableItem.LongClickHandler)view).longClicked();
} }
return success; return success;
} }
@ -494,8 +493,8 @@ public class GamesList extends XWExpandableListActivity
} ); } );
} }
// GameListAdapter.LoadItemCB interface // SelectableItem interface
public void itemClicked( GameListAdapter.ClickHandler clicked, public void itemClicked( SelectableItem.LongClickHandler clicked,
GameSummary summary ) GameSummary summary )
{ {
// We need a way to let the user get back to the basic-config // We need a way to let the user get back to the basic-config
@ -512,7 +511,7 @@ public class GamesList extends XWExpandableListActivity
} }
} }
public void itemToggled( GameListAdapter.ClickHandler toggled, public void itemToggled( SelectableItem.LongClickHandler toggled,
boolean selected ) boolean selected )
{ {
if ( toggled instanceof GameListItem ) { if ( toggled instanceof GameListItem ) {
@ -536,7 +535,7 @@ public class GamesList extends XWExpandableListActivity
setTitleBar(); setTitleBar();
} }
public boolean getSelected( GameListAdapter.ClickHandler obj ) public boolean getSelected( SelectableItem.LongClickHandler obj )
{ {
boolean selected; boolean selected;
if ( obj instanceof GameListItem ) { if ( obj instanceof GameListItem ) {

View file

@ -0,0 +1,38 @@
/* -*- compile-command: "cd ../../../../../; ant debug install"; -*- */
/*
* Copyright 2009-2013 by Eric House (xwords@eehouse.org). All
* rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.eehouse.android.xw4;
import org.eehouse.android.xw4.jni.GameSummary;
// Interfaces used for (list) items that are selectable via
// long-tapping.
public interface SelectableItem {
public interface LongClickHandler {
public void longClicked();
}
public void itemClicked( LongClickHandler clicked, GameSummary summary );
public void itemToggled( LongClickHandler toggled, boolean selected );
public boolean getSelected( LongClickHandler obj );
}