public void getLeague(int leagueId) { Call<SoccerSeason> call = mApiService.getSoccerSeason(leagueId); call.enqueue( new Callback<SoccerSeason>() { @Override public void onResponse( Call<SoccerSeason> call, retrofit2.Response<SoccerSeason> response) { int statusCode = response.code(); Log.d(LOG_TAG, "getLeague statusCode #" + statusCode); if (statusCode != 200) { return; } SoccerSeason season = response.body(); mContext .getContentResolver() .insert(AppProvider.Seasons.withId(season.getId()), season.getContentValues()); Log.d(LOG_TAG, "getLeague Complete league ID: " + season.getId()); updateWidgets(mContext); } @Override public void onFailure(Call<SoccerSeason> call, Throwable t) { // Log error here since request failed // TODO log unable fetch league Log.e(LOG_TAG, "getLeague onFailure", t); } }); }
public void getTeam(final int teamId) { Call<Team> call = mApiService.getTeam(teamId); call.enqueue( new Callback<Team>() { @Override public void onResponse(Call<Team> call, retrofit2.Response<Team> response) { int statusCode = response.code(); Log.d(LOG_TAG, "getTeam statusCode #" + statusCode); if (statusCode != 200) { return; } Team team = response.body(); if (team.getCrestUrl().length() > 0) { GlideHelper.preloadTeamCrest(mContext, mHttpClient, team.getCrestUrl(), team.getId()); File internalFile = mContext.getFileStreamPath("crestTeam" + teamId + ".png"); Uri internal = Uri.fromFile(internalFile); team.setCrestUrl(internal.toString()); } mContext .getContentResolver() .insert(AppProvider.Teams.withId(team.getId()), team.getContentValues()); Log.d(LOG_TAG, "getTeam Complete team ID: " + team.getId()); updateWidgets(mContext); } @Override public void onFailure(Call<Team> call, Throwable t) { // Log error here since request failed // TODO log unable fetch league Log.e(LOG_TAG, "getTeam onFailure", t); } }); }
public void fetchFixtures(String timeFrame, String league) { Map<String, String> options = new HashMap<>(); options.put(QUERY_TIME_FRAME, timeFrame); if (league != null) { options.put(QUERY_LEAGUE, league); } Call<FixtureCollection> call = mApiService.getFixtures(options); call.enqueue( new Callback<FixtureCollection>() { @Override public void onResponse( Call<FixtureCollection> call, retrofit2.Response<FixtureCollection> response) { int statusCode = response.code(); Log.d(LOG_TAG, "fetchFixtures statusCode #" + statusCode); if (statusCode != 200) { // TODO set status return; } FixtureCollection fixtureCollection = response.body(); Log.d(LOG_TAG, "Count #" + fixtureCollection.getCount()); Log.d(LOG_TAG, "Time Frame Start " + fixtureCollection.getTimeFrameStart()); Log.d(LOG_TAG, "Time Frame End " + fixtureCollection.getTimeFrameEnd()); Vector<ContentValues> values = new Vector<>(fixtureCollection.getFixtures().size()); for (Fixture fixture : fixtureCollection.getFixtures()) { try { values.add(fixture.getContentValues()); Log.v(LOG_TAG, fixture.getContentValues().toString()); } catch (ParseException e) { e.printStackTrace(); } } int inserted_data; ContentValues[] insert_data = new ContentValues[values.size()]; values.toArray(insert_data); inserted_data = mContext .getContentResolver() .bulkInsert(AppProvider.Fixtures.CONTENT_URI, insert_data); Log.i(LOG_TAG, "fetchMovieItems Complete. " + inserted_data + " Inserted"); // fetch look up data LookupSyncAdapter.syncNow(mContext); updateWidgets(mContext); } @Override public void onFailure(Call<FixtureCollection> call, Throwable t) { // Log error here since request failed Log.e(LOG_TAG, "fetchFixtures onFailure", t); } }); }