Commit befbfb25 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Rename UserAvatarHelper to AvatarHelper since it's also being used for the server avatar

parent ac4f99d5
......@@ -24,7 +24,7 @@ import chat.rocket.android.fragment.sidebar.SidebarMainFragment;
import chat.rocket.android.helper.KeyboardHelper;
import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.android.widget.RoomToolbar;
import chat.rocket.android.widget.helper.UserAvatarHelper;
import chat.rocket.android.widget.helper.AvatarHelper;
import chat.rocket.core.interactors.CanCreateRoomInteractor;
import chat.rocket.core.interactors.RoomInteractor;
import chat.rocket.core.interactors.SessionInteractor;
......@@ -190,7 +190,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
serverButton.setOnClickListener(view -> changeServerIfNeeded(serverHostname));
Drawable drawable = UserAvatarHelper.INSTANCE.getTextDrawable(serverHostname,this);
Drawable drawable = AvatarHelper.INSTANCE.getTextDrawable(serverHostname,this);
serverButton.getHierarchy().setPlaceholderImage(drawable);
serverButton.setController(Fresco.newDraweeControllerBuilder().setAutoPlayAnimations(true).build());
......
......@@ -6,7 +6,7 @@ import chat.rocket.android.R
import chat.rocket.android.helper.DateTime
import chat.rocket.android.widget.AbsoluteUrl
import chat.rocket.android.widget.RocketChatAvatar
import chat.rocket.android.widget.helper.UserAvatarHelper
import chat.rocket.android.widget.helper.AvatarHelper
import chat.rocket.android.widget.message.RocketChatMessageAttachmentsLayout
import chat.rocket.android.widget.message.RocketChatMessageLayout
import chat.rocket.android.widget.message.RocketChatMessageUrlsLayout
......@@ -21,12 +21,12 @@ class MessageRenderer(val message: Message, val autoLoadImage: Boolean) {
fun showAvatar(rocketChatAvatarWidget: RocketChatAvatar, hostname: String) {
val username: String? = message.user?.username
if (username != null) {
val placeholderDrawable = UserAvatarHelper.getTextDrawable(username, rocketChatAvatarWidget.context)
val placeholderDrawable = AvatarHelper.getTextDrawable(username, rocketChatAvatarWidget.context)
if (message.avatar != null) {
// Load user's avatar image from Oauth provider URI.
rocketChatAvatarWidget.loadImage(message.avatar, placeholderDrawable)
} else {
rocketChatAvatarWidget.loadImage(UserAvatarHelper.getUri(hostname, username), placeholderDrawable)
rocketChatAvatarWidget.loadImage(AvatarHelper.getUri(hostname, username), placeholderDrawable)
}
} else {
rocketChatAvatarWidget.visibility = View.GONE
......
......@@ -4,7 +4,7 @@ import android.view.View
import android.widget.ImageView
import android.widget.TextView
import chat.rocket.android.widget.RocketChatAvatar
import chat.rocket.android.widget.helper.UserAvatarHelper
import chat.rocket.android.widget.helper.AvatarHelper
import chat.rocket.core.models.User
class UserRenderer(val user: User) {
......@@ -15,7 +15,7 @@ class UserRenderer(val user: User) {
fun showAvatar(rocketChatAvatarWidget: RocketChatAvatar, hostname: String) {
val username: String? = user.username
if (username != null) {
rocketChatAvatarWidget.loadImage(UserAvatarHelper.getUri(hostname, username), UserAvatarHelper.getTextDrawable(username, rocketChatAvatarWidget.context))
rocketChatAvatarWidget.loadImage(AvatarHelper.getUri(hostname, username), AvatarHelper.getTextDrawable(username, rocketChatAvatarWidget.context))
} else {
rocketChatAvatarWidget.visibility = View.GONE
}
......
......@@ -7,7 +7,7 @@ import chat.rocket.android.widget.AbsoluteUrl
import com.amulyakhare.textdrawable.TextDrawable
import java.net.URLEncoder
object UserAvatarHelper {
object AvatarHelper {
/**
* Returns the user avatar URI.
......
......@@ -4,13 +4,11 @@ import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import chat.rocket.android.widget.AbsoluteUrl;
import chat.rocket.android.widget.R;
import chat.rocket.android.widget.RocketChatAvatar;
import chat.rocket.android.widget.helper.UserAvatarHelper;
import chat.rocket.android.widget.helper.AvatarHelper;
import chat.rocket.android.widget.message.autocomplete.AutocompleteViewHolder;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class UserViewHolder extends AutocompleteViewHolder<UserItem> {
private final TextView titleTextView;
......@@ -45,8 +43,8 @@ public class UserViewHolder extends AutocompleteViewHolder<UserItem> {
}
if (avatar != null) {
String absoluteUri = UserAvatarHelper.INSTANCE.getAbsoluteUri(userItem.getAbsoluteUrl(), suggestion);
Drawable placeholderDrawable = UserAvatarHelper.INSTANCE.getTextDrawable(suggestion, itemView.getContext());
String absoluteUri = AvatarHelper.INSTANCE.getAbsoluteUri(userItem.getAbsoluteUrl(), suggestion);
Drawable placeholderDrawable = AvatarHelper.INSTANCE.getTextDrawable(suggestion, itemView.getContext());
avatar.loadImage(absoluteUri, placeholderDrawable);
}
......
import chat.rocket.android.widget.helper.AvatarHelper
import org.junit.Test
import kotlin.test.assertEquals
class AvatarHelperTest {
@Test
fun getUsernameInitialsTest() {
assertEquals("?", AvatarHelper.getUsernameInitials(""))
assertEquals("?", AvatarHelper.getUsernameInitials("?"))
assertEquals("F", AvatarHelper.getUsernameInitials("f"))
assertEquals("B", AvatarHelper.getUsernameInitials("B"))
assertEquals("FO", AvatarHelper.getUsernameInitials("Fo"))
assertEquals("FO", AvatarHelper.getUsernameInitials("FO"))
assertEquals("FO", AvatarHelper.getUsernameInitials("fOo"))
assertEquals("FO", AvatarHelper.getUsernameInitials("FOO"))
assertEquals("FO", AvatarHelper.getUsernameInitials("F.O"))
assertEquals("FO", AvatarHelper.getUsernameInitials("F.o"))
assertEquals("FB", AvatarHelper.getUsernameInitials("Foo.bar"))
assertEquals("FB", AvatarHelper.getUsernameInitials("Foobar.bar"))
assertEquals("FZ", AvatarHelper.getUsernameInitials("Foobar.bar.zab"))
assertEquals("..", AvatarHelper.getUsernameInitials(".."))
assertEquals("..", AvatarHelper.getUsernameInitials("..."))
assertEquals(".F", AvatarHelper.getUsernameInitials(".Foo."))
assertEquals("FO", AvatarHelper.getUsernameInitials("Foo.."))
}
}
\ No newline at end of file
import chat.rocket.android.widget.helper.UserAvatarHelper
import org.junit.Test
import kotlin.test.assertEquals
class UserAvatarHelperTest {
@Test
fun getUsernameInitialsTest() {
assertEquals("?", UserAvatarHelper.getUsernameInitials(""))
assertEquals("?", UserAvatarHelper.getUsernameInitials("?"))
assertEquals("F", UserAvatarHelper.getUsernameInitials("f"))
assertEquals("B", UserAvatarHelper.getUsernameInitials("B"))
assertEquals("FO", UserAvatarHelper.getUsernameInitials("Fo"))
assertEquals("FO", UserAvatarHelper.getUsernameInitials("FO"))
assertEquals("FO", UserAvatarHelper.getUsernameInitials("fOo"))
assertEquals("FO", UserAvatarHelper.getUsernameInitials("FOO"))
assertEquals("FO", UserAvatarHelper.getUsernameInitials("F.O"))
assertEquals("FO", UserAvatarHelper.getUsernameInitials("F.o"))
assertEquals("FB", UserAvatarHelper.getUsernameInitials("Foo.bar"))
assertEquals("FB", UserAvatarHelper.getUsernameInitials("Foobar.bar"))
assertEquals("FZ", UserAvatarHelper.getUsernameInitials("Foobar.bar.zab"))
assertEquals("..", UserAvatarHelper.getUsernameInitials(".."))
assertEquals("..", UserAvatarHelper.getUsernameInitials("..."))
assertEquals(".F", UserAvatarHelper.getUsernameInitials(".Foo."))
assertEquals("FO", UserAvatarHelper.getUsernameInitials("Foo.."))
}
}
\ No newline at end of file
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