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
14cc4292
Unverified
Commit
14cc4292
authored
Apr 29, 2019
by
Filipe de Lima Brito
Committed by
GitHub
Apr 29, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2263 from NBAMIR/2254-nbamir
[NEW] Sort chats by unread on top.
parents
fdf25924
df90f988
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
12 deletions
+102
-12
ChatRoomsRepository.kt
...t/android/chatrooms/infrastructure/ChatRoomsRepository.kt
+13
-1
ChatRoomsFragment.kt
...ava/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt
+4
-4
ChatRoomsViewModel.kt
.../rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt
+31
-7
ChatRoomDao.kt
app/src/main/java/chat/rocket/android/db/ChatRoomDao.kt
+54
-0
No files found.
app/src/main/java/chat/rocket/android/chatrooms/infrastructure/ChatRoomsRepository.kt
View file @
14cc4292
...
...
@@ -15,6 +15,10 @@ class ChatRoomsRepository @Inject constructor(private val dao: ChatRoomDao) {
Order
.
GROUPED_ACTIVITY
->
dao
.
getAllGrouped
()
Order
.
NAME
->
dao
.
getAllAlphabetically
()
Order
.
GROUPED_NAME
->
dao
.
getAllAlphabeticallyGrouped
()
Order
.
UNREAD_ON_TOP_ACTIVITY
->
dao
.
getAllUnread
();
Order
.
UNREAD_ON_TOP_NAME
->
dao
.
getAllAlphabeticallyUnread
();
Order
.
UNREAD_ON_TOP_GROUPED_ACTIVITY
->
dao
.
getAllGroupedUnread
();
Order
.
UNREAD_ON_TOP_GROUPED_NAME
->
dao
.
getAllAlphabeticallyGroupedUnread
();
}
}
...
...
@@ -28,8 +32,16 @@ class ChatRoomsRepository @Inject constructor(private val dao: ChatRoomDao) {
GROUPED_ACTIVITY
,
NAME
,
GROUPED_NAME
,
UNREAD_ON_TOP_ACTIVITY
,
UNREAD_ON_TOP_NAME
,
UNREAD_ON_TOP_GROUPED_ACTIVITY
,
UNREAD_ON_TOP_GROUPED_NAME
}
}
fun
ChatRoomsRepository
.
Order
.
isGrouped
():
Boolean
=
this
==
ChatRoomsRepository
.
Order
.
GROUPED_ACTIVITY
||
this
==
ChatRoomsRepository
.
Order
.
GROUPED_NAME
\ No newline at end of file
||
this
==
ChatRoomsRepository
.
Order
.
GROUPED_NAME
fun
ChatRoomsRepository
.
Order
.
isUnreadOnTop
():
Boolean
=
this
==
ChatRoomsRepository
.
Order
.
UNREAD_ON_TOP_ACTIVITY
||
this
==
ChatRoomsRepository
.
Order
.
UNREAD_ON_TOP_NAME
app/src/main/java/chat/rocket/android/chatrooms/ui/ChatRoomsFragment.kt
View file @
14cc4292
...
...
@@ -301,10 +301,10 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
this
.
isGroupByFavorites
=
isGroupByFavorites
if
(
isSortByName
)
{
viewModel
.
setQuery
(
Query
.
ByName
(
isGroupByType
))
viewModel
.
setQuery
(
Query
.
ByName
(
isGroupByType
,
isUnreadOnTop
))
changeSortByTitle
(
getString
(
R
.
string
.
msg_sort_by_name
))
}
else
{
viewModel
.
setQuery
(
Query
.
ByActivity
(
isGroupByType
))
viewModel
.
setQuery
(
Query
.
ByActivity
(
isGroupByType
,
isUnreadOnTop
))
changeSortByTitle
(
getString
(
R
.
string
.
msg_sort_by_activity
))
}
}
...
...
@@ -324,9 +324,9 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
private
fun
showAllChats
()
{
if
(
isSortByName
)
{
viewModel
.
setQuery
(
Query
.
ByName
(
isGroupByType
))
viewModel
.
setQuery
(
Query
.
ByName
(
isGroupByType
,
isUnreadOnTop
))
}
else
{
viewModel
.
setQuery
(
Query
.
ByActivity
(
isGroupByType
))
viewModel
.
setQuery
(
Query
.
ByActivity
(
isGroupByType
,
isUnreadOnTop
))
}
}
...
...
app/src/main/java/chat/rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt
View file @
14cc4292
...
...
@@ -140,8 +140,10 @@ sealed class LoadingState {
}
sealed
class
Query
{
data class
ByActivity
(
val
grouped
:
Boolean
=
false
)
:
Query
()
data class
ByName
(
val
grouped
:
Boolean
=
false
)
:
Query
()
data class
ByActivity
(
val
grouped
:
Boolean
=
false
,
val
unreadOnTop
:
Boolean
=
false
)
:
Query
()
data class
ByName
(
val
grouped
:
Boolean
=
false
,
val
unreadOnTop
:
Boolean
=
false
)
:
Query
()
data class
Search
(
val
query
:
String
)
:
Query
()
}
...
...
@@ -155,22 +157,44 @@ fun Query.isGrouped(): Boolean {
}
}
fun
Query
.
isUnreadOnTop
():
Boolean
{
return
when
(
this
)
{
is
Query
.
Search
->
false
is
Query
.
ByName
->
unreadOnTop
is
Query
.
ByActivity
->
unreadOnTop
}
}
fun
Query
.
asSortingOrder
():
ChatRoomsRepository
.
Order
{
return
when
(
this
)
{
is
Query
.
ByName
->
{
if
(
grouped
)
{
if
(
grouped
&&
!
unreadOnTop
)
{
ChatRoomsRepository
.
Order
.
GROUPED_NAME
}
else
{
}
else
if
(
unreadOnTop
&&
!
grouped
){
ChatRoomsRepository
.
Order
.
UNREAD_ON_TOP_NAME
}
else
if
(
unreadOnTop
&&
grouped
){
ChatRoomsRepository
.
Order
.
UNREAD_ON_TOP_GROUPED_NAME
}
else
{
ChatRoomsRepository
.
Order
.
NAME
}
}
is
Query
.
ByActivity
->
{
if
(
grouped
)
{
if
(
grouped
&&
!
unreadOnTop
)
{
ChatRoomsRepository
.
Order
.
GROUPED_ACTIVITY
}
else
{
}
else
if
(
unreadOnTop
&&
!
grouped
){
ChatRoomsRepository
.
Order
.
UNREAD_ON_TOP_ACTIVITY
}
else
if
(
unreadOnTop
&&
grouped
){
ChatRoomsRepository
.
Order
.
UNREAD_ON_TOP_GROUPED_ACTIVITY
}
else
{
ChatRoomsRepository
.
Order
.
ACTIVITY
}
}
else
->
throw
IllegalArgumentException
(
"Should be ByName or ByActivity"
)
}
}
}
\ No newline at end of file
app/src/main/java/chat/rocket/android/db/ChatRoomDao.kt
View file @
14cc4292
...
...
@@ -65,6 +65,54 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> {
"""
)
abstract
fun
getAllGrouped
():
LiveData
<
List
<
ChatRoom
>>
@Transaction
@Query
(
"""
$BASE_QUERY
$FILTER_NOT_OPENED
ORDER BY
$UNREAD,
CASE
WHEN lastMessageTimeStamp IS NOT NULL THEN lastMessageTimeStamp
ELSE updatedAt
END DESC
"""
)
abstract
fun
getAllUnread
():
LiveData
<
List
<
ChatRoom
>>
@Transaction
@Query
(
"""
$BASE_QUERY
$FILTER_NOT_OPENED
ORDER BY
$UNREAD,
name COLLATE NOCASE
"""
)
abstract
fun
getAllAlphabeticallyUnread
():
LiveData
<
List
<
ChatRoom
>>
@Transaction
@Query
(
"""
$BASE_QUERY
$FILTER_NOT_OPENED
ORDER BY
$TYPE_ORDER,
$UNREAD,
name COLLATE NOCASE
"""
)
abstract
fun
getAllAlphabeticallyGroupedUnread
():
LiveData
<
List
<
ChatRoom
>>
@Transaction
@Query
(
"""
$BASE_QUERY
$FILTER_NOT_OPENED
ORDER BY
$TYPE_ORDER,
$UNREAD,
CASE
WHEN lastMessageTimeStamp IS NOT NULL THEN lastMessageTimeStamp
ELSE updatedAt
END DESC
"""
)
abstract
fun
getAllGroupedUnread
():
LiveData
<
List
<
ChatRoom
>>
@Transaction
@Query
(
"""
$BASE_QUERY
...
...
@@ -139,5 +187,11 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> {
ELSE 5
END
"""
const
val
UNREAD
=
"""
CASE
WHEN alert OR unread > 0 THEN 1
ELSE 2
END
"""
}
}
\ No newline at end of file
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