Commit da668d26 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Update RoomListItemViewHolder.java

parent f9944c00
...@@ -4,6 +4,7 @@ import android.support.v7.widget.RecyclerView; ...@@ -4,6 +4,7 @@ import android.support.v7.widget.RecyclerView;
import chat.rocket.android.widget.internal.RoomListItemView; import chat.rocket.android.widget.internal.RoomListItemView;
import chat.rocket.core.models.Room; import chat.rocket.core.models.Room;
import chat.rocket.core.models.RoomSidebar;
import chat.rocket.core.models.Spotlight; import chat.rocket.core.models.Spotlight;
import chat.rocket.core.models.User; import chat.rocket.core.models.User;
...@@ -17,66 +18,49 @@ public class RoomListItemViewHolder extends RecyclerView.ViewHolder { ...@@ -17,66 +18,49 @@ public class RoomListItemViewHolder extends RecyclerView.ViewHolder {
itemView.setOnClickListener(view -> { itemView.setOnClickListener(view -> {
Object object = view.getTag(); Object object = view.getTag();
if (object instanceof Room) { if (object instanceof RoomSidebar) {
listener.onItemClick((Room)object); listener.onItemClick((RoomSidebar)object);
} else if (object instanceof Spotlight) { } else if (object instanceof Spotlight) {
listener.onItemClick((Spotlight)object); listener.onItemClick((Spotlight)object);
} }
}); });
} }
public void bind(RoomSidebar roomSidebar) {
itemView.setRoomId(roomSidebar.getRoomId());
itemView.setRoomName(roomSidebar.getRoomName());
itemView.setAlert(roomSidebar.isAlert());
itemView.setUnreadCount(roomSidebar.getUnread());
itemView.setTag(roomSidebar);
public void bind(Room room) { String roomType = roomSidebar.getType();
itemView if (roomType.equals(Room.TYPE_DIRECT_MESSAGE)) {
.setRoomId(room.getRoomId()) showUserStatusIcon(roomSidebar.getUserStatus());
.setRoomName(room.getName()) } else {
.setAlert(room.isAlert()) showRoomIcon(roomType);
.setUnreadCount(room.getUnread()) }
.setTag(room);
showRoomIcon(room.getType());
} }
public void bind(Spotlight spotlight) { public void bind(Spotlight spotlight) {
itemView itemView.setRoomId(spotlight.getId());
.setRoomId(spotlight.getId()) itemView.setRoomName(spotlight.getName());
.setRoomName(spotlight.getName()) itemView.setAlert(false);
.setAlert(false) itemView.setUnreadCount(0);
.setUnreadCount(0) itemView.setTag(spotlight);
.setTag(spotlight);
showRoomIcon(spotlight.getType()); showRoomIcon(spotlight.getType());
} }
/**
* Only shows the room icon if it is a PRIVATE CHANNEL or PUBLIC CHANNEL, otherwise you should use {@link #bind(User)} to show the correct icon.
* @param roomType The type of Room.
* @see Room
*/
private void showRoomIcon(String roomType) {
if(!roomType.equals(Room.TYPE_DIRECT_MESSAGE)) {
switch (roomType) {
case Room.TYPE_CHANNEL:
itemView.showPublicChannelIcon();
break;
case Room.TYPE_PRIVATE:
itemView.showPrivateChannelIcon();
break;
}
}
}
/** /**
* Shows the user status icon. * Shows the user status icon.
* @param user The user to show its status. * @param userStatus The user status to show the correspondent icon.
* @see User * @see User
*/ */
public void bind(User user) { private void showUserStatusIcon(String userStatus) {
String userStatus = user.getStatus();
if (userStatus == null) { if (userStatus == null) {
itemView.showOfflineUserStatusIcon(); itemView.showOfflineUserStatusIcon();
} else { } else {
switch (user.getStatus()) { switch (userStatus) {
case User.STATUS_ONLINE: case User.STATUS_ONLINE:
itemView.showOnlineUserStatusIcon(); itemView.showOnlineUserStatusIcon();
break; break;
...@@ -92,4 +76,20 @@ public class RoomListItemViewHolder extends RecyclerView.ViewHolder { ...@@ -92,4 +76,20 @@ public class RoomListItemViewHolder extends RecyclerView.ViewHolder {
} }
} }
} }
/**
* Only shows the room icon if it is a PRIVATE CHANNEL or PUBLIC CHANNEL, otherwise you should use {@link #showUserStatusIcon(String)} to show the icon.
* @param roomType The type of Room.
* @see Room
*/
private void showRoomIcon(String roomType) {
switch (roomType) {
case Room.TYPE_CHANNEL:
itemView.showPublicChannelIcon();
break;
case Room.TYPE_PRIVATE:
itemView.showPrivateChannelIcon();
break;
}
}
} }
\ 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