-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58ea1c9
commit e7c6d4a
Showing
12 changed files
with
395 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/io/catter2/cat_api/FetchCatImagesUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.catter2.cat_api; | ||
|
||
import android.util.Log; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.Response; | ||
import retrofit2.Retrofit; | ||
import retrofit2.converter.simplexml.SimpleXmlConverterFactory; | ||
|
||
public class FetchCatImagesUseCase { | ||
public interface Callback { | ||
void imagesUrls(List<String> urls); | ||
} | ||
|
||
private static String TAG = "FetchCatImagesUseCase"; | ||
|
||
public void getImagesUrls(final Callback callback) { | ||
Retrofit retrofit = new Retrofit.Builder() | ||
.baseUrl("http://thecatapi.com/api/") | ||
.addConverterFactory(SimpleXmlConverterFactory.create()) | ||
.build(); | ||
RetrofitTheCatAPI retrofitTheCatApi = retrofit.create(RetrofitTheCatAPI.class); | ||
retrofitTheCatApi.listCatsWithHat().enqueue(new retrofit2.Callback<CatImagesModel>() { | ||
@Override | ||
public void onResponse(Call<CatImagesModel> call, Response<CatImagesModel> response) { | ||
ArrayList<String> imageUrls = new ArrayList<>(); | ||
if (response.body().catImages != null) { | ||
for (CatImageModel img : response.body().catImages) { | ||
Log.d(TAG, "Found: " + img.url); | ||
imageUrls.add(img.url); | ||
} | ||
} | ||
callback.imagesUrls(imageUrls); | ||
} | ||
|
||
@Override | ||
public void onFailure(Call<CatImagesModel> call, Throwable t) { | ||
Log.e(TAG, "Error fetching cat images", t); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.