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
701430de
Commit
701430de
authored
Jan 16, 2017
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unread message indicator
parent
1e2a248d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
126 additions
and
3 deletions
+126
-3
RoomFragment.java
...a/chat/rocket/android/fragment/chatroom/RoomFragment.java
+73
-3
RecyclerViewAutoScrollManager.java
.../rocket/android/helper/RecyclerViewAutoScrollManager.java
+6
-0
NewMessageIndicatorManager.java
...oid/layouthelper/chatroom/NewMessageIndicatorManager.java
+43
-0
Message.java
app/src/main/java/chat/rocket/android/model/ddp/Message.java
+1
-0
strings.xml
app/src/main/res/values/strings.xml
+3
-0
No files found.
app/src/main/java/chat/rocket/android/fragment/chatroom/RoomFragment.java
View file @
701430de
...
...
@@ -6,6 +6,7 @@ import android.content.Intent;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.design.widget.Snackbar
;
import
android.support.v4.view.GravityCompat
;
import
android.support.v4.widget.DrawerLayout
;
import
android.support.v4.widget.SlidingPaneLayout
;
...
...
@@ -32,6 +33,7 @@ import chat.rocket.android.helper.RecyclerViewScrolledToBottomListener;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.layouthelper.chatroom.MessageFormManager
;
import
chat.rocket.android.layouthelper.chatroom.MessageListAdapter
;
import
chat.rocket.android.layouthelper.chatroom.NewMessageIndicatorManager
;
import
chat.rocket.android.layouthelper.chatroom.PairedMessage
;
import
chat.rocket.android.layouthelper.extra_action.MessageExtraActionBehavior
;
import
chat.rocket.android.layouthelper.extra_action.upload.AbstractUploadActionItem
;
...
...
@@ -73,6 +75,9 @@ public class RoomFragment extends AbstractChatRoomFragment
private
RealmObjectObserver
<
LoadMessageProcedure
>
procedureObserver
;
private
MessageFormManager
messageFormManager
;
private
RecyclerViewAutoScrollManager
autoScrollManager
;
private
NewMessageIndicatorManager
newMessageIndicatorManager
;
private
Snackbar
unreadIndicator
;
private
boolean
previousUnreadMessageExists
;
public
RoomFragment
()
{
}
...
...
@@ -148,7 +153,14 @@ public class RoomFragment extends AbstractChatRoomFragment
LinearLayoutManager
layoutManager
=
new
LinearLayoutManager
(
getContext
(),
LinearLayoutManager
.
VERTICAL
,
true
);
listView
.
setLayoutManager
(
layoutManager
);
autoScrollManager
=
new
RecyclerViewAutoScrollManager
(
layoutManager
);
autoScrollManager
=
new
RecyclerViewAutoScrollManager
(
layoutManager
)
{
@Override
protected
void
onAutoScrollMissed
()
{
if
(
newMessageIndicatorManager
!=
null
)
{
newMessageIndicatorManager
.
updateNewMessageCount
(
getUnreadMessageCount
());
}
}
};
adapter
.
registerAdapterDataObserver
(
autoScrollManager
);
scrollListener
=
new
LoadMoreScrollListener
(
layoutManager
,
40
)
{
...
...
@@ -161,10 +173,59 @@ public class RoomFragment extends AbstractChatRoomFragment
listView
.
addOnScrollListener
(
new
RecyclerViewScrolledToBottomListener
(
layoutManager
,
1
,
this
::
markAsReadIfNeeded
));
newMessageIndicatorManager
=
new
NewMessageIndicatorManager
()
{
@Override
protected
void
onShowIndicator
(
int
count
,
boolean
onlyAlreadyShown
)
{
if
((
onlyAlreadyShown
&&
unreadIndicator
!=
null
&&
unreadIndicator
.
isShown
())
||
!
onlyAlreadyShown
)
{
unreadIndicator
=
getUnreadCountIndicatorView
(
count
);
unreadIndicator
.
show
();
}
}
@Override
protected
void
onHideIndicator
()
{
if
(
unreadIndicator
!=
null
&&
unreadIndicator
.
isShown
())
{
unreadIndicator
.
dismiss
();
}
}
};
setupSideMenu
();
setupMessageComposer
();
}
private
void
scrollToLatestMessage
()
{
RecyclerView
listView
=
(
RecyclerView
)
rootView
.
findViewById
(
R
.
id
.
recyclerview
);
if
(
listView
!=
null
)
{
listView
.
smoothScrollToPosition
(
0
);
}
}
private
Snackbar
getUnreadCountIndicatorView
(
int
count
)
{
// TODO: replace with another custom View widget, not to hide message composer.
final
String
caption
=
getResources
().
getString
(
R
.
string
.
fmt_dialog_view_latest_message_title
,
count
);
return
Snackbar
.
make
(
rootView
,
caption
,
Snackbar
.
LENGTH_LONG
)
.
setAction
(
R
.
string
.
dialog_view_latest_message_action
,
view
->
scrollToLatestMessage
());
}
private
int
getUnreadMessageCount
()
{
RoomSubscription
room
=
realmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
RoomSubscription
.
class
).
equalTo
(
RoomSubscription
.
ROOM_ID
,
roomId
).
findFirst
());
if
(
room
!=
null
)
{
return
realmHelper
.
executeTransactionForReadResults
(
realm
->
realm
.
where
(
Message
.
class
)
.
equalTo
(
Message
.
ROOM_ID
,
roomId
)
.
greaterThanOrEqualTo
(
Message
.
TIMESTAMP
,
room
.
getLastSeen
())
.
notEqualTo
(
Message
.
USER_ID
,
userId
)
.
findAll
()).
size
();
}
else
{
return
0
;
}
}
@Override
public
void
onDestroyView
()
{
RecyclerView
listView
=
(
RecyclerView
)
rootView
.
findViewById
(
R
.
id
.
recyclerview
);
...
...
@@ -244,7 +305,11 @@ public class RoomFragment extends AbstractChatRoomFragment
.
put
(
Message
.
SYNC_STATE
,
SyncState
.
NOT_SYNCED
)
.
put
(
Message
.
TIMESTAMP
,
System
.
currentTimeMillis
())
.
put
(
Message
.
ROOM_ID
,
roomId
)
.
put
(
Message
.
MESSAGE
,
messageText
))));
.
put
(
Message
.
MESSAGE
,
messageText
)))
.
onSuccess
(
_task
->
{
scrollToLatestMessage
();
return
null
;
}));
messageFormManager
.
registerExtraActionItem
(
new
ImageUploadActionItem
());
messageFormManager
.
registerExtraActionItem
(
new
AudioUploadActionItem
());
messageFormManager
.
registerExtraActionItem
(
new
VideoUploadActionItem
());
...
...
@@ -289,6 +354,12 @@ public class RoomFragment extends AbstractChatRoomFragment
setToolbarRoomIcon
(
0
);
}
setToolbarTitle
(
roomSubscription
.
getName
());
boolean
unreadMessageExists
=
roomSubscription
.
isAlert
();
if
(
newMessageIndicatorManager
!=
null
&&
previousUnreadMessageExists
&&
!
unreadMessageExists
)
{
newMessageIndicatorManager
.
reset
();
}
previousUnreadMessageExists
=
unreadMessageExists
;
}
private
void
onUpdateLoadMessageProcedure
(
LoadMessageProcedure
procedure
)
{
...
...
@@ -360,7 +431,6 @@ public class RoomFragment extends AbstractChatRoomFragment
roomObserver
.
sub
();
procedureObserver
.
sub
();
closeSideMenuIfNeeded
();
markAsReadIfNeeded
();
}
@Override
...
...
app/src/main/java/chat/rocket/android/helper/RecyclerViewAutoScrollManager.java
View file @
701430de
...
...
@@ -20,6 +20,12 @@ public class RecyclerViewAutoScrollManager extends RecyclerView.AdapterDataObser
if
(
linearLayoutManager
.
findFirstVisibleItemPosition
()
<=
positionStart
)
{
linearLayoutManager
.
scrollToPosition
(
positionStart
);
}
else
{
onAutoScrollMissed
();
}
}
protected
void
onAutoScrollMissed
()
{
//do nothing by default.
}
}
app/src/main/java/chat/rocket/android/layouthelper/chatroom/NewMessageIndicatorManager.java
0 → 100644
View file @
701430de
package
chat
.
rocket
.
android
.
layouthelper
.
chatroom
;
/**
* manager class for showing "You have XX messages" indicator.
*/
public
abstract
class
NewMessageIndicatorManager
{
private
int
count
;
private
boolean
onlyAlreadyShown
;
/**
* update the number of unread message.
*/
public
void
updateNewMessageCount
(
int
count
)
{
if
(
count
>
0
)
{
this
.
count
=
count
;
update
();
onlyAlreadyShown
=
true
;
}
else
{
reset
();
}
}
/**
* Should call this method when user checked new message.
*/
public
void
reset
()
{
count
=
0
;
onlyAlreadyShown
=
false
;
update
();
}
private
void
update
()
{
if
(
count
>
0
)
{
onShowIndicator
(
count
,
onlyAlreadyShown
);
}
else
{
onHideIndicator
();
}
}
protected
abstract
void
onShowIndicator
(
int
count
,
boolean
onlyAlreadyShown
);
protected
abstract
void
onHideIndicator
();
}
app/src/main/java/chat/rocket/android/model/ddp/Message.java
View file @
701430de
...
...
@@ -25,6 +25,7 @@ public class Message extends RealmObject {
@SuppressWarnings
({
"PMD.AvoidFieldNameMatchingTypeName"
})
public
static
final
String
MESSAGE
=
"msg"
;
public
static
final
String
USER
=
"u"
;
public
static
final
String
USER_ID
=
"u._id"
;
public
static
final
String
GROUPABLE
=
"groupable"
;
public
static
final
String
ATTACHMENTS
=
"attachments"
;
public
static
final
String
URLS
=
"urls"
;
...
...
app/src/main/res/values/strings.xml
View file @
701430de
...
...
@@ -18,6 +18,9 @@
<string
name=
"resend"
>
Resend
</string>
<string
name=
"discard"
>
Discard
</string>
<string
name=
"fmt_dialog_view_latest_message_title"
>
New %d messages
</string>
<string
name=
"dialog_view_latest_message_action"
>
View
</string>
<string
name=
"file_uploading_title"
>
Uploading…
</string>
<string
name=
"dialog_user_registration_email"
>
Email
</string>
...
...
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