I have a large application that has:
- some fragments that need to show real-time data received via Bluetooth (using a Foreground Service to keep the connection alive with a Health Device).
- some fragments that show stored data - may need to access a Repo (and thus, using a MVVM Architectural Component pattern is fine, moreover, even recommended).
My question is simple:
Is it right (from architectural point of view/app design) not to use the flow: View-ViewModel-Repo-DB/Cloud access, for the whole application? - applying the Android's pattern just for those Fragments/Activities that do show stored data.
I am asking this, as long as showing real-time data (not stored in a persistant storage, but broadcasted by the Service) does not fold on MVVM pattern: (Repo of what? I haven't 2-3-4-5 sources of data to manage them; ViewModel of what?) I can just have several LiveData objects - in a Singleton class - updated by the Service / or the Service can send "real-time" broadcasts (so the Activities are just binding to the Service or observing some LiveData objects from the Singleton class), it doesn't matter).
The idea behind this problem is that the Foreground Service is a source of data but not persistent data. If applying the Android's MVVM design for the whole app, an additional question arises:
- where is "placed" the Foreground Service in this diagram? It is an app component, so it should be on the same level with Activity/Fragment. On the other hand, it is a source of data. (and thus, it should be placed under Repository).
Also, I have some SharedPref used by UI and the Service, for example:
- ALERT_HEART_RATE - the Service alerts the user when the value received is >= ALERT_HEART_RATE; - the Activity shows this value/offer the posibility to change this value.
Thanks.