/** Merges multiple sections to reduce visual raggedness. */ private void mergeSections() { // Ignore merging until we have an algorithm and a valid row size if (mMergeAlgorithm == null || mNumAppsPerRow == 0) { return; } // Go through each section and try and merge some of the sections if (!hasFilter()) { int sectionAppCount = 0; for (int i = 0; i < mSections.size() - 1; i++) { SectionInfo section = mSections.get(i); sectionAppCount = section.numApps; int mergeCount = 1; // Merge rows based on the current strategy while (i < (mSections.size() - 1) && mMergeAlgorithm.continueMerging( section, mSections.get(i + 1), sectionAppCount, mNumAppsPerRow, mergeCount)) { SectionInfo nextSection = mSections.remove(i + 1); // Remove the next section break mAdapterItems.remove(nextSection.sectionBreakItem); int pos = mAdapterItems.indexOf(section.firstAppItem); // Point the section for these new apps to the merged section int nextPos = pos + section.numApps; for (int j = nextPos; j < (nextPos + nextSection.numApps); j++) { AdapterItem item = mAdapterItems.get(j); item.sectionInfo = section; item.sectionAppIndex += section.numApps; } // Update the following adapter items of the removed section item pos = mAdapterItems.indexOf(nextSection.firstAppItem); for (int j = pos; j < mAdapterItems.size(); j++) { AdapterItem item = mAdapterItems.get(j); item.position--; } section.numApps += nextSection.numApps; sectionAppCount += nextSection.numApps; if (DEBUG) { Log.d( TAG, "Merging: " + nextSection.firstAppItem.sectionName + " to " + section.firstAppItem.sectionName + " mergedNumRows: " + (sectionAppCount / mNumAppsPerRow)); } mergeCount++; } } } }
/** * Does the content merge. The three texts base, ours and theirs are specified with {@link * CanonicalTreeParser}. If any of the parsers is specified as <code>null</code> then an empty * text will be used instead. * * @param base * @param ours * @param theirs * @return the result of the content merge * @throws IOException */ private MergeResult<RawText> contentMerge( CanonicalTreeParser base, CanonicalTreeParser ours, CanonicalTreeParser theirs) throws IOException { RawText baseText = base == null ? RawText.EMPTY_TEXT : getRawText(base.getEntryObjectId(), reader); RawText ourText = ours == null ? RawText.EMPTY_TEXT : getRawText(ours.getEntryObjectId(), reader); RawText theirsText = theirs == null ? RawText.EMPTY_TEXT : getRawText(theirs.getEntryObjectId(), reader); return (mergeAlgorithm.merge(RawTextComparator.DEFAULT, baseText, ourText, theirsText)); }