Search in sources :

Example 1 with BaseModel

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();
    }
}
Also used : BaseModel(com.mxt.anitrend.model.api.retro.anilist.BaseModel) List(java.util.List) Genre(com.mxt.anitrend.model.entity.anilist.Genre) IOException(java.io.IOException) BasePresenter(com.mxt.anitrend.presenter.base.BasePresenter)

Aggregations

BaseModel (com.mxt.anitrend.model.api.retro.anilist.BaseModel)1 Genre (com.mxt.anitrend.model.entity.anilist.Genre)1 BasePresenter (com.mxt.anitrend.presenter.base.BasePresenter)1 IOException (java.io.IOException)1 List (java.util.List)1