use of com.mxt.anitrend.model.api.retro.anilist.BaseModel in project anitrend-app by AniTrend.
the class TagGenreService method onHandleIntent.
@Override
protected void onHandleIntent(@Nullable Intent intent) {
try {
initAnalytics();
BasePresenter basePresenter = new BasePresenter(getApplicationContext());
BaseModel baseModel = WebFactory.createService(BaseModel.class, getApplicationContext());
if (basePresenter.getDatabase().getBoxStore(MediaTag.class).count() < 1) {
Response<List<MediaTag>> tagsResponse = baseModel.getTags(GraphUtil.getDefaultQuery(false)).execute();
if (tagsResponse.isSuccessful() && tagsResponse.body() != null)
basePresenter.getDatabase().saveMediaTags(tagsResponse.body());
else
Log.e(ServiceName, ErrorUtil.getError(tagsResponse));
}
if (basePresenter.getDatabase().getBoxStore(Genre.class).count() < 1) {
Response<List<String>> genreResponse = baseModel.getGenres(GraphUtil.getDefaultQuery(false)).execute();
List<String> genres;
if (genreResponse.isSuccessful() && (genres = genreResponse.body()) != null) {
List<Genre> genreList = Stream.of(genres).map(Genre::new).toList();
basePresenter.getDatabase().saveGenreCollection(genreList);
} else
Log.e(ServiceName, ErrorUtil.getError(genreResponse));
}
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations