DynamicGrid icon indicating copy to clipboard operation
DynamicGrid copied to clipboard

Adapter with complex object not working

Open laaptu opened this issue 10 years ago • 1 comments

First of all, great and awesome library. Many many THANKS for it. I have implemented your library and it works fine,but when I use it with custom Objects , it won't work as desired i.e. views are overlapped . The reason of it seems to be due to stableId. I have checked this issue https://github.com/askerov/DynamicGrid/issues/25 which seems similar to mine.But, could you just hint me on how to make your awesome library work smoothly for complex object. I have an ArrayList of ImageInfo Object. The library works as desired when I remove extends BaseNodeone.

public class ImageInfo extends BaseNode implements Serializable {

    public String imageUri;
    public int rotation;
}

 public class BaseNode implements Parcelable {

    public static final String _ID = "_id";
    public static final String ID = "mId";

    @DatabaseField(generatedId = true)
    int _id;

    @DatabaseField(columnName = "mId")
    @SerializedName("id")
    String mId;

    public BaseNode() {
    }

    public String getId() {
        return mId;
    }

    public void setId(String mId) {
        this.mId = mId;
    }

    public int getDatabaseId() {
        return _id;
    }

    public void setDatabaseId(int _id) {
        this._id = _id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || ((Object) this).getClass() != o.getClass()) return false;

        BaseNode baseNode = (BaseNode) o;

        if (mId != null ? !mId.equals(baseNode.mId) : baseNode.mId != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return mId != null ? mId.hashCode() : 0;
    }


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {

        dest.writeString(mId);
        dest.writeInt(_id);
    }

    protected BaseNode(Parcel in) {

        mId = in.readString();
        _id = in.readInt();
    }

}

P.S. Though this is not an issue, I am trying to implement alpha method while making drag and drop like

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void startWobbleAnimation() {
        for (int i = 0; i < getChildCount(); i++) {
            View v = getChildAt(i);
            if (v != null && Boolean.TRUE != v.getTag(R.id.dgv_wobble_tag)) {
                if (i % 2 == 0)
                    animateWobble(v);
                else
                    animateWobbleInverse(v);
                v.setTag(R.id.dgv_wobble_tag, true);
                v.setAlpha(0.65f);
            }
        }
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void stopWobble(boolean resetRotation) {
        for (Animator wobbleAnimator : mWobbleAnimators) {
            wobbleAnimator.cancel();
        }
        mWobbleAnimators.clear();
        for (int i = 0; i < getChildCount(); i++) {
            View v = getChildAt(i);
            if (v != null) {
                if (resetRotation) v.setRotation(0);
                v.setTag(R.id.dgv_wobble_tag, false);
                v.setAlpha(1);
            }
        }
    }

It works but when I begin to drag and scroll the view some items get alpha effect whereas some doesn't . Is there anything I am missing.

Lastly, thanks a million for this awesome library ;)

laaptu avatar Sep 17 '14 07:09 laaptu

If it is still an issue you can try to check issue #26 and the pull request attached to it.

denisk20 avatar Oct 23 '14 18:10 denisk20