diff options
author | linyuh <linyuh@google.com> | 2018-01-08 15:55:39 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-01-08 17:14:16 -0800 |
commit | e29b98635ce078c61029e9068504c9b96ce99e74 (patch) | |
tree | 9d40fe621d5f81fb22641d459f15d99368147e9a | |
parent | d886c96011340fb05d73b806ce2745d8049d81ca (diff) |
Simplifying implementation of the coalescing logic in the new call log.
Bug: 70388714
Test: Existing tests
PiperOrigin-RevId: 181231987
Change-Id: I0c7386f60e92f7087f9f5ad1b1f454b43b7227e7
-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; } |