GSoC 2021: Android Client Project 3.0.x - Offline Feature Strategies

Hello, I am trying to think of how we can implement offline support for the client. I’ve already explored and tested the code for the current provider module which supports offline operations, and I’ve raised these issues about this: AC-968, AC-969, AC-970

(AC-969 is similar to what described and solved here on Github AC-747 PR)

I fixed these issues and will make PRs once marked ready for work, but I want to discuss my thoughts about the structure of the offline mode:

  1. First, about the strategy we can follow in offline support that should avoid some problems that are consequences of the above issues. The current provider module in the app displays only the local DB as long as it is not empty, however, suppose that the client is offline and some changes are done locally for a patient or a provider, and someone else using another client or the web app, or the server itself modifies the same patient. Now the first client gets back online, should that client sync to the server or the server sync to the client?
  • My thought is that we can display a dialog to the client requesting to select which data is correct and synced to the other (like Git: Accept yours? or theirs?).
  1. There is another thing that may make a problem: When the client creates a new local provider during offline mode in the current provider module and then gets back online, sometimes the Worker is not triggered to sync data immediately. If we try to edit or delete this provider before it gets synced and before retrieving its UUID, we won’t be able to! because the current UUID is null, thus we can’t search for it in the DB.
  • We can use the local id of that provider in Room DB when working offline as long as there is no UUID retrieved yet?
  1. Lastly, can we remove the sync icon in the app bar after we implement offline mode for the whole app? As the data will be automatically synced once getting back online. Is it required to provide the choice of not to sync? Currently, when switching on wifi, we have to switch on the sync button as well, which delays the Worker as it depends on NetworkUtils.isOnline() thus fails when the sync button is off and retries after a while. Also, I think that when the user tries to get a list of data from the server (e.g. providers) in an activity, we should sync with it immediately before displaying it instead of waiting for the Worker to sync, as it won’t be a great UX waiting for the message of success and displaying old data even though the network is on, as well as to avoid possible bugs that may occur if the Worker has updated data during locally modifying the old ones.

I would appreciate your time! @saurabh @rishabh997

(although, its very unlikely to edit the same field of a patient from 2 seperate devices concurrently) IMO first the server should sync and then on top of that the offline edit should be applied.

Yes I think so the ProviderDAO has some methods using Ids instead of UUIDs would need to check though.

That can be done but for now I think we should keep it as it is and work on the functionality first, if it poses some problems we can discuss about it in any specific Issue on JIRA.

Made the Issues Ready lets discuss more on the specific Issues so that conversation dosent gets fragmented. :+1:

1 Like

Thank you! I am working on them now.