Commit 4b4c84f7 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Update RoomListItemView.java

parent d407dfb8
...@@ -3,29 +3,31 @@ package chat.rocket.android.widget.internal; ...@@ -3,29 +3,31 @@ package chat.rocket.android.widget.internal;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import java.util.HashMap;
import chat.rocket.android.widget.R; import chat.rocket.android.widget.R;
import chat.rocket.android.widget.helper.DrawableHelper;
/** /**
* Room list-item view used in sidebar. * Room list-item view used in sidebar.
*/ */
public class RoomListItemView extends FrameLayout { public class RoomListItemView extends FrameLayout {
private static HashMap<String, Integer> ICON_TABLE = new HashMap<String, Integer>() {
{
put("c", R.string.fa_hashtag);
put("p", R.string.fa_lock);
put("d", R.string.fa_at);
}
};
private String roomId; private String roomId;
private String roomName; private ImageView roomTypeImage;
private ImageView userStatusImage;
private TextView roomNameText;
private TextView alertCountText;
private Drawable privateChannelDrawable;
private Drawable publicChannelDrawable;
private Drawable userStatusDrawable;
public RoomListItemView(Context context) { public RoomListItemView(Context context) {
super(context); super(context);
...@@ -49,8 +51,7 @@ public class RoomListItemView extends FrameLayout { ...@@ -49,8 +51,7 @@ public class RoomListItemView extends FrameLayout {
} }
private void initialize(Context context) { private void initialize(Context context) {
setLayoutParams(new LinearLayout.LayoutParams( setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
TypedArray array2 = context.getTheme().obtainStyledAttributes(new int[]{ TypedArray array2 = context.getTheme().obtainStyledAttributes(new int[]{
R.attr.selectableItemBackground R.attr.selectableItemBackground
...@@ -59,6 +60,15 @@ public class RoomListItemView extends FrameLayout { ...@@ -59,6 +60,15 @@ public class RoomListItemView extends FrameLayout {
array2.recycle(); array2.recycle();
View.inflate(context, R.layout.room_list_item, this); View.inflate(context, R.layout.room_list_item, this);
roomTypeImage = findViewById(R.id.image_room_type);
userStatusImage = findViewById(R.id.image_user_status);
roomNameText = findViewById(R.id.text_room_name);
alertCountText = findViewById(R.id.text_alert_count);
privateChannelDrawable = VectorDrawableCompat.create(getResources(), R.drawable.ic_lock_white_24dp, null);
publicChannelDrawable = VectorDrawableCompat.create(getResources(), R.drawable.ic_hashtag_white_24dp, null);
userStatusDrawable = VectorDrawableCompat.create(getResources(), R.drawable.ic_user_status_black_24dp, null);
} }
public String getRoomId() { public String getRoomId() {
...@@ -70,43 +80,64 @@ public class RoomListItemView extends FrameLayout { ...@@ -70,43 +80,64 @@ public class RoomListItemView extends FrameLayout {
return this; return this;
} }
public RoomListItemView setRoomType(String type) {
if (ICON_TABLE.containsKey(type)) {
TextView icon = (TextView) findViewById(R.id.icon);
icon.setText(ICON_TABLE.get(type));
}
return this;
}
public RoomListItemView setUnreadCount(int count) { public RoomListItemView setUnreadCount(int count) {
View alertCountContainer = findViewById(R.id.alert_count_container);
TextView alertCount = (TextView) findViewById(R.id.alert_count);
if (count > 0) { if (count > 0) {
alertCount.setText(Integer.toString(count)); alertCountText.setText(String.valueOf(count));
alertCountContainer.setVisibility(View.VISIBLE); alertCountText.setVisibility(View.VISIBLE);
} else { } else {
alertCountContainer.setVisibility(View.GONE); alertCountText.setVisibility(View.GONE);
} }
return this; return this;
} }
public RoomListItemView setAlert(boolean alert) { public RoomListItemView setAlert(boolean alert) {
setAlpha(alert ? 1.0f : 0.62f); setAlpha(alert ? 1.0f : 0.62f);
return this; return this;
} }
public String getRoomName() { public String getRoomName() {
return roomName; return roomNameText.toString();
} }
public RoomListItemView setRoomName(String roomName) { public RoomListItemView setRoomName(String roomName) {
this.roomName = roomName; roomNameText.setText(roomName);
TextView text = (TextView) findViewById(R.id.text); return this;
text.setText(roomName); }
public RoomListItemView showPrivateChannelIcon() {
roomTypeImage.setImageDrawable(privateChannelDrawable);
roomTypeImage.setVisibility(VISIBLE);
return this; return this;
} }
}
public RoomListItemView showPublicChannelIcon() {
roomTypeImage.setImageDrawable(publicChannelDrawable);
roomTypeImage.setVisibility(VISIBLE);
return this;
}
public RoomListItemView showOnlineUserStatusIcon() {
prepareDrawableAndShow(R.color.color_user_status_online);
return this;
}
public RoomListItemView showBusyUserStatusIcon() {
prepareDrawableAndShow(R.color.color_user_status_busy);
return this;
}
public RoomListItemView showAwayUserStatusIcon() {
prepareDrawableAndShow(R.color.color_user_status_away);
return this;
}
public RoomListItemView showOfflineUserStatusIcon() {
prepareDrawableAndShow(R.color.color_user_status_offline);
return this;
}
private void prepareDrawableAndShow(int colorResId) {
DrawableHelper.INSTANCE.wrapDrawable(userStatusDrawable);
DrawableHelper.INSTANCE.tintDrawable(userStatusDrawable, getContext(), colorResId);
userStatusImage.setImageDrawable(userStatusDrawable);
userStatusImage.setVisibility(VISIBLE);
}
}
\ 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