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
f2791a03
Commit
f2791a03
authored
Dec 19, 2016
by
Tiago Cunha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unread mode
parent
9bc47756
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
156 additions
and
104 deletions
+156
-104
SidebarMainFragment.java
.../rocket/android/fragment/sidebar/SidebarMainFragment.java
+19
-4
RoomListManager.java
...rocket/android/layouthelper/chatroom/RoomListManager.java
+78
-37
User.java
app/src/main/java/chat/rocket/android/model/ddp/User.java
+5
-0
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+6
-6
fragment_sidebar_main.xml
app/src/main/res/layout/fragment_sidebar_main.xml
+48
-57
No files found.
app/src/main/java/chat/rocket/android/fragment/sidebar/SidebarMainFragment.java
View file @
f2791a03
...
...
@@ -7,16 +7,14 @@ import android.widget.CompoundButton;
import
android.widget.ImageView
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
com.jakewharton.rxbinding.view.RxView
;
import
com.jakewharton.rxbinding.widget.RxCompoundButton
;
import
chat.rocket.android.R
;
import
chat.rocket.android.RocketChatCache
;
import
chat.rocket.android.api.MethodCallHelper
;
import
chat.rocket.android.fragment.AbstractFragment
;
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.fragment.sidebar.dialog.AddChannelDialogFragment
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.layouthelper.chatroom.RoomListManager
;
...
...
@@ -29,6 +27,9 @@ import chat.rocket.android.realm_helper.RealmObjectObserver;
import
chat.rocket.android.realm_helper.RealmStore
;
import
chat.rocket.android.renderer.UserRenderer
;
import
com.jakewharton.rxbinding.view.RxView
;
import
com.jakewharton.rxbinding.widget.RxCompoundButton
;
public
class
SidebarMainFragment
extends
AbstractFragment
{
private
String
serverConfigId
;
...
...
@@ -75,7 +76,7 @@ public class SidebarMainFragment extends AbstractFragment {
currentUserObserver
=
realmHelper
.
createObjectObserver
(
User:
:
queryCurrentUser
)
.
setOnUpdateListener
(
this
::
on
Render
CurrentUser
);
.
setOnUpdateListener
(
this
::
onCurrentUser
);
methodCallHelper
=
new
MethodCallHelper
(
getContext
(),
serverConfigId
);
}
...
...
@@ -103,6 +104,8 @@ public class SidebarMainFragment extends AbstractFragment {
setupAddChannelButton
();
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
->
{
...
...
@@ -142,6 +145,11 @@ public class SidebarMainFragment extends AbstractFragment {
}
}
private
void
onCurrentUser
(
User
user
)
{
onRenderCurrentUser
(
user
);
updateRoomListMode
(
user
);
}
private
void
onRenderCurrentUser
(
User
user
)
{
if
(
user
!=
null
&&
!
TextUtils
.
isEmpty
(
hostname
))
{
new
UserRenderer
(
getContext
(),
user
)
...
...
@@ -151,6 +159,13 @@ public class SidebarMainFragment extends AbstractFragment {
}
}
private
void
updateRoomListMode
(
User
user
)
{
if
(
user
==
null
||
user
.
getSettings
()
==
null
||
user
.
getSettings
().
getPreferences
()
==
null
)
{
return
;
}
roomListManager
.
setUnreadRoomMode
(
user
.
getSettings
().
getPreferences
().
isUnreadRoomsMode
());
}
private
void
setupLogoutButton
()
{
rootView
.
findViewById
(
R
.
id
.
btn_logout
).
setOnClickListener
(
view
->
{
if
(
methodCallHelper
!=
null
)
{
...
...
app/src/main/java/chat/rocket/android/layouthelper/chatroom/RoomListManager.java
View file @
f2791a03
...
...
@@ -3,61 +3,60 @@ package chat.rocket.android.layouthelper.chatroom;
import
android.view.View
;
import
android.view.ViewGroup
;
import
java.util.List
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.ddp.RoomSubscription
;
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
<
RoomSubscription
>
roomSubscriptionList
;
/**
* 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
(
ViewGroup
channelsContainer
,
ViewGroup
dmContainer
)
{
public
RoomListManager
(
View
unreadTitle
,
ViewGroup
unreadRoomsContainer
,
ViewGroup
channelsContainer
,
ViewGroup
dmContainer
,
boolean
unreadRoomMode
)
{
this
.
unreadTitle
=
unreadTitle
;
this
.
unreadRoomsContainer
=
unreadRoomsContainer
;
this
.
channelsContainer
=
channelsContainer
;
this
.
dmContainer
=
dmContainer
;
}
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
;
}
}
this
.
unreadRoomMode
=
unreadRoomMode
;
}
/**
* update ViewGroups with room list.
*/
public
void
setRooms
(
List
<
RoomSubscription
>
roomSubscriptionList
)
{
removeDeletedItem
(
channelsContainer
,
roomSubscriptionList
);
removeDeletedItem
(
dmContainer
,
roomSubscriptionList
);
for
(
RoomSubscription
roomSubscription
:
roomSubscriptionList
)
{
String
name
=
roomSubscription
.
getName
();
if
(
TextUtils
.
isEmpty
(
name
))
{
continue
;
}
String
type
=
roomSubscription
.
getType
();
if
(
RoomSubscription
.
TYPE_CHANNEL
.
equals
(
type
)
||
RoomSubscription
.
TYPE_PRIVATE
.
equals
(
type
))
{
insertOrUpdateItem
(
channelsContainer
,
roomSubscription
);
removeItemIfExists
(
dmContainer
,
name
);
}
else
if
(
RoomSubscription
.
TYPE_DIRECT_MESSAGE
.
equals
(
type
))
{
removeItemIfExists
(
channelsContainer
,
name
);
insertOrUpdateItem
(
dmContainer
,
roomSubscription
);
}
}
this
.
roomSubscriptionList
=
roomSubscriptionList
;
updateRoomsList
();
}
/**
...
...
@@ -86,6 +85,11 @@ public class RoomListManager {
}
}
public
void
setUnreadRoomMode
(
boolean
unreadRoomMode
)
{
this
.
unreadRoomMode
=
unreadRoomMode
;
updateRoomsList
();
}
private
void
insertOrUpdateItem
(
ViewGroup
parent
,
RoomSubscription
roomSubscription
)
{
final
String
roomName
=
roomSubscription
.
getName
();
...
...
@@ -129,10 +133,47 @@ public class RoomListManager {
}
}
/**
* Callback interface for List item clicked.
*/
public
interface
OnItemClickListener
{
void
onItemClick
(
RoomListItemView
roomListItemView
);
private
void
updateRoomsList
()
{
removeDeletedItem
(
unreadRoomsContainer
,
roomSubscriptionList
);
removeDeletedItem
(
channelsContainer
,
roomSubscriptionList
);
removeDeletedItem
(
dmContainer
,
roomSubscriptionList
);
for
(
RoomSubscription
roomSubscription
:
roomSubscriptionList
)
{
String
name
=
roomSubscription
.
getName
();
if
(
TextUtils
.
isEmpty
(
name
))
{
continue
;
}
String
type
=
roomSubscription
.
getType
();
if
(
unreadRoomMode
&&
roomSubscription
.
getUnread
()
>
0
)
{
insertOrUpdateItem
(
unreadRoomsContainer
,
roomSubscription
);
removeItemIfExists
(
channelsContainer
,
name
);
removeItemIfExists
(
dmContainer
,
name
);
}
else
if
(
RoomSubscription
.
TYPE_CHANNEL
.
equals
(
type
)
||
RoomSubscription
.
TYPE_PRIVATE
.
equals
(
type
))
{
removeItemIfExists
(
unreadRoomsContainer
,
name
);
insertOrUpdateItem
(
channelsContainer
,
roomSubscription
);
removeItemIfExists
(
dmContainer
,
name
);
}
else
if
(
RoomSubscription
.
TYPE_DIRECT_MESSAGE
.
equals
(
type
))
{
removeItemIfExists
(
unreadRoomsContainer
,
name
);
removeItemIfExists
(
channelsContainer
,
name
);
insertOrUpdateItem
(
dmContainer
,
roomSubscription
);
}
}
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/model/ddp/User.java
View file @
f2791a03
...
...
@@ -22,6 +22,7 @@ public class User extends RealmObject {
private
String
status
;
private
double
utcOffset
;
private
RealmList
<
Email
>
emails
;
private
Settings
settings
;
public
static
RealmQuery
<
User
>
queryCurrentUser
(
Realm
realm
)
{
return
realm
.
where
(
User
.
class
).
isNotEmpty
(
"emails"
);
...
...
@@ -66,4 +67,8 @@ public class User extends RealmObject {
public
void
setEmails
(
RealmList
<
Email
>
emails
)
{
this
.
emails
=
emails
;
}
public
Settings
getSettings
()
{
return
settings
;
}
}
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
f2791a03
...
...
@@ -140,7 +140,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
* synchronize the state of the thread with ServerConfig.
*/
@DebugLog
public
void
keep
a
live
()
{
public
void
keep
A
live
()
{
if
(
ddpClient
==
null
||
!
ddpClient
.
isConnected
())
{
defaultRealm
.
executeTransaction
(
realm
->
{
ServerConfig
config
=
realm
.
where
(
ServerConfig
.
class
)
...
...
@@ -242,9 +242,9 @@ public class RocketChatWebSocketThread extends HandlerThread {
Object
obj
=
ctor
.
newInstance
(
appContext
,
hostname
,
serverConfigRealm
,
ddpClient
);
if
(
obj
instanceof
Registrable
)
{
Registrable
regist
e
rable
=
(
Registrable
)
obj
;
regist
e
rable
.
register
();
listeners
.
add
(
regist
e
rable
);
Registrable
registrable
=
(
Registrable
)
obj
;
registrable
.
register
();
listeners
.
add
(
registrable
);
}
}
catch
(
Exception
exception
)
{
RCLog
.
w
(
exception
,
"Failed to register listeners!!"
);
...
...
@@ -260,8 +260,8 @@ public class RocketChatWebSocketThread extends HandlerThread {
Iterator
<
Registrable
>
iterator
=
listeners
.
iterator
();
while
(
iterator
.
hasNext
())
{
Registrable
regist
e
rable
=
iterator
.
next
();
regist
e
rable
.
unregister
();
Registrable
registrable
=
iterator
.
next
();
registrable
.
unregister
();
iterator
.
remove
();
}
if
(
ddpClient
!=
null
)
{
...
...
app/src/main/res/layout/fragment_sidebar_main.xml
View file @
f2791a03
This diff is collapsed.
Click to expand it.
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