|
|
|
@ -47,11 +47,9 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public SearchResult getLessSearchResult(String[] searchText) { |
|
|
|
|
|
|
|
|
|
if (ArrayUtils.isEmpty(searchText)) { |
|
|
|
|
return new SearchResult(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.modelList = new SearchResult(); |
|
|
|
|
this.recommendModelList = new SearchResult(); |
|
|
|
|
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainRecommend()) { |
|
|
|
@ -61,14 +59,13 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
|
|
|
|
|
String result = HttpToolbox.get(AlphaFineConstants.SEARCH_API + CodeUtils.cjkEncode(searchText[j])); |
|
|
|
|
AlphaFineHelper.checkCancel(); |
|
|
|
|
JSONObject jsonObject = new JSONObject(result); |
|
|
|
|
if (jsonObject.optString("status").equals("success")) { |
|
|
|
|
if ("success".equals(jsonObject.optString("status"))) { |
|
|
|
|
JSONArray jsonArray = jsonObject.optJSONArray("result"); |
|
|
|
|
if (jsonArray != null && jsonArray.length() > 0) { |
|
|
|
|
for (int i = 0; i < jsonArray.length(); i++) { |
|
|
|
|
AlphaFineHelper.checkCancel(); |
|
|
|
|
AlphaCellModel alphaCellModel = CellModelHelper.getModelFromJson((JSONObject) jsonArray.get(i)); |
|
|
|
|
if (alphaCellModel != null && !alreadyContain(alphaCellModel)) { |
|
|
|
|
|
|
|
|
|
this.recommendModelList.add(alphaCellModel); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -91,58 +88,15 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
|
|
|
|
|
complementAdviceModelList = ComplementAdviceManager.getInstance().getAllSearchResult(searchText); |
|
|
|
|
moreModelList.clear(); |
|
|
|
|
|
|
|
|
|
if (recommendModelList.size() > 0) { |
|
|
|
|
if (complementAdviceModelList.size() == 0) { |
|
|
|
|
if (recommendModelList.size() > AlphaFineConstants.SHOW_SIZE - 2) { |
|
|
|
|
if (recommendModelList.size() > AlphaFineConstants.SHOW_SIZE) { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND)); |
|
|
|
|
} else { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false)); |
|
|
|
|
} |
|
|
|
|
modelList.addAll(recommendModelList.subList(0, AlphaFineConstants.SHOW_SIZE - 2)); |
|
|
|
|
moreModelList.addAll(recommendModelList.subList(AlphaFineConstants.SHOW_SIZE - 2, recommendModelList.size())); |
|
|
|
|
} else { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false)); |
|
|
|
|
modelList.addAll(recommendModelList); |
|
|
|
|
} |
|
|
|
|
if (!recommendModelList.isEmpty()) { |
|
|
|
|
if (complementAdviceModelList.isEmpty()) { |
|
|
|
|
getRecommendSearchResult(); |
|
|
|
|
} else { |
|
|
|
|
if (recommendModelList.size() + complementAdviceModelList.size() > AlphaFineConstants.SHOW_SIZE) { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND)); |
|
|
|
|
if (recommendModelList.size() > AlphaFineConstants.SHOW_SIZE - 2) { |
|
|
|
|
modelList.addAll(recommendModelList.subList(0, AlphaFineConstants.SHOW_SIZE - 2)); |
|
|
|
|
moreModelList.addAll(recommendModelList.subList(AlphaFineConstants.SHOW_SIZE - 2, recommendModelList.size())); |
|
|
|
|
|
|
|
|
|
if (complementAdviceModelList.size() >= 2) { |
|
|
|
|
modelList.addAll(complementAdviceModelList.subList(0, 2)); |
|
|
|
|
moreModelList.addAll(complementAdviceModelList.subList(2, complementAdviceModelList.size())); |
|
|
|
|
} else { |
|
|
|
|
modelList.addAll(complementAdviceModelList); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
modelList.addAll(recommendModelList); |
|
|
|
|
if (complementAdviceModelList.size() >= (AlphaFineConstants.SHOW_SIZE - recommendModelList.size())) { |
|
|
|
|
modelList.addAll(complementAdviceModelList.subList(0, AlphaFineConstants.SHOW_SIZE - recommendModelList.size())); |
|
|
|
|
moreModelList.addAll(complementAdviceModelList.subList(2, complementAdviceModelList.size())); |
|
|
|
|
} else { |
|
|
|
|
modelList.addAll(complementAdviceModelList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false)); |
|
|
|
|
modelList.addAll(recommendModelList); |
|
|
|
|
modelList.addAll(complementAdviceModelList); |
|
|
|
|
} |
|
|
|
|
getRecommendAndAdviceSearchResult(); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (complementAdviceModelList.size() > 0) { |
|
|
|
|
if (complementAdviceModelList.size() > AlphaFineConstants.SHOW_SIZE) { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND)); |
|
|
|
|
modelList.addAll(complementAdviceModelList.subList(0, AlphaFineConstants.SHOW_SIZE)); |
|
|
|
|
moreModelList.addAll(complementAdviceModelList.subList(AlphaFineConstants.SHOW_SIZE, complementAdviceModelList.size())); |
|
|
|
|
} else { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false)); |
|
|
|
|
modelList.addAll(complementAdviceModelList); |
|
|
|
|
} |
|
|
|
|
if (!complementAdviceModelList.isEmpty()) { |
|
|
|
|
getComplementAdviceSearchResult(); |
|
|
|
|
} else { |
|
|
|
|
return modelList; |
|
|
|
|
} |
|
|
|
@ -151,6 +105,70 @@ public class RecommendSearchManager implements AlphaFineSearchProvider {
|
|
|
|
|
return modelList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 将推荐接口获取的数据分别放入“显示部分”,“显示更多”的list |
|
|
|
|
*/ |
|
|
|
|
private void getRecommendSearchResult(){ |
|
|
|
|
if (recommendModelList.size() > AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM) { |
|
|
|
|
if (recommendModelList.size() > AlphaFineConstants.SHOW_SIZE) { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND)); |
|
|
|
|
} else { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false)); |
|
|
|
|
} |
|
|
|
|
modelList.addAll(recommendModelList.subList(0, AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM)); |
|
|
|
|
moreModelList.addAll(recommendModelList.subList(AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM, recommendModelList.size())); |
|
|
|
|
} else { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false)); |
|
|
|
|
modelList.addAll(recommendModelList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 将补全接口获取的数据分别放入“显示部分”,“显示更多”的list |
|
|
|
|
*/ |
|
|
|
|
private void getComplementAdviceSearchResult(){ |
|
|
|
|
if (complementAdviceModelList.size() > AlphaFineConstants.SHOW_SIZE) { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND)); |
|
|
|
|
modelList.addAll(complementAdviceModelList.subList(0, AlphaFineConstants.SHOW_SIZE)); |
|
|
|
|
moreModelList.addAll(complementAdviceModelList.subList(AlphaFineConstants.SHOW_SIZE, complementAdviceModelList.size())); |
|
|
|
|
} else { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false)); |
|
|
|
|
modelList.addAll(complementAdviceModelList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 将推荐接口和补全接口获取的数据分别放入“显示部分”,“显示更多”的list |
|
|
|
|
*/ |
|
|
|
|
private void getRecommendAndAdviceSearchResult(){ |
|
|
|
|
if (recommendModelList.size() + complementAdviceModelList.size() > AlphaFineConstants.SHOW_SIZE) { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_ShowAll"), true, CellType.RECOMMEND)); |
|
|
|
|
if (recommendModelList.size() > AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM) { |
|
|
|
|
modelList.addAll(recommendModelList.subList(0, AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM)); |
|
|
|
|
moreModelList.addAll(recommendModelList.subList(AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM, recommendModelList.size())); |
|
|
|
|
|
|
|
|
|
if (complementAdviceModelList.size() >= AlphaFineConstants.SHOW_SIZE - AlphaFineConstants.RECOMMEND_MAX_ITEM_NUM) { |
|
|
|
|
modelList.addAll(complementAdviceModelList.subList(0, 2)); |
|
|
|
|
moreModelList.addAll(complementAdviceModelList.subList(2, complementAdviceModelList.size())); |
|
|
|
|
} else { |
|
|
|
|
modelList.addAll(complementAdviceModelList); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
modelList.addAll(recommendModelList); |
|
|
|
|
if (complementAdviceModelList.size() >= (AlphaFineConstants.SHOW_SIZE - recommendModelList.size())) { |
|
|
|
|
modelList.addAll(complementAdviceModelList.subList(0, AlphaFineConstants.SHOW_SIZE - recommendModelList.size())); |
|
|
|
|
moreModelList.addAll(complementAdviceModelList.subList(2, complementAdviceModelList.size())); |
|
|
|
|
} else { |
|
|
|
|
modelList.addAll(complementAdviceModelList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
modelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Recommend"), false)); |
|
|
|
|
modelList.addAll(recommendModelList); |
|
|
|
|
modelList.addAll(complementAdviceModelList); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 是否已包含该model |
|
|
|
|
* |
|
|
|
|