Commit 7d35b2ac authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Improve failed message sync state

parent dc2aa663
...@@ -2,6 +2,7 @@ package chat.rocket.android.layouthelper.chatroom; ...@@ -2,6 +2,7 @@ package chat.rocket.android.layouthelper.chatroom;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
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;
...@@ -12,6 +13,7 @@ import chat.rocket.core.SyncState; ...@@ -12,6 +13,7 @@ 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 errorImageView;
protected final TextView username; protected final TextView username;
protected final TextView subUsername; protected final TextView subUsername;
protected final TextView timestamp; protected final TextView timestamp;
...@@ -26,6 +28,7 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe ...@@ -26,6 +28,7 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe
public AbstractMessageViewHolder(View itemView, AbsoluteUrl absoluteUrl) { public AbstractMessageViewHolder(View itemView, AbsoluteUrl absoluteUrl) {
super(itemView); super(itemView);
avatar = itemView.findViewById(R.id.user_avatar); avatar = itemView.findViewById(R.id.user_avatar);
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);
timestamp = itemView.findViewById(R.id.timestamp); timestamp = itemView.findViewById(R.id.timestamp);
...@@ -39,11 +42,12 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe ...@@ -39,11 +42,12 @@ 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) {
if (pairedMessage.target.getSyncState() != SyncState.SYNCED) { if (pairedMessage.target.getSyncState() == SyncState.FAILED) {
itemView.setAlpha(0.6f); avatar.setVisibility(View.GONE);
} errorImageView.setVisibility(View.VISIBLE);
else { } else {
itemView.setAlpha(1.0f); errorImageView.setVisibility(View.GONE);
avatar.setVisibility(View.VISIBLE);
} }
bindMessage(pairedMessage, autoloadImages); bindMessage(pairedMessage, autoloadImages);
......
...@@ -21,7 +21,6 @@ import java.util.List; ...@@ -21,7 +21,6 @@ import java.util.List;
* Renderer for RealmMessage model. * Renderer for RealmMessage model.
*/ */
public class MessageRenderer extends AbstractRenderer<Message> { public class MessageRenderer extends AbstractRenderer<Message> {
private final UserRenderer userRenderer; private final UserRenderer userRenderer;
private final boolean autoloadImages; private final boolean autoloadImages;
...@@ -39,17 +38,13 @@ public class MessageRenderer extends AbstractRenderer<Message> { ...@@ -39,17 +38,13 @@ public class MessageRenderer extends AbstractRenderer<Message> {
return this; return this;
} }
switch (object.getSyncState()){ if(object.getSyncState() != SyncState.FAILED) {
case SyncState.FAILED: if (TextUtils.isEmpty(object.getAvatar())) {
userRenderer.avatarInto(rocketChatAvatar, absoluteUrl, true); userRenderer.avatarInto(rocketChatAvatar, absoluteUrl);
break; // Avatar from oauth providers
default: } else {
if (TextUtils.isEmpty(object.getAvatar())) { rocketChatAvatar.loadImage(object.getAvatar());
userRenderer.avatarInto(rocketChatAvatar, absoluteUrl, false); }
} else {
rocketChatAvatar.loadImage(object.getAvatar());
}
break;
} }
return this; return this;
} }
......
<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:fillColor="#FF000000"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/>
</vector>
<?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:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -19,6 +20,15 @@ ...@@ -19,6 +20,15 @@
android:layout_height="32dp" android:layout_height="32dp"
android:layout_margin="8dp" /> android:layout_margin="8dp" />
<ImageView
android:id="@+id/errorImageView"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="8dp"
android:tint="@color/colorAccent"
app:srcCompat="@drawable/ic_error_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"
......
<?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:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -18,6 +19,15 @@ ...@@ -18,6 +19,15 @@
android:layout_height="32dp" android:layout_height="32dp"
android:layout_margin="8dp" /> android:layout_margin="8dp" />
<ImageView
android:id="@+id/errorImageView"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="8dp"
android:tint="@color/colorAccent"
app:srcCompat="@drawable/ic_error_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"
......
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