Commit 4bfa9448 authored by Tiago Cunha's avatar Tiago Cunha

PR feedback

parent 8088bf55
......@@ -30,16 +30,10 @@ public class Avatar {
};
private final String hostname;
private final String username;
private final String avatarUrl;
public Avatar(String hostname, String username) {
this(hostname, username, null);
}
public Avatar(String hostname, String username, String avatarUrl) {
this.hostname = hostname;
this.username = username;
this.avatarUrl = avatarUrl;
}
private static int getColorForUser(String username) {
......@@ -82,15 +76,11 @@ public class Avatar {
private String getImageUrl() {
//from Rocket.Chat:packages/rocketchat-ui/lib/avatar.coffee
//REMARK! this is often SVG image! (see: Rocket.Chat:server/startup/avatar.coffee)
if (TextUtils.isEmpty(avatarUrl)) {
try {
return "https://" + hostname + "/avatar/" + URLEncoder.encode(username, "UTF-8") + ".jpg";
} catch (UnsupportedEncodingException exception) {
RCLog.e(exception, "failed to get URL for user: %s", username);
return null;
}
} else {
return avatarUrl;
try {
return "https://" + hostname + "/avatar/" + URLEncoder.encode(username, "UTF-8") + ".jpg";
} catch (UnsupportedEncodingException exception) {
RCLog.e(exception, "failed to get URL for user: %s", username);
return null;
}
}
......@@ -109,7 +99,7 @@ public class Avatar {
.into(imageView);
}
private Drawable getTextDrawable(Context context) {
public Drawable getTextDrawable(Context context) {
if (username == null) {
return null;
}
......
package chat.rocket.android.renderer;
import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import chat.rocket.android.R;
import chat.rocket.android.helper.Avatar;
import chat.rocket.android.helper.DateTime;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.SyncState;
import chat.rocket.android.model.ddp.Message;
import chat.rocket.android.model.ddp.User;
import chat.rocket.android.widget.message.RocketChatMessageAttachmentsLayout;
import chat.rocket.android.widget.message.RocketChatMessageLayout;
import chat.rocket.android.widget.message.RocketChatMessageUrlsLayout;
......@@ -30,13 +38,14 @@ public class MessageRenderer extends AbstractRenderer<Message> {
* show Avatar image.
*/
public MessageRenderer avatarInto(ImageView imageView, String hostname) {
switch (object.getSyncState()) {
case SyncState.FAILED:
imageView.setImageResource(R.drawable.ic_error_outline_black_24dp);
break;
default:
userRenderer.avatarInto(imageView, hostname, object.getAvatar());
break;
if (object.getSyncState() == SyncState.FAILED) {
imageView.setImageResource(R.drawable.ic_error_outline_black_24dp);
} else if (TextUtils.isEmpty(object.getAvatar())) {
userRenderer.avatarInto(imageView, hostname);
} else {
final User user = object.getUser();
setAvatarInto(object.getAvatar(), hostname, user == null ? null : user.getUsername(),
imageView);
}
return this;
}
......@@ -45,7 +54,12 @@ public class MessageRenderer extends AbstractRenderer<Message> {
* show Username in textView.
*/
public MessageRenderer usernameInto(TextView textView) {
userRenderer.usernameInto(textView, object.getAlias());
if (TextUtils.isEmpty(object.getAlias())) {
userRenderer.usernameInto(textView);
} else {
final User user = object.getUser();
setAliasInto(object.getAlias(), user == null ? null : user.getUsername(), textView);
}
return this;
}
......@@ -124,4 +138,29 @@ public class MessageRenderer extends AbstractRenderer<Message> {
return this;
}
private void setAvatarInto(String avatar, String hostname, String username, ImageView imageView) {
Picasso.with(context)
.load(avatar)
.placeholder(
new Avatar(hostname, username).getTextDrawable(context))
.into(imageView);
}
private void setAliasInto(String alias, String username, TextView textView) {
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.BLACK);
spannableStringBuilder.append(alias);
if (username != null) {
spannableStringBuilder.append(" @");
spannableStringBuilder.append(username);
}
spannableStringBuilder
.setSpan(foregroundColorSpan, 0, alias.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
textView.setText(spannableStringBuilder);
}
}
......@@ -23,37 +23,23 @@ public class UserRenderer extends AbstractRenderer<User> {
}
/**
* show Avatar image.
* show Avatar image
*/
public UserRenderer avatarInto(ImageView imageView, String hostname) {
return avatarInto(imageView, hostname, null);
}
/**
* show Avatar image - overriding the user default.
*/
public UserRenderer avatarInto(ImageView imageView, String hostname, String avatar) {
if (!shouldHandle(imageView)) {
return this;
}
if (!TextUtils.isEmpty(object.getUsername()) || !TextUtils.isEmpty(avatar)) {
new Avatar(hostname, object.getUsername(), avatar).into(imageView);
if (!TextUtils.isEmpty(object.getUsername())) {
new Avatar(hostname, object.getUsername()).into(imageView);
}
return this;
}
/**
* show Username in textView.
* show Username in textView
*/
public UserRenderer usernameInto(TextView textView) {
return usernameInto(textView, null);
}
/**
* show Username in textView - adding the alias first.
*/
public UserRenderer usernameInto(TextView textView, String alias) {
if (!shouldHandle(textView)) {
return this;
}
......@@ -61,17 +47,9 @@ public class UserRenderer extends AbstractRenderer<User> {
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.BLACK);
if (TextUtils.isEmpty(alias)) {
spannableStringBuilder.append(object.getUsername());
spannableStringBuilder.setSpan(foregroundColorSpan, 0, object.getUsername().length(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
} else {
spannableStringBuilder.append(alias);
spannableStringBuilder.append(" @");
spannableStringBuilder.append(object.getUsername());
spannableStringBuilder
.setSpan(foregroundColorSpan, 0, alias.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
}
spannableStringBuilder.append(object.getUsername());
spannableStringBuilder.setSpan(foregroundColorSpan, 0, object.getUsername().length(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
textView.setText(spannableStringBuilder);
......
......@@ -9,8 +9,7 @@
android:id="@+id/field_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="@android:color/black"
android:textAppearance="@style/TextAppearance.RocketChat.MessageAttachment.Field.Title"
tools:text="Test" />
<TextView
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TextAppearance.RocketChat" parent="TextAppearance.AppCompat"/>
<style name="TextAppearance.RocketChat" parent="TextAppearance.AppCompat" />
<style name="TextAppearance.RocketChat.MessageBody" parent="TextAppearance.AppCompat.Body1">
......@@ -13,13 +13,13 @@
<item name="android:textStyle">bold</item>
</style>
<style name="TextAppearance.RocketChat.MessageAttachment" parent="TextAppearance.AppCompat.Body1"/>
<style name="TextAppearance.RocketChat.MessageAttachment" parent="TextAppearance.AppCompat.Body1" />
<style name="TextAppearance.RocketChat.MessageAttachment.Title" parent="TextAppearance.AppCompat.Title">
<item name="android:textSize">14sp</item>
</style>
<style name="TextAppearance.RocketChat.MessageAttachment.Title.Link" parent="TextAppearance.RocketChat.MessageAttachment.Title">
<style name="TextAppearance.RocketChat.MessageAttachment.Title.Link">
<item name="android:textColor">?android:attr/textColorLink</item>
</style>
......@@ -27,11 +27,15 @@
<item name="android:textSize">12sp</item>
</style>
<style name="TextAppearance.RocketChat.MessageAttachment.Hostname"
parent="TextAppearance.AppCompat.Caption">
<style name="TextAppearance.RocketChat.MessageAttachment.Hostname" parent="TextAppearance.AppCompat.Caption">
<item name="android:textSize">8sp</item>
</style>
<style name="TextAppearance.RocketChat.MessageAttachment.Field.Title" parent="TextAppearance.AppCompat.Body1">
<item name="android:textStyle">bold</item>
<item name="android:textColor">@android:color/black</item>
</style>
<color name="highlight_text_color">#333</color>
<color name="highlight_text_background_color">#f8f8f8</color>
<color name="highlight_text_border_color">#ccc</color>
......
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