Description
This is not an issue, just an architectural question...
Let's say that our application has a SQLite database, a Content Provider that exposes this data and an IntentService that is responsible for syncing data by calling the REST service and updating the database.
Where these two components should be placed?
I think The ContentProvider would easily be placed in the data module.
An additional Repository implementation in the data module would query the content provider and transform the cursor data into entity objects in order to be consumed by the Use Cases. For the UseCase there's no difference. It will still talk to the interface and it will get back the data it wants. Of course, the proper concrete implementation would be injected via dagger.
The Service could also be placed in the data module.
A new interface could be introduced in the domain, i.e. SyncRepository which will be used by the Use Case. The actual implementation of it (in the data module) will start the service with an Intent.
What do you think?
Activity
J-vandenBerg commentedon Oct 20, 2015
+1
cesards commentedon Oct 21, 2015
That's actually a very good question.
alexandru-calinoiu commentedon Oct 21, 2015
The content provider is just another data source for the repository so I agree with your decision.
I will place the service on the presentation layer, is a services folder, it will trigger a use case to sync the data using just a repository implementation. I think that the intent service is just another way of inputing data in the system.
BillBosiolis commentedon Oct 21, 2015
One of the things that concerns me is that these components cannot run in sequence.
In the current implementation, when the UI asks for data the following take place
In case a Service is used, the workflow could be the following
After that the UI should be informed about the changes and update its contents.
We can accomplish this by using a ContentObserver but in that case, the presentation layer is bound to a concrete data implementation (ContentProvider), so I don't think this is a good idea.
Another option, is that the data layer keeps a reference to the Subscriber (UseCase) and when needed (new changes saved onto the db) informs him again. The UseCase in turn will notify the Presentation's Subscriber which will ask from the View to update.
@alexandru-calinoiu I agree that the Service could be placed in the presentation layer. For instance, the user may need to manually refresh the data, so the Presenter can start the Service.
alexandru-calinoiu commentedon Oct 22, 2015
I will comment on this part:
I don't understand why is a IntentService needed?
The way I've done this in the past is using a reactive, with rxjava, have a Repository implemetation that return Obeservable and subscribe to this, I have an example of this here
BillBosiolis commentedon Oct 23, 2015
@alexandru-calinoiu I haven't looked at your example in great detail but I would use an IntentService along with a SyncAdapter if I wanted to sync my data regularly without necessarily the need to display the "new" data to the UI at that moment.
sinistance commentedon Nov 20, 2015
good explaination @BillBosiolis. i think this repo should have a branch that represents how to deal with databases because many of us is using database in everyday project.
connexion2000 commentedon Feb 17, 2016
And what about CursorLoaders, where do they belong?
How should I pass Cursor from data layer (where content provider belongs) to presentation layer (where cursor adapter belongs)?
lenguyenthanh commentedon Feb 18, 2016
+1
jpventura commentedon Feb 18, 2016
@BillBosiolis, I try to follow the approach presented at Google I/O 2010 talk "Android REST client applications", which is the same approach used by Udacity Android Nanodegree course.
Basically you can use:
talhakosen commentedon Mar 24, 2016
+1
10 remaining items