use of com.tmall.wireless.tangram.structure.style.DelegateStyle in project Tangram-Android by alibaba.
the class FusionCard method parseStyle.
@Override
public void parseStyle(JSONObject data) {
style = new DelegateStyle();
if (data != null) {
style.parseWith(data);
for (DelegateStyle.CardInfo info : ((DelegateStyle) style).cardInfos) {
try {
info.data.put("load", load);
info.data.put("loadMore", loadMore);
info.data.put("hasMore", hasMore);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
use of com.tmall.wireless.tangram.structure.style.DelegateStyle in project Tangram-Android by alibaba.
the class FusionCard method getCards.
@SuppressWarnings("unchecked")
@Override
public List<Card> getCards(final CardResolver cardResolver) {
if (serviceManager == null)
return Collections.emptyList();
final CardLoadSupport loadSupport = serviceManager.getService(CardLoadSupport.class);
final MVHelper cellResolver = serviceManager.getService(MVHelper.class);
final ViewFactory viewFactory = serviceManager.getService(ViewFactory.class);
if (loadSupport == null || cellResolver == null || cardResolver == null)
return Collections.emptyList();
if (style instanceof DelegateStyle) {
DelegateStyle dStyle = (DelegateStyle) this.style;
final Card anchorCard = cardResolver.create(String.valueOf(TangramBuilder.TYPE_SINGLE_COLUMN));
final BaseCell emptyCell = new BaseCell(TangramBuilder.TYPE_EMPTY_VIEW);
if (emptyCell.style != null)
emptyCell.style.height = 0;
anchorCard.addCell(emptyCell);
final Card headerCard = cardResolver.create(String.valueOf(TangramBuilder.TYPE_STICKY_START));
final BaseCell tabCell = mCells.get(0);
mCells.remove(0);
// asign header id
headerCard.id = id + "-tabheader";
headerCard.addCell(tabCell);
final DelegateStyle.CardInfo info = dStyle.cardInfos.get(0);
final String cardType = info.type;
final Card originalCard = cardResolver.create(String.valueOf(info.type));
// no cell is needed
originalCard.setStringType(info.type);
// assign id;
originalCard.id = id;
originalCard.parseWith(info.data, cellResolver);
final Card contentCard = new FusionContentCard(originalCard, (tabCell instanceof SwitchTabHeaderCell) ? (SwitchTabHeaderCell) tabCell : null, 0);
if (viewFactory != null) {
View view = viewFactory.create();
int defaultHeight = viewFactory.getDefaultHeight();
if (view != null && defaultHeight > 0)
contentCard.enablePlaceholderView(view, defaultHeight);
}
contentCard.loadMore = true;
contentCard.hasMore = true;
if (TextUtils.isEmpty(contentCard.load))
contentCard.load = this.load;
if (TextUtils.isEmpty(contentCard.load))
return Collections.emptyList();
if (mCells.size() > 0) {
contentCard.addCells(mCells);
}
if (mPendingCells.size() > 0) {
contentCard.addCells(mPendingCells);
}
if ((tabCell instanceof SwitchTabHeaderCell)) {
final SwitchTabHeaderCell switchHeader = (SwitchTabHeaderCell) tabCell;
switchHeader.setSwitchTabTrigger(new SwitchTabTrigger() {
private Map<Integer, IndexCache> mCacheMap = new HashMap<>();
private int currentIndex = 0;
private Card currentCard = contentCard;
@Override
public void invalidate(int index) {
mCacheMap.remove(index);
if (currentIndex == index) {
currentIndex = -1;
}
}
@Override
public void switchTo(int index, @NonNull Cell cell, Map<String, Object> params) {
switchTo(index, FusionCard.this.id, cell, params);
}
@Override
public void switchTo(int index, String id, @NonNull Cell cell, @Nullable Map<String, Object> params) {
if (currentIndex == index) {
// reassign id
currentCard.id = id;
currentCard.setParams(params);
return;
}
if (currentIndex >= 0)
mCacheMap.put(currentIndex, new IndexCache(currentIndex, currentCard));
IndexCache indexCache = mCacheMap.get(index);
if (indexCache == null) {
Card newCard = cardResolver.create(cardType);
// no cell is needed
newCard.setStringType(cardType);
// assign id
newCard.id = id;
newCard.parseWith(info.data, cellResolver);
newCard = new FusionContentCard(newCard, switchHeader, index);
newCard.loadMore = true;
newCard.hasMore = true;
if (viewFactory != null) {
View view = viewFactory.create();
int defaultHeight = viewFactory.getDefaultHeight();
if (view != null && defaultHeight > 0)
newCard.enablePlaceholderView(view, defaultHeight);
}
indexCache = new IndexCache(index, newCard);
}
indexCache.card.setParams(params);
// TODO: not generic!!!
Engine engine = (Engine) FusionCard.this.serviceManager;
if (engine != null) {
// first stopScrolling!!!
engine.scrollToPosition(headerCard);
engine.replaceCard(currentCard, indexCache.card);
currentCard = indexCache.card;
if (!currentCard.loaded)
loadSupport.loadMore(currentCard);
}
currentIndex = index;
}
});
} else {
return Collections.emptyList();
}
return Arrays.asList(anchorCard, headerCard, contentCard);
}
return Collections.emptyList();
}
Aggregations