Show Verified votes in change list

If a change has several Verified votes with different values, only the
vote with the lowest value is shown in the change list.

Change-Id: I02b3ac529e46feedf2118dec51784d9d6ef43880
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/app/src/main/java/com/google/reviewit/widget/ChangeEntry.java b/app/src/main/java/com/google/reviewit/widget/ChangeEntry.java
index 8226434..9b50764 100644
--- a/app/src/main/java/com/google/reviewit/widget/ChangeEntry.java
+++ b/app/src/main/java/com/google/reviewit/widget/ChangeEntry.java
@@ -48,5 +48,6 @@
     WidgetUtil.setText(findViewById(R.id.subject), info.subject);
 
     ((CodeReviewVotes)findViewById(R.id.codeReviewVotes)).init(change);
+    ((VerifiedVotes)findViewById(R.id.verifiedVotes)).init(change);
   }
 }
diff --git a/app/src/main/java/com/google/reviewit/widget/VerifiedVotes.java b/app/src/main/java/com/google/reviewit/widget/VerifiedVotes.java
new file mode 100644
index 0000000..8f61959
--- /dev/null
+++ b/app/src/main/java/com/google/reviewit/widget/VerifiedVotes.java
@@ -0,0 +1,103 @@
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.reviewit.widget;
+
+import android.content.Context;
+import android.support.annotation.DrawableRes;
+import android.util.AttributeSet;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+
+import com.google.gerrit.extensions.common.ApprovalInfo;
+import com.google.reviewit.R;
+import com.google.reviewit.app.Change;
+import com.google.reviewit.util.WidgetUtil;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static com.google.reviewit.util.LayoutUtil.matchLayout;
+import static com.google.reviewit.util.WidgetUtil.setInvisible;
+
+public class VerifiedVotes extends LinearLayout {
+  private final WidgetUtil widgetUtil;
+
+  public VerifiedVotes(Context context) {
+    this(context, null, 0);
+  }
+
+  public VerifiedVotes(Context context, AttributeSet attrs) {
+    this(context, attrs, 0);
+  }
+
+  public VerifiedVotes(Context context, AttributeSet attrs, int defStyle) {
+    super(context, attrs, defStyle);
+    this.widgetUtil = new WidgetUtil(getContext());
+
+    setOrientation(VERTICAL);
+  }
+
+  public void init(Change change) {
+    List<ApprovalInfo> codeReviewApprovals =
+        (change.info.labels != null
+            && change.info.labels.get("Verified") != null)
+            ? change.info.labels.get("Verified").all : null;
+
+    if (codeReviewApprovals == null) {
+      setLayoutParams(new LinearLayout.LayoutParams(
+          widgetUtil.dpToPx(48), widgetUtil.dpToPx(48)));
+      return;
+    }
+
+    Set<Integer> values = new HashSet<>();
+    for (ApprovalInfo approval : codeReviewApprovals) {
+      values.add(approval.value);
+    }
+
+    values.remove(0);
+
+    if (values.contains(-1)) {
+      ImageView icon = createVoteIcon(-1);
+      icon.setLayoutParams(matchLayout());
+      addView(icon);
+    } else if (values.contains(1)) {
+      ImageView icon = createVoteIcon(1);
+      icon.setLayoutParams(matchLayout());
+      addView(icon);
+    } else {
+      ImageView icon = createVoteIcon(0);
+      icon.setLayoutParams(matchLayout());
+      setInvisible(icon);
+      addView(icon);
+    }
+  }
+
+  private ImageView createVoteIcon(int verifiedVote) {
+    ImageView icon = new ImageView(getContext());
+    @DrawableRes int iconRes;
+    if (verifiedVote == -1) {
+      icon.setColorFilter(widgetUtil.color(R.color.voteNegative));
+      iconRes = R.drawable.ic_clear_black_48dp;
+    } else if (verifiedVote == 0) {
+      iconRes = R.drawable.ic_exposure_zero_black_48dp;
+    } else {
+      icon.setColorFilter(widgetUtil.color(R.color.votePositive));
+      iconRes = R.drawable.ic_done_black_48dp;
+    }
+    icon.setImageDrawable(widgetUtil.getDrawable(iconRes));
+    return icon;
+  }
+}
diff --git a/app/src/main/res/drawable-hdpi/ic_clear_black_48dp.png b/app/src/main/res/drawable-hdpi/ic_clear_black_48dp.png
new file mode 100644
index 0000000..51b4401
--- /dev/null
+++ b/app/src/main/res/drawable-hdpi/ic_clear_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-hdpi/ic_done_black_48dp.png b/app/src/main/res/drawable-hdpi/ic_done_black_48dp.png
new file mode 100644
index 0000000..c9c0174
--- /dev/null
+++ b/app/src/main/res/drawable-hdpi/ic_done_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-hdpi/ic_exposure_zero_black_48dp.png b/app/src/main/res/drawable-hdpi/ic_exposure_zero_black_48dp.png
new file mode 100644
index 0000000..a2ee087
--- /dev/null
+++ b/app/src/main/res/drawable-hdpi/ic_exposure_zero_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-mdpi/ic_clear_black_48dp.png b/app/src/main/res/drawable-mdpi/ic_clear_black_48dp.png
new file mode 100644
index 0000000..6bc4372
--- /dev/null
+++ b/app/src/main/res/drawable-mdpi/ic_clear_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-mdpi/ic_done_black_48dp.png b/app/src/main/res/drawable-mdpi/ic_done_black_48dp.png
new file mode 100644
index 0000000..64a4944
--- /dev/null
+++ b/app/src/main/res/drawable-mdpi/ic_done_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-mdpi/ic_exposure_zero_black_48dp.png b/app/src/main/res/drawable-mdpi/ic_exposure_zero_black_48dp.png
new file mode 100644
index 0000000..b33224a
--- /dev/null
+++ b/app/src/main/res/drawable-mdpi/ic_exposure_zero_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_clear_black_48dp.png b/app/src/main/res/drawable-xhdpi/ic_clear_black_48dp.png
new file mode 100644
index 0000000..df42fee
--- /dev/null
+++ b/app/src/main/res/drawable-xhdpi/ic_clear_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_done_black_48dp.png b/app/src/main/res/drawable-xhdpi/ic_done_black_48dp.png
new file mode 100644
index 0000000..2f6d638
--- /dev/null
+++ b/app/src/main/res/drawable-xhdpi/ic_done_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_exposure_zero_black_48dp.png b/app/src/main/res/drawable-xhdpi/ic_exposure_zero_black_48dp.png
new file mode 100644
index 0000000..bae047f
--- /dev/null
+++ b/app/src/main/res/drawable-xhdpi/ic_exposure_zero_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_clear_black_48dp.png b/app/src/main/res/drawable-xxhdpi/ic_clear_black_48dp.png
new file mode 100644
index 0000000..e2ee25f
--- /dev/null
+++ b/app/src/main/res/drawable-xxhdpi/ic_clear_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_done_black_48dp.png b/app/src/main/res/drawable-xxhdpi/ic_done_black_48dp.png
new file mode 100644
index 0000000..5697dba
--- /dev/null
+++ b/app/src/main/res/drawable-xxhdpi/ic_done_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_exposure_zero_black_48dp.png b/app/src/main/res/drawable-xxhdpi/ic_exposure_zero_black_48dp.png
new file mode 100644
index 0000000..979bf9b
--- /dev/null
+++ b/app/src/main/res/drawable-xxhdpi/ic_exposure_zero_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_clear_black_48dp.png b/app/src/main/res/drawable-xxxhdpi/ic_clear_black_48dp.png
new file mode 100644
index 0000000..8c6f57c
--- /dev/null
+++ b/app/src/main/res/drawable-xxxhdpi/ic_clear_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_done_black_48dp.png b/app/src/main/res/drawable-xxxhdpi/ic_done_black_48dp.png
new file mode 100644
index 0000000..0875136
--- /dev/null
+++ b/app/src/main/res/drawable-xxxhdpi/ic_done_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/drawable-xxxhdpi/ic_exposure_zero_black_48dp.png b/app/src/main/res/drawable-xxxhdpi/ic_exposure_zero_black_48dp.png
new file mode 100644
index 0000000..e1a5ce5
--- /dev/null
+++ b/app/src/main/res/drawable-xxxhdpi/ic_exposure_zero_black_48dp.png
Binary files differ
diff --git a/app/src/main/res/layout/change_entry.xml b/app/src/main/res/layout/change_entry.xml
index 745a02f..edd4a86 100644
--- a/app/src/main/res/layout/change_entry.xml
+++ b/app/src/main/res/layout/change_entry.xml
@@ -63,6 +63,11 @@
         android:id="@+id/codeReviewVotes"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"/>
+
+      <com.google.reviewit.widget.VerifiedVotes
+        android:id="@+id/verifiedVotes"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"/>
     </LinearLayout>
   </LinearLayout>
 </LinearLayout>
\ No newline at end of file