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) {
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
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 {
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))
}
}
......
......@@ -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,19 +157,41 @@ 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
}
}
......
......@@ -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
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