Search in sources :

Example 1 with Pin

use of com.gracecode.android.presentation.dao.Pin in project Presentation by feelinglucky.

the class PstRequest method getPinsFromResponse.

private int getPinsFromResponse(String response) {
    JsonObject jsonObject = (JsonObject) new JsonParser().parse(response);
    JsonArray jsonArrayPins = jsonObject.getAsJsonArray("pins");
    mAffectedRows = 0;
    for (int i = 0; i < jsonArrayPins.size(); i++) {
        JsonObject tmp = (JsonObject) jsonArrayPins.get(i);
        Pin pin = mGson.fromJson(tmp, Pin.class);
        Pin.File file = mGson.fromJson(tmp.getAsJsonObject("file"), Pin.File.class);
        pin.setKey(file.key);
        pin.setWidth(file.width);
        pin.setHeight(file.height);
        // ignore gif and some 'bad' images.
        if (file.frames == 1 && (file.width / (float) file.height < .38f)) {
            try {
                Dao.CreateOrUpdateStatus status = mDatabaseHelper.getPinsDAO().createOrUpdate(pin);
                mAffectedRows += status.getNumLinesChanged();
            } catch (SQLException e) {
                Logger.e(e.getMessage());
            }
        }
    }
    mListener.onSaved(mAffectedRows);
    return mAffectedRows;
}
Also used : JsonArray(com.google.gson.JsonArray) Dao(com.j256.ormlite.dao.Dao) Pin(com.gracecode.android.presentation.dao.Pin) SQLException(java.sql.SQLException) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 2 with Pin

use of com.gracecode.android.presentation.dao.Pin in project Presentation by feelinglucky.

the class PinsAdapter method getView.

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    Pin pin = getItem(i);
    String imageUrl = mHuabanApp.isDownloadRetinaImage() ? pin.getRetinaSquareThumbUrl() : pin.getSquareThumbUrl();
    if (view == null) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        view = inflater.inflate(R.layout.grid, null);
    }
    if (i > getCount() - 2) {
        loadPinsByMaxId(true);
    }
    Holder h = Holder.get(view);
    Logger.v("Load image from " + imageUrl);
    h.mImageView.setImageUrl(imageUrl, mHuabanApp.getImageLoader());
    h.mTitle.setText(pin.getText());
    if (pin.getText().trim().length() > 0) {
        h.mTitle.setVisibility(View.VISIBLE);
    } else {
        h.mTitle.setVisibility(View.INVISIBLE);
    }
    return view;
}
Also used : Pin(com.gracecode.android.presentation.dao.Pin) LayoutInflater(android.view.LayoutInflater)

Aggregations

Pin (com.gracecode.android.presentation.dao.Pin)2 LayoutInflater (android.view.LayoutInflater)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 Dao (com.j256.ormlite.dao.Dao)1 SQLException (java.sql.SQLException)1