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