Bug 832773 - Fix Send Tab button enabling logic. r=rnewman a=nonlibxul

This commit is contained in:
Nick Alexander 2013-01-21 13:30:41 -08:00
Родитель ad4dad9c67
Коммит a048161b7f
1 изменённых файлов: 18 добавлений и 6 удалений

Просмотреть файл

@ -24,7 +24,6 @@ public class ClientRecordArrayAdapter extends ArrayAdapter<ClientRecord> {
public static final String LOG_TAG = "ClientRecArrayAdapter"; public static final String LOG_TAG = "ClientRecArrayAdapter";
private boolean[] checkedItems; private boolean[] checkedItems;
private int numCheckedGUIDs;
private SendTabActivity sendTabActivity; private SendTabActivity sendTabActivity;
public ClientRecordArrayAdapter(Context context, public ClientRecordArrayAdapter(Context context,
@ -37,7 +36,6 @@ public class ClientRecordArrayAdapter extends ArrayAdapter<ClientRecord> {
public synchronized void setClientRecordList(final Collection<ClientRecord> clientRecordList) { public synchronized void setClientRecordList(final Collection<ClientRecord> clientRecordList) {
this.clear(); this.clear();
this.checkedItems = new boolean[clientRecordList.size()]; this.checkedItems = new boolean[clientRecordList.size()];
this.numCheckedGUIDs = 0;
for (ClientRecord clientRecord : clientRecordList) { for (ClientRecord clientRecord : clientRecordList) {
this.add(clientRecord); this.add(clientRecord);
} }
@ -72,10 +70,8 @@ public class ClientRecordArrayAdapter extends ArrayAdapter<ClientRecord> {
} }
checkedItems[position] = checked; checkedItems[position] = checked;
numCheckedGUIDs += checked ? 1 : -1; sendTabActivity.enableSend(getNumCheckedGUIDs() > 0);
if (numCheckedGUIDs <= 0) {
sendTabActivity.enableSend(numCheckedGUIDs > 0);
}
return true; return true;
} }
@ -118,6 +114,11 @@ public class ClientRecordArrayAdapter extends ArrayAdapter<ClientRecord> {
return row; return row;
} }
/**
* Get list of checked GUIDs.
*
* @return non-null list.
*/
public synchronized List<String> getCheckedGUIDs() { public synchronized List<String> getCheckedGUIDs() {
final List<String> guids = new ArrayList<String>(); final List<String> guids = new ArrayList<String>();
for (int i = 0; i < checkedItems.length; i++) { for (int i = 0; i < checkedItems.length; i++) {
@ -128,7 +129,18 @@ public class ClientRecordArrayAdapter extends ArrayAdapter<ClientRecord> {
return guids; return guids;
} }
/**
* Get number of checked GUIDs.
*
* @return non-negative integer.
*/
public synchronized int getNumCheckedGUIDs() { public synchronized int getNumCheckedGUIDs() {
int numCheckedGUIDs = 0;
for (int i = 0; i < checkedItems.length; i++) {
if (checkedItems[i]) {
numCheckedGUIDs += 1;
}
}
return numCheckedGUIDs; return numCheckedGUIDs;
} }