Commit 331567fd authored by Tiago Cunha's avatar Tiago Cunha

The room list is a recycler view

parent 659952bf
package chat.rocket.android.fragment.sidebar; package chat.rocket.android.fragment.sidebar;
import android.support.annotation.NonNull;
import java.util.List; import java.util.List;
import chat.rocket.android.shared.BaseContract; import chat.rocket.android.shared.BaseContract;
import chat.rocket.core.models.Room; import chat.rocket.core.models.Room;
...@@ -13,7 +15,7 @@ public interface SidebarMainContract { ...@@ -13,7 +15,7 @@ public interface SidebarMainContract {
void showEmptyScreen(); void showEmptyScreen();
void showRoomList(List<Room> roomList); void showRoomList(@NonNull List<Room> roomList);
void showUser(User user); void showUser(User user);
} }
......
package chat.rocket.android.fragment.sidebar; package chat.rocket.android.fragment.sidebar;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.jakewharton.rxbinding.widget.RxCompoundButton; import com.jakewharton.rxbinding.widget.RxCompoundButton;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import chat.rocket.android.BuildConfig; import chat.rocket.android.BuildConfig;
import chat.rocket.android.R; import chat.rocket.android.R;
...@@ -20,7 +23,11 @@ import chat.rocket.android.fragment.sidebar.dialog.AbstractAddRoomDialogFragment ...@@ -20,7 +23,11 @@ import chat.rocket.android.fragment.sidebar.dialog.AbstractAddRoomDialogFragment
import chat.rocket.android.fragment.sidebar.dialog.AddChannelDialogFragment; import chat.rocket.android.fragment.sidebar.dialog.AddChannelDialogFragment;
import chat.rocket.android.fragment.sidebar.dialog.AddDirectMessageDialogFragment; import chat.rocket.android.fragment.sidebar.dialog.AddDirectMessageDialogFragment;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.layouthelper.chatroom.RoomListManager; import chat.rocket.android.layouthelper.chatroom.roomlist.ChannelRoomListHeader;
import chat.rocket.android.layouthelper.chatroom.roomlist.DirectMessageRoomListHeader;
import chat.rocket.android.layouthelper.chatroom.roomlist.RoomListAdapter;
import chat.rocket.android.layouthelper.chatroom.roomlist.RoomListHeader;
import chat.rocket.android.layouthelper.chatroom.roomlist.UnreadRoomListHeader;
import chat.rocket.core.interactors.RoomInteractor; import chat.rocket.core.interactors.RoomInteractor;
import chat.rocket.core.models.Room; import chat.rocket.core.models.Room;
import chat.rocket.core.models.User; import chat.rocket.core.models.User;
...@@ -36,7 +43,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain ...@@ -36,7 +43,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
private SidebarMainContract.Presenter presenter; private SidebarMainContract.Presenter presenter;
private RoomListManager roomListManager; private RoomListAdapter adapter;
private String hostname; private String hostname;
...@@ -93,19 +100,17 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain ...@@ -93,19 +100,17 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
setupUserActionToggle(); setupUserActionToggle();
setupUserStatusButtons(); setupUserStatusButtons();
setupLogoutButton(); setupLogoutButton();
setupAddChannelButton();
setupVersionInfo(); setupVersionInfo();
roomListManager = new RoomListManager( adapter = new RoomListAdapter();
rootView.findViewById(R.id.unread_title), adapter.setOnItemClickListener(room -> RocketChatCache.get(getContext()).edit()
(LinearLayout) rootView.findViewById(R.id.unread_container), .putString(RocketChatCache.KEY_SELECTED_ROOM_ID, room.getRoomId())
(LinearLayout) rootView.findViewById(R.id.channels_container), .apply());
(LinearLayout) rootView.findViewById(R.id.direct_messages_container));
roomListManager.setOnItemClickListener(view -> { RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.room_list_container);
RocketChatCache.get(view.getContext()).edit() recyclerView.setLayoutManager(
.putString(RocketChatCache.KEY_SELECTED_ROOM_ID, view.getRoomId()) new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
.apply(); recyclerView.setAdapter(adapter);
});
} }
private void setupUserActionToggle() { private void setupUserActionToggle() {
...@@ -152,10 +157,25 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain ...@@ -152,10 +157,25 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
} }
private void updateRoomListMode(User user) { private void updateRoomListMode(User user) {
if (user == null || user.getSettings() == null || user.getSettings().getPreferences() == null) { final List<RoomListHeader> roomListHeaders = new ArrayList<>();
return;
if (user != null && user.getSettings() != null && user.getSettings().getPreferences() != null
&& user.getSettings().getPreferences().isUnreadRoomsMode()) {
roomListHeaders.add(new UnreadRoomListHeader(
getString(R.string.fragment_sidebar_main_unread_rooms_title)
));
} }
roomListManager.setUnreadRoomMode(user.getSettings().getPreferences().isUnreadRoomsMode());
roomListHeaders.add(new ChannelRoomListHeader(
getString(R.string.fragment_sidebar_main_channels_title),
() -> showAddRoomDialog(AddChannelDialogFragment.create(hostname))
));
roomListHeaders.add(new DirectMessageRoomListHeader(
getString(R.string.fragment_sidebar_main_direct_messages_title),
() -> showAddRoomDialog(AddDirectMessageDialogFragment.create(hostname))
));
adapter.setRoomListHeaders(roomListHeaders);
} }
private void setupLogoutButton() { private void setupLogoutButton() {
...@@ -173,16 +193,6 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain ...@@ -173,16 +193,6 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
} }
} }
private void setupAddChannelButton() {
rootView.findViewById(R.id.btn_add_channel).setOnClickListener(view -> {
showAddRoomDialog(AddChannelDialogFragment.create(hostname));
});
rootView.findViewById(R.id.btn_add_direct_message).setOnClickListener(view -> {
showAddRoomDialog(AddDirectMessageDialogFragment.create(hostname));
});
}
private void setupVersionInfo() { private void setupVersionInfo() {
TextView versionInfoView = (TextView) rootView.findViewById(R.id.version_info); TextView versionInfoView = (TextView) rootView.findViewById(R.id.version_info);
versionInfoView.setText(getString(R.string.version_info_text, BuildConfig.VERSION_NAME)); versionInfoView.setText(getString(R.string.version_info_text, BuildConfig.VERSION_NAME));
...@@ -203,8 +213,8 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain ...@@ -203,8 +213,8 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
} }
@Override @Override
public void showRoomList(List<Room> roomList) { public void showRoomList(@NonNull List<Room> roomList) {
roomListManager.setRooms(roomList); adapter.setRooms(roomList);
} }
@Override @Override
......
package chat.rocket.android.layouthelper.chatroom;
import android.view.View;
import android.view.ViewGroup;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.core.models.Room;
import chat.rocket.android.widget.internal.RoomListItemView;
import java.util.List;
/**
* Utility class for mapping Room list into channel list ViewGroup.
*/
public class RoomListManager {
private View unreadTitle;
private ViewGroup unreadRoomsContainer;
private ViewGroup channelsContainer;
private ViewGroup dmContainer;
private boolean unreadRoomMode = false;
private List<Room> roomList;
/**
* Callback interface for List item clicked.
*/
public interface OnItemClickListener {
void onItemClick(RoomListItemView roomListItemView);
}
private OnItemClickListener listener;
/**
* constructor with three ViewGroups.
*/
public RoomListManager(View unreadTitle, ViewGroup unreadRoomsContainer,
ViewGroup channelsContainer, ViewGroup dmContainer) {
this(unreadTitle, unreadRoomsContainer, channelsContainer, dmContainer, false);
}
/**
* constructor with two ViewGroups.
*/
public RoomListManager(View unreadTitle, ViewGroup unreadRoomsContainer,
ViewGroup channelsContainer, ViewGroup dmContainer,
boolean unreadRoomMode) {
this.unreadTitle = unreadTitle;
this.unreadRoomsContainer = unreadRoomsContainer;
this.channelsContainer = channelsContainer;
this.dmContainer = dmContainer;
this.unreadRoomMode = unreadRoomMode;
}
/**
* update ViewGroups with room list.
*/
public void setRooms(List<Room> roomList) {
this.roomList = roomList;
updateRoomsList();
}
/**
* set callback on List item clicked.
*/
public void setOnItemClickListener(OnItemClickListener listener) {
this.listener = listener;
}
private void removeDeletedItem(ViewGroup parent, List<Room> roomList) {
for (int index = parent.getChildCount() - 1; index >= 0; index--) {
RoomListItemView roomListItemView = (RoomListItemView) parent.getChildAt(index);
final String targetRoomName = roomListItemView.getRoomName();
if (!TextUtils.isEmpty(targetRoomName)) {
boolean found = false;
for (Room room : roomList) {
if (targetRoomName.equals(room.getName())) {
found = true;
break;
}
}
if (!found) {
parent.removeViewAt(index);
}
}
}
}
public void setUnreadRoomMode(boolean unreadRoomMode) {
this.unreadRoomMode = unreadRoomMode;
updateRoomsList();
}
private void insertOrUpdateItem(ViewGroup parent, Room room) {
final String roomName = room.getName();
int index;
for (index = 0; index < parent.getChildCount(); index++) {
RoomListItemView roomListItemView = (RoomListItemView) parent.getChildAt(index);
final String targetRoomName = roomListItemView.getRoomName();
if (roomName.equals(targetRoomName)) {
updateRoomItemView(roomListItemView, room);
return;
}
if (roomName.compareToIgnoreCase(targetRoomName) < 0) {
break;
}
}
RoomListItemView roomListItemView = new RoomListItemView(parent.getContext());
updateRoomItemView(roomListItemView, room);
if (index == parent.getChildCount()) {
parent.addView(roomListItemView);
} else {
parent.addView(roomListItemView, index);
}
}
private void updateRoomItemView(RoomListItemView roomListItemView,
Room room) {
roomListItemView
.setRoomId(room.getRoomId())
.setRoomName(room.getName())
.setRoomType(room.getType())
.setAlert(room.isAlert())
.setUnreadCount(room.getUnread());
roomListItemView.setOnClickListener(this::onItemClick);
}
private void onItemClick(View view) {
if (view instanceof RoomListItemView && listener != null) {
listener.onItemClick((RoomListItemView) view);
}
}
private void updateRoomsList() {
if (roomList == null) {
return;
}
removeDeletedItem(unreadRoomsContainer, roomList);
removeDeletedItem(channelsContainer, roomList);
removeDeletedItem(dmContainer, roomList);
for (Room room : roomList) {
String name = room.getName();
if (TextUtils.isEmpty(name)) {
continue;
}
String type = room.getType();
if (unreadRoomMode && room.isAlert()) {
insertOrUpdateItem(unreadRoomsContainer, room);
removeItemIfExists(channelsContainer, name);
removeItemIfExists(dmContainer, name);
} else if (Room.TYPE_CHANNEL.equals(type)
|| Room.TYPE_PRIVATE.equals(type)) {
removeItemIfExists(unreadRoomsContainer, name);
insertOrUpdateItem(channelsContainer, room);
removeItemIfExists(dmContainer, name);
} else if (Room.TYPE_DIRECT_MESSAGE.equals(type)) {
removeItemIfExists(unreadRoomsContainer, name);
removeItemIfExists(channelsContainer, name);
insertOrUpdateItem(dmContainer, room);
}
}
boolean showUnread = unreadRoomMode && unreadRoomsContainer.getChildCount() != 0;
unreadTitle.setVisibility(showUnread ? View.VISIBLE : View.GONE);
unreadRoomsContainer.setVisibility(showUnread ? View.VISIBLE : View.GONE);
}
private static void removeItemIfExists(ViewGroup parent, String roomName) {
for (int i = 0; i < parent.getChildCount(); i++) {
RoomListItemView roomListItemView = (RoomListItemView) parent.getChildAt(i);
if (roomName.equals(roomListItemView.getRoomName())) {
parent.removeViewAt(i);
break;
}
}
}
}
package chat.rocket.android.layouthelper.chatroom.roomlist;
import android.support.annotation.NonNull;
import java.util.List;
import chat.rocket.core.models.Room;
public class ChannelRoomListHeader implements RoomListHeader {
private final String title;
private final ClickListener clickListener;
public ChannelRoomListHeader(String title, ClickListener clickListener) {
this.title = title;
this.clickListener = clickListener;
}
@Override
public String getTitle() {
return title;
}
@Override
public boolean owns(Room room) {
return room.isChannel() || room.isPrivate();
}
@Override
public boolean shouldShow(@NonNull List<Room> roomList) {
return true;
}
@Override
public ClickListener getClickListener() {
return clickListener;
}
}
package chat.rocket.android.layouthelper.chatroom.roomlist;
import android.support.annotation.NonNull;
import java.util.List;
import chat.rocket.core.models.Room;
public class DirectMessageRoomListHeader implements RoomListHeader {
private final String title;
private final ClickListener clickListener;
public DirectMessageRoomListHeader(String title, ClickListener clickListener) {
this.title = title;
this.clickListener = clickListener;
}
@Override
public String getTitle() {
return title;
}
@Override
public boolean owns(Room room) {
return room.isDirectMessage();
}
@Override
public boolean shouldShow(@NonNull List<Room> roomList) {
return true;
}
@Override
public ClickListener getClickListener() {
return clickListener;
}
}
package chat.rocket.android.layouthelper.chatroom.roomlist;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import chat.rocket.android.R;
import chat.rocket.android.widget.internal.RoomListItemView;
import chat.rocket.core.models.Room;
public class RoomListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int VIEW_TYPE_HEADER = 0;
private static final int VIEW_TYPE_ROOM = 1;
private List<Room> roomList = Collections.emptyList();
private List<RoomListHeader> roomListHeaders = Collections.emptyList();
private Map<Integer, RoomListHeader> headersPosition = new HashMap<>();
private OnItemClickListener externalListener;
private OnItemClickListener listener = room -> {
if (externalListener != null) {
externalListener.onItemClick(room);
}
};
public void setRoomListHeaders(@NonNull List<RoomListHeader> roomListHeaders) {
this.roomListHeaders = roomListHeaders;
updateRoomList();
}
public void setRooms(@NonNull List<Room> roomList) {
this.roomList = roomList;
updateRoomList();
}
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
externalListener = onItemClickListener;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == VIEW_TYPE_HEADER) {
return new RoomListHeaderViewHolder(
LayoutInflater.from(parent.getContext())
.inflate(R.layout.room_list_header, parent, false)
);
}
return new RoomListItemViewHolder(new RoomListItemView(parent.getContext()), listener);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (getItemViewType(position) == VIEW_TYPE_HEADER) {
((RoomListHeaderViewHolder) holder)
.bind(headersPosition.get(position));
return;
}
((RoomListItemViewHolder) holder)
.bind(roomList.get(position - getTotalHeadersBeforePosition(position)));
}
@Override
public int getItemCount() {
return roomList.size() + headersPosition.size();
}
@Override
public int getItemViewType(int position) {
if (headersPosition.containsKey(position)) {
return VIEW_TYPE_HEADER;
}
return VIEW_TYPE_ROOM;
}
private void updateRoomList() {
sortRoomList();
calculateHeadersPosition();
notifyDataSetChanged();
}
private void sortRoomList() {
int totalHeaders = roomListHeaders.size();
Collections.sort(roomList, (room, anotherRoom) -> {
for (int i = 0; i < totalHeaders; i++) {
final RoomListHeader header = roomListHeaders.get(i);
if (header.owns(room) && !header.owns(anotherRoom)) {
return -1;
} else if (!header.owns(room) && header.owns(anotherRoom)) {
return 1;
}
}
return room.getName().compareTo(anotherRoom.getName());
});
}
private void calculateHeadersPosition() {
headersPosition.clear();
int roomIdx = 0;
int totalRooms = roomList.size();
int totalHeaders = roomListHeaders.size();
for (int i = 0; i < totalHeaders; i++) {
final RoomListHeader header = roomListHeaders.get(i);
if (!header.shouldShow(roomList)) {
continue;
}
headersPosition.put(roomIdx + headersPosition.size(), header);
for (; roomIdx < totalRooms; roomIdx++) {
final Room room = roomList.get(roomIdx);
if (!header.owns(room)) {
break;
}
}
}
}
private int getTotalHeadersBeforePosition(int position) {
int totalHeaders = headersPosition.size();
Integer[] keySet = headersPosition.keySet().toArray(new Integer[totalHeaders]);
int totalBefore = 0;
for (int i = 0; i < totalHeaders; i++) {
if (keySet[i] <= position) {
totalBefore++;
}
}
return totalBefore;
}
public interface OnItemClickListener {
void onItemClick(Room room);
}
}
package chat.rocket.android.layouthelper.chatroom.roomlist;
import android.support.annotation.NonNull;
import java.util.List;
import chat.rocket.core.models.Room;
public interface RoomListHeader {
String getTitle();
boolean owns(Room room);
boolean shouldShow(@NonNull List<Room> roomList);
ClickListener getClickListener();
interface ClickListener {
void onClick();
}
}
package chat.rocket.android.layouthelper.chatroom.roomlist;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import chat.rocket.android.R;
public class RoomListHeaderViewHolder extends RecyclerView.ViewHolder {
private TextView title;
private Button button;
public RoomListHeaderViewHolder(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.title);
button = (Button) itemView.findViewById(R.id.btn_add);
}
public void bind(RoomListHeader roomListHeader) {
final RoomListHeader.ClickListener clickListener = roomListHeader.getClickListener();
if (clickListener == null) {
button.setVisibility(View.GONE);
} else {
button.setVisibility(View.VISIBLE);
button.setOnClickListener(v -> clickListener.onClick());
}
title.setText(roomListHeader.getTitle());
}
}
package chat.rocket.android.layouthelper.chatroom.roomlist;
import android.support.v7.widget.RecyclerView;
import chat.rocket.android.widget.internal.RoomListItemView;
import chat.rocket.core.models.Room;
public class RoomListItemViewHolder extends RecyclerView.ViewHolder {
public RoomListItemViewHolder(RoomListItemView itemView,
RoomListAdapter.OnItemClickListener listener) {
super(itemView);
itemView.setOnClickListener(view -> {
if (listener != null) {
listener.onItemClick((Room) view.getTag());
}
});
}
public void bind(Room room) {
((RoomListItemView) itemView)
.setRoomId(room.getRoomId())
.setRoomName(room.getName())
.setRoomType(room.getType())
.setAlert(room.isAlert())
.setUnreadCount(room.getUnread())
.setTag(room);
}
}
package chat.rocket.android.layouthelper.chatroom.roomlist;
import android.support.annotation.NonNull;
import java.util.List;
import chat.rocket.core.models.Room;
public class UnreadRoomListHeader implements RoomListHeader {
private final String title;
public UnreadRoomListHeader(String title) {
this.title = title;
}
@Override
public String getTitle() {
return title;
}
@Override
public boolean owns(Room room) {
return room.isAlert();
}
@Override
public boolean shouldShow(@NonNull List<Room> roomList) {
for (int i = 0, size = roomList.size(); i < size; i++) {
if (roomList.get(i).isAlert()) {
return true;
}
}
return false;
}
@Override
public ClickListener getClickListener() {
return null;
}
}
...@@ -55,108 +55,13 @@ ...@@ -55,108 +55,13 @@
</LinearLayout> </LinearLayout>
<android.support.v4.widget.NestedScrollView <android.support.v7.widget.RecyclerView
android:id="@+id/room_list_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="@+id/user_info_container" android:layout_below="@+id/user_info_container"
android:background="?attr/colorPrimary"> android:layout_alignParentBottom="true"
android:background="?attr/colorPrimary" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="?attr/listPreferredItemPaddingLeft"
android:paddingLeft="?attr/listPreferredItemPaddingLeft">
<TextView
android:id="@+id/unread_title"
android:layout_marginTop="@dimen/margin_8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="48dp"
android:alpha="0.62"
android:text="@string/fragment_sidebar_main_unread_rooms_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/unread_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="?attr/listPreferredItemPaddingRight"
android:orientation="vertical"
android:layout_marginRight="?attr/listPreferredItemPaddingRight" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_8">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:alpha="0.62"
android:text="@string/fragment_sidebar_main_channels_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textStyle="bold" />
<io.github.yusukeiwaki.android.widget.FontAwesomeButton
android:id="@+id/btn_add_channel"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="end|center_vertical"
android:text="@string/fa_plus"
android:textSize="12dp" />
</FrameLayout>
<LinearLayout
android:id="@+id/channels_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="?attr/listPreferredItemPaddingRight"
android:orientation="vertical"
android:layout_marginRight="?attr/listPreferredItemPaddingRight" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_8">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:alpha="0.62"
android:text="@string/fragment_sidebar_main_direct_messages_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textStyle="bold" />
<io.github.yusukeiwaki.android.widget.FontAwesomeButton
android:id="@+id/btn_add_direct_message"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="end|center_vertical"
android:text="@string/fa_plus"
android:textSize="12dp" />
</FrameLayout>
<LinearLayout
android:id="@+id/direct_messages_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="?attr/listPreferredItemPaddingRight"
android:orientation="vertical"
android:layout_marginRight="?attr/listPreferredItemPaddingRight" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.v4.widget.NestedScrollView <android.support.v4.widget.NestedScrollView
android:id="@+id/user_action_outer_container" android:id="@+id/user_action_outer_container"
...@@ -167,7 +72,7 @@ ...@@ -167,7 +72,7 @@
android:background="?attr/colorPrimaryDark" android:background="?attr/colorPrimaryDark"
android:elevation="2dp" android:elevation="2dp"
android:visibility="gone" android:visibility="gone"
tools:visibility="visible"> tools:visibility="gone">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="48dp"
android:layout_marginTop="@dimen/margin_8"
android:paddingStart="?attr/listPreferredItemPaddingLeft"
android:paddingLeft="?attr/listPreferredItemPaddingLeft">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:alpha="0.62"
android:text="@string/fragment_sidebar_main_channels_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textStyle="bold" />
<io.github.yusukeiwaki.android.widget.FontAwesomeButton
android:id="@+id/btn_add"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="end|center_vertical"
android:text="@string/fa_plus"
android:textSize="12dp" />
</FrameLayout>
\ No newline at end of file
...@@ -6,6 +6,7 @@ import android.content.res.TypedArray; ...@@ -6,6 +6,7 @@ import android.content.res.TypedArray;
import android.os.Build; import android.os.Build;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
...@@ -15,7 +16,7 @@ import chat.rocket.android.widget.R; ...@@ -15,7 +16,7 @@ import chat.rocket.android.widget.R;
/** /**
* Room list-item view used in sidebar. * Room list-item view used in sidebar.
*/ */
public class RoomListItemView extends LinearLayout { public class RoomListItemView extends FrameLayout {
private static HashMap<String, Integer> ICON_TABLE = new HashMap<String, Integer>() { private static HashMap<String, Integer> ICON_TABLE = new HashMap<String, Integer>() {
{ {
put("c", R.string.fa_hashtag); put("c", R.string.fa_hashtag);
...@@ -48,7 +49,8 @@ public class RoomListItemView extends LinearLayout { ...@@ -48,7 +49,8 @@ public class RoomListItemView extends LinearLayout {
} }
private void initialize(Context context) { private void initialize(Context context) {
setOrientation(HORIZONTAL); setLayoutParams(new LinearLayout.LayoutParams(
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
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:paddingStart="?attr/listPreferredItemPaddingLeft"
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
android:paddingRight="?attr/listPreferredItemPaddingRight"
android:paddingEnd="?attr/listPreferredItemPaddingRight">
<FrameLayout <FrameLayout
android:layout_width="32dp" android:layout_width="32dp"
...@@ -19,7 +23,7 @@ ...@@ -19,7 +23,7 @@
<TextView <TextView
android:id="@+id/text" android:id="@+id/text"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="?attr/listPreferredItemHeightSmall" android:layout_height="?attr/listPreferredItemHeightSmall"
android:layout_weight="1" android:layout_weight="1"
android:gravity="center_vertical" android:gravity="center_vertical"
...@@ -44,4 +48,4 @@ ...@@ -44,4 +48,4 @@
android:layout_gravity="center" android:layout_gravity="center"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" /> android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
</FrameLayout> </FrameLayout>
</merge> </LinearLayout>
\ No newline at end of file \ No newline at end of file
...@@ -27,6 +27,18 @@ public abstract class Room { ...@@ -27,6 +27,18 @@ public abstract class Room {
public abstract long getLastSeen(); public abstract long getLastSeen();
public boolean isChannel() {
return TYPE_CHANNEL.equals(getType());
}
public boolean isPrivate() {
return TYPE_PRIVATE.equals(getType());
}
public boolean isDirectMessage() {
return TYPE_DIRECT_MESSAGE.equals(getType());
}
public static Builder builder() { public static Builder builder() {
return new AutoValue_Room.Builder(); return new AutoValue_Room.Builder();
} }
......
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