use of com.linroid.weather.model.Data in project steps by linroid.
the class MainActivity method onAddCity.
@Override
public void onAddCity(String cityName) {
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("添加中....");
dialog.show();
WeatherApp app = (WeatherApp) getApplication();
WeatherService service = app.getWeatherService();
service.getDataAsync(cityName, new Callback<Data>() {
@Override
public void success(Data data, Response response) {
Result result = data.getResults().get(0);
getContentResolver().insert(DataContract.Weather.CONTENT_URI, result.toContentValues());
// triggerSync();
Toast.makeText(MainActivity.this, R.string.add_city_success, Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
@Override
public void failure(RetrofitError retrofitError) {
Toast.makeText(MainActivity.this, R.string.add_city_fail, Toast.LENGTH_SHORT).show();
}
});
}
use of com.linroid.weather.model.Data in project steps by linroid.
the class SyncAdapter method onPerformSync.
@Override
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {
ArrayList<ContentProviderOperation> operations = new ArrayList<>();
try {
Cursor cursor = provider.query(DataContract.Weather.CONTENT_URI, null, null, null, null);
Timber.d("cursor count:%d", cursor.getCount());
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToPosition(i);
Weather weather = Weather.fromCursor(cursor);
Data data = weatherService.getData(weather.getCurrentCity());
if (data.getResults() != null && data.getResults().size() > 0) {
Uri uri = DataContract.Weather.CONTENT_URI.buildUpon().appendPath(String.valueOf(weather.getId())).build();
Timber.i("update uri: %s", uri.toString());
ContentValues values = data.getResults().get(0).toContentValues();
ContentProviderOperation operation = ContentProviderOperation.newUpdate(uri).withValues(values).build();
operations.add(operation);
Timber.d("获取 %s 城市天气成功", data.getResults().get(0).getCurrentCity());
} else {
Timber.e("(获取 %s 城市天气失败 %d)Status:%s, message:%s", weather.getCurrentCity(), data.getError(), data.getStatus(), data.getMessage());
}
syncResult.stats.numUpdates++;
}
Timber.i("同步了%d条数据", syncResult.stats.numUpdates);
} catch (RemoteException e) {
e.printStackTrace();
}
}
Aggregations