Commit 66d709c3 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Add hostname attribute/parameter

parent d27a602a
......@@ -188,7 +188,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
protected void onSetupView() {
messageRecyclerView = rootView.findViewById(R.id.messageRecyclerView);
messageListAdapter = new MessageListAdapter(getContext());
messageListAdapter = new MessageListAdapter(getContext(), hostname);
messageRecyclerView.setAdapter(messageListAdapter);
messageListAdapter.setOnItemClickListener(this);
messageListAdapter.setOnItemLongClickListener(this);
......@@ -369,7 +369,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
new DefaultTempSpotlightUserCaller(methodCallHelper)
),
pair.first.get(),
RocketChatUserStatusProvider.getInstance(),
RocketChatUserStatusProvider.INSTANCE,
AndroidSchedulers.from(BackgroundLooper.get()),
AndroidSchedulers.mainThread()
)
......
......@@ -117,7 +117,7 @@ public class UsersOfRoomDialogFragment extends AbstractChatRoomDialogFragment {
RecyclerView recyclerView = (RecyclerView) getDialog().findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
recyclerView.setAdapter(
new RoomUserAdapter(getContext(), realmHelper, rocketChatAbsoluteUrlOptional.get()));
new RoomUserAdapter(getContext(), realmHelper, rocketChatAbsoluteUrlOptional.get(), hostname));
}
private void requestGetUsersOfRoom() {
......
......@@ -224,10 +224,10 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
private void onRenderCurrentUser(User user, RocketChatAbsoluteUrl absoluteUrl) {
if (user != null && absoluteUrl != null) {
new UserRenderer(getContext(), user)
.avatarInto(rootView.findViewById(R.id.current_user_avatar), absoluteUrl)
.usernameInto(rootView.findViewById(R.id.current_user_name))
.statusColorInto(rootView.findViewById(R.id.current_user_status));
UserRenderer userRenderer = new UserRenderer(user);
userRenderer.showAvatar(rootView.findViewById(R.id.current_user_avatar), hostname);
userRenderer.showUsername(rootView.findViewById(R.id.current_user_name));
userRenderer.showStatusColor(rootView.findViewById(R.id.current_user_status));
}
}
......
......@@ -97,7 +97,7 @@ public class AddDirectMessageDialogFragment extends AbstractAddRoomDialogFragmen
(realm, text) -> realm.where(RealmUser.class)
.contains(RealmUser.USERNAME, text, Case.INSENSITIVE)
.findAllSorted(RealmUser.USERNAME),
context -> new SuggestUserAdapter(context, rocketChatAbsoluteUrlOptional.get()));
context -> new SuggestUserAdapter(context, rocketChatAbsoluteUrlOptional.get(), hostname));
autoCompleteTextView.setAdapter(adapter);
}
......
......@@ -19,13 +19,14 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe
protected final TextView timestamp;
protected final View userAndTimeContainer;
protected final AbsoluteUrl absoluteUrl;
protected final String hostname;
protected final View newDayContainer;
protected final TextView newDayText;
/**
* constructor WITH hostname.
*/
public AbstractMessageViewHolder(View itemView, AbsoluteUrl absoluteUrl) {
public AbstractMessageViewHolder(View itemView, AbsoluteUrl absoluteUrl, String hostname) {
super(itemView);
avatar = itemView.findViewById(R.id.user_avatar);
errorImageView = itemView.findViewById(R.id.errorImageView);
......@@ -36,6 +37,7 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe
newDayContainer = itemView.findViewById(R.id.newday_container);
newDayText = itemView.findViewById(R.id.newday_text);
this.absoluteUrl = absoluteUrl;
this.hostname = hostname;
}
/**
......
......@@ -22,14 +22,16 @@ public class MessageListAdapter extends ExtModelListAdapter<Message, PairedMessa
private static final int VIEW_TYPE_NORMAL_MESSAGE = 1;
private static final int VIEW_TYPE_SYSTEM_MESSAGE = 2;
private String hostname;
private AbsoluteUrl absoluteUrl;
private boolean autoloadImages = false;
private boolean hasNext;
private boolean isLoaded;
public MessageListAdapter(Context context) {
public MessageListAdapter(Context context, String hostname) {
super(context);
this.hostname = hostname;
}
public void setAbsoluteUrl(AbsoluteUrl absoluteUrl) {
......@@ -92,11 +94,11 @@ public class MessageListAdapter extends ExtModelListAdapter<Message, PairedMessa
protected AbstractMessageViewHolder onCreateRealmModelViewHolder(int viewType, View itemView) {
switch (viewType) {
case VIEW_TYPE_NORMAL_MESSAGE:
return new MessageNormalViewHolder(itemView, absoluteUrl);
return new MessageNormalViewHolder(itemView, absoluteUrl, hostname);
case VIEW_TYPE_SYSTEM_MESSAGE:
return new MessageSystemViewHolder(itemView, absoluteUrl);
return new MessageSystemViewHolder(itemView, absoluteUrl, hostname);
default:
return new AbstractMessageViewHolder(itemView, absoluteUrl) {
return new AbstractMessageViewHolder(itemView, absoluteUrl, hostname) {
@Override
protected void bindMessage(PairedMessage pairedMessage, boolean autoloadImages) {}
};
......
......@@ -19,8 +19,8 @@ public class MessageNormalViewHolder extends AbstractMessageViewHolder {
/**
* constructor WITH hostname.
*/
public MessageNormalViewHolder(View itemView, AbsoluteUrl absoluteUrl) {
super(itemView, absoluteUrl);
public MessageNormalViewHolder(View itemView, AbsoluteUrl absoluteUrl, String hostname) {
super(itemView, absoluteUrl, hostname);
body = itemView.findViewById(R.id.message_body);
urls = itemView.findViewById(R.id.message_urls);
attachments = itemView.findViewById(R.id.message_attachments);
......@@ -28,12 +28,12 @@ public class MessageNormalViewHolder extends AbstractMessageViewHolder {
@Override
protected void bindMessage(PairedMessage pairedMessage, boolean autoloadImages) {
new MessageRenderer(itemView.getContext(), pairedMessage.target, autoloadImages)
.avatarInto(avatar, absoluteUrl)
.usernameInto(username, subUsername)
.timestampInto(timestamp)
.bodyInto(body)
.urlsInto(urls)
.attachmentsInto(attachments, absoluteUrl);
MessageRenderer messageRenderer = new MessageRenderer(pairedMessage.target, autoloadImages);
messageRenderer.showAvatar(avatar, hostname);
messageRenderer.showUsername(username, subUsername);
messageRenderer.showTimestampOrMessageState(timestamp);
messageRenderer.showBody(body);
messageRenderer.showUrl(urls);
messageRenderer.showAttachment(attachments, absoluteUrl);
}
}
......@@ -16,18 +16,17 @@ public class MessageSystemViewHolder extends AbstractMessageViewHolder {
/**
* constructor WITH hostname.
*/
public MessageSystemViewHolder(View itemView, AbsoluteUrl absoluteUrl) {
super(itemView, absoluteUrl);
public MessageSystemViewHolder(View itemView, AbsoluteUrl absoluteUrl, String hostname) {
super(itemView, absoluteUrl, hostname);
body = itemView.findViewById(R.id.message_body);
}
@Override
protected void bindMessage(PairedMessage pairedMessage, boolean autoloadImages) {
new MessageRenderer(itemView.getContext(), pairedMessage.target, autoloadImages)
.avatarInto(avatar, absoluteUrl)
.usernameInto(username, subUsername)
.timestampInto(timestamp);
MessageRenderer messageRenderer = new MessageRenderer(pairedMessage.target, autoloadImages);
messageRenderer.showAvatar(avatar, hostname);
messageRenderer.showUsername(username, subUsername);
messageRenderer.showTimestampOrMessageState(timestamp);
if (pairedMessage.target != null) {
body.setText(MessageType.parse(pairedMessage.target.getType())
.getString(body.getContext(), pairedMessage.target));
......
......@@ -24,16 +24,18 @@ public class RoomUserAdapter extends RecyclerView.Adapter<RoomUserViewHolder> {
private final LayoutInflater inflater;
private final RealmHelper realmHelper;
private final AbsoluteUrl absoluteUrl;
private final String hostname;
private List<String> usernames;
/**
* Constructor with required parameters.
*/
public RoomUserAdapter(Context context, RealmHelper realmHelper, AbsoluteUrl absoluteUrl) {
public RoomUserAdapter(Context context, RealmHelper realmHelper, AbsoluteUrl absoluteUrl, String hostname) {
this.context = context;
this.inflater = LayoutInflater.from(context);
this.realmHelper = realmHelper;
this.absoluteUrl = absoluteUrl;
this.hostname = hostname;
}
@Override
......@@ -57,14 +59,15 @@ public class RoomUserAdapter extends RecyclerView.Adapter<RoomUserViewHolder> {
.setUsername(username)
.setUtcOffset(0)
.build();
new UserRenderer(context, user)
.avatarInto(holder.avatar, absoluteUrl)
.usernameInto(holder.username);
UserRenderer userRenderer = new UserRenderer(user);
userRenderer.showAvatar(holder.avatar, hostname);
userRenderer.showUsername(holder.username);
} else {
new UserRenderer(context, realmUser.asUser())
.statusColorInto(holder.status)
.avatarInto(holder.avatar, absoluteUrl)
.usernameInto(holder.username);
UserRenderer userRenderer = new UserRenderer(realmUser.asUser());
userRenderer.showAvatar(holder.avatar, hostname);
userRenderer.showUsername(holder.username);
userRenderer.showStatusColor(holder.status);
}
}
......
......@@ -16,17 +16,19 @@ import chat.rocket.android.renderer.UserRenderer;
*/
public class SuggestUserAdapter extends RealmAutoCompleteAdapter<RealmUser> {
private final AbsoluteUrl absoluteUrl;
private final String hostname;
public SuggestUserAdapter(Context context, AbsoluteUrl absoluteUrl) {
public SuggestUserAdapter(Context context, AbsoluteUrl absoluteUrl, String hostname) {
super(context, R.layout.listitem_room_user, R.id.room_user_name);
this.absoluteUrl = absoluteUrl;
this.hostname = hostname;
}
@Override
protected void onBindItemView(View itemView, RealmUser user) {
new UserRenderer(itemView.getContext(), user.asUser())
.statusColorInto(itemView.findViewById(R.id.room_user_status))
.avatarInto(itemView.findViewById(R.id.room_user_avatar), absoluteUrl);
UserRenderer userRenderer = new UserRenderer(user.asUser());
userRenderer.showStatusColor(itemView.findViewById(R.id.room_user_status));
userRenderer.showAvatar(itemView.findViewById(R.id.room_user_avatar), hostname);
}
@Override
......
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