Commit 7d58b105 authored by Lucio Maciel's avatar Lucio Maciel Committed by GitHub

Merge pull request #377 from filipedelimabrito/avatar-with-username-initials

Remove user not found handling.
parents 8ac51b53 d6b188cc
...@@ -13,7 +13,6 @@ import chat.rocket.core.SyncState; ...@@ -13,7 +13,6 @@ import chat.rocket.core.SyncState;
public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMessage> { public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMessage> {
protected final RocketChatAvatar avatar; protected final RocketChatAvatar avatar;
protected final ImageView userNotFoundAvatarImageView;
protected final ImageView errorImageView; protected final ImageView errorImageView;
protected final TextView username; protected final TextView username;
protected final TextView subUsername; protected final TextView subUsername;
...@@ -30,7 +29,6 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe ...@@ -30,7 +29,6 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe
public AbstractMessageViewHolder(View itemView, AbsoluteUrl absoluteUrl, String hostname) { public AbstractMessageViewHolder(View itemView, AbsoluteUrl absoluteUrl, String hostname) {
super(itemView); super(itemView);
avatar = itemView.findViewById(R.id.user_avatar); avatar = itemView.findViewById(R.id.user_avatar);
userNotFoundAvatarImageView = itemView.findViewById(R.id.userNotFoundAvatarImageView);
errorImageView = itemView.findViewById(R.id.errorImageView); errorImageView = itemView.findViewById(R.id.errorImageView);
username = itemView.findViewById(R.id.username); username = itemView.findViewById(R.id.username);
subUsername = itemView.findViewById(R.id.sub_username); subUsername = itemView.findViewById(R.id.sub_username);
......
...@@ -29,7 +29,7 @@ public class MessageNormalViewHolder extends AbstractMessageViewHolder { ...@@ -29,7 +29,7 @@ public class MessageNormalViewHolder extends AbstractMessageViewHolder {
@Override @Override
protected void bindMessage(PairedMessage pairedMessage, boolean autoloadImages) { protected void bindMessage(PairedMessage pairedMessage, boolean autoloadImages) {
MessageRenderer messageRenderer = new MessageRenderer(pairedMessage.target, autoloadImages); MessageRenderer messageRenderer = new MessageRenderer(pairedMessage.target, autoloadImages);
messageRenderer.showAvatar(avatar, hostname, userNotFoundAvatarImageView); messageRenderer.showAvatar(avatar, hostname);
messageRenderer.showUsername(username, subUsername); messageRenderer.showUsername(username, subUsername);
messageRenderer.showTimestampOrMessageState(timestamp); messageRenderer.showTimestampOrMessageState(timestamp);
messageRenderer.showBody(body); messageRenderer.showBody(body);
......
...@@ -24,7 +24,7 @@ public class MessageSystemViewHolder extends AbstractMessageViewHolder { ...@@ -24,7 +24,7 @@ public class MessageSystemViewHolder extends AbstractMessageViewHolder {
@Override @Override
protected void bindMessage(PairedMessage pairedMessage, boolean autoloadImages) { protected void bindMessage(PairedMessage pairedMessage, boolean autoloadImages) {
MessageRenderer messageRenderer = new MessageRenderer(pairedMessage.target, autoloadImages); MessageRenderer messageRenderer = new MessageRenderer(pairedMessage.target, autoloadImages);
messageRenderer.showAvatar(avatar, hostname, userNotFoundAvatarImageView); messageRenderer.showAvatar(avatar, hostname);
messageRenderer.showUsername(username, subUsername); messageRenderer.showUsername(username, subUsername);
messageRenderer.showTimestampOrMessageState(timestamp); messageRenderer.showTimestampOrMessageState(timestamp);
if (pairedMessage.target != null) { if (pairedMessage.target != null) {
......
package chat.rocket.android.renderer package chat.rocket.android.renderer
import android.view.View import android.view.View
import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.helper.DateTime import chat.rocket.android.helper.DateTime
...@@ -19,10 +18,9 @@ class MessageRenderer(val message: Message, val autoLoadImage: Boolean) { ...@@ -19,10 +18,9 @@ class MessageRenderer(val message: Message, val autoLoadImage: Boolean) {
/** /**
* Show user's avatar image in RocketChatAvatar widget. * Show user's avatar image in RocketChatAvatar widget.
*/ */
fun showAvatar(rocketChatAvatarWidget: RocketChatAvatar, hostname: String, userNotFoundAvatarImageView: ImageView) { fun showAvatar(rocketChatAvatarWidget: RocketChatAvatar, hostname: String) {
val username: String? = message.user?.username val username: String? = message.user?.username
if (username != null) { if (username != null) {
userNotFoundAvatarImageView.visibility = View.GONE
val placeholderDrawable = UserAvatarHelper.getTextDrawable(username, rocketChatAvatarWidget.context) val placeholderDrawable = UserAvatarHelper.getTextDrawable(username, rocketChatAvatarWidget.context)
if (message.avatar != null) { if (message.avatar != null) {
// Load user's avatar image from Oauth provider URI. // Load user's avatar image from Oauth provider URI.
...@@ -32,7 +30,6 @@ class MessageRenderer(val message: Message, val autoLoadImage: Boolean) { ...@@ -32,7 +30,6 @@ class MessageRenderer(val message: Message, val autoLoadImage: Boolean) {
} }
} else { } else {
rocketChatAvatarWidget.visibility = View.GONE rocketChatAvatarWidget.visibility = View.GONE
userNotFoundAvatarImageView.visibility = View.VISIBLE
} }
} }
...@@ -40,14 +37,16 @@ class MessageRenderer(val message: Message, val autoLoadImage: Boolean) { ...@@ -40,14 +37,16 @@ class MessageRenderer(val message: Message, val autoLoadImage: Boolean) {
* Show username in textView. * Show username in textView.
*/ */
fun showUsername(usernameTextView: TextView, subUsernameTextView: TextView?) { fun showUsername(usernameTextView: TextView, subUsernameTextView: TextView?) {
if (message.alias == null) { val username: String? = message.user?.username
usernameTextView.text = message.user?.username ?: usernameTextView.context.getText(R.string.user_not_found) if (username != null) {
} else { if (message.alias == null) {
usernameTextView.text = message.alias usernameTextView.text = username
val username: String? = message.user?.username } else {
if (username != null && subUsernameTextView != null) { usernameTextView.text = message.alias
subUsernameTextView.text = subUsernameTextView.context.getString(R.string.sub_username, username) if (subUsernameTextView != null) {
subUsernameTextView.visibility = View.VISIBLE subUsernameTextView.text = subUsernameTextView.context.getString(R.string.sub_username, username)
subUsernameTextView.visibility = View.VISIBLE
}
} }
} }
} }
......
...@@ -3,7 +3,6 @@ package chat.rocket.android.renderer ...@@ -3,7 +3,6 @@ package chat.rocket.android.renderer
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import chat.rocket.android.R
import chat.rocket.android.widget.RocketChatAvatar import chat.rocket.android.widget.RocketChatAvatar
import chat.rocket.android.widget.helper.UserAvatarHelper import chat.rocket.android.widget.helper.UserAvatarHelper
import chat.rocket.core.models.User import chat.rocket.core.models.User
...@@ -26,7 +25,10 @@ class UserRenderer(val user: User) { ...@@ -26,7 +25,10 @@ class UserRenderer(val user: User) {
* Show username in textView. * Show username in textView.
*/ */
fun showUsername(textView: TextView) { fun showUsername(textView: TextView) {
textView.text = user.username ?: textView.context.getText(R.string.user_not_found) val username: String? = user.username
if (username != null) {
textView.text = username
}
} }
/** /**
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M-0,0L24,0L24,24L-0,24L-0,0ZM11.963,17.661L12.036,17.661L17.162,17.661C17.162,13.975 13.979,13.915 13.178,12.982L13.082,12.474C14.095,11.946 14.807,10.699 14.807,9.245C14.807,7.313 13.55,5.746 12,5.746C10.45,5.746 9.193,7.313 9.193,9.245C9.193,10.712 9.917,11.966 10.944,12.486L10.86,12.933C10.129,13.913 6.837,13.912 6.837,17.661L11.963,17.661Z"
android:fillColor="#FF000000"/>
</vector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:theme="@style/AppTheme">
<include layout="@layout/list_item_message_newday" />
<FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="2dp"> android:orientation="vertical"
android:theme="@style/AppTheme">
<chat.rocket.android.widget.RocketChatAvatar
android:id="@+id/user_avatar"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="8dp" />
<ImageView <include layout="@layout/list_item_message_newday" />
android:id="@+id/userNotFoundAvatarImageView"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="8dp"
app:srcCompat="@drawable/ic_user_not_found_avatar_black_24dp"
android:visibility="gone" />
<LinearLayout <FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="48dp"
android:orientation="vertical"
android:layout_marginRight="8dp"
android:layout_marginLeft="48dp">
<LinearLayout
android:id="@+id/user_and_timestamp_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:layout_marginBottom="2dp">
<TextView <chat.rocket.android.widget.RocketChatAvatar
android:id="@+id/username" android:id="@+id/user_avatar"
android:layout_width="wrap_content" android:layout_width="32dp"
android:layout_height="wrap_content" android:layout_height="32dp"
android:textAppearance="@style/TextAppearance.RocketChat.Message.Username" android:layout_margin="8dp" />
tools:text="John Doe" />
<LinearLayout
<Space android:layout_width="match_parent"
android:layout_width="4dp" android:layout_height="wrap_content"
android:layout_height="wrap_content" /> android:layout_marginEnd="8dp"
android:layout_marginStart="48dp"
<TextView android:orientation="vertical"
android:id="@+id/sub_username" android:layout_marginRight="8dp"
android:layout_width="wrap_content" android:layout_marginLeft="48dp">
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.RocketChat.Message.SubUsername" <LinearLayout
tools:text="\@John Doe" android:id="@+id/user_and_timestamp_container"
android:visibility="gone" /> android:layout_width="match_parent"
android:layout_height="wrap_content"
<Space android:orientation="horizontal">
android:layout_width="@dimen/margin_8"
android:layout_height="wrap_content" /> <TextView
android:id="@+id/username"
<TextView android:layout_width="wrap_content"
android:id="@+id/timestamp" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:textAppearance="@style/TextAppearance.RocketChat.Message.Username"
android:layout_height="wrap_content" tools:text="John Doe" />
android:enabled="false"
tools:text="12:34" /> <Space
android:layout_width="4dp"
<View android:layout_height="wrap_content" />
android:layout_width="0dp"
android:layout_height="0dp" <TextView
android:layout_weight="1" /> android:id="@+id/sub_username"
android:layout_width="wrap_content"
<ImageView android:layout_height="wrap_content"
android:id="@+id/errorImageView" android:textAppearance="@style/TextAppearance.RocketChat.Message.SubUsername"
android:layout_width="wrap_content" tools:text="\@John Doe"
android:layout_height="16dp" android:visibility="gone" />
android:layout_gravity="end"
android:gravity="end" <Space
android:tint="@color/colorRed400" android:layout_width="@dimen/margin_8"
app:srcCompat="@drawable/ic_error_black_24dp" android:layout_height="wrap_content" />
android:visibility="gone" />
</LinearLayout> <TextView
android:id="@+id/timestamp"
<chat.rocket.android.widget.message.RocketChatMessageLayout android:layout_width="wrap_content"
android:id="@+id/message_body" android:layout_height="wrap_content"
android:layout_width="match_parent" android:enabled="false"
android:layout_height="wrap_content" /> tools:text="12:34" />
<chat.rocket.android.widget.message.RocketChatMessageUrlsLayout <View
android:id="@+id/message_urls" android:layout_width="0dp"
android:layout_width="match_parent" android:layout_height="0dp"
android:layout_height="wrap_content" /> android:layout_weight="1" />
<chat.rocket.android.widget.message.RocketChatMessageAttachmentsLayout <ImageView
android:id="@+id/message_attachments" android:id="@+id/errorImageView"
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="16dp"
</LinearLayout> android:layout_gravity="end"
</FrameLayout> android:gravity="end"
android:tint="@color/colorRed400"
app:srcCompat="@drawable/ic_error_black_24dp"
android:visibility="gone" />
</LinearLayout>
<chat.rocket.android.widget.message.RocketChatMessageLayout
android:id="@+id/message_body"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<chat.rocket.android.widget.message.RocketChatMessageUrlsLayout
android:id="@+id/message_urls"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<chat.rocket.android.widget.message.RocketChatMessageAttachmentsLayout
android:id="@+id/message_attachments"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
</LinearLayout> </LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:theme="@style/AppTheme">
<include layout="@layout/list_item_message_newday" />
<FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:orientation="vertical"
android:theme="@style/AppTheme">
<include layout="@layout/list_item_message_newday" />
<chat.rocket.android.widget.RocketChatAvatar <FrameLayout
android:id="@+id/user_avatar" android:layout_width="match_parent"
android:layout_width="32dp" android:layout_height="wrap_content">
android:layout_height="32dp"
android:layout_margin="8dp" />
<ImageView <chat.rocket.android.widget.RocketChatAvatar
android:id="@+id/userNotFoundAvatarImageView" android:id="@+id/user_avatar"
android:layout_width="32dp" android:layout_width="32dp"
android:layout_height="32dp" android:layout_height="32dp"
android:layout_margin="8dp" android:layout_margin="8dp" />
app:srcCompat="@drawable/ic_user_not_found_avatar_black_24dp"
android:visibility="gone" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:layout_marginStart="48dp" android:layout_marginStart="48dp"
android:orientation="vertical" android:orientation="vertical"
android:layout_marginRight="8dp" android:layout_marginRight="8dp"
android:layout_marginLeft="48dp"> android:layout_marginLeft="48dp">
<LinearLayout <LinearLayout
android:id="@+id/user_and_timestamp_container" android:id="@+id/user_and_timestamp_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView <TextView
android:id="@+id/username" android:id="@+id/username"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.RocketChat.Message.Username" android:textAppearance="@style/TextAppearance.RocketChat.Message.Username"
tools:text="John Doe" /> tools:text="John Doe" />
<Space <Space
android:layout_width="@dimen/margin_8" android:layout_width="@dimen/margin_8"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<TextView <TextView
android:id="@+id/timestamp" android:id="@+id/timestamp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:enabled="false" android:enabled="false"
tools:text="12:34" /> tools:text="12:34" />
<View <View
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" /> android:layout_weight="1" />
<ImageView <ImageView
android:id="@+id/errorImageView" android:id="@+id/errorImageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="16dp" android:layout_height="16dp"
android:layout_gravity="end" android:layout_gravity="end"
android:gravity="end" android:gravity="end"
android:tint="@color/colorRed400" android:tint="@color/colorRed400"
app:srcCompat="@drawable/ic_error_black_24dp" app:srcCompat="@drawable/ic_error_black_24dp"
android:visibility="gone" /> android:visibility="gone" />
</LinearLayout> </LinearLayout>
<TextView <TextView
android:id="@+id/message_body" android:id="@+id/message_body"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textStyle="italic" android:textStyle="italic"
android:enabled="false" /> android:enabled="false" />
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>
\ No newline at end of file
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
<string name="dialog_user_registration_email">Email</string> <string name="dialog_user_registration_email">Email</string>
<string name="dialog_user_registration_username">Username</string> <string name="dialog_user_registration_username">Username</string>
<string name="sub_username">\@%s</string> <string name="sub_username">\@%s</string>
<string name="user_not_found">User not found</string>
<string name="dialog_user_registration_password">Password</string> <string name="dialog_user_registration_password">Password</string>
<string name="fragment_home_welcome_message">Welcome to Rocket.Chat.Android\nSelect a channel from the drawer.</string> <string name="fragment_home_welcome_message">Welcome to Rocket.Chat.Android\nSelect a channel from the drawer.</string>
<string name="fragment_input_hostname_hostname">Hostname</string> <string name="fragment_input_hostname_hostname">Hostname</string>
......
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