use of com.linroid.weather.model.Weather in project steps by linroid.
the class CityPagerAdapter method instantiateItem.
@Override
public Object instantiateItem(ViewGroup container, int position) {
WeatherFragment fragment = (WeatherFragment) super.instantiateItem(container, position);
Weather weather = weathers.get(position);
fragment.setWeatherData(weather);
return fragment;
}
use of com.linroid.weather.model.Weather 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();
}
}
use of com.linroid.weather.model.Weather in project steps by linroid.
the class CityPagerAdapter method setCursor.
public void setCursor(Cursor cursor) {
int count = cursor == null ? 0 : cursor.getCount();
Timber.d("cursor count : %d", count);
weathers.clear();
if (count == 0) {
return;
}
for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
Weather weather = Weather.fromCursor(cursor);
weathers.add(weather);
}
// removeALlFragments();
notifyDataSetChanged();
}
use of com.linroid.weather.model.Weather in project steps by linroid.
the class CityPagerAdapter method getItem.
@Override
public Fragment getItem(int position) {
Weather weather = weathers.get(position);
Fragment fragment = WeatherFragment.newInstance(weather);
fragments.put(position, fragment);
return fragment;
}
Aggregations