From e29b98635ce078c61029e9068504c9b96ce99e74 Mon Sep 17 00:00:00 2001 From: linyuh Date: Mon, 8 Jan 2018 15:55:39 -0800 Subject: Simplifying implementation of the coalescing logic in the new call log. Bug: 70388714 Test: Existing tests PiperOrigin-RevId: 181231987 Change-Id: I0c7386f60e92f7087f9f5ad1b1f454b43b7227e7 --- .../android/dialer/calllog/database/Coalescer.java | 51 ++++++++++++---------- 1 file 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 currentRowGroup = new ArrayList<>(); + if (!allAnnotatedCallLogRowsSortedByTimestampDesc.moveToFirst()) { + return allCoalescedRowsMatrixCursor; + } - do { - ContentValues currentRow = - cursorRowToContentValues(allAnnotatedCallLogRowsSortedByTimestampDesc); + int coalescedRowId = 0; + List 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; } -- cgit v1.2.3