Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Fix bugs on tangram3.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAfc committed Mar 1, 2019
1 parent 049b241 commit 90762f2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;

import com.alibaba.android.vlayout.VirtualLayoutManager;
import com.alibaba.fastjson.JSONArray;
Expand Down Expand Up @@ -57,7 +58,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -343,7 +343,7 @@ public Card parseSingleGroup(@Nullable JSONObject data, @NonNull final ServiceMa

for (BaseCell cell : card.mCells) {
if (cell.style.extras != null) {
int colSpan = cell.style.extras.getIntValue("colSpan");
int colSpan = cell.style.extras.getIntValue("colspan");
if (colSpan == 0) {
colSpan = 1;
}
Expand Down Expand Up @@ -386,9 +386,9 @@ public Card parseSingleGroup(@Nullable JSONObject data, @NonNull final ServiceMa
bannerCard.cell.setIndicatorGap(Style.parseSize(styleJson.getString(ATTR_INDICATOR_GAP), 0));
bannerCard.cell.setIndicatorMargin(Style.parseSize(styleJson.getString(ATTR_INDICATOR_MARGIN), 0));
bannerCard.cell.setIndicatorHeight(Style.parseSize(styleJson.getString(ATTR_INDICATOR_HEIGHT), 0));
bannerCard.cell.setPageWidth(styleJson.getDoubleValue(ATTR_PAGE_WIDTH));
bannerCard.cell.setPageWidth(Utils.getJsonFloatValue(styleJson, ATTR_PAGE_WIDTH));
bannerCard.cell.sethGap(Style.parseSize(styleJson.getString(ATTR_HGAP), 0));
bannerCard.cell.itemRatio = styleJson.getDoubleValue(ATTR_ITEM_RATIO);
bannerCard.cell.itemRatio = Utils.getJsonDoubleValue(styleJson, ATTR_ITEM_RATIO);
bannerCard.cell.itemMargin[0] = Style.parseSize(styleJson.getString(ATTR_ITEM_MARGIN_LEFT), 0);
bannerCard.cell.itemMargin[1] = Style.parseSize(styleJson.getString(ATTR_ITEM_MARGIN_RIGHT), 0);
Style style = new Style();
Expand Down Expand Up @@ -572,7 +572,7 @@ public Card parseSingleGroup(@Nullable JSONObject data, @NonNull final ServiceMa
}
linearScrollCard.cell.maxRows = maxRows;
try {
linearScrollCard.cell.maxCols = Integer.parseInt(styleJson.getString(LinearScrollCell.KEY_MAX_COLS));
linearScrollCard.cell.maxCols = (int) styleJson.getDoubleValue(LinearScrollCell.KEY_MAX_COLS);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -684,11 +684,18 @@ public <T extends Style> T parseStyle(@NonNull T style, @Nullable JSONObject dat
style.bgImgUrl = backgroundImage;
}

style.aspectRatio = data.getFloatValue(KEY_ASPECT_RATIO);
Float aspectRatio = data.getFloat(KEY_ASPECT_RATIO);
if (aspectRatio == null) {
style.aspectRatio = Float.NaN;
} else {
style.aspectRatio = aspectRatio;
}

Float ratio = data.getFloat(KEY_RATIO);
if (ratio != null) {
style.aspectRatio = ratio;
} else {
style.aspectRatio = Float.NaN;
}

style.zIndex = data.getIntValue(KEY_ZINDEX);
Expand Down Expand Up @@ -824,6 +831,9 @@ private BaseCell createCell(@Nullable Card parent, @NonNull MVHelper resolver, @
} else {
BaseCellBinderResolver componentBinderResolver = serviceManager.getService(BaseCellBinderResolver.class);
// if cell type not register and has component info, register it!
if (TangramBuilder.isPrintLog()) {
LogUtils.e("PojoDataParser", "createCell status: cellType=" + cellType + ", componentInfoMap=" + (componentInfoMap == null ? "null" : componentInfoMap.toString()));
}
if (!componentBinderResolver.has(cellType) && componentInfoMap != null && componentInfoMap.containsKey(cellType)) {
componentBinderResolver.register(cellType, new BaseCellBinder<>(cellType, resolver));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ public void setBgColor(int bgColor) {
this.mBgColor = bgColor;
}

public void setPageWidth(double pageWidth) {
this.pageWidth = (float) pageWidth;
public void setPageWidth(float pageWidth) {
this.pageWidth = pageWidth;
}

public void sethGap(int hGap) {
Expand Down
17 changes: 17 additions & 0 deletions tangram/src/main/java/com/tmall/wireless/tangram3/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,21 @@ public static boolean isCard(String type) {
}
}

public static Float getJsonFloatValue(JSONObject json, String key) {
Float tmp = json.getFloat(key);
if (tmp == null) {
return Float.NaN;
} else {
return tmp;
}
}

public static Double getJsonDoubleValue(JSONObject json, String key) {
Double tmp = json.getDouble(key);
if (tmp == null) {
return Double.NaN;
} else {
return tmp;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,8 @@ public void postBindView(BaseCell cell) {
if (bannerCell.mCells.size() <= bannerCell.mInfiniteMinCount) {
setInfiniteLoop(false);
} else {
// setInfiniteLoop(bannerCell.mInfinite);
setInfiniteLoop(bannerCell.mInfinite);
}
mUltraViewPager.setRatio(1);
setIndicatorGravity(getIndicatorGravity(bannerCell.mIndicatorGravity));
setIndicatorPos(bannerCell.mIndicatorPos);
int indicatorGap = bannerCell.mIndicatorGap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private int getScreenWidth() {
}

private void bindHeaderView(BaseCell cell) {
if (cell.isValid()) {
if (cell != null && cell.isValid()) {
View header = getViewFromRecycler(cell);
if (header != null) {
header.setId(R.id.TANGRAM_BANNER_HEADER_ID);
Expand All @@ -355,7 +355,7 @@ private void bindHeaderView(BaseCell cell) {
}

private void bindFooterView(BaseCell cell) {
if (cell.isValid()) {
if (cell != null && cell.isValid()) {
View footer = getViewFromRecycler(cell);
if (footer != null) {
footer.setId(R.id.TANGRAM_BANNER_FOOTER_ID);
Expand Down

0 comments on commit 90762f2

Please sign in to comment.