Unverified Commit 3eaba537 authored by Upendra Reddy's avatar Upendra Reddy Committed by GitHub

Merge branch 'develop' into issue-profile-render

parents a377458f 14cc4292
...@@ -15,6 +15,10 @@ class ChatRoomsRepository @Inject constructor(private val dao: ChatRoomDao) { ...@@ -15,6 +15,10 @@ class ChatRoomsRepository @Inject constructor(private val dao: ChatRoomDao) {
Order.GROUPED_ACTIVITY -> dao.getAllGrouped() Order.GROUPED_ACTIVITY -> dao.getAllGrouped()
Order.NAME -> dao.getAllAlphabetically() Order.NAME -> dao.getAllAlphabetically()
Order.GROUPED_NAME -> dao.getAllAlphabeticallyGrouped() 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) { ...@@ -28,8 +32,16 @@ class ChatRoomsRepository @Inject constructor(private val dao: ChatRoomDao) {
GROUPED_ACTIVITY, GROUPED_ACTIVITY,
NAME, NAME,
GROUPED_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 fun ChatRoomsRepository.Order.isGrouped(): Boolean = this == ChatRoomsRepository.Order.GROUPED_ACTIVITY
|| this == ChatRoomsRepository.Order.GROUPED_NAME || this == ChatRoomsRepository.Order.GROUPED_NAME
\ No newline at end of file
fun ChatRoomsRepository.Order.isUnreadOnTop(): Boolean = this == ChatRoomsRepository.Order.UNREAD_ON_TOP_ACTIVITY
|| this == ChatRoomsRepository.Order.UNREAD_ON_TOP_NAME
...@@ -301,10 +301,10 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { ...@@ -301,10 +301,10 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
this.isGroupByFavorites = isGroupByFavorites this.isGroupByFavorites = isGroupByFavorites
if (isSortByName) { if (isSortByName) {
viewModel.setQuery(Query.ByName(isGroupByType)) viewModel.setQuery(Query.ByName(isGroupByType, isUnreadOnTop))
changeSortByTitle(getString(R.string.msg_sort_by_name)) changeSortByTitle(getString(R.string.msg_sort_by_name))
} else { } else {
viewModel.setQuery(Query.ByActivity(isGroupByType)) viewModel.setQuery(Query.ByActivity(isGroupByType, isUnreadOnTop))
changeSortByTitle(getString(R.string.msg_sort_by_activity)) changeSortByTitle(getString(R.string.msg_sort_by_activity))
} }
} }
...@@ -324,9 +324,9 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { ...@@ -324,9 +324,9 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
private fun showAllChats() { private fun showAllChats() {
if (isSortByName) { if (isSortByName) {
viewModel.setQuery(Query.ByName(isGroupByType)) viewModel.setQuery(Query.ByName(isGroupByType, isUnreadOnTop))
} else { } else {
viewModel.setQuery(Query.ByActivity(isGroupByType)) viewModel.setQuery(Query.ByActivity(isGroupByType, isUnreadOnTop))
} }
} }
......
...@@ -140,8 +140,10 @@ sealed class LoadingState { ...@@ -140,8 +140,10 @@ sealed class LoadingState {
} }
sealed class Query { 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() data class Search(val query: String) : Query()
} }
...@@ -155,22 +157,44 @@ fun Query.isGrouped(): Boolean { ...@@ -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 { fun Query.asSortingOrder(): ChatRoomsRepository.Order {
return when(this) { return when(this) {
is Query.ByName -> { is Query.ByName -> {
if (grouped) { if (grouped && !unreadOnTop) {
ChatRoomsRepository.Order.GROUPED_NAME 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 ChatRoomsRepository.Order.NAME
} }
} }
is Query.ByActivity -> { is Query.ByActivity -> {
if (grouped) { if (grouped && !unreadOnTop) {
ChatRoomsRepository.Order.GROUPED_ACTIVITY 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 ChatRoomsRepository.Order.ACTIVITY
} }
} }
else -> throw IllegalArgumentException("Should be ByName or ByActivity") else -> throw IllegalArgumentException("Should be ByName or ByActivity")
} }
} }
\ No newline at end of file
...@@ -65,6 +65,54 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> { ...@@ -65,6 +65,54 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> {
""") """)
abstract fun getAllGrouped(): LiveData<List<ChatRoom>> 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 @Transaction
@Query(""" @Query("""
$BASE_QUERY $BASE_QUERY
...@@ -139,5 +187,11 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> { ...@@ -139,5 +187,11 @@ abstract class ChatRoomDao : BaseDao<ChatRoomEntity> {
ELSE 5 ELSE 5
END END
""" """
const val UNREAD = """
CASE
WHEN alert OR unread > 0 THEN 1
ELSE 2
END
"""
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment