Search in sources :

Example 21 with Card

use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.

the class TangramEngine method updateCard.

public void updateCard(Card card) {
    if (card != null && mGroupBasicAdapter != null) {
        Range<Integer> cardRange = mGroupBasicAdapter.getCardRange(card);
        for (int i = cardRange.getLower(); i < cardRange.getUpper(); i++) {
            BaseCell cell = mGroupBasicAdapter.getItemByPosition(i);
            cell.extras.put("_flag_invalidate_", true);
        }
        mGroupBasicAdapter.notifyItemRangeChanged(cardRange.getLower(), cardRange.getUpper());
    }
}
Also used : BaseCell(com.tmall.wireless.tangram3.structure.BaseCell)

Example 22 with Card

use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.

the class BaseTangramEngine method findGroups.

@SuppressWarnings("unchecked")
@NonNull
public List<Card> findGroups(final Predicate<Card> predicate) {
    Preconditions.checkState(mGroupBasicAdapter != null, "Must call bindView() first");
    List<Card> groups = (List<Card>) mGroupBasicAdapter.getGroups();
    if (predicate == null) {
        return groups;
    }
    List<Card> rs = new LinkedList<Card>();
    for (Card g : groups) {
        if (predicate.isMatch(g)) {
            rs.add(g);
        }
    }
    return rs;
}
Also used : LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList) Card(com.tmall.wireless.tangram3.dataparser.concrete.Card) NonNull(android.support.annotation.NonNull)

Example 23 with Card

use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.

the class PojoDataParser method parseGroup.

@NonNull
@Override
public List<Card> parseGroup(@Nullable JSONArray data, @NonNull final ServiceManager serviceManager) {
    if (data == null) {
        return new ArrayList<>();
    }
    try {
        checkCardResolverAndMVHelper(serviceManager);
        final int size = data.size();
        final List<Card> result = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            JSONObject cardData = data.getJSONObject(i);
            final Card card = parseSingleGroup(cardData, serviceManager);
            if (card instanceof IDelegateCard) {
                List<Card> cards = ((IDelegateCard) card).getCards(new CardResolver() {

                    @Override
                    public Card create(String type) {
                        Card c = cardResolver.create(type);
                        c.serviceManager = serviceManager;
                        c.id = card.id;
                        c.setStringType(type);
                        c.rowId = card.rowId;
                        return c;
                    }
                });
                for (Card c : cards) {
                    if (c.isValid()) {
                        result.add(c);
                    }
                }
            } else {
                result.add(card);
            }
        }
        mvHelper.resolver().setCards(result);
        return result;
    } catch (Exception e) {
        if (errorSupport == null) {
            errorSupport = serviceManager.getService(InternalErrorSupport.class);
        }
        HashMap<String, Object> params = new HashMap<>();
        params.put("exception", Log.getStackTraceString(e));
        errorSupport.onError(InternalErrorSupport.ERROR_PARSE_CARDS_ERROR, "Parse group error.", params);
        e.printStackTrace();
    }
    return null;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StickyCard(com.tmall.wireless.tangram3.structure.card.StickyCard) LinearScrollCard(com.tmall.wireless.tangram3.structure.card.LinearScrollCard) SlideCard(com.tmall.wireless.tangram3.structure.card.SlideCard) StickyEndCard(com.tmall.wireless.tangram3.structure.card.StickyEndCard) WrapCellCard(com.tmall.wireless.tangram3.structure.card.WrapCellCard) GridCard(com.tmall.wireless.tangram3.structure.card.GridCard) FixLinearScrollCard(com.tmall.wireless.tangram3.structure.card.FixLinearScrollCard) BannerCard(com.tmall.wireless.tangram3.structure.card.BannerCard) FixCard(com.tmall.wireless.tangram3.structure.card.FixCard) StaggeredCard(com.tmall.wireless.tangram3.structure.card.StaggeredCard) OnePlusNCard(com.tmall.wireless.tangram3.structure.card.OnePlusNCard) NonNull(android.support.annotation.NonNull)

Example 24 with Card

use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.

the class PojoDataParser method parseCard.

protected void parseCard(Card card, JSONObject data, ServiceManager serviceManager, Map<String, ComponentInfo> componentInfoMap) {
    card.id = data.getString(KEY_ID);
    if (card.id == null) {
        card.id = "";
    }
    // parsing header
    JSONObject header = data.getJSONObject(KEY_HEADER);
    BaseCell headerCell = parseSingleComponent(header, card, serviceManager, componentInfoMap);
    parseHeaderCell(headerCell, card);
    // parsing body
    JSONArray componentArray = data.getJSONArray(KEY_ITEMS);
    if (componentArray != null) {
        final int cellLength = componentArray.size();
        for (int i = 0; i < cellLength; i++) {
            final JSONObject cellData = componentArray.getJSONObject(i);
            parseSingleComponent(cellData, card, card.serviceManager, componentInfoMap);
        }
    }
    // parsing footer
    JSONObject footer = data.getJSONObject(KEY_FOOTER);
    BaseCell footerCell = parseSingleComponent(footer, card, serviceManager, componentInfoMap);
    parseFooterCell(footerCell, card);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) BaseCell(com.tmall.wireless.tangram3.structure.BaseCell) JSONArray(com.alibaba.fastjson.JSONArray)

Example 25 with Card

use of com.tmall.wireless.tangram3.dataparser.concrete.Card in project Tangram-Android by alibaba.

the class PojoDataParser method parseHeaderCell.

protected void parseHeaderCell(BaseCell headerCell, Card card) {
    card.mHeader = headerCell;
    if (card instanceof GridCard) {
        GridCard gridCard = (GridCard) card;
        gridCard.ensureBlock(card.mHeader);
    } else if (card instanceof OnePlusNCard) {
        OnePlusNCard onePlusNCard = (OnePlusNCard) card;
        onePlusNCard.ensureBlock(card.mHeader);
    }
}
Also used : GridCard(com.tmall.wireless.tangram3.structure.card.GridCard) OnePlusNCard(com.tmall.wireless.tangram3.structure.card.OnePlusNCard)

Aggregations

BaseCell (com.tmall.wireless.tangram3.structure.BaseCell)15 Card (com.tmall.wireless.tangram3.dataparser.concrete.Card)11 Range (com.alibaba.android.vlayout.Range)6 ArrayList (java.util.ArrayList)6 NonNull (android.support.annotation.NonNull)5 GridCard (com.tmall.wireless.tangram3.structure.card.GridCard)5 OnePlusNCard (com.tmall.wireless.tangram3.structure.card.OnePlusNCard)5 RecyclerView (android.support.v7.widget.RecyclerView)4 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)4 JSONObject (com.alibaba.fastjson.JSONObject)4 View (android.view.View)3 LayoutHelper (com.alibaba.android.vlayout.LayoutHelper)3 JSONArray (com.alibaba.fastjson.JSONArray)3 BannerCard (com.tmall.wireless.tangram3.structure.card.BannerCard)3 FixCard (com.tmall.wireless.tangram3.structure.card.FixCard)3 FixLinearScrollCard (com.tmall.wireless.tangram3.structure.card.FixLinearScrollCard)3 LinearScrollCard (com.tmall.wireless.tangram3.structure.card.LinearScrollCard)3 SlideCard (com.tmall.wireless.tangram3.structure.card.SlideCard)3 StaggeredCard (com.tmall.wireless.tangram3.structure.card.StaggeredCard)3 StickyCard (com.tmall.wireless.tangram3.structure.card.StickyCard)3