lundi 6 mai 2019

How to implement a reusable multistep state-machine into MVP?

In my Android app I have a multi step login procedure:

  1. Enter a id, and send to backend: firstCall(id)
    • If id was not found, request correct/another id
    • if id correct, continue step with 2.
  2. Enter Password and send (hash) to backend secondCall(password)
    • if password wrong, request again (limited)
    • if password correct continue with 3.
  3. Backend responds with a time limited token for this session (sessionToken)
    1. Do one thing with this token

There are wrongId() and correctId() callbacks for 1. There are wrongPassword() and correctPassword() callbacks for 2.

I have implemented this already successfully in my Android app by means of using MVP pattern.

Since I use this login procedure on different Activities (all in MVP), I have a lot of duplicate code. I extracted this login to a separat class, what would be used still in the presenter. But then I have the problem of requesting wrong passwords?

Do I need the callbacks implemented in all my presenters? How would I notify the currently used presenter of wrong passwords etc?

Aucun commentaire:

Enregistrer un commentaire