Commit 720d4500 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Update some classes.

parent aea73b91
......@@ -21,14 +21,6 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import com.fernandocejas.arrow.optional.Optional;
import com.jakewharton.rxbinding2.support.v4.widget.RxDrawerLayout;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import chat.rocket.android.BackgroundLooper;
import chat.rocket.android.R;
import chat.rocket.android.api.MethodCallHelper;
......@@ -78,10 +70,15 @@ import chat.rocket.persistence.realm.repositories.RealmSessionRepository;
import chat.rocket.persistence.realm.repositories.RealmSpotlightRoomRepository;
import chat.rocket.persistence.realm.repositories.RealmSpotlightUserRepository;
import chat.rocket.persistence.realm.repositories.RealmUserRepository;
import com.fernandocejas.arrow.optional.Optional;
import com.jakewharton.rxbinding2.support.v4.widget.RxDrawerLayout;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import permissions.dispatcher.NeedsPermission;
import permissions.dispatcher.RuntimePermissions;
......@@ -104,6 +101,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
private String roomId;
private LoadMoreScrollListener scrollListener;
private MessageFormManager messageFormManager;
private RecyclerView messageRecyclerView;
private RecyclerViewAutoScrollManager recyclerViewAutoScrollManager;
protected AbstractNewMessageIndicatorManager newMessageIndicatorManager;
protected Snackbar unreadIndicator;
......@@ -188,7 +186,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
@Override
protected void onSetupView() {
RecyclerView messageRecyclerView = (RecyclerView) rootView.findViewById(R.id.messageRecyclerView);
messageRecyclerView = rootView.findViewById(R.id.messageRecyclerView);
messageListAdapter = new MessageListAdapter(getContext());
messageRecyclerView.setAdapter(messageListAdapter);
......@@ -247,10 +245,8 @@ public class RoomFragment extends AbstractChatRoomFragment implements
}
private void scrollToLatestMessage() {
RecyclerView listView = (RecyclerView) rootView.findViewById(R.id.messageRecyclerView);
if (listView != null) {
listView.scrollToPosition(0);
}
if (messageRecyclerView != null)
messageRecyclerView.scrollToPosition(0);
}
protected Snackbar getUnreadCountIndicatorView(int count) {
......@@ -264,13 +260,9 @@ public class RoomFragment extends AbstractChatRoomFragment implements
@Override
public void onDestroyView() {
RecyclerView listView = (RecyclerView) rootView.findViewById(R.id.messageRecyclerView);
if (listView != null) {
RecyclerView.Adapter adapter = listView.getAdapter();
if (adapter != null) {
RecyclerView.Adapter adapter = messageRecyclerView.getAdapter();
if (adapter != null)
adapter.unregisterAdapterDataObserver(recyclerViewAutoScrollManager);
}
}
compositeDisposable.clear();
......@@ -551,12 +543,11 @@ public class RoomFragment extends AbstractChatRoomFragment implements
@Override
public void updateHistoryState(boolean hasNext, boolean isLoaded) {
RecyclerView listView = (RecyclerView) rootView.findViewById(R.id.messageRecyclerView);
if (listView == null || !(listView.getAdapter() instanceof MessageListAdapter)) {
if (messageRecyclerView == null || !(messageRecyclerView.getAdapter() instanceof MessageListAdapter)) {
return;
}
MessageListAdapter adapter = (MessageListAdapter) listView.getAdapter();
MessageListAdapter adapter = (MessageListAdapter) messageRecyclerView.getAdapter();
if (isLoaded) {
scrollListener.setLoadingDone();
}
......@@ -608,4 +599,4 @@ public class RoomFragment extends AbstractChatRoomFragment implements
edittingMessage = message;
messageFormManager.setEditMessage(message.getMessage());
}
}
}
\ No newline at end of file
......@@ -6,6 +6,8 @@ import android.graphics.Canvas;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.graphics.drawable.VectorDrawableCompat;
import chat.rocket.android.R;
import com.amulyakhare.textdrawable.TextDrawable;
import java.io.UnsupportedEncodingException;
......@@ -91,6 +93,14 @@ public class Avatar {
rocketChatAvatar.loadImage(getImageUrl(), getTextDrawable(context));
}
/**
* render error avatar into RocketChatAvatar.
*/
public void errorInto(final RocketChatAvatar rocketChatAvatar) {
final Context context = rocketChatAvatar.getContext();
rocketChatAvatar.loadImage(VectorDrawableCompat.create(context.getResources(), R.drawable.ic_error_outline_black_24dp, null));
}
public Drawable getTextDrawable(Context context) {
if (username == null) {
return null;
......
......@@ -44,7 +44,8 @@ public class MessageRenderer extends AbstractRenderer<Message> {
}
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));
userRenderer.errorAvatarInto(rocketChatAvatar);
else if (TextUtils.isEmpty(object.getAvatar()))
userRenderer.avatarInto(rocketChatAvatar, absoluteUrl);
else {
......
......@@ -32,6 +32,20 @@ public class UserRenderer extends AbstractRenderer<User> {
return this;
}
/**
* show Avatar error image
*/
public UserRenderer errorAvatarInto(RocketChatAvatar rocketChatAvatar) {
if (!shouldHandle(rocketChatAvatar)) {
return this;
}
if (!TextUtils.isEmpty(object.getUsername())) {
new Avatar(null, object.getUsername()).errorInto(rocketChatAvatar);
}
return this;
}
/**
* show Username in textView
*/
......
......@@ -11,6 +11,7 @@ import android.widget.FrameLayout;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
......@@ -49,8 +50,18 @@ public class RocketChatAvatar extends FrameLayout {
}
public void loadImage(Drawable drawable) {
// final GenericDraweeHierarchy hierarchy = draweeView.getHierarchy();
// hierarchy.setImage(drawable, 100, true); // Is there a better way?
final GenericDraweeHierarchy hierarchy = draweeView.getHierarchy();
hierarchy.setImage(drawable, 100, true); // Is there a better way?
hierarchy.setPlaceholderImage(drawable);
hierarchy.setFailureImage(drawable);
final DraweeController controller = Fresco.newDraweeControllerBuilder()
.setAutoPlayAnimations(true)
.build();
draweeView.setController(controller);
}
public void loadImage(String url, Drawable placeholder) {
......
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