Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
331567fd
Commit
331567fd
authored
Feb 21, 2017
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
The room list is a recycler view
parent
659952bf
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
444 additions
and
320 deletions
+444
-320
SidebarMainContract.java
.../rocket/android/fragment/sidebar/SidebarMainContract.java
+3
-1
SidebarMainFragment.java
.../rocket/android/fragment/sidebar/SidebarMainFragment.java
+39
-29
RoomListManager.java
...rocket/android/layouthelper/chatroom/RoomListManager.java
+0
-183
ChannelRoomListHeader.java
...layouthelper/chatroom/roomlist/ChannelRoomListHeader.java
+37
-0
DirectMessageRoomListHeader.java
...helper/chatroom/roomlist/DirectMessageRoomListHeader.java
+37
-0
RoomListAdapter.java
...droid/layouthelper/chatroom/roomlist/RoomListAdapter.java
+146
-0
RoomListHeader.java
...ndroid/layouthelper/chatroom/roomlist/RoomListHeader.java
+21
-0
RoomListHeaderViewHolder.java
...outhelper/chatroom/roomlist/RoomListHeaderViewHolder.java
+32
-0
RoomListItemViewHolder.java
...ayouthelper/chatroom/roomlist/RoomListItemViewHolder.java
+29
-0
UnreadRoomListHeader.java
.../layouthelper/chatroom/roomlist/UnreadRoomListHeader.java
+41
-0
fragment_sidebar_main.xml
app/src/main/res/layout/fragment_sidebar_main.xml
+6
-101
room_list_header.xml
app/src/main/res/layout/room_list_header.xml
+29
-0
RoomListItemView.java
...chat/rocket/android/widget/internal/RoomListItemView.java
+4
-2
room_list_item.xml
...at-android-widgets/src/main/res/layout/room_list_item.xml
+8
-4
Room.java
...chat-core/src/main/java/chat/rocket/core/models/Room.java
+12
-0
No files found.
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainContract.java
View file @
331567fd
package
chat
.
rocket
.
android
.
fragment
.
sidebar
;
import
android.support.annotation.NonNull
;
import
java.util.List
;
import
chat.rocket.android.shared.BaseContract
;
import
chat.rocket.core.models.Room
;
...
...
@@ -13,7 +15,7 @@ public interface SidebarMainContract {
void
showEmptyScreen
();
void
showRoomList
(
List
<
Room
>
roomList
);
void
showRoomList
(
@NonNull
List
<
Room
>
roomList
);
void
showUser
(
User
user
);
}
...
...
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainFragment.java
View file @
331567fd
package
chat
.
rocket
.
android
.
fragment
.
sidebar
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.v4.app.DialogFragment
;
import
android.support.v7.widget.LinearLayoutManager
;
import
android.support.v7.widget.RecyclerView
;
import
android.view.View
;
import
android.widget.CompoundButton
;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
com.jakewharton.rxbinding.widget.RxCompoundButton
;
import
java.util.ArrayList
;
import
java.util.List
;
import
chat.rocket.android.BuildConfig
;
import
chat.rocket.android.R
;
...
...
@@ -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.AddDirectMessageDialogFragment
;
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.models.Room
;
import
chat.rocket.core.models.User
;
...
...
@@ -36,7 +43,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
private
SidebarMainContract
.
Presenter
presenter
;
private
RoomList
Manager
roomListManag
er
;
private
RoomList
Adapter
adapt
er
;
private
String
hostname
;
...
...
@@ -93,19 +100,17 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
setupUserActionToggle
();
setupUserStatusButtons
();
setupLogoutButton
();
setupAddChannelButton
();
setupVersionInfo
();
roomListManager
=
new
RoomListManager
(
rootView
.
findViewById
(
R
.
id
.
unread_title
),
(
LinearLayout
)
rootView
.
findViewById
(
R
.
id
.
unread_container
),
(
LinearLayout
)
rootView
.
findViewById
(
R
.
id
.
channels_container
),
(
LinearLayout
)
rootView
.
findViewById
(
R
.
id
.
direct_messages_container
));
roomListManager
.
setOnItemClickListener
(
view
->
{
RocketChatCache
.
get
(
view
.
getContext
()).
edit
()
.
putString
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
,
view
.
getRoomId
())
.
apply
();
});
adapter
=
new
RoomListAdapter
();
adapter
.
setOnItemClickListener
(
room
->
RocketChatCache
.
get
(
getContext
()).
edit
()
.
putString
(
RocketChatCache
.
KEY_SELECTED_ROOM_ID
,
room
.
getRoomId
())
.
apply
());
RecyclerView
recyclerView
=
(
RecyclerView
)
rootView
.
findViewById
(
R
.
id
.
room_list_container
);
recyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
getContext
(),
LinearLayoutManager
.
VERTICAL
,
false
));
recyclerView
.
setAdapter
(
adapter
);
}
private
void
setupUserActionToggle
()
{
...
...
@@ -152,10 +157,25 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
}
private
void
updateRoomListMode
(
User
user
)
{
if
(
user
==
null
||
user
.
getSettings
()
==
null
||
user
.
getSettings
().
getPreferences
()
==
null
)
{
return
;
final
List
<
RoomListHeader
>
roomListHeaders
=
new
ArrayList
<>();
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
()
{
...
...
@@ -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
()
{
TextView
versionInfoView
=
(
TextView
)
rootView
.
findViewById
(
R
.
id
.
version_info
);
versionInfoView
.
setText
(
getString
(
R
.
string
.
version_info_text
,
BuildConfig
.
VERSION_NAME
));
...
...
@@ -203,8 +213,8 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
}
@Override
public
void
showRoomList
(
List
<
Room
>
roomList
)
{
roomListManag
er
.
setRooms
(
roomList
);
public
void
showRoomList
(
@NonNull
List
<
Room
>
roomList
)
{
adapt
er
.
setRooms
(
roomList
);
}
@Override
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/RoomListManager.java
deleted
100644 → 0
View file @
659952bf
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
;
}
}
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/roomlist/ChannelRoomListHeader.java
0 → 100644
View file @
331567fd
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
;
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/roomlist/DirectMessageRoomListHeader.java
0 → 100644
View file @
331567fd
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
;
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/roomlist/RoomListAdapter.java
0 → 100644
View file @
331567fd
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
);
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/roomlist/RoomListHeader.java
0 → 100644
View file @
331567fd
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
();
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/roomlist/RoomListHeaderViewHolder.java
0 → 100644
View file @
331567fd
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
());
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/roomlist/RoomListItemViewHolder.java
0 → 100644
View file @
331567fd
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
);
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/roomlist/UnreadRoomListHeader.java
0 → 100644
View file @
331567fd
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
;
}
}
app/src/main/res/layout/fragment_sidebar_main.xml
View file @
331567fd
...
...
@@ -55,108 +55,13 @@
</LinearLayout>
<android.support.v4.widget.NestedScrollView
<android.support.v7.widget.RecyclerView
android:id=
"@+id/room_list_container"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_alignParentBottom=
"true"
android:layout_height=
"match_parent"
android:layout_below=
"@+id/user_info_container"
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:layout_alignParentBottom=
"true"
android:background=
"?attr/colorPrimary"
/>
<android.support.v4.widget.NestedScrollView
android:id=
"@+id/user_action_outer_container"
...
...
@@ -167,7 +72,7 @@
android:background=
"?attr/colorPrimaryDark"
android:elevation=
"2dp"
android:visibility=
"gone"
tools:visibility=
"
visibl
e"
>
tools:visibility=
"
gon
e"
>
<LinearLayout
android:layout_width=
"match_parent"
...
...
app/src/main/res/layout/room_list_header.xml
0 → 100644
View file @
331567fd
<?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
rocket-chat-android-widgets/src/main/java/chat/rocket/android/widget/internal/RoomListItemView.java
View file @
331567fd
...
...
@@ -6,6 +6,7 @@ import android.content.res.TypedArray;
import
android.os.Build
;
import
android.util.AttributeSet
;
import
android.view.View
;
import
android.widget.FrameLayout
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
...
...
@@ -15,7 +16,7 @@ import chat.rocket.android.widget.R;
/**
* Room list-item view used in sidebar.
*/
public
class
RoomListItemView
extends
Linear
Layout
{
public
class
RoomListItemView
extends
Frame
Layout
{
private
static
HashMap
<
String
,
Integer
>
ICON_TABLE
=
new
HashMap
<
String
,
Integer
>()
{
{
put
(
"c"
,
R
.
string
.
fa_hashtag
);
...
...
@@ -48,7 +49,8 @@ public class RoomListItemView extends LinearLayout {
}
private
void
initialize
(
Context
context
)
{
setOrientation
(
HORIZONTAL
);
setLayoutParams
(
new
LinearLayout
.
LayoutParams
(
LayoutParams
.
MATCH_PARENT
,
LayoutParams
.
WRAP_CONTENT
));
TypedArray
array2
=
context
.
getTheme
().
obtainStyledAttributes
(
new
int
[]{
R
.
attr
.
selectableItemBackground
...
...
rocket-chat-android-widgets/src/main/res/layout/room_list_item.xml
View file @
331567fd
<?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_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
android:layout_width=
"32dp"
...
...
@@ -19,7 +23,7 @@
<TextView
android:id=
"@+id/text"
android:layout_width=
"
wrap_content
"
android:layout_width=
"
0dp
"
android:layout_height=
"?attr/listPreferredItemHeightSmall"
android:layout_weight=
"1"
android:gravity=
"center_vertical"
...
...
@@ -44,4 +48,4 @@
android:layout_gravity=
"center"
android:textAppearance=
"@style/TextAppearance.AppCompat.Body1"
/>
</FrameLayout>
</merge>
\ No newline at end of file
</LinearLayout>
\ No newline at end of file
rocket-chat-core/src/main/java/chat/rocket/core/models/Room.java
View file @
331567fd
...
...
@@ -27,6 +27,18 @@ public abstract class Room {
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
()
{
return
new
AutoValue_Room
.
Builder
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment