dynamite8 / resources-android-dev

Collection of resources for becoming an Android developer
7 stars 7 forks source link

Fixes #42: Updated ResourceDao #45

Closed SomayahSA closed 6 years ago

SomayahSA commented 6 years ago

Created the methods required for the database interaction.

SomayahSA commented 6 years ago

@JaeW Please check the Resource and AppDatabase classes. The compiler was complaining and I did some changes.

JaeW commented 6 years ago

@Somayah88 There were likely to be some issues as the 5 Room components were written separately. I assume the compiler wanted the setId method? I think the method signature must be there, but the method itself should be left blank since resourceId is the PrimaryKey and is auto-generated. If resourceId can be modified then we are open to a variety of different db problems.

SomayahSA commented 6 years ago

@JaeW Yes, one of the problems is the setter for the Id. It won't run without it.

JaeW commented 6 years ago

@Somayah88 I understand that the method signature has to be there, but can the method itself be left blank? Or does the compiler object to that? Like so:

public void setResourceId(int id){ //this method intentionally left blank
}

JaeW commented 6 years ago

@Somayah88 Well done on all of the Room components! There are a few additions which should be added to the Repository class. Here is how Google in its App Architecture Guide, describes the Repository:

Repository modules are responsible for handling data operations. They provide a clean API to the rest of the app. They know where to get the data from and what API calls to make when data is updated. You can consider them as mediators between different data sources (persistent model, web service, cache, etc.).

The UI will ask the ViewModel for the resources the user requests, and the ViewModel will pass that request on to the Repository. This may seem redundant (why not have the ViewModel query the db directly, right?) but remember that the Repository will ALSO be responsible for retrieving resources from Firebase in addition to the local db (this is what @dynamite8 will be working on) as well as the logic needed to cache that information. Since it functions as an API to the rest of the app, that means that all of the query methods defined in the dao class should be exposed (methods to call the dao methods should be defined and implemented) within the Repository.

Hopefully this was neither too long nor too short, but please let me know if you have questions. Thank you!