levibostian / Wendy-Android

Build offline first Android mobile apps. Remove loading screens, perform tasks instantly.
https://levibostian.github.io/Wendy-Android/wendy/
MIT License
64 stars 16 forks source link

Support an app with multiple users. #42

Closed levibostian closed 6 years ago

levibostian commented 6 years ago

Use case: A user logs into your app. They do some tasks that are performed by Wendy. The user logs out and another user logs in.

What do you do?

  1. You could warn the user via a View that there are some tasks that need to sync with your backend successfully.
  2. Keep the Wendy tasks running for both users at the same time to sync both.
  3. Delete all Wendy data for the current user and go onto the next.
  4. Create a new database for the new user leaving the old database for the other to use if they wish in the future to switch back to.

There are pros and cons to all of the options above, but it all depends on how you are building your app. I don't want to be opinionated, so I should add functionality and give the power to the user on how to do each.

Here is the action plan for all of the above options:

  1. Technically, you can already do this. We provide Wendy.shared.getAllTasks() to check if it's empty. You can then add a task runner listener and watch progress if you wish on the runner as it goes through tasks. Done!
  2. If Wendy has 1 single database with all of the PendingTasks for all users, you can already do this. I would have the dataId for a PendingTask have a suffix for the user ID of a user. Done!
  3. There is no ability for this. I should add it. A way to stop Wendy from running and delete the whole database and shared prefs. All data. Reset.
  4. I like this idea as well. Having multiple databases. I like this idea because this is how I build apps. Having Wendy use a default database until it is told to belong to a specific user where it then uses a new database. Then when it's given a new user id again, it will switch to an existing database or create a new one. And the task runner will only run tasks for a given user.
levibostian commented 6 years ago

After some thoughts on this, I am going to skip option (4) above. I do not see a big reason to add multiple databases right now. Technically, you can hack Wendy right now for multiple user's logged in at once and separate their data. No need for multiple databases. As long as it aligns with the correct user, it doesn't matter.

As far as clearing data, I have added that ability and it will be released with the newest release of the library.