added avatar replacement image if user has no avatar in comments too

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@94799 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2014-04-13 10:07:10 +00:00
parent 1ebc89d0b4
commit 636c93a72a
7 changed files with 136 additions and 19 deletions

View File

@ -102,11 +102,6 @@ public class NewsFeedPanel extends Composite {
private static final String warning = GWT.getModuleBaseURL() + "../images/warning_blue.png"; private static final String warning = GWT.getModuleBaseURL() + "../images/warning_blue.png";
private static final String spacer = GWT.getModuleBaseURL() + "../images/feeds-spacer.gif"; private static final String spacer = GWT.getModuleBaseURL() + "../images/feeds-spacer.gif";
public static final String loading = GWT.getModuleBaseURL() + "../images/feeds-loader.gif"; public static final String loading = GWT.getModuleBaseURL() + "../images/feeds-loader.gif";
/**
* since we want to maintain the color assigned to an avatar replacement through all the session
* this hashmap maintain the assigned users color, chosen reandomly at the beginning
*/
public static final HashMap<String, String> avatarReplacementAssignedColors = new HashMap<String, String>();
public static final String GET_OID_PARAMETER = "oid"; public static final String GET_OID_PARAMETER = "oid";
@ -837,9 +832,10 @@ public class NewsFeedPanel extends Composite {
@Override @Override
public void onSuccess(Comment result) { public void onSuccess(Comment result) {
if (result != null) { if (result != null) {
owner.addComment(new SingleComment(result, owner, (result.getUserid().equals(myUserInfo.getUsername())) )); owner.addComment(new SingleComment(result, owner, (result.getUserid().equals(myUserInfo.getUsername()))), false);
owner.setCommentingDisabled(false); owner.setCommentingDisabled(false);
owner.updateCommentsNumberCount(); owner.updateCommentsNumberCount();
owner.showAddCommentForm(false);
} }
else { else {
Window.alert("Could not deliver this comment. Please try again in a short while."); Window.alert("Could not deliver this comment. Please try again in a short while.");
@ -858,7 +854,7 @@ public class NewsFeedPanel extends Composite {
@Override @Override
public void onSuccess(Comment result) { public void onSuccess(Comment result) {
if (result != null) { if (result != null) {
owner.addComment(new SingleComment(result, owner, (result.getUserid().equals(myUserInfo.getUsername())) )); owner.addComment(new SingleComment(result, owner, (result.getUserid().equals(myUserInfo.getUsername()))), true);
owner.setCommentingDisabled(false); owner.setCommentingDisabled(false);
} }
else { else {
@ -883,7 +879,7 @@ public class NewsFeedPanel extends Composite {
public void onSuccess(ArrayList<Comment> comments) { public void onSuccess(ArrayList<Comment> comments) {
owner.clearComments(); owner.clearComments();
for (Comment comment :comments) for (Comment comment :comments)
owner.addComment(new SingleComment(comment, owner,(comment.getUserid().equals(myUserInfo.getUsername())) )); owner.addComment(new SingleComment(comment, owner,(comment.getUserid().equals(myUserInfo.getUsername())) ), false);
owner.setCommentsFetched(true); owner.setCommentsFetched(true);
if (commentForm2Add) if (commentForm2Add)
owner.showAddCommentForm(false); owner.showAddCommentForm(false);

View File

@ -1,5 +1,7 @@
package org.gcube.portlets.user.newsfeed.client.ui; package org.gcube.portlets.user.newsfeed.client.ui;
import java.util.HashMap;
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel; import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
@ -12,8 +14,13 @@ import com.google.gwt.user.client.ui.Widget;
public class AvatarReplacement extends Composite { public class AvatarReplacement extends Composite {
private static NoAvatarUiBinder uiBinder = GWT private static NoAvatarUiBinder uiBinder = GWT.create(NoAvatarUiBinder.class);
.create(NoAvatarUiBinder.class);
/**
* to maintain the color assigned to an avatar replacement, for each page load
* this hashmap maintain the assigned users color, chosen reandomly at the beginning
*/
public static final HashMap<String, String> avatarReplacementAssignedColors = new HashMap<String, String>();
interface NoAvatarUiBinder extends UiBinder<Widget, AvatarReplacement> { interface NoAvatarUiBinder extends UiBinder<Widget, AvatarReplacement> {
} }
@ -55,12 +62,12 @@ public class AvatarReplacement extends Composite {
* @param username * @param username
*/ */
private void pickRandomColor(String username) { private void pickRandomColor(String username) {
if (! NewsFeedPanel.avatarReplacementAssignedColors.containsKey(username)) { if (! avatarReplacementAssignedColors.containsKey(username)) {
String randomColor = randomColors[Random.nextInt(randomColors.length)]; String randomColor = randomColors[Random.nextInt(randomColors.length)];
avatarBox.getElement().getStyle().setBackgroundColor(randomColor); avatarBox.getElement().getStyle().setBackgroundColor(randomColor);
NewsFeedPanel.avatarReplacementAssignedColors.put(username, randomColor); avatarReplacementAssignedColors.put(username, randomColor);
} else } else
avatarBox.getElement().getStyle().setBackgroundColor(NewsFeedPanel.avatarReplacementAssignedColors.get(username)); avatarBox.getElement().getStyle().setBackgroundColor(avatarReplacementAssignedColors.get(username));
} }

View File

@ -0,0 +1,68 @@
package org.gcube.portlets.user.newsfeed.client.ui;
import java.util.HashMap;
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
public class AvatarReplacement4Comments extends Composite {
private static NoAvatarUiBinder uiBinder = GWT.create(NoAvatarUiBinder.class);
interface NoAvatarUiBinder extends UiBinder<Widget, AvatarReplacement4Comments> {
}
@UiField HTML avatarBox;
/**
* the random colors
*/
private String[] randomColors = {
"#8e8e93",
"#ff2d55",
"#ff3b30",
"#ff9500",
"#ffcc00",
"#4cd964",
"#5ac8fa",
"#34aadc",
"#007aff",
"#5856d6"
};
public AvatarReplacement4Comments() {
initWidget(uiBinder.createAndBindUi(this));
}
public void setInitials(String username, String firstName, String lastName) {
pickRandomColor(username);
String first = "A";
if (firstName != null && firstName.trim().length() > 0)
first = firstName.trim().substring(0, 1);
String second = "Z";
if (lastName != null && lastName.trim().length() > 0)
second = lastName.trim().substring(0, 1);
avatarBox.setText(first+second);
}
/**
* randomize of does not find it, else color is maintained through all the session
* @param username
*/
private void pickRandomColor(String username) {
if (! AvatarReplacement.avatarReplacementAssignedColors.containsKey(username)) {
String randomColor = randomColors[Random.nextInt(randomColors.length)];
avatarBox.getElement().getStyle().setBackgroundColor(randomColor);
AvatarReplacement.avatarReplacementAssignedColors.put(username, randomColor);
} else
avatarBox.getElement().getStyle().setBackgroundColor(AvatarReplacement.avatarReplacementAssignedColors.get(username));
}
}

View File

@ -0,0 +1,23 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.avatar-frame {
border: 1px solid #E6E6E6;
padding: 2px;
}
.avatar-replacement {
display: table-cell;
text-align: center;
vertical-align: middle;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: 300;
font-size: 12px;
padding: 0;
color: #FFF;
}
</ui:style>
<g:HTMLPanel width="30px" height="30px" styleName="{style.avatar-frame}">
<g:HTML width="30px" height="30px" styleName="{style.avatar-replacement}" ui:field="avatarBox"></g:HTML>
</g:HTMLPanel>
</ui:UiBinder>

View File

@ -4,7 +4,6 @@ import org.gcube.portal.databook.client.GCubeSocialNetworking;
import org.gcube.portal.databook.client.util.Encoder; import org.gcube.portal.databook.client.util.Encoder;
import org.gcube.portal.databook.shared.Comment; import org.gcube.portal.databook.shared.Comment;
import org.gcube.portlets.user.newsfeed.client.event.DeleteCommentEvent; import org.gcube.portlets.user.newsfeed.client.event.DeleteCommentEvent;
import org.gcube.portlets.user.newsfeed.client.panels.NewsFeedPanel;
import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
@ -37,6 +36,7 @@ public class SingleComment extends Composite {
@UiField HTMLPanel mainPanel; @UiField HTMLPanel mainPanel;
@UiField Image avatarImage; @UiField Image avatarImage;
@UiField AvatarReplacement4Comments avatarReplacement;
@UiField HTML commentText; @UiField HTML commentText;
@UiField HTML timeArea; @UiField HTML timeArea;
@UiField HTML closeImage; @UiField HTML closeImage;
@ -53,6 +53,25 @@ public class SingleComment extends Composite {
avatarImage.setPixelSize(30, 30); avatarImage.setPixelSize(30, 30);
avatarImage.setUrl(toShow.getThumbnailURL()); avatarImage.setUrl(toShow.getThumbnailURL());
//check if the user has his own avatar
if (toShow.getThumbnailURL().endsWith("img_id=0") || !toShow.getThumbnailURL().contains("?")) { //it means no avatar is set
avatarImage.setVisible(false);
String f = "A";
String s = "Z";
if (toShow.getFullName() != null) {
String[] parts = toShow.getFullName().split("\\s");
if (parts.length > 0) {
f = parts[0].toUpperCase();
s = parts[parts.length-1].toUpperCase();
} else {
f = toShow.getFullName().substring(0,1);
s = toShow.getFullName().substring(1,2);
}
}
avatarReplacement.setInitials(toShow.getUserid(), f, s);
avatarReplacement.setVisible(true);
}
String commentToShow = toShow.getText(); String commentToShow = toShow.getText();
//replace the < & and > //replace the < & and >

View File

@ -1,6 +1,6 @@
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent"> <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder" <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"> xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:m="urn:import:org.gcube.portlets.user.newsfeed.client.ui">
<ui:style> <ui:style>
.important { .important {
font-weight: bold; font-weight: bold;
@ -12,7 +12,8 @@
<td width="30px;" align="middle"> <td width="30px;" align="middle">
<g:Image styleName="member-photo" url="" ui:field="avatarImage" <g:Image styleName="member-photo" url="" ui:field="avatarImage"
width="30" height="30" /> width="30" height="30" />
<m:AvatarReplacement4Comments visible="false"
ui:field="avatarReplacement"></m:AvatarReplacement4Comments>
</td> </td>
<td width="100%" valign="TOP"> <td width="100%" valign="TOP">
<div class="commentsPanel"> <div class="commentsPanel">

View File

@ -239,7 +239,7 @@ public class TweetTemplate extends Composite {
commentsNo.setTitle("Show all Comments"); commentsNo.setTitle("Show all Comments");
} }
for (Comment comment : myFeed.getComments()) { for (Comment comment : myFeed.getComments()) {
addComment(new SingleComment(comment, this, (comment.getUserid().equals(myUserInfo.getUsername())))); addComment(new SingleComment(comment, this, (comment.getUserid().equals(myUserInfo.getUsername()))), false);
} }
showAddCommentForm(false); showAddCommentForm(false);
} }
@ -442,9 +442,12 @@ public class TweetTemplate extends Composite {
mainHTML.remove(w); mainHTML.remove(w);
} }
public void addComment(SingleComment comment) { public void addComment(SingleComment comment, boolean isEdit) {
if (isEdit)
commentsPanel.insert(comment, commentsPanel.getWidgetCount()-1);
else
commentsPanel.add(comment);
myComments.add(comment); myComments.add(comment);
commentsPanel.add(comment);
} }
public void clearComments() { public void clearComments() {