cleanup: track only checked items, not all items.

This commit is contained in:
Eric House 2016-01-19 06:53:43 -08:00
parent eee13bcdd6
commit 7ba7879a55

View file

@ -50,7 +50,7 @@ import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify.InviteMeans;
public class BTInviteDelegate extends InviteDelegate { public class BTInviteDelegate extends InviteDelegate {
private Activity m_activity; private Activity m_activity;
private Set<String> m_checked; private Set<LinearLayout> m_checked;
private Map<String, Integer> m_counts; private Map<String, Integer> m_counts;
private boolean m_setChecked; private boolean m_setChecked;
private BTDevsAdapter m_adapter; private BTDevsAdapter m_adapter;
@ -78,7 +78,7 @@ public class BTInviteDelegate extends InviteDelegate {
@Override @Override
protected void init( Bundle savedInstanceState ) protected void init( Bundle savedInstanceState )
{ {
m_checked = new HashSet<String>(); m_checked = new HashSet<LinearLayout>();
m_counts = new HashMap<String, Integer>(); m_counts = new HashMap<String, Integer>();
String msg = getString( R.string.bt_pick_addall_button ); String msg = getString( R.string.bt_pick_addall_button );
@ -156,9 +156,11 @@ public class BTInviteDelegate extends InviteDelegate {
} }
int nxt = 0; int nxt = 0;
for ( Iterator<String> iter = m_checked.iterator(); for ( Iterator<LinearLayout> iter = m_checked.iterator();
iter.hasNext(); ) { iter.hasNext(); ) {
String btAddr = iter.next(); LinearLayout layout = iter.next();
CheckBox box = (CheckBox)layout.findViewById( R.id.inviter_check );
String btAddr = (String)box.getTag();
devs[nxt] = btAddr; devs[nxt] = btAddr;
if ( null != counts ) { if ( null != counts ) {
counts[nxt] = m_counts.get( btAddr ); counts[nxt] = m_counts.get( btAddr );
@ -185,31 +187,19 @@ public class BTInviteDelegate extends InviteDelegate {
private class BTDevsAdapter extends XWListAdapter { private class BTDevsAdapter extends XWListAdapter {
private String[] m_devAddrs; private String[] m_devAddrs;
private String[] m_devNames; private String[] m_devNames;
private LinearLayout[] m_views;
public BTDevsAdapter( String[] btAddrs, String[] btNames ) public BTDevsAdapter( String[] btAddrs, String[] btNames )
{ {
super( null == btAddrs? 0 : btAddrs.length ); super( null == btAddrs? 0 : btAddrs.length );
m_devAddrs = btAddrs; m_devAddrs = btAddrs;
m_devNames = btNames; m_devNames = btNames;
m_views = new LinearLayout[getCount()];
}
public void clearCheckedExcept( CompoundButton buttonView )
{
for ( LinearLayout layout : m_views ) {
if ( null != layout ) {
CheckBox box = (CheckBox)layout.findViewById( R.id.inviter_check );
box.setChecked( box.equals(buttonView) );
}
}
} }
public Object getItem( int position ) { return m_devNames[position]; } public Object getItem( int position ) { return m_devNames[position]; }
public View getView( int position, View convertView, ViewGroup parent ) { public View getView( int position, View convertView, ViewGroup parent ) {
final String btAddr = m_devAddrs[position]; final String btAddr = m_devAddrs[position];
LinearLayout layout = (LinearLayout)inflate( R.layout.btinviter_item ); final LinearLayout layout = (LinearLayout)inflate( R.layout.btinviter_item );
CheckBox box = (CheckBox)layout.findViewById( R.id.inviter_check ); CheckBox box = (CheckBox)layout.findViewById( R.id.inviter_check );
box.setText( m_devNames[position] ); box.setText( m_devNames[position] );
box.setTag( btAddr ); box.setTag( btAddr );
@ -243,17 +233,19 @@ public class BTInviteDelegate extends InviteDelegate {
CompoundButton.OnCheckedChangeListener listener = CompoundButton.OnCheckedChangeListener listener =
new CompoundButton.OnCheckedChangeListener() { new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged( CompoundButton buttonView, public void onCheckedChanged( CompoundButton buttonView,
boolean isChecked ) boolean isChecked ) {
{
if ( isChecked ) { if ( isChecked ) {
if ( 1 == m_nMissing && 1 == m_checked.size() ) { if ( 1 == m_nMissing && 1 == m_checked.size() ) {
LinearLayout checked = m_checked.iterator().next();
CheckBox box = (CheckBox)checked
.findViewById( R.id.inviter_check );
box.setChecked( false );
m_checked.clear(); m_checked.clear();
m_adapter.clearCheckedExcept( buttonView );
} }
m_checked.add( btAddr ); m_checked.add( layout );
} else { } else {
m_checked.remove( btAddr ); m_checked.remove( layout );
// User's now making changes; don't check new views // User's now making changes; don't check new views
m_setChecked = false; m_setChecked = false;
} }
@ -262,13 +254,12 @@ public class BTInviteDelegate extends InviteDelegate {
}; };
box.setOnCheckedChangeListener( listener ); box.setOnCheckedChangeListener( listener );
if ( m_setChecked || m_checked.contains( btAddr ) ) { if ( m_setChecked || m_checked.contains( layout ) ) {
box.setChecked( true ); box.setChecked( true );
} else if ( null != m_lastDev && m_lastDev.equals( btAddr ) ) { } else if ( null != m_lastDev && m_lastDev.equals( btAddr ) ) {
m_lastDev = null; m_lastDev = null;
box.setChecked( true ); box.setChecked( true );
} }
m_views[position] = layout;
return layout; return layout;
} }