From 7ba7879a55e9959e5bd9d3222c3d52efbb8a0a7c Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 19 Jan 2016 06:53:43 -0800 Subject: [PATCH] cleanup: track only checked items, not all items. --- .../eehouse/android/xw4/BTInviteDelegate.java | 39 +++++++------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTInviteDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTInviteDelegate.java index fe68db3ba..99ff62cc1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTInviteDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTInviteDelegate.java @@ -50,7 +50,7 @@ import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify.InviteMeans; public class BTInviteDelegate extends InviteDelegate { private Activity m_activity; - private Set m_checked; + private Set m_checked; private Map m_counts; private boolean m_setChecked; private BTDevsAdapter m_adapter; @@ -78,7 +78,7 @@ public class BTInviteDelegate extends InviteDelegate { @Override protected void init( Bundle savedInstanceState ) { - m_checked = new HashSet(); + m_checked = new HashSet(); m_counts = new HashMap(); String msg = getString( R.string.bt_pick_addall_button ); @@ -156,9 +156,11 @@ public class BTInviteDelegate extends InviteDelegate { } int nxt = 0; - for ( Iterator iter = m_checked.iterator(); + for ( Iterator iter = m_checked.iterator(); 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; if ( null != counts ) { counts[nxt] = m_counts.get( btAddr ); @@ -185,31 +187,19 @@ public class BTInviteDelegate extends InviteDelegate { private class BTDevsAdapter extends XWListAdapter { private String[] m_devAddrs; private String[] m_devNames; - private LinearLayout[] m_views; public BTDevsAdapter( String[] btAddrs, String[] btNames ) { super( null == btAddrs? 0 : btAddrs.length ); m_devAddrs = btAddrs; 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 View getView( int position, View convertView, ViewGroup parent ) { 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 ); box.setText( m_devNames[position] ); box.setTag( btAddr ); @@ -243,17 +233,19 @@ public class BTInviteDelegate extends InviteDelegate { CompoundButton.OnCheckedChangeListener listener = new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged( CompoundButton buttonView, - boolean isChecked ) - { + boolean isChecked ) { if ( isChecked ) { 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_adapter.clearCheckedExcept( buttonView ); } - m_checked.add( btAddr ); + m_checked.add( layout ); } else { - m_checked.remove( btAddr ); + m_checked.remove( layout ); // User's now making changes; don't check new views m_setChecked = false; } @@ -262,13 +254,12 @@ public class BTInviteDelegate extends InviteDelegate { }; box.setOnCheckedChangeListener( listener ); - if ( m_setChecked || m_checked.contains( btAddr ) ) { + if ( m_setChecked || m_checked.contains( layout ) ) { box.setChecked( true ); } else if ( null != m_lastDev && m_lastDev.equals( btAddr ) ) { m_lastDev = null; box.setChecked( true ); } - m_views[position] = layout; return layout; }