mcharmas/shoppinglist-clean-architecture-example

Android loaders support

Opened this issue · 1 comments

Wow,

This looks very promising and looks like you put great effort into it. I'm not familiar with RxJAva but it looks like you're using it to load data.

What keeps me thinking, is what would happen if we'd like to drop rxjava and use loaders instead. I think that loaders are one of the most encouraged patterns by Google and community, so it'd be really nice to try to follow clean architecture with loaders.

Where does android loaders & loader callbacks belong here? My wild guess would be that they should end up in data package, but on the other hand they depend on ui lifecycle.

Hi Filip,
glad you find it usefull. To be honest I am not a greatest fan of loaders especially
when I am not deailing directly with ContentProviders - I find them rather buggy and painfull to use.

But let's think where should we use them...
In this example app all UseCases are sync and they are dealing with database, so their execution should be performed in background thread. Loaders are technical detail so they shouldn't be for sure in domain layer, nor in data layer - which should only server data storage implementation. Loaders by design are used to deliver data to UI layer and they are bound with it (LoaderManger is part of Activity) so I would use loaders for sure in UI layer. I don't have direct idea how to plug them into existing codebase without bigger refactor though - it is really strongly bound with activity. If you have any idea how to use them clearly please attach some code as an example.

By the way I recommend you looking at RxJava - it is really amazing tool.