Skip to content

Instantly share code, notes, and snippets.

@jezinka
Created August 18, 2018 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jezinka/065ae22e7fa377e5bb85b987836e920c to your computer and use it in GitHub Desktop.
Save jezinka/065ae22e7fa377e5bb85b987836e920c to your computer and use it in GitHub Desktop.
private void refreshWidget() {
final Context mContext = this;
WeatherService weatherService = WeatherService.retrofit.create(WeatherService.class);
final Call<JsonObject> call = weatherService.loadData();
call.enqueue(new Callback<JsonObject>() {
@Override
public void onResponse(@NonNull Call<JsonObject> call, @NonNull Response<JsonObject> response) {
JsonObject body = response.body();
if (body != null) {
Sensor sensor = createSensorsFromJsonObject(body);
if (sensor != null) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
int[] widgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(mContext, SensorWidgetProvider.class));
SensorWidgetProvider.updateSensorWidgets(mContext, appWidgetManager, sensor, widgetIds);
}
}
}
@Override
public void onFailure(@NonNull Call<JsonObject> call, @NonNull Throwable t) {
Log.e("LOAD_DATA", t.getLocalizedMessage());
Toast.makeText(mContext, R.string.connection_error, Toast.LENGTH_LONG).show();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment