Bug 1261527 - Add active/inactive client state. r=sebastian, a=lizzard
authorChenxia Liu <liuche@mozilla.com>
Wed, 27 Apr 2016 16:43:53 -0700
changeset 332734 e702eabb5ec7cb0aae38e951702dac5d5dceee34
parent 332733 7cd6e6a653dd6e28967d7183011f6358fdaec3a0
child 332735 7e7a0d76f09c4f1dcdf85c274bd8f04b90abd550
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, lizzard
bugs1261527
milestone48.0a2
Bug 1261527 - Add active/inactive client state. r=sebastian, a=lizzard MozReview-Commit-ID: 39Qy3cYE6ro
mobile/android/base/java/org/mozilla/gecko/db/RemoteClient.java
mobile/android/base/java/org/mozilla/gecko/home/ClientsAdapter.java
mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryItem.java
--- a/mobile/android/base/java/org/mozilla/gecko/db/RemoteClient.java
+++ b/mobile/android/base/java/org/mozilla/gecko/db/RemoteClient.java
@@ -57,9 +57,13 @@ public class RemoteClient implements Par
             return client;
         }
 
         @Override
         public RemoteClient[] newArray(final int size) {
             return new RemoteClient[size];
         }
     };
+
+    public boolean isDesktop() {
+        return "desktop".equals(deviceType);
+    }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/home/ClientsAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/ClientsAdapter.java
@@ -85,17 +85,17 @@ public class ClientsAdapter extends Recy
     public void onBindViewHolder (CombinedHistoryItem holder, final int position){
        final CombinedHistoryItem.ItemType itemType = getItemTypeForPosition(position);
 
         switch (itemType) {
             case CLIENT:
                 final CombinedHistoryItem.ClientItem clientItem = (CombinedHistoryItem.ClientItem) holder;
                 final String clientGuid = adapterList.get(position).first;
                 final RemoteClient client = visibleClients.get(clientGuid);
-                clientItem.bind(client, context);
+                clientItem.bind(context, client, sState.isClientCollapsed(clientGuid));
                 break;
 
             case CHILD:
                 final Pair<String, Integer> pair = adapterList.get(position);
                 RemoteTab remoteTab = visibleClients.get(pair.first).tabs.get(pair.second);
                 ((CombinedHistoryItem.HistoryItem) holder).bind(remoteTab);
                 break;
 
@@ -178,32 +178,34 @@ public class ClientsAdapter extends Recy
         if (pair.second != -1) {
             return;
         }
 
         final String clientGuid = pair.first;
         final RemoteClient client = visibleClients.get(clientGuid);
 
         final boolean isCollapsed = sState.isClientCollapsed(clientGuid);
+
+        sState.setClientCollapsed(clientGuid, !isCollapsed);
+        notifyItemChanged(position);
+
         if (isCollapsed) {
             for (int i = client.tabs.size() - 1; i > -1; i--) {
                 // Insert child tabs at the index right after the client item that was clicked.
                 adapterList.add(position + 1, new Pair<>(clientGuid, i));
             }
             notifyItemRangeInserted(position + 1, client.tabs.size());
         } else {
             int i = client.tabs.size();
             while (i > 0) {
                 adapterList.remove(position + 1);
                 i--;
             }
             notifyItemRangeRemoved(position + 1, client.tabs.size());
         }
-        // TODO: Update arrow direction of expanded state.
-        sState.setClientCollapsed(clientGuid, !isCollapsed);
     }
 
     public void unhideClients(List<RemoteClient> selectedClients) {
         final int numClients = selectedClients.size();
         if (numClients == 0) {
             return;
         }
 
--- a/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryItem.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/CombinedHistoryItem.java
@@ -11,17 +11,16 @@ import android.support.v7.widget.Recycle
 import android.util.Log;
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.TextView;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.RemoteTabsExpandableListAdapter;
 import org.mozilla.gecko.db.RemoteClient;
 import org.mozilla.gecko.db.RemoteTab;
-import org.w3c.dom.Text;
 
 public abstract class CombinedHistoryItem extends RecyclerView.ViewHolder {
     private static final String LOGTAG = "CombinedHistoryItem";
 
     public CombinedHistoryItem(View view) {
         super(view);
     }
 
@@ -96,19 +95,26 @@ public abstract class CombinedHistoryIte
         public ClientItem(View view) {
             super(view);
             nameView = (TextView) view.findViewById(R.id.client);
             deviceTypeView = (ImageView) view.findViewById(R.id.device_type);
             lastModifiedView = (TextView) view.findViewById(R.id.last_synced);
             deviceExpanded = (ImageView) view.findViewById(R.id.device_expanded);
         }
 
-        public void bind(RemoteClient client, Context context) {
+        public void bind(Context context, RemoteClient client, boolean isCollapsed) {
             this.nameView.setText(client.name);
-            this.nameView.setTextColor(ContextCompat.getColor(context, R.color.placeholder_active_grey));
-            this.deviceTypeView.setImageResource("desktop".equals(client.deviceType) ? R.drawable.sync_desktop : R.drawable.sync_mobile);
-            this.deviceExpanded.setImageResource(client.tabs.isEmpty() ? 0 : R.drawable.home_group_collapsed);
-
             final long now = System.currentTimeMillis();
             this.lastModifiedView.setText(RemoteTabsExpandableListAdapter.getLastSyncedString(context, now, client.lastModified));
+
+            if (client.isDesktop()) {
+                deviceTypeView.setImageResource(isCollapsed ? R.drawable.sync_desktop_inactive : R.drawable.sync_desktop);
+            } else {
+                deviceTypeView.setImageResource(isCollapsed ? R.drawable.sync_mobile_inactive : R.drawable.sync_mobile);
+            }
+
+            nameView.setTextColor(ContextCompat.getColor(context, isCollapsed ? R.color.tabs_tray_icon_grey : R.color.placeholder_active_grey));
+            if (client.tabs.size() > 0) {
+                deviceExpanded.setImageResource(isCollapsed ? R.drawable.home_group_collapsed : R.drawable.arrow_down);
+            }
         }
     }
 }