public void buildCorpusGroups() { Suggestions suggestions = getSuggestions(); SuggestionCursor promoted = getCurrentPromotedSuggestions(); HashSet<String> promotedSuggestions = new HashSet<String>(); if (promoted != null && promoted.getCount() > 0) { promoted.moveTo(0); do { promotedSuggestions.add(SuggestionUtils.getSuggestionKey(promoted)); } while (promoted.moveToNext()); } if (suggestions == null) { mCorpusGroups = null; } else { if (mCorpusGroups == null) { mCorpusGroups = new ArrayList<SuggestionCursor>(); } else { mCorpusGroups.clear(); } for (CorpusResult result : suggestions.getCorpusResults()) { ListSuggestionCursor corpusSuggestions = new ListSuggestionCursor(result.getUserQuery()); for (int i = 0; i < result.getCount(); ++i) { result.moveTo(i); if (!result.isWebSearchSuggestion()) { if (!promotedSuggestions.contains(SuggestionUtils.getSuggestionKey(result))) { corpusSuggestions.add(new SuggestionPosition(result, i)); } } } if (corpusSuggestions.getCount() > 0) { mCorpusGroups.add(corpusSuggestions); } corpusSuggestions.close(); } } }
@Override public Suggestion getChild(int groupPosition, int childPosition) { SuggestionCursor c = getGroup(groupPosition); if (c != null) { c.moveTo(childPosition); return new SuggestionPosition(c, childPosition); } return null; }