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; ...@@ -21,14 +21,6 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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.BackgroundLooper;
import chat.rocket.android.R; import chat.rocket.android.R;
import chat.rocket.android.api.MethodCallHelper; import chat.rocket.android.api.MethodCallHelper;
...@@ -78,10 +70,15 @@ import chat.rocket.persistence.realm.repositories.RealmSessionRepository; ...@@ -78,10 +70,15 @@ import chat.rocket.persistence.realm.repositories.RealmSessionRepository;
import chat.rocket.persistence.realm.repositories.RealmSpotlightRoomRepository; import chat.rocket.persistence.realm.repositories.RealmSpotlightRoomRepository;
import chat.rocket.persistence.realm.repositories.RealmSpotlightUserRepository; import chat.rocket.persistence.realm.repositories.RealmSpotlightUserRepository;
import chat.rocket.persistence.realm.repositories.RealmUserRepository; 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.Single;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable; 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.NeedsPermission;
import permissions.dispatcher.RuntimePermissions; import permissions.dispatcher.RuntimePermissions;
...@@ -104,6 +101,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -104,6 +101,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
private String roomId; private String roomId;
private LoadMoreScrollListener scrollListener; private LoadMoreScrollListener scrollListener;
private MessageFormManager messageFormManager; private MessageFormManager messageFormManager;
private RecyclerView messageRecyclerView;
private RecyclerViewAutoScrollManager recyclerViewAutoScrollManager; private RecyclerViewAutoScrollManager recyclerViewAutoScrollManager;
protected AbstractNewMessageIndicatorManager newMessageIndicatorManager; protected AbstractNewMessageIndicatorManager newMessageIndicatorManager;
protected Snackbar unreadIndicator; protected Snackbar unreadIndicator;
...@@ -188,7 +186,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -188,7 +186,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
@Override @Override
protected void onSetupView() { protected void onSetupView() {
RecyclerView messageRecyclerView = (RecyclerView) rootView.findViewById(R.id.messageRecyclerView); messageRecyclerView = rootView.findViewById(R.id.messageRecyclerView);
messageListAdapter = new MessageListAdapter(getContext()); messageListAdapter = new MessageListAdapter(getContext());
messageRecyclerView.setAdapter(messageListAdapter); messageRecyclerView.setAdapter(messageListAdapter);
...@@ -247,10 +245,8 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -247,10 +245,8 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
private void scrollToLatestMessage() { private void scrollToLatestMessage() {
RecyclerView listView = (RecyclerView) rootView.findViewById(R.id.messageRecyclerView); if (messageRecyclerView != null)
if (listView != null) { messageRecyclerView.scrollToPosition(0);
listView.scrollToPosition(0);
}
} }
protected Snackbar getUnreadCountIndicatorView(int count) { protected Snackbar getUnreadCountIndicatorView(int count) {
...@@ -264,13 +260,9 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -264,13 +260,9 @@ public class RoomFragment extends AbstractChatRoomFragment implements
@Override @Override
public void onDestroyView() { public void onDestroyView() {
RecyclerView listView = (RecyclerView) rootView.findViewById(R.id.messageRecyclerView); RecyclerView.Adapter adapter = messageRecyclerView.getAdapter();
if (listView != null) { if (adapter != null)
RecyclerView.Adapter adapter = listView.getAdapter();
if (adapter != null) {
adapter.unregisterAdapterDataObserver(recyclerViewAutoScrollManager); adapter.unregisterAdapterDataObserver(recyclerViewAutoScrollManager);
}
}
compositeDisposable.clear(); compositeDisposable.clear();
...@@ -551,12 +543,11 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -551,12 +543,11 @@ public class RoomFragment extends AbstractChatRoomFragment implements
@Override @Override
public void updateHistoryState(boolean hasNext, boolean isLoaded) { public void updateHistoryState(boolean hasNext, boolean isLoaded) {
RecyclerView listView = (RecyclerView) rootView.findViewById(R.id.messageRecyclerView); if (messageRecyclerView == null || !(messageRecyclerView.getAdapter() instanceof MessageListAdapter)) {
if (listView == null || !(listView.getAdapter() instanceof MessageListAdapter)) {
return; return;
} }
MessageListAdapter adapter = (MessageListAdapter) listView.getAdapter(); MessageListAdapter adapter = (MessageListAdapter) messageRecyclerView.getAdapter();
if (isLoaded) { if (isLoaded) {
scrollListener.setLoadingDone(); scrollListener.setLoadingDone();
} }
......
...@@ -6,6 +6,8 @@ import android.graphics.Canvas; ...@@ -6,6 +6,8 @@ import android.graphics.Canvas;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.graphics.drawable.VectorDrawableCompat;
import chat.rocket.android.R;
import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.TextDrawable;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
...@@ -91,6 +93,14 @@ public class Avatar { ...@@ -91,6 +93,14 @@ public class Avatar {
rocketChatAvatar.loadImage(getImageUrl(), getTextDrawable(context)); 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) { public Drawable getTextDrawable(Context context) {
if (username == null) { if (username == null) {
return null; return null;
......
...@@ -44,7 +44,8 @@ public class MessageRenderer extends AbstractRenderer<Message> { ...@@ -44,7 +44,8 @@ public class MessageRenderer extends AbstractRenderer<Message> {
} }
if (object.getSyncState() == SyncState.FAILED) 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())) else if (TextUtils.isEmpty(object.getAvatar()))
userRenderer.avatarInto(rocketChatAvatar, absoluteUrl); userRenderer.avatarInto(rocketChatAvatar, absoluteUrl);
else { else {
......
...@@ -32,6 +32,20 @@ public class UserRenderer extends AbstractRenderer<User> { ...@@ -32,6 +32,20 @@ public class UserRenderer extends AbstractRenderer<User> {
return this; 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 * show Username in textView
*/ */
......
...@@ -11,6 +11,7 @@ import android.widget.FrameLayout; ...@@ -11,6 +11,7 @@ import android.widget.FrameLayout;
import com.facebook.drawee.backends.pipeline.Fresco; import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.generic.GenericDraweeHierarchy; import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.interfaces.DraweeController; import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView; import com.facebook.drawee.view.SimpleDraweeView;
...@@ -49,8 +50,18 @@ public class RocketChatAvatar extends FrameLayout { ...@@ -49,8 +50,18 @@ public class RocketChatAvatar extends FrameLayout {
} }
public void loadImage(Drawable drawable) { 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(); 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) { 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