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;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import chat.rocket.android.R;
import chat.rocket.android.helper.DateTime;
......@@ -12,6 +13,7 @@ import chat.rocket.core.SyncState;
public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMessage> {
protected final RocketChatAvatar avatar;
protected final ImageView errorImageView;
protected final TextView username;
protected final TextView subUsername;
protected final TextView timestamp;
......@@ -26,6 +28,7 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe
public AbstractMessageViewHolder(View itemView, AbsoluteUrl absoluteUrl) {
super(itemView);
avatar = itemView.findViewById(R.id.user_avatar);
errorImageView = itemView.findViewById(R.id.errorImageView);
username = itemView.findViewById(R.id.username);
subUsername = itemView.findViewById(R.id.sub_username);
timestamp = itemView.findViewById(R.id.timestamp);
......@@ -39,11 +42,12 @@ public abstract class AbstractMessageViewHolder extends ModelViewHolder<PairedMe
* bind the view model.
*/
public final void bind(PairedMessage pairedMessage, boolean autoloadImages) {
if (pairedMessage.target.getSyncState() != SyncState.SYNCED) {
itemView.setAlpha(0.6f);
}
else {
itemView.setAlpha(1.0f);
if (pairedMessage.target.getSyncState() == SyncState.FAILED) {
avatar.setVisibility(View.GONE);
errorImageView.setVisibility(View.VISIBLE);
} else {
errorImageView.setVisibility(View.GONE);
avatar.setVisibility(View.VISIBLE);
}
bindMessage(pairedMessage, autoloadImages);
......
......@@ -21,7 +21,6 @@ import java.util.List;
* Renderer for RealmMessage model.
*/
public class MessageRenderer extends AbstractRenderer<Message> {
private final UserRenderer userRenderer;
private final boolean autoloadImages;
......@@ -39,17 +38,13 @@ public class MessageRenderer extends AbstractRenderer<Message> {
return this;
}
switch (object.getSyncState()){
case SyncState.FAILED:
userRenderer.avatarInto(rocketChatAvatar, absoluteUrl, true);
break;
default:
if (TextUtils.isEmpty(object.getAvatar())) {
userRenderer.avatarInto(rocketChatAvatar, absoluteUrl, false);
} else {
rocketChatAvatar.loadImage(object.getAvatar());
}
break;
if(object.getSyncState() != SyncState.FAILED) {
if (TextUtils.isEmpty(object.getAvatar())) {
userRenderer.avatarInto(rocketChatAvatar, absoluteUrl);
// Avatar from oauth providers
} else {
rocketChatAvatar.loadImage(object.getAvatar());
}
}
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"?>
<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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -19,6 +20,15 @@
android:layout_height="32dp"
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
android:layout_width="match_parent"
android:layout_height="wrap_content"
......
<?xml version="1.0" encoding="utf-8"?>
<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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
......@@ -18,6 +19,15 @@
android:layout_height="32dp"
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
android:layout_width="match_parent"
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