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
78947080
Commit
78947080
authored
Aug 30, 2017
by
Filipe de Lima Brito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update RoomListAdapter.java
parent
296a06c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
27 deletions
+26
-27
RoomListAdapter.java
...droid/layouthelper/chatroom/roomlist/RoomListAdapter.java
+26
-27
No files found.
app/src/main/java/chat/rocket/android/layouthelper/chatroom/roomlist/RoomListAdapter.java
View file @
78947080
...
...
@@ -5,6 +5,7 @@ import android.support.v7.widget.RecyclerView;
import
android.view.LayoutInflater
;
import
android.view.ViewGroup
;
import
chat.rocket.core.models.RoomSidebar
;
import
chat.rocket.core.models.Spotlight
;
import
java.util.Collections
;
import
java.util.HashMap
;
...
...
@@ -12,7 +13,6 @@ 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
>
{
...
...
@@ -22,7 +22,7 @@ public class RoomListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
private
static
final
int
VIEW_TYPE_HEADER
=
0
;
private
static
final
int
VIEW_TYPE_ROOM
=
1
;
private
List
<
Room
>
room
List
=
Collections
.
emptyList
();
private
List
<
Room
Sidebar
>
roomSidebar
List
=
Collections
.
emptyList
();
private
List
<
Spotlight
>
spotlightList
=
Collections
.
emptyList
();
private
List
<
RoomListHeader
>
roomListHeaders
=
Collections
.
emptyList
();
private
Map
<
Integer
,
RoomListHeader
>
headersPosition
=
new
HashMap
<>();
...
...
@@ -32,9 +32,9 @@ public class RoomListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
private
OnItemClickListener
externalListener
;
private
OnItemClickListener
listener
=
new
OnItemClickListener
()
{
@Override
public
void
onItemClick
(
Room
room
)
{
public
void
onItemClick
(
Room
Sidebar
roomSidebar
)
{
if
(
externalListener
!=
null
)
{
externalListener
.
onItemClick
(
room
);
externalListener
.
onItemClick
(
room
Sidebar
);
}
}
...
...
@@ -48,17 +48,17 @@ public class RoomListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
public
void
setRoomListHeaders
(
@NonNull
List
<
RoomListHeader
>
roomListHeaders
)
{
this
.
roomListHeaders
=
roomListHeaders
;
updateRoomList
();
updateRoom
Sidebar
List
();
}
public
void
setRoom
s
(
@NonNull
List
<
Room
>
room
List
)
{
this
.
room
List
=
room
List
;
updateRoomList
();
public
void
setRoom
SidebarList
(
@NonNull
List
<
RoomSidebar
>
roomSidebar
List
)
{
this
.
room
SidebarList
=
roomSidebar
List
;
updateRoom
Sidebar
List
();
}
public
void
setSpotlightList
(
@NonNull
List
<
Spotlight
>
spotlightList
)
{
this
.
spotlightList
=
spotlightList
;
updateRoomList
();
updateRoom
Sidebar
List
();
}
public
void
setMode
(
int
mode
)
{
...
...
@@ -77,9 +77,9 @@ public class RoomListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
@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
RoomListHeaderViewHolder
(
LayoutInflater
.
from
(
parent
.
getContext
())
.
inflate
(
R
.
layout
.
room_list_header
,
parent
,
false
)
);
}
return
new
RoomListItemViewHolder
(
new
RoomListItemView
(
parent
.
getContext
()),
listener
);
...
...
@@ -89,13 +89,12 @@ public class RoomListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
public
void
onBindViewHolder
(
RecyclerView
.
ViewHolder
holder
,
int
position
)
{
if
(
mode
==
MODE_ROOM
)
{
if
(
getItemViewType
(
position
)
==
VIEW_TYPE_HEADER
)
{
((
RoomListHeaderViewHolder
)
holder
)
.
bind
(
headersPosition
.
get
(
position
));
((
RoomListHeaderViewHolder
)
holder
).
bind
(
headersPosition
.
get
(
position
));
return
;
}
((
RoomListItemViewHolder
)
holder
)
.
bind
(
roomList
.
get
(
position
-
getTotalHeadersBeforePosition
(
position
))
);
RoomSidebar
roomSidebar
=
roomSidebarList
.
get
(
position
-
getTotalHeadersBeforePosition
(
position
));
((
RoomListItemViewHolder
)
holder
).
bind
(
roomSidebar
);
}
else
if
(
mode
==
MODE_SPOTLIGHT
)
{
((
RoomListItemViewHolder
)
holder
).
bind
(
spotlightList
.
get
(
position
));
}
...
...
@@ -106,7 +105,7 @@ public class RoomListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
if
(
mode
==
MODE_SPOTLIGHT
)
{
return
spotlightList
.
size
();
}
return
roomList
.
size
()
+
headersPosition
.
size
();
return
room
Sidebar
List
.
size
()
+
headersPosition
.
size
();
}
@Override
...
...
@@ -121,7 +120,7 @@ public class RoomListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
return
VIEW_TYPE_ROOM
;
}
private
void
updateRoomList
()
{
private
void
updateRoom
Sidebar
List
()
{
if
(
mode
==
MODE_ROOM
)
{
sortRoomList
();
calculateHeadersPosition
();
...
...
@@ -132,18 +131,18 @@ public class RoomListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
private
void
sortRoomList
()
{
int
totalHeaders
=
roomListHeaders
.
size
();
Collections
.
sort
(
room
List
,
(
room
,
anotherRoom
)
->
{
Collections
.
sort
(
room
SidebarList
,
(
roomSidebar
,
anotherRoom
)
->
{
for
(
int
i
=
0
;
i
<
totalHeaders
;
i
++)
{
final
RoomListHeader
header
=
roomListHeaders
.
get
(
i
);
if
(
header
.
owns
(
room
)
&&
!
header
.
owns
(
anotherRoom
))
{
if
(
header
.
owns
(
room
Sidebar
)
&&
!
header
.
owns
(
anotherRoom
))
{
return
-
1
;
}
else
if
(!
header
.
owns
(
room
)
&&
header
.
owns
(
anotherRoom
))
{
}
else
if
(!
header
.
owns
(
room
Sidebar
)
&&
header
.
owns
(
anotherRoom
))
{
return
1
;
}
}
return
room
.
getName
().
compareTo
(
anotherRoom
.
get
Name
());
return
room
Sidebar
.
getRoomName
().
compareTo
(
anotherRoom
.
getRoom
Name
());
});
}
...
...
@@ -151,19 +150,19 @@ public class RoomListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
headersPosition
.
clear
();
int
roomIdx
=
0
;
int
totalRooms
=
roomList
.
size
();
int
totalRooms
=
room
Sidebar
List
.
size
();
int
totalHeaders
=
roomListHeaders
.
size
();
for
(
int
i
=
0
;
i
<
totalHeaders
;
i
++)
{
final
RoomListHeader
header
=
roomListHeaders
.
get
(
i
);
if
(!
header
.
shouldShow
(
roomList
))
{
if
(!
header
.
shouldShow
(
room
Sidebar
List
))
{
continue
;
}
headersPosition
.
put
(
roomIdx
+
headersPosition
.
size
(),
header
);
for
(;
roomIdx
<
totalRooms
;
roomIdx
++)
{
final
Room
room
=
room
List
.
get
(
roomIdx
);
if
(!
header
.
owns
(
room
))
{
final
Room
Sidebar
roomSidebar
=
roomSidebar
List
.
get
(
roomIdx
);
if
(!
header
.
owns
(
room
Sidebar
))
{
break
;
}
}
...
...
@@ -185,7 +184,7 @@ public class RoomListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
public
interface
OnItemClickListener
{
void
onItemClick
(
Room
room
);
void
onItemClick
(
Room
Sidebar
roomSidebar
);
void
onItemClick
(
Spotlight
spotlight
);
}
...
...
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