Search in sources :

Example 1 with MVHelper

use of com.tmall.wireless.tangram.MVHelper in project Tangram-Android by alibaba.

the class Card method addCellInternal.

private boolean addCellInternal(Card parent, int index, @Nullable BaseCell cell, boolean silent) {
    if (cell != null) {
        cell.parentId = parent.id;
        cell.parent = parent;
        cell.serviceManager = serviceManager;
        MVHelper mvHelper = getMVHelper();
        if (mvHelper != null) {
            if (mvHelper.isValid(cell, serviceManager)) {
                if (cell.position >= 0 && !TextUtils.isEmpty(load)) {
                    cell.pos = cell.position;
                    mPendingCells.add(cell);
                    return true;
                } else {
                    // FixMe pos not correct when insert cell
                    cell.pos = mHeader != null ? this.mCells.size() + 1 : this.mCells.size();
                }
                if (!silent && mIsActivated) {
                    // do cell added
                    cell.added();
                }
                this.mCells.add(index, cell);
                if (mFooter != null) {
                    mFooter.pos = cell.pos + 1;
                }
                return true;
            }
        }
    }
    return false;
}
Also used : MVHelper(com.tmall.wireless.tangram.MVHelper)

Example 2 with MVHelper

use of com.tmall.wireless.tangram.MVHelper in project Tangram-Android by alibaba.

the class PojoAdapterBuilder method newAdapter.

@Override
public PojoGroupBasicAdapter newAdapter(@NonNull final Context context, @NonNull final VirtualLayoutManager layoutManager, @NonNull final ServiceManager serviceManager) {
    BaseCellBinderResolver componentBinderResolver = serviceManager.getService(BaseCellBinderResolver.class);
    BaseCardBinderResolver cardBinderResolver = serviceManager.getService(BaseCardBinderResolver.class);
    MVHelper mvHelper = serviceManager.getService(MVHelper.class);
    ViewManager viewManager = serviceManager.getService(ViewManager.class);
    final PojoGroupBasicAdapter adapter = new PojoGroupBasicAdapter(context, layoutManager, componentBinderResolver, cardBinderResolver, mvHelper, viewManager);
    return adapter;
}
Also used : MVHelper(com.tmall.wireless.tangram.MVHelper) ViewManager(com.tmall.wireless.vaf.framework.ViewManager)

Example 3 with MVHelper

use of com.tmall.wireless.tangram.MVHelper in project Tangram-Android by alibaba.

the class PojoDataParser method parseSingleGroup.

/**
 * {@inheritDoc}
 */
@NonNull
@Override
public Card parseSingleGroup(@Nullable JSONObject data, final ServiceManager serviceManager) {
    if (data == null) {
        return Card.NaN;
    }
    final CardResolver cardResolver = serviceManager.getService(CardResolver.class);
    Preconditions.checkState(cardResolver != null, "Must register CardResolver into ServiceManager first");
    final MVHelper cellResolver = serviceManager.getService(MVHelper.class);
    Preconditions.checkState(cellResolver != null, "Must register CellResolver into ServiceManager first");
    final String cardType = data.optString(Card.KEY_TYPE);
    if (!TextUtils.isEmpty(cardType)) {
        final Card card = cardResolver.create(cardType);
        if (card != null) {
            card.serviceManager = serviceManager;
            card.parseWith(data, cellResolver);
            card.type = data.optInt(Card.KEY_TYPE, -1);
            card.stringType = cardType;
            if (card.isValid()) {
                if (card.style.slidable) {
                    return new SlideCard(card);
                } else {
                    return card;
                }
            }
        } else {
            final Card cellCard = new WrapCellCard();
            if (cellCard != null) {
                cellCard.serviceManager = serviceManager;
                cellCard.parseWith(data, cellResolver);
                cellCard.setStringType(TangramBuilder.TYPE_CONTAINER_1C_FLOW);
                if (cellCard.isValid()) {
                    return cellCard;
                }
            }
        }
    } else {
        LogUtils.w(TAG, "Invalid card type when parse JSON data");
    }
    return Card.NaN;
}
Also used : SlideCard(com.tmall.wireless.tangram.structure.card.SlideCard) WrapCellCard(com.tmall.wireless.tangram.structure.card.WrapCellCard) MVHelper(com.tmall.wireless.tangram.MVHelper) WrapCellCard(com.tmall.wireless.tangram.structure.card.WrapCellCard) SlideCard(com.tmall.wireless.tangram.structure.card.SlideCard) NonNull(android.support.annotation.NonNull)

Example 4 with MVHelper

use of com.tmall.wireless.tangram.MVHelper in project Tangram-Android by alibaba.

the class PojoDataParser method parseSingleComponent.

/**
 * {@inheritDoc}
 */
@NonNull
@Override
public BaseCell parseSingleComponent(@Nullable JSONObject data, Card parent, ServiceManager serviceManager) {
    if (data == null) {
        return BaseCell.NaN;
    }
    final CardResolver cardResolver = serviceManager.getService(CardResolver.class);
    Preconditions.checkState(cardResolver != null, "Must register CardResolver into ServiceManager first");
    final MVHelper cellResolver = serviceManager.getService(MVHelper.class);
    Preconditions.checkState(cellResolver != null, "Must register CellResolver into ServiceManager first");
    BaseCell cell = Card.createCell(parent, cellResolver, data, serviceManager, true);
    if (cellResolver.isValid(cell, serviceManager)) {
        return cell;
    } else {
        return BaseCell.NaN;
    }
}
Also used : BaseCell(com.tmall.wireless.tangram.structure.BaseCell) MVHelper(com.tmall.wireless.tangram.MVHelper) NonNull(android.support.annotation.NonNull)

Example 5 with MVHelper

use of com.tmall.wireless.tangram.MVHelper in project Tangram-Android by alibaba.

the class SampleDataParser method parseGroup.

@Nullable
@Override
public List<Card> parseGroup(@Nullable JSONArray data, ServiceManager serviceManager) {
    final CardResolver cardResolver = serviceManager.getService(CardResolver.class);
    Preconditions.checkState(cardResolver != null, "Must register CardResolver into ServiceManager first");
    final MVHelper cellResolver = serviceManager.getService(MVHelper.class);
    Preconditions.checkState(cellResolver != null, "Must register CellResolver into ServiceManager first");
    final int size = data.length();
    final List<Card> result = new ArrayList<>(size);
    for (int i = 0; i < size; i++) {
        JSONObject cardData = data.optJSONObject(i);
        if (cardData != null) {
            // maybe custom card
            final String cardType = cardData.optString(Card.KEY_TYPE);
            if (!TextUtils.isEmpty(cardType)) {
                final Card card = cardResolver.create(cardType);
                if (card != null) {
                    card.serviceManager = serviceManager;
                    // add card style
                    addCardStyle(cardData, card);
                    // custom items element key if need.
                    transformCardCellData(cardData);
                    // parser card
                    card.parseWith(cardData, cellResolver);
                    card.type = cardData.optInt(Card.KEY_TYPE, -1);
                    card.stringType = cardType;
                    result.add(card);
                }
            }
        }
    }
    cellResolver.resolver().setCards(result);
    return result;
}
Also used : CardResolver(com.tmall.wireless.tangram.dataparser.concrete.CardResolver) JSONObject(org.json.JSONObject) MVHelper(com.tmall.wireless.tangram.MVHelper) ArrayList(java.util.ArrayList) BannerCard(com.tmall.wireless.tangram.structure.card.BannerCard) Card(com.tmall.wireless.tangram.dataparser.concrete.Card) GridCard(com.tmall.wireless.tangram.structure.card.GridCard) Nullable(android.support.annotation.Nullable)

Aggregations

MVHelper (com.tmall.wireless.tangram.MVHelper)8 NonNull (android.support.annotation.NonNull)3 JSONObject (org.json.JSONObject)3 Card (com.tmall.wireless.tangram.dataparser.concrete.Card)2 BaseCell (com.tmall.wireless.tangram.structure.BaseCell)2 SlideCard (com.tmall.wireless.tangram.structure.card.SlideCard)2 WrapCellCard (com.tmall.wireless.tangram.structure.card.WrapCellCard)2 ArrayList (java.util.ArrayList)2 Nullable (android.support.annotation.Nullable)1 View (android.view.View)1 Engine (com.tmall.wireless.tangram.Engine)1 CardResolver (com.tmall.wireless.tangram.dataparser.concrete.CardResolver)1 Cell (com.tmall.wireless.tangram.dataparser.concrete.Cell)1 IDelegateCard (com.tmall.wireless.tangram.dataparser.concrete.IDelegateCard)1 WrapperCard (com.tmall.wireless.tangram.dataparser.concrete.WrapperCard)1 BannerCard (com.tmall.wireless.tangram.structure.card.BannerCard)1 GridCard (com.tmall.wireless.tangram.structure.card.GridCard)1 DelegateStyle (com.tmall.wireless.tangram.structure.style.DelegateStyle)1 CardLoadSupport (com.tmall.wireless.tangram.support.async.CardLoadSupport)1 ViewManager (com.tmall.wireless.vaf.framework.ViewManager)1