mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
cleanup: track only checked items, not all items.
This commit is contained in:
parent
eee13bcdd6
commit
7ba7879a55
1 changed files with 15 additions and 24 deletions
|
@ -50,7 +50,7 @@ import org.eehouse.android.xw4.DlgDelegate.DlgClickNotify.InviteMeans;
|
|||
public class BTInviteDelegate extends InviteDelegate {
|
||||
|
||||
private Activity m_activity;
|
||||
private Set<String> m_checked;
|
||||
private Set<LinearLayout> m_checked;
|
||||
private Map<String, Integer> 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<String>();
|
||||
m_checked = new HashSet<LinearLayout>();
|
||||
m_counts = new HashMap<String, Integer>();
|
||||
|
||||
String msg = getString( R.string.bt_pick_addall_button );
|
||||
|
@ -156,9 +156,11 @@ public class BTInviteDelegate extends InviteDelegate {
|
|||
}
|
||||
|
||||
int nxt = 0;
|
||||
for ( Iterator<String> iter = m_checked.iterator();
|
||||
for ( Iterator<LinearLayout> 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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue