Search in sources :

Example 11 with Card

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

the class Tangram3Activity method onCreate.

@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    recyclerView = (RecyclerView) findViewById(R.id.main_view);
    // Step 1: init tangram
    TangramBuilder.init(this.getApplicationContext(), new IInnerImageSetter() {

        @Override
        public <IMAGE extends ImageView> void doLoadImageUrl(@NonNull IMAGE view, @Nullable String url) {
            Picasso.with(Tangram3Activity.this.getApplicationContext()).load(url).into(view);
        }
    }, ImageView.class);
    // Tangram.switchLog(true);
    mMainHandler = new Handler(getMainLooper());
    // Step 2: register build=in cells and cards
    builder = TangramBuilder.newInnerBuilder(this);
    // Step 3: register business cells and cards
    // recommend to use string type to register component
    builder.registerCell("testView", TestBlockView.class);
    builder.registerCell("Debug", TestBlockView.class);
    builder.registerCell("singleImgView", TestImageView.class);
    builder.registerRenderService(new VirtualViewRenderService());
    // Step 4: new engine
    engine = builder.build();
    Utils.setUedScreenWidth(720);
    // engine.addSimpleClickSupport(new SampleClickSupport());
    // Step 6: enable auto load more if your page's data is lazy loaded
    engine.enableAutoLoadMore(true);
    // engine.register(InternalErrorSupport.class, new SampleErrorSupport());
    // Step 7: bind recyclerView to engine
    engine.bindView(recyclerView);
    // Step 8: listener recyclerView onScroll event to trigger auto load more
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            engine.onScrolled();
        }
    });
    // Step 9: set an offset to fix card
    engine.getLayoutManager().setFixOffset(0, 40, 0, 0);
    // Step 10: get tangram data and pass it to engine
    String json = new String(getAssertsFile(this, "data3.0.json"));
    JSONArray data = null;
    try {
        data = JSON.parseArray(json);
        engine.setData(data);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // Demo for component to listen container's event
    engine.register(SampleScrollSupport.class, new SampleScrollSupport(recyclerView));
}
Also used : IInnerImageSetter(com.tmall.wireless.tangram3.util.IInnerImageSetter) JSONArray(com.alibaba.fastjson.JSONArray) SampleScrollSupport(com.tmall.wireless.tangram.example.support.SampleScrollSupport) Handler(android.os.Handler) RecyclerView(android.support.v7.widget.RecyclerView) IOException(java.io.IOException) TargetApi(android.annotation.TargetApi)

Example 12 with Card

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

the class GridCard method offsetChildCard.

@Override
public void offsetChildCard(Card anchorCard, int offset) {
    if (anchorCard == null) {
        return;
    }
    ArrayMap<Range<Integer>, Card> newChildren = new ArrayMap<>();
    boolean startOffset = false;
    for (int i = 0, size = mChildren.size(); i < size; i++) {
        Range<Integer> key = mChildren.keyAt(i);
        Card child = mChildren.valueAt(i);
        if (child == anchorCard) {
            Range<Integer> newKey = Range.create(key.getLower().intValue(), key.getUpper().intValue() + offset);
            newChildren.put(newKey, child);
            startOffset = true;
            continue;
        }
        if (startOffset) {
            Range<Integer> newKey = Range.create(key.getLower().intValue() + offset, key.getUpper().intValue() + offset);
            newChildren.put(newKey, child);
        } else {
            newChildren.put(key, child);
        }
    }
    mChildren.clear();
    mChildren.putAll((SimpleArrayMap<? extends Range<Integer>, ? extends Card>) newChildren);
}
Also used : SimpleArrayMap(android.support.v4.util.SimpleArrayMap) ArrayMap(android.support.v4.util.ArrayMap) Range(com.alibaba.android.vlayout.Range) Card(com.tmall.wireless.tangram3.dataparser.concrete.Card)

Example 13 with Card

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

the class PojoGroupBasicAdapter method insertComponents.

@Override
public void insertComponents(int pos, List<BaseCell> components) {
    if (mData != null && mData.size() > 0 && components != null && !components.isEmpty() && pos >= 0) {
        int newItemSize = components.size();
        if (mCards != null) {
            List<Pair<Range<Integer>, Card>> newCards = new ArrayList<>();
            for (int i = 0, size = mCards.size(); i < size; i++) {
                Pair<Range<Integer>, Card> pair = mCards.get(i);
                int start = pair.first.getLower();
                int end = pair.first.getUpper();
                if (end < pos) {
                    // do nothing
                    newCards.add(pair);
                } else if (start <= pos && pos < end) {
                    Pair<Range<Integer>, Card> newPair = new Pair<>(Range.create(start, end + newItemSize), pair.second);
                    newCards.add(newPair);
                } else if (pos <= start) {
                    Pair<Range<Integer>, Card> newPair = new Pair<>(Range.create(start + newItemSize, end + newItemSize), pair.second);
                    newCards.add(newPair);
                }
            }
            mCards.clear();
            mCards.addAll(newCards);
        }
        for (int i = 0, size = components.size(); i < size; i++) {
            BaseCell cell = components.get(i);
            if (cell != null) {
                cell.added();
            }
        }
        for (int i = 0; i < newItemSize; i++) {
            if ((pos + i) < mData.size()) {
                mData.add(pos + i, components.get(i));
            } else {
                mData.add(components.get(i));
            }
        }
        notifyItemRangeInserted(pos, newItemSize);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BaseCell(com.tmall.wireless.tangram3.structure.BaseCell) ArrayList(java.util.ArrayList) Range(com.alibaba.android.vlayout.Range) Pair(android.util.Pair)

Example 14 with Card

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

the class GridCard method addChildCard.

@Override
public void addChildCard(Card card) {
    if (card == null) {
        return;
    }
    List<BaseCell> subCells = card.getCells();
    if (subCells != null && !subCells.isEmpty()) {
        addCells(card.getCells());
        int startOffset = mCells.indexOf(subCells.get(0));
        int endOffset = mCells.indexOf(subCells.get(subCells.size() - 1));
        Range range = Range.create(startOffset, endOffset);
        mChildren.put(range, card);
    }
}
Also used : BaseCell(com.tmall.wireless.tangram3.structure.BaseCell) Range(com.alibaba.android.vlayout.Range)

Example 15 with Card

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

the class Card method addCellInternal.

public 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;
                }
                if (mHeader != null) {
                    mHeader.pos = 0;
                }
                return true;
            }
        }
    }
    return false;
}
Also used : MVHelper(com.tmall.wireless.tangram3.MVHelper)

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