Search in sources :

Example 1 with Weather

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;
}
Also used : Weather(com.linroid.weather.model.Weather)

Example 2 with Weather

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();
    }
}
Also used : Weather(com.linroid.weather.model.Weather) ContentValues(android.content.ContentValues) ContentProviderOperation(android.content.ContentProviderOperation) ArrayList(java.util.ArrayList) Data(com.linroid.weather.model.Data) Cursor(android.database.Cursor) RemoteException(android.os.RemoteException) Uri(android.net.Uri)

Example 3 with Weather

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();
}
Also used : Weather(com.linroid.weather.model.Weather)

Example 4 with Weather

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;
}
Also used : Weather(com.linroid.weather.model.Weather) Fragment(android.support.v4.app.Fragment)

Aggregations

Weather (com.linroid.weather.model.Weather)4 ContentProviderOperation (android.content.ContentProviderOperation)1 ContentValues (android.content.ContentValues)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 RemoteException (android.os.RemoteException)1 Fragment (android.support.v4.app.Fragment)1 Data (com.linroid.weather.model.Data)1 ArrayList (java.util.ArrayList)1