jaredsburrows / android-gif-search

Gif LazyVerticalGrid MVVM using Dagger 2 + Hilt with Retrofit 2, Moshi, Kotlin Coroutines, JUnit, Espresso and Robolectric tests!

Home Page:https://play.google.com/store/apps/details?id=com.burrowsapps.gif.search

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use Dagger 2 for Rest services

jaredsburrows opened this issue · comments

Use Dagger 2 for Rest services

I rewrote the REST services to be injected through Dagger 2.
I added NetworkModule.java, (interface)Repository.java , GiphyService.java and removed ServiceUtil.java

Repository is injected so now

//MainFragment, Field Injection
@Inject Repository mRepository
...
...
...

void loadTrendingImages(){
loadImages(mRepository.getTrendingResults())
}

GiphyService implements repository and the lower abstraction methods are now private

//Constructor injection
@Inject
public GiphyService(String accessToken, GiphyApiService service){...}
@OverRide
public Observable getTrendingResults(){
return getTrendingResults(mAccessToken);
// and lower abstractions such as limits, searches etc.
}

However I did not rewrite the GiphyServiceTest since I'm not yet totally sure how to do it with Dagger, but I'm working on learning it. If you know how to do it feel free to fix it

In the meantime you can check my fork here if you want

Ok cool. I will check it out!