I think the tutorial its really nice
I just have a concern:
why are you using Serializable instead of Parcelabe for the models is there any reason in specific?
Awesome article! One thing I would have liked to have seen though is at least a little bit more of a reference to how the data provider is abstracted. Specifically, maybe a diagram making it clear that you might have both network and local DB acting as data providers, and that itâs the responsibility of the Repository to figure out which to use and how to sync between them.
kind of like this. I realize the implementation for this is probably out of scope for a tutorial article like this, though but some reference on how to approach this common pattern or where to go for examples would be great.
I realize this probably happened during course of writing the article - you started out with a project structure with a certain name but in packaging the tutorial for starter / final projects things may have changed. In the point of the tutorial where you first have the reader do stuff in Android Studio, you say:
Right click on MajesticReader in Project explorer and select New ⸠Module or select File ⸠New ⸠New Module
This is incorrect in relation to the project the reader actually downloads, and the screenshots are also incorrect.
The only folder named majestic reader is too far down on the hierarchy. Comparing to the final project, the place they should be creating the new module is at the project root.
Actually, I canât get the starter or final projects to run. Opening them in Android Studio, it says âmodule not specifiedâ and there is no module to choose from. Something seems to be missing from the project files to get the projects to work out of the box?
Also, the final project code does not match the code as per the tutorial. For example, there is a step which says:
Open MajesticReaderApplication and replace onCreate() with the following, making sure you add all the necessary imports:
The code from this step is nowhere to be found in the final project. It seems perhaps the wrong code was submitted for the final project?
I uploaded a new version of the tutorial materials that should have addressed this problem. Let us know if youâre still unable to build the project in Android Studio 3.5 or later.
Also, the MajesticReaderApplication class is in the framework package of the app module.
Hi @sagarsuri,
thanks for the question! Iâm glad that you like the article
viewModelScope would be the appropriate scope to use but it was added in version 2.1.0 of androidx.lifecycle:lifecycle-viewmodel-ktx library which wasnât available at the time of writing. To keep things as simple as possible we used GlobalScope.
@sagarsuri If you are referring to a folder that would hold Dependency Injection related code, the right place for it is framework package in the app module.
I have some questions related to the graph that shows communication between the layers:
Why did you add arrows in both directions between layers? For example between 'Presentation layer â and âUse cases layerâ or âData Layerâ and âDomain layerâ?
Why there is no arrow between âUse cases layerâ and âDomain Layerâ because, for example, âAddBookmarkâ class (from âinteractorsâ package) has direct access to âBookmarkâ and âDocumentâ classes from domain layer.
Hi,
thank you, Iâm glad that you like the tutorial!
Iâve added arrows in both directions to show that a lower layer requests information from a higher layer and gets a result. For example ViewModel from Presentation layer calls function from Interactor and gets a result.
That is correct. I wanted to note that âBookmarkâ and âDocumentâ classes from Domain layer are accessed through Data layer - for example AddBookmark class uses BookmarkRepository to add a new Bookmark.
Great tutorial, but I donât viewModel should hold the application context,.
If i am not wrong the viewModel should not know anything about Android framework.
Looking at the official documentation, using Application context in ViewModel is permitted. It is important to not reference anything that may hold a reference to the activity context since ViewModel can outlive Activity.
A quote from the documentation:
A ViewModel must never reference a view, Lifecycle, or any class that may hold a reference to the activity context.
Android Jetpack even provides AndroidViewModel which can be extended and has a reference to Application.