OSDN Git Service

Fixing issue with history icons getting clobbered.
authorWinson <winsonc@google.com>
Thu, 4 Feb 2016 23:08:01 +0000 (15:08 -0800)
committerWinson <winsonc@google.com>
Fri, 5 Feb 2016 01:33:26 +0000 (17:33 -0800)
- If the view holder is rebound before the other task is recycled, there
  could be multiple callbacks attached to different tasks for the same
  view holder, which can cause the wrong icon (which is loaded in the
  bg, to be loaded into the wrong view holder).  Now, we unbind the
  callback from the old task when the new task’s callbacks are bound.

Change-Id: If0dfada24985944daf4302c4db0616a00a770f06

packages/SystemUI/src/com/android/systemui/recents/history/RecentsHistoryAdapter.java

index ee3eb02..5eeda72 100644 (file)
@@ -67,9 +67,30 @@ public class RecentsHistoryAdapter extends RecyclerView.Adapter<RecentsHistoryAd
     public static class ViewHolder extends RecyclerView.ViewHolder implements Task.TaskCallbacks {
         public final View content;
 
-        public ViewHolder(View v) {
-            super(v);
-            content = v;
+        private Task mTask;
+
+        public ViewHolder(View content) {
+            super(content);
+            this.content = content;
+        }
+
+        /**
+         * Binds this view holder to the given task.
+         */
+        public void bindToTask(Task newTask) {
+            unbindFromTask();
+            mTask = newTask;
+            mTask.addCallback(this);
+        }
+
+        /**
+         * Unbinds this view holder from the
+         */
+        public void unbindFromTask() {
+            if (mTask != null) {
+                mTask.removeCallback(this);
+                mTask = null;
+            }
         }
 
         @Override
@@ -267,12 +288,13 @@ public class RecentsHistoryAdapter extends RecyclerView.Adapter<RecentsHistoryAd
             }
             case TASK_ROW_VIEW_TYPE: {
                 TaskRow taskRow = (TaskRow) row;
-                taskRow.task.addCallback(holder);
                 TextView tv = (TextView) holder.content.findViewById(R.id.description);
                 tv.setText(taskRow.task.title);
                 ImageView iv = (ImageView) holder.content.findViewById(R.id.icon);
                 iv.setAlpha(0f);
                 holder.content.setOnClickListener(taskRow);
+
+                holder.bindToTask(taskRow.task);
                 loader.loadTaskData(taskRow.task, false /* fetchAndInvalidateThumbnails */);
                 break;
             }
@@ -289,7 +311,7 @@ public class RecentsHistoryAdapter extends RecyclerView.Adapter<RecentsHistoryAd
             if (viewType == TASK_ROW_VIEW_TYPE) {
                 TaskRow taskRow = (TaskRow) row;
                 loader.unloadTaskData(taskRow.task);
-                taskRow.task.removeCallback(holder);
+                holder.unbindFromTask();
             }
         }
     }