Commit b6b134db authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

[WIP] RecyclerView wrong avatar solution

parent 043c783e
......@@ -215,14 +215,12 @@ public class RoomFragment extends AbstractChatRoomFragment implements
}
};
messageRecyclerView.addOnScrollListener(scrollListener);
messageRecyclerView.addOnScrollListener(
new RecyclerViewScrolledToBottomListener(linearLayoutManager, 1, this::markAsReadIfNeeded));
messageRecyclerView.addOnScrollListener(new RecyclerViewScrolledToBottomListener(linearLayoutManager, 1, this::markAsReadIfNeeded));
newMessageIndicatorManager = new AbstractNewMessageIndicatorManager() {
@Override
protected void onShowIndicator(int count, boolean onlyAlreadyShown) {
if ((onlyAlreadyShown && unreadIndicator != null && unreadIndicator.isShown())
|| !onlyAlreadyShown) {
if ((onlyAlreadyShown && unreadIndicator != null && unreadIndicator.isShown()) || !onlyAlreadyShown) {
unreadIndicator = getUnreadCountIndicatorView(count);
unreadIndicator.show();
}
......
......@@ -230,8 +230,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
private void onRenderCurrentUser(User user, RocketChatAbsoluteUrl absoluteUrl) {
if (user != null && absoluteUrl != null) {
new UserRenderer(getContext(), user)
.avatarInto((RocketChatAvatar) rootView.findViewById(R.id.current_user_avatar),
absoluteUrl)
.avatarInto((RocketChatAvatar) rootView.findViewById(R.id.current_user_avatar), absoluteUrl)
.usernameInto((TextView) rootView.findViewById(R.id.current_user_name))
.statusColorInto((ImageView) rootView.findViewById(R.id.current_user_status));
}
......
......@@ -11,8 +11,7 @@ import chat.rocket.android.layouthelper.chatroom.ModelViewHolder;
/**
* ModelListAdapter with header and footer.
*/
public abstract class ExtModelListAdapter<T, VM, VH extends ModelViewHolder<VM>>
extends ModelListAdapter<T, VM, VH> {
public abstract class ExtModelListAdapter<T, VM, VH extends ModelViewHolder<VM>> extends ModelListAdapter<T, VM, VH> {
protected static final int VIEW_TYPE_HEADER = -1;
protected static final int VIEW_TYPE_FOOTER = -2;
......
......@@ -40,17 +40,14 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe
* bind the view model.
*/
public final void bind(PairedMessage pairedMessage, boolean autoloadImages) {
bindMessage(pairedMessage, autoloadImages);
if (pairedMessage.target != null) {
int syncState = pairedMessage.target.getSyncState();
if (syncState == SyncState.NOT_SYNCED || syncState == SyncState.SYNCING) {
if (pairedMessage.target.getSyncState() != SyncState.SYNCED)
itemView.setAlpha(0.6f);
} else {
else
itemView.setAlpha(1.0f);
}
}
bindMessage(pairedMessage, autoloadImages);
renderNewDayAndSequential(pairedMessage);
}
......@@ -73,19 +70,17 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe
private void setSequential(boolean sequential) {
if (avatar != null) {
if (sequential) {
if (sequential)
avatar.setVisibility(View.GONE);
} else {
else
avatar.setVisibility(View.VISIBLE);
}
}
if (userAndTimeContainer != null) {
if (sequential) {
if (sequential)
userAndTimeContainer.setVisibility(View.GONE);
} else {
else
userAndTimeContainer.setVisibility(View.VISIBLE);
}
}
}
......
......@@ -16,8 +16,7 @@ import chat.rocket.core.models.Message;
/**
* target list adapter for chat room.
*/
public class MessageListAdapter
extends ExtModelListAdapter<Message, PairedMessage, AbstractMessageViewHolder> {
public class MessageListAdapter extends ExtModelListAdapter<Message, PairedMessage, AbstractMessageViewHolder> {
private static final int VIEW_TYPE_UNKNOWN = 0;
private static final int VIEW_TYPE_NORMAL_MESSAGE = 1;
......@@ -99,8 +98,7 @@ public class MessageListAdapter
default:
return new AbstractMessageViewHolder(itemView, absoluteUrl) {
@Override
protected void bindMessage(PairedMessage pairedMessage, boolean autoloadImages) {
}
protected void bindMessage(PairedMessage pairedMessage, boolean autoloadImages) {}
};
}
}
......@@ -173,4 +171,4 @@ public class MessageListAdapter
return oldMessage.equals(newMessage);
}
}
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ import chat.rocket.android.widget.AbsoluteUrl;
import chat.rocket.android.widget.message.RocketChatMessageAttachmentsLayout;
import chat.rocket.android.widget.message.RocketChatMessageLayout;
import chat.rocket.android.widget.message.RocketChatMessageUrlsLayout;
import chat.rocket.core.SyncState;
/**
* ViewData holder of NORMAL chat message.
......@@ -24,8 +25,7 @@ public class MessageNormalViewHolder extends AbstractMessageViewHolder {
super(itemView, absoluteUrl);
body = (RocketChatMessageLayout) itemView.findViewById(R.id.message_body);
urls = (RocketChatMessageUrlsLayout) itemView.findViewById(R.id.message_urls);
attachments =
(RocketChatMessageAttachmentsLayout) itemView.findViewById(R.id.message_attachments);
attachments = (RocketChatMessageAttachmentsLayout) itemView.findViewById(R.id.message_attachments);
}
@Override
......
......@@ -12,8 +12,7 @@ import android.view.ViewGroup;
import java.util.List;
@SuppressWarnings("PMD.GenericsNaming")
public abstract class ModelListAdapter<T, VM, VH extends ModelViewHolder<VM>>
extends RecyclerView.Adapter<VH> {
public abstract class ModelListAdapter<T, VM, VH extends ModelViewHolder<VM>> extends RecyclerView.Adapter<VH> {
protected final LayoutInflater inflater;
private List<VM> adapterData;
......
......@@ -39,15 +39,19 @@ public class MessageRenderer extends AbstractRenderer<Message> {
* show Avatar image.
*/
public MessageRenderer avatarInto(RocketChatAvatar rocketChatAvatar, AbsoluteUrl absoluteUrl) {
if (object.getSyncState() == SyncState.FAILED) {
if (!shouldHandle(rocketChatAvatar)) {
return this;
}
if (object.getSyncState() == SyncState.FAILED)
rocketChatAvatar.loadImage(VectorDrawableCompat.create(context.getResources(), R.drawable.ic_error_outline_black_24dp, null));
} else if (TextUtils.isEmpty(object.getAvatar())) {
else if (TextUtils.isEmpty(object.getAvatar()))
userRenderer.avatarInto(rocketChatAvatar, absoluteUrl);
} else {
else {
final User user = object.getUser();
setAvatarInto(object.getAvatar(), absoluteUrl, user == null ? null : user.getUsername(),
rocketChatAvatar);
setAvatarInto(object.getAvatar(), absoluteUrl, user == null ? null : user.getUsername(), rocketChatAvatar);
}
return this;
}
......@@ -78,6 +82,9 @@ public class MessageRenderer extends AbstractRenderer<Message> {
case SyncState.SYNCING:
textView.setText(R.string.sending);
break;
case SyncState.NOT_SYNCED:
textView.setText(R.string.not_synced);
break;
case SyncState.FAILED:
textView.setText(R.string.failed_to_sync);
break;
......@@ -142,8 +149,7 @@ public class MessageRenderer extends AbstractRenderer<Message> {
return this;
}
private void setAvatarInto(String avatar, AbsoluteUrl absoluteUrl, String username,
RocketChatAvatar imageView) {
private void setAvatarInto(String avatar, AbsoluteUrl absoluteUrl, String username, RocketChatAvatar imageView) {
imageView.loadImage(avatar, new Avatar(absoluteUrl, username).getTextDrawable(context));
}
......
......@@ -3,12 +3,11 @@ package chat.rocket.android.renderer;
import android.content.Context;
import android.widget.ImageView;
import android.widget.TextView;
import chat.rocket.android.helper.Avatar;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.widget.AbsoluteUrl;
import chat.rocket.core.models.User;
import chat.rocket.android.widget.RocketChatAvatar;
import chat.rocket.core.models.User;
/**
* Renderer for RealmUser model.
......
......@@ -74,13 +74,17 @@ public class LoadMessageProcedureObserver extends AbstractModelObserver<LoadMess
).continueWithTask(task -> {
if (task.isFaulted()) {
RCLog.w(task.getError());
return realmHelper.executeTransaction(realm ->
realmHelper.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(LoadMessageProcedure.class, new JSONObject()
.put(LoadMessageProcedure.ID, roomId)
.put(LoadMessageProcedure.SYNC_STATE, SyncState.FAILED)));
} else {
return Task.forResult(null);
realmHelper.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(LoadMessageProcedure.class, new JSONObject()
.put(LoadMessageProcedure.ID, roomId)
.put(LoadMessageProcedure.SYNC_STATE, SyncState.SYNCED)));
}
return null;
});
}
}
}
\ 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