diff options
-rw-r--r-- | java/com/android/dialer/calllog/database/Coalescer.java | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/java/com/android/dialer/calllog/database/Coalescer.java b/java/com/android/dialer/calllog/database/Coalescer.java index f4ef02a25..9b788140a 100644 --- a/java/com/android/dialer/calllog/database/Coalescer.java +++ b/java/com/android/dialer/calllog/database/Coalescer.java @@ -80,40 +80,45 @@ public class Coalescer { CoalescedAnnotatedCallLog.ALL_COLUMNS, Assert.isNotNull(allAnnotatedCallLogRowsSortedByTimestampDesc).getCount()); - if (allAnnotatedCallLogRowsSortedByTimestampDesc.moveToFirst()) { - int coalescedRowId = 0; - - List<ContentValues> currentRowGroup = new ArrayList<>(); + if (!allAnnotatedCallLogRowsSortedByTimestampDesc.moveToFirst()) { + return allCoalescedRowsMatrixCursor; + } - do { - ContentValues currentRow = - cursorRowToContentValues(allAnnotatedCallLogRowsSortedByTimestampDesc); + int coalescedRowId = 0; + List<ContentValues> currentRowGroup = new ArrayList<>(); - if (currentRowGroup.isEmpty()) { - currentRowGroup.add(currentRow); - continue; - } + ContentValues firstRow = cursorRowToContentValues(allAnnotatedCallLogRowsSortedByTimestampDesc); + currentRowGroup.add(firstRow); - ContentValues previousRow = currentRowGroup.get(currentRowGroup.size() - 1); + while (!currentRowGroup.isEmpty()) { + // Group consecutive rows + ContentValues firstRowInGroup = currentRowGroup.get(0); + ContentValues currentRow = null; + while (allAnnotatedCallLogRowsSortedByTimestampDesc.moveToNext()) { + currentRow = cursorRowToContentValues(allAnnotatedCallLogRowsSortedByTimestampDesc); - if (!rowsShouldBeCombined(dialerPhoneNumberUtil, previousRow, currentRow)) { - ContentValues coalescedRow = coalesceRowsForAllDataSources(currentRowGroup); - coalescedRow.put( - CoalescedAnnotatedCallLog.COALESCED_IDS, - getCoalescedIds(currentRowGroup).toByteArray()); - addContentValuesToMatrixCursor( - coalescedRow, allCoalescedRowsMatrixCursor, coalescedRowId++); - currentRowGroup.clear(); + if (!rowsShouldBeCombined(dialerPhoneNumberUtil, firstRowInGroup, currentRow)) { + break; } + currentRowGroup.add(currentRow); - } while (allAnnotatedCallLogRowsSortedByTimestampDesc.moveToNext()); + } - // Deal with leftover rows. + // Coalesce the group into a single row ContentValues coalescedRow = coalesceRowsForAllDataSources(currentRowGroup); coalescedRow.put( CoalescedAnnotatedCallLog.COALESCED_IDS, getCoalescedIds(currentRowGroup).toByteArray()); - addContentValuesToMatrixCursor(coalescedRow, allCoalescedRowsMatrixCursor, coalescedRowId); + addContentValuesToMatrixCursor(coalescedRow, allCoalescedRowsMatrixCursor, coalescedRowId++); + + // Clear the current group after the rows are coalesced. + currentRowGroup.clear(); + + // Add the first of the remaining rows to the current group. + if (!allAnnotatedCallLogRowsSortedByTimestampDesc.isAfterLast()) { + currentRowGroup.add(currentRow); + } } + return allCoalescedRowsMatrixCursor; } |