Commit 464896d4 authored by shubhsherl's avatar shubhsherl

Notify new message in the chat room

parent 4c5a07f7
...@@ -257,7 +257,7 @@ class ChatRoomPresenter @Inject constructor( ...@@ -257,7 +257,7 @@ class ChatRoomPresenter @Inject constructor(
newMessage, RoomUiModel( newMessage, RoomUiModel(
roles = chatRoles, isBroadcast = chatIsBroadcast roles = chatRoles, isBroadcast = chatIsBroadcast
) )
) ), false
) )
client.sendMessage(id, chatRoomId, text) client.sendMessage(id, chatRoomId, text)
} catch (ex: Exception) { } catch (ex: Exception) {
...@@ -447,7 +447,7 @@ class ChatRoomPresenter @Inject constructor( ...@@ -447,7 +447,7 @@ class ChatRoomPresenter @Inject constructor(
messagesRepository.saveAll(messages.result) messagesRepository.saveAll(messages.result)
launchUI(strategy) { launchUI(strategy) {
view.showNewMessage(models) view.showNewMessage(models, true)
} }
if (messages.result.size == 50) { if (messages.result.size == 50) {
...@@ -959,7 +959,7 @@ class ChatRoomPresenter @Inject constructor( ...@@ -959,7 +959,7 @@ class ChatRoomPresenter @Inject constructor(
} else { } else {
Timber.d("Adding new message") Timber.d("Adding new message")
messagesRepository.save(streamedMessage) messagesRepository.save(streamedMessage)
view.showNewMessage(viewModelStreamedMessage) view.showNewMessage(viewModelStreamedMessage, true)
} }
} }
} }
......
...@@ -67,7 +67,7 @@ interface ChatRoomView : LoadingView, MessageView { ...@@ -67,7 +67,7 @@ interface ChatRoomView : LoadingView, MessageView {
* *
* @param message The (recent) message sent to a chat room. * @param message The (recent) message sent to a chat room.
*/ */
fun showNewMessage(message: List<BaseUiModel<*>>) fun showNewMessage(message: List<BaseUiModel<*>>, isMessageReceived: Boolean)
/** /**
* Dispatch to the recycler views adapter that we should remove a message. * Dispatch to the recycler views adapter that we should remove a message.
......
...@@ -126,6 +126,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -126,6 +126,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
private lateinit var chatRoomId: String private lateinit var chatRoomId: String
private lateinit var chatRoomName: String private lateinit var chatRoomName: String
private lateinit var chatRoomType: String private lateinit var chatRoomType: String
private var newMessageCount: Int = 0
private var chatRoomMessage: String? = null private var chatRoomMessage: String? = null
private var isSubscribed: Boolean = true private var isSubscribed: Boolean = true
private var isReadOnly: Boolean = false private var isReadOnly: Boolean = false
...@@ -425,10 +426,13 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -425,10 +426,13 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
private val fabScrollListener = object : RecyclerView.OnScrollListener() { private val fabScrollListener = object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
if (!recyclerView.canScrollVertically(1)) { if (!recyclerView.canScrollVertically(1)) {
text_count.visibility = View.INVISIBLE
button_fab.hide() button_fab.hide()
newMessageCount = 0
} else { } else {
if (dy < 0 && !button_fab.isVisible) { if (dy < 0 && !button_fab.isVisible) {
button_fab.show() button_fab.show()
if (newMessageCount !=0) text_count.visibility = View.VISIBLE
} }
} }
} }
...@@ -486,9 +490,21 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -486,9 +490,21 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
showMessage(getString(R.string.msg_invalid_file)) showMessage(getString(R.string.msg_invalid_file))
} }
override fun showNewMessage(message: List<BaseUiModel<*>>) { override fun showNewMessage(message: List<BaseUiModel<*>>, isMessageReceived: Boolean) {
ui { ui {
adapter.prependData(message) adapter.prependData(message)
if (isMessageReceived && button_fab.visibility == View.VISIBLE) {
newMessageCount++
if (newMessageCount <= 99)
text_count.text = newMessageCount.toString()
else
text_count.text = "99+"
text_count.visibility = View.VISIBLE
}
else if (button_fab.visibility == View.GONE)
recycler_view.scrollToPosition(0)
verticalScrollOffset.set(0) verticalScrollOffset.set(0)
empty_chat_view.isVisible = adapter.itemCount == 0 empty_chat_view.isVisible = adapter.itemCount == 0
} }
...@@ -723,7 +739,9 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR ...@@ -723,7 +739,9 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardListener, EmojiR
button_fab.setOnClickListener { button_fab.setOnClickListener {
recycler_view.scrollToPosition(0) recycler_view.scrollToPosition(0)
verticalScrollOffset.set(0) verticalScrollOffset.set(0)
text_count.visibility = View.INVISIBLE
button_fab.hide() button_fab.hide()
newMessageCount = 0
} }
} }
......
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#30a7fe" />
<size
android:height="20dp"
android:width="20dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
...@@ -10,18 +11,44 @@ ...@@ -10,18 +11,44 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollbars="vertical" /> android:scrollbars="vertical" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/button_fab" <RelativeLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="16dp" android:layout_alignParentEnd="true"
android:src="@drawable/ic_arrow_downward_24dp" android:layout_alignParentBottom="true"
android:theme="@style/Theme.AppCompat"
android:tint="@color/actionMenuColor"
android:visibility="invisible"
app:backgroundTint="@color/colorWhite"
app:fabSize="mini"
app:layout_anchor="@id/recycler_view" app:layout_anchor="@id/recycler_view"
app:layout_anchorGravity="bottom|end" /> app:layout_anchorGravity="bottom|end">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/button_fab"
android:layout_alignParentEnd="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_margin="16dp"
android:src="@drawable/ic_arrow_downward_24dp"
android:theme="@style/Theme.AppCompat"
android:tint="@color/actionMenuColor"
app:backgroundTint="@color/colorWhite"
app:fabSize="mini" />
<TextView
android:id="@+id/text_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="7dp"
android:padding="2dp"
android:gravity="center"
android:layout_margin="10dp"
android:textColor="@color/colorWhite"
android:visibility="invisible"
android:layout_alignParentRight="true"
android:textSize="@dimen/message_time_text_size"
android:background="@drawable/round_textview" />
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
\ 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