Refactor: Implement avatar/user control as view
This way it can be reused in other places.
Change-Id: I2861135e6ca3fa8d209ce5db0b9574b4c7855be6
Signed-off-by: Edwin Kempin <ekempin@google.com>
diff --git a/app/src/main/java/com/google/reviewit/widget/ChangeBox.java b/app/src/main/java/com/google/reviewit/widget/ChangeBox.java
index 9089e99..dd5288e 100644
--- a/app/src/main/java/com/google/reviewit/widget/ChangeBox.java
+++ b/app/src/main/java/com/google/reviewit/widget/ChangeBox.java
@@ -84,14 +84,12 @@
public void display(ReviewItApp app, Change change) {
configureInfo(app);
- ((ProjectBranchTopicAgeView)v(R.id.projectBranchTopicAge)).init(change);
-
ChangeInfo info = change.info;
+ ((ProjectBranchTopicAgeView)v(R.id.projectBranchTopicAge)).init(change);
+ ((UserView)v(R.id.owner)).init(app, info.owner);
WidgetUtil.setText(v(R.id.subject), info.subject);
WidgetUtil.setText(v(R.id.commitMessage),
FormatUtil.formatMessage(change));
- displayAvatar(app, info.owner);
- WidgetUtil.setText(v(R.id.owner), FormatUtil.format(info.owner));
WidgetUtil.setText(v(R.id.patchsets),
FormatUtil.format(change.currentRevision()._number));
setInlineCommentCount(app, change);
@@ -205,10 +203,6 @@
return false;
}
- private void displayAvatar(ReviewItApp app,AccountInfo account) {
- WidgetUtil.displayAvatar(app, account, (ImageView) v(R.id.avatar));
- }
-
private View v(@IdRes int id) {
return findViewById(id);
}
diff --git a/app/src/main/java/com/google/reviewit/widget/UserView.java b/app/src/main/java/com/google/reviewit/widget/UserView.java
new file mode 100644
index 0000000..58e61d5
--- /dev/null
+++ b/app/src/main/java/com/google/reviewit/widget/UserView.java
@@ -0,0 +1,49 @@
+// 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.util.AttributeSet;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+
+import com.google.gerrit.extensions.common.AccountInfo;
+import com.google.reviewit.R;
+import com.google.reviewit.app.ReviewItApp;
+import com.google.reviewit.util.FormatUtil;
+import com.google.reviewit.util.WidgetUtil;
+
+public class UserView extends LinearLayout {
+ public UserView(Context context) {
+ this(context, null, 0);
+ }
+
+ public UserView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public UserView(
+ Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+
+ inflate(context, R.layout.user, this);
+ }
+
+ public void init(ReviewItApp app, AccountInfo account) {
+ WidgetUtil.displayAvatar(app, account,
+ (ImageView) findViewById(R.id.avatar));
+ WidgetUtil.setText(findViewById(R.id.userName), FormatUtil.format(account));
+ }
+}
diff --git a/app/src/main/res/layout/change_box.xml b/app/src/main/res/layout/change_box.xml
index 7f42d22..f802d0e 100644
--- a/app/src/main/res/layout/change_box.xml
+++ b/app/src/main/res/layout/change_box.xml
@@ -76,23 +76,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="4dp">
-
- <ImageView
- android:id="@+id/avatar"
- android:layout_width="20dp"
- android:layout_height="20dp"
- android:layout_marginRight="3dp"/>
-
- <TextView
- android:id="@+id/owner"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- </LinearLayout>
+ <com.google.reviewit.widget.UserView
+ android:id="@+id/owner"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="4dp"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
diff --git a/app/src/main/res/layout/user.xml b/app/src/main/res/layout/user.xml
new file mode 100644
index 0000000..190b04b
--- /dev/null
+++ b/app/src/main/res/layout/user.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- 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. -->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+
+ <ImageView
+ android:id="@+id/avatar"
+ android:layout_width="20dp"
+ android:layout_height="20dp"
+ android:layout_marginRight="3dp"/>
+
+ <TextView
+ android:id="@+id/userName"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+</LinearLayout>