Commit 98f6f04b authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[ProfileCard] Add creator information to profile card

The creator information shown on the proile card will be:
- name
- description
- avatar image
- post frequency

Bug: 1051147
Change-Id: I5ce047a063eaccc087a0490b730f40ab148b12c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2051529
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Reviewed-by: default avatarsebsg <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740925}
parent 36dc58a2
...@@ -11,6 +11,12 @@ ...@@ -11,6 +11,12 @@
android:orientation="vertical" android:orientation="vertical"
android:padding="16dp"> android:padding="16dp">
<ImageView
android:id="@+id/avatar"
android:contentDescription="@strings/creator_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -21,4 +27,8 @@ ...@@ -21,4 +27,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
<TextView
android:id="@+id/post_freq"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</org.chromium.chrome.browser.profile_card.ProfileCardView> </org.chromium.chrome.browser.profile_card.ProfileCardView>
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
package org.chromium.chrome.browser.profile_card; package org.chromium.chrome.browser.profile_card;
import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.AVATAR_BITMAP;
import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.DESCRIPTION; import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.DESCRIPTION;
import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.IS_DIALOG_VISIBLE; import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.IS_DIALOG_VISIBLE;
import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.POST_FREQUENCY;
import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.TITLE; import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.TITLE;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
...@@ -23,8 +25,10 @@ class ProfileCardMediator { ...@@ -23,8 +25,10 @@ class ProfileCardMediator {
ProfileCardMediator(PropertyModel model, ProfileCardData profileCardData) { ProfileCardMediator(PropertyModel model, ProfileCardData profileCardData) {
mModel = model; mModel = model;
mProfileCardData = profileCardData; mProfileCardData = profileCardData;
mModel.set(AVATAR_BITMAP, mProfileCardData.getAvatarBitmap());
mModel.set(TITLE, mProfileCardData.getTitle()); mModel.set(TITLE, mProfileCardData.getTitle());
mModel.set(DESCRIPTION, mProfileCardData.getDescription()); mModel.set(DESCRIPTION, mProfileCardData.getDescription());
mModel.set(POST_FREQUENCY, mProfileCardData.getPostFrequency());
} }
public void show() { public void show() {
......
...@@ -4,16 +4,22 @@ ...@@ -4,16 +4,22 @@
package org.chromium.chrome.browser.profile_card; package org.chromium.chrome.browser.profile_card;
import android.graphics.Bitmap;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
class ProfileCardProperties extends PropertyModel { class ProfileCardProperties extends PropertyModel {
public static final PropertyModel.WritableObjectPropertyKey<Bitmap> AVATAR_BITMAP =
new PropertyModel.WritableObjectPropertyKey<Bitmap>();
public static final PropertyModel.WritableObjectPropertyKey<String> TITLE = public static final PropertyModel.WritableObjectPropertyKey<String> TITLE =
new PropertyModel.WritableObjectPropertyKey<String>(); new PropertyModel.WritableObjectPropertyKey<String>();
public static final PropertyModel.WritableObjectPropertyKey<String> DESCRIPTION = public static final PropertyModel.WritableObjectPropertyKey<String> DESCRIPTION =
new PropertyModel.WritableObjectPropertyKey<String>(); new PropertyModel.WritableObjectPropertyKey<String>();
public static final PropertyModel.WritableObjectPropertyKey<String> POST_FREQUENCY =
new PropertyModel.WritableObjectPropertyKey<String>();
public static final PropertyModel.WritableBooleanPropertyKey IS_DIALOG_VISIBLE = public static final PropertyModel.WritableBooleanPropertyKey IS_DIALOG_VISIBLE =
new PropertyModel.WritableBooleanPropertyKey(); new PropertyModel.WritableBooleanPropertyKey();
public static final PropertyKey[] ALL_KEYS = public static final PropertyKey[] ALL_KEYS = new PropertyKey[] {
new PropertyKey[] {TITLE, DESCRIPTION, IS_DIALOG_VISIBLE}; AVATAR_BITMAP, TITLE, DESCRIPTION, POST_FREQUENCY, IS_DIALOG_VISIBLE};
} }
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
package org.chromium.chrome.browser.profile_card; package org.chromium.chrome.browser.profile_card;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.text.method.ScrollingMovementMethod; import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
...@@ -20,6 +22,8 @@ public class ProfileCardView extends LinearLayout { ...@@ -20,6 +22,8 @@ public class ProfileCardView extends LinearLayout {
private View mMainContentView; private View mMainContentView;
private TextView mTitleTextView; private TextView mTitleTextView;
private TextView mDescriptionTextView; private TextView mDescriptionTextView;
private ImageView mAvatarView;
private TextView mPostFrequencyTextView;
public ProfileCardView(Context context) { public ProfileCardView(Context context) {
super(context); super(context);
...@@ -33,6 +37,11 @@ public class ProfileCardView extends LinearLayout { ...@@ -33,6 +37,11 @@ public class ProfileCardView extends LinearLayout {
mTitleTextView = mMainContentView.findViewById(R.id.title); mTitleTextView = mMainContentView.findViewById(R.id.title);
mDescriptionTextView = mMainContentView.findViewById(R.id.description); mDescriptionTextView = mMainContentView.findViewById(R.id.description);
mDescriptionTextView.setMovementMethod(new ScrollingMovementMethod()); mDescriptionTextView.setMovementMethod(new ScrollingMovementMethod());
mPostFrequencyTextView = mMainContentView.findViewById(R.id.post_freq);
}
void setAvatarBitmap(Bitmap avatarBitmap) {
mAvatarView.setImageBitmap(avatarBitmap);
} }
void setTitle(String title) { void setTitle(String title) {
...@@ -49,6 +58,14 @@ public class ProfileCardView extends LinearLayout { ...@@ -49,6 +58,14 @@ public class ProfileCardView extends LinearLayout {
mDescriptionTextView.setText(description); mDescriptionTextView.setText(description);
} }
void setPostFrequency(String postFrequency) {
if (mPostFrequencyTextView == null) {
throw new IllegalStateException(
"Current dialog doesn't have a post frequency text view");
}
mPostFrequencyTextView.setText(postFrequency);
}
void setVisibility(boolean visible) { void setVisibility(boolean visible) {
if (visible) { if (visible) {
mMainContentView.setVisibility(View.VISIBLE); mMainContentView.setVisibility(View.VISIBLE);
......
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
package org.chromium.chrome.browser.profile_card; package org.chromium.chrome.browser.profile_card;
import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.AVATAR_BITMAP;
import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.DESCRIPTION; import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.DESCRIPTION;
import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.IS_DIALOG_VISIBLE; import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.IS_DIALOG_VISIBLE;
import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.POST_FREQUENCY;
import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.TITLE; import static org.chromium.chrome.browser.profile_card.ProfileCardProperties.TITLE;
import org.chromium.ui.modelutil.PropertyKey; import org.chromium.ui.modelutil.PropertyKey;
...@@ -19,10 +21,14 @@ class ProfileCardViewBinder { ...@@ -19,10 +21,14 @@ class ProfileCardViewBinder {
* @param propertyKey The key for the property to update for. * @param propertyKey The key for the property to update for.
*/ */
public static void bind(PropertyModel model, ProfileCardView view, PropertyKey propertyKey) { public static void bind(PropertyModel model, ProfileCardView view, PropertyKey propertyKey) {
if (TITLE == propertyKey) { if (AVATAR_BITMAP == propertyKey) {
view.setAvatarBitmap(model.get(AVATAR_BITMAP));
} else if (TITLE == propertyKey) {
view.setTitle(model.get(TITLE)); view.setTitle(model.get(TITLE));
} else if (DESCRIPTION == propertyKey) { } else if (DESCRIPTION == propertyKey) {
view.setDescription(model.get(DESCRIPTION)); view.setDescription(model.get(DESCRIPTION));
} else if (POST_FREQUENCY == propertyKey) {
view.setPostFrequency(model.get(POST_FREQUENCY));
} else if (IS_DIALOG_VISIBLE == propertyKey) { } else if (IS_DIALOG_VISIBLE == propertyKey) {
view.setVisibility(model.get(IS_DIALOG_VISIBLE)); view.setVisibility(model.get(IS_DIALOG_VISIBLE));
} }
......
...@@ -4,14 +4,25 @@ ...@@ -4,14 +4,25 @@
package org.chromium.chrome.browser.profile_card; package org.chromium.chrome.browser.profile_card;
import android.graphics.Bitmap;
/** Defines the profile card data. */ /** Defines the profile card data. */
public class ProfileCardData { public class ProfileCardData {
private Bitmap mAvatarBitmap;
private String mTitle; private String mTitle;
private String mDescription; private String mDescription;
private String mPostFrequency;
public ProfileCardData(String title, String description) { public ProfileCardData(
Bitmap avatarBitmap, String title, String description, String postFrequency) {
mAvatarBitmap = avatarBitmap;
mTitle = title; mTitle = title;
mDescription = description; mDescription = description;
mPostFrequency = postFrequency;
}
public Bitmap getAvatarBitmap() {
return mAvatarBitmap;
} }
public String getTitle() { public String getTitle() {
...@@ -21,4 +32,8 @@ public class ProfileCardData { ...@@ -21,4 +32,8 @@ public class ProfileCardData {
public String getDescription() { public String getDescription() {
return mDescription; return mDescription;
} }
public String getPostFrequency() {
return mPostFrequency;
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment