Skip to content

Commit

Permalink
Added TheCatAPIService to the App lifetime
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanHasegawa committed Jul 31, 2017
1 parent e39ee8c commit a8180a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/io/catter2/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.catter2;

import android.app.Application;

import io.catter2.cat_api.CacheTheCatAPI;
import io.catter2.cat_api.RetrofitTheCatAPI;
import io.catter2.cat_api.TheCatAPI;

public class App extends Application {
private static TheCatAPI theCatAPI;

public static TheCatAPI getTheCatAPIService() {
return App.theCatAPI;
}

@Override
public void onCreate() {
super.onCreate();

TheCatAPI theCatAPIService = new RetrofitTheCatAPI();
TheCatAPI theCatAPICache = new CacheTheCatAPI(theCatAPIService);
App.theCatAPI = theCatAPICache;
}

}
7 changes: 1 addition & 6 deletions app/src/main/java/io/catter2/ListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

import java.util.List;

import io.catter2.cat_api.CacheTheCatAPI;
import io.catter2.cat_api.FetchCatImagesUseCase;
import io.catter2.cat_api.RetrofitTheCatAPI;
import io.catter2.cat_api.TheCatAPI;
import io.catter2.favorites.AddFavoriteUseCase;
import io.catter2.favorites.FavoritesRepository;
import io.catter2.favorites.SharedPrefFavoritesRepository;
Expand Down Expand Up @@ -67,9 +64,7 @@ public void imageClicked(ImageView view, String url) {

FavoritesRepository favoritesRepository = new SharedPrefFavoritesRepository(this, userToken);
addFavoriteUseCase = new AddFavoriteUseCase(favoritesRepository);
TheCatAPI catAPIService = new RetrofitTheCatAPI();
TheCatAPI catAPICached = new CacheTheCatAPI(catAPIService);
fetchCatImagesUseCase = new FetchCatImagesUseCase(catAPICached);
fetchCatImagesUseCase = new FetchCatImagesUseCase(App.getTheCatAPIService());

fetchCatImagesUseCase.getImagesUrls(new FetchCatImagesUseCase.Callback() {
@Override
Expand Down

0 comments on commit a8180a9

Please sign in to comment.