I am building an android chat application, where I am storing the data on the local device using SQLite Database. I am struggling to figure out how to stop chat message recycler view from blinking.
For the background. I am using websockets for sending and receiving chat messages. So, whenever the application is opened, the websocket connects and its starts fetching new messages.
Suppose, I am in a chat window talking to some person and somehow my internet went off. At this point, the other person sent some messages that got stored in server. And now in the meantime i send two messages for which I have not received the acknoledgement yet(as I am not connected to internet), but i have added them to my chat window. Now when my internet comes back, I fetch previous messages. Which in then get added to my local database from where my live data is getting updated and i get a callback and I insert the updated messages into recycler view. Now as per the server the two messages that the other person sent were before my unsent messages. They get added in between, which is leading to blinking in recycler view. I am not sure how to avoid it?