Bug 832773 - Fix Send Tab button enabling logic. r=rnewman a=nonlibxul
authorNick Alexander <nalexander@mozilla.com>
Mon, 21 Jan 2013 13:30:41 -0800
changeset 119439 99139490db7a6d56e3427537e6d052f5638669f5
parent 119438 445fd00264554dbb0c5a1fe5c2a9ca7a2606e3fd
child 119440 33e8b01d811aa3883c9cc3695c3714599e448cd9
push id24204
push usereakhgari@mozilla.com
push dateTue, 22 Jan 2013 17:50:00 +0000
treeherdermozilla-central@8962a7fabc33 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, nonlibxul
bugs832773
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 832773 - Fix Send Tab button enabling logic. r=rnewman a=nonlibxul
mobile/android/base/sync/setup/activities/ClientRecordArrayAdapter.java
--- a/mobile/android/base/sync/setup/activities/ClientRecordArrayAdapter.java
+++ b/mobile/android/base/sync/setup/activities/ClientRecordArrayAdapter.java
@@ -19,30 +19,28 @@ import android.widget.ArrayAdapter;
 import android.widget.CheckBox;
 import android.widget.ImageView;
 import android.widget.TextView;
 
 public class ClientRecordArrayAdapter extends ArrayAdapter<ClientRecord> {
   public static final String LOG_TAG = "ClientRecArrayAdapter";
 
   private boolean[] checkedItems;
-  private int numCheckedGUIDs;
   private SendTabActivity sendTabActivity;
 
   public ClientRecordArrayAdapter(Context context,
                                   int textViewResourceId) {
     super(context, textViewResourceId, new ArrayList<ClientRecord>());
     this.checkedItems = new boolean[0];
     this.sendTabActivity = (SendTabActivity) context;
   }
 
   public synchronized void setClientRecordList(final Collection<ClientRecord> clientRecordList) {
     this.clear();
     this.checkedItems = new boolean[clientRecordList.size()];
-    this.numCheckedGUIDs = 0;
     for (ClientRecord clientRecord : clientRecordList) {
       this.add(clientRecord);
     }
     this.notifyDataSetChanged();
   }
 
   /**
    * If we have only a single client record in the list, mark it as checked.
@@ -67,20 +65,18 @@ public class ClientRecordArrayAdapter ex
    */
   protected synchronized boolean setRowChecked(int position, boolean checked) {
     boolean current = checkedItems[position];
     if (current == checked) {
       return false;
     }
 
     checkedItems[position] = checked;
-    numCheckedGUIDs += checked ? 1 : -1;
-    if (numCheckedGUIDs <= 0) {
-      sendTabActivity.enableSend(numCheckedGUIDs > 0);
-    }
+    sendTabActivity.enableSend(getNumCheckedGUIDs() > 0);
+
     return true;
   }
 
   @Override
   public View getView(final int position, View convertView, ViewGroup parent) {
     final Context context = this.getContext();
 
     // Reuse View objects if they exist.
@@ -113,27 +109,43 @@ public class ClientRecordArrayAdapter ex
         item.setChecked(checked);
         setRowChecked(position, checked);
       }
     });
 
     return row;
   }
 
+  /**
+   * Get list of checked GUIDs.
+   *
+   * @return non-null list.
+   */
   public synchronized List<String> getCheckedGUIDs() {
     final List<String> guids = new ArrayList<String>();
     for (int i = 0; i < checkedItems.length; i++) {
       if (checkedItems[i]) {
         guids.add(this.getItem(i).guid);
       }
     }
     return guids;
   }
 
+  /**
+   * Get number of checked GUIDs.
+   *
+   * @return non-negative integer.
+   */
   public synchronized int getNumCheckedGUIDs() {
+    int numCheckedGUIDs = 0;
+    for (int i = 0; i < checkedItems.length; i++) {
+      if (checkedItems[i]) {
+        numCheckedGUIDs += 1;
+      }
+    }
     return numCheckedGUIDs;
   }
 
   private int getImage(ClientRecord record) {
     if ("mobile".equals(record.type)) {
       return R.drawable.mobile;
     }
     return R.drawable.desktop;