dimanche 3 février 2019

Having problems applying android code architecture/design patterns

I want to achieve the following:

I receive a notification via FCM with a specific id in the data properties. I get the id both when my app is in foreground and in the background/closed...so far so good.
Now I want to do the following:

  1. Make a volley request to e.g. /books/id to get the corresponding book informations.
  2. Save those informations persistently in a Room database
  3. Display them in a RecyclerView

Scenario 1: App with RecyclerView is in foreground:
As soon as I receive a new id via the FCM notification data, I want my RecyclerView to append another list item with the newly fetched book informations.

Scenario 2: App is in background - notification gets clicked:
When the notification gets clicked, the MainActivity with the RecyclerView gets loaded, showing the newly fetched book informations.

Scenario 3: App is in background - notification gets swiped away:
After some time the notification was swiped away the user re-opens or restarts the app. The MainActivity with the RecyclerView and the newly fetched book informations is shown.

My problem:
I don't quite know how to structure my code to accomplish this. I tried making the volley request inside of FCM's onMessageReceived() but that resulted in an error and I don't know where and how I could do that otherwise. I tested the volley request in another project and it worked there. Currently I try to learn how to work with the Room database.

I would really appreciate if someone can give me an insight of how to accomplish something like that. I really need to get this to work soon.

Thanks in advance! :)

Aucun commentaire:

Enregistrer un commentaire