Android-CleanArchitecture
Android-CleanArchitecture copied to clipboard
Q: How to deal with some IM(Instant Messaging) App
I am confused about how this architecture handles some frequently pushed messages(need to be presented as far as they can).
It seems to me that the event flow was just passive(presentationLayer ask for some not expired data from dataLayer and presented).
Am I wrong? if not, how about data from server like webSocket?
Hi, maybe my repository may help: https://github.com/roscrazy/Android-RealtimeUpdate-CleanArchitecture Even it's not up to date but I hope you can get the idea. The main point that we are using Rxjava, so you can listen from an Observable (incase Observable can emit many items at anytime). In data layer, you have to create Observable which will emit socket messages.
THX
I'm also struggling with this requirement of non-UI generated events. I did not find the above repo any help in this regard.
So typically, an event is fired on the UI layer and the presenter calls a Use Case. The Use Case manipulates one or more repositories and returns data to the presenter for (potentially) further transformation to a view model and pushed to the UI to display. This works.
So, for example, user requests to go to the Chat List screen, the presenter calls the GetChatList Use case (passing in the page number). The Use case queries the ChatRepository and the UserRepository to return a List of Chats to the presenter, which is subscribed for results.
However, my application has Chat functionality and the component that listens for incoming messages from the server is in the data layer and not known to the domain layer.
The approach I have taken is where I have Relays (customised rx subjects) are exposed to the ChatRepository the presenter listens to for events.
Even though it works, it completely subverts the use case approach and find its lack of symmetry troubling. Any thoughts?
Maybe this thread help you to get some ideas.
What I do in those scenarios is to implement an event bus. Events are pushed from Data layer and a Presenter subscribes to them. Then the presenter knows that something has changed and it has to refreshed its view by calling a Use Case to get the new info.
Remember Events should contain the minimum information as possible. You should not pass the entire message through it.