Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a150bdc authored by Danny Baumann's avatar Danny Baumann
Browse files

Fix call grouping.

We can not assume the only type of call duplication is international
prefix vs. no international prefix. There's also other cases, like in
the US: 1 123-456-7890 vs. (123) 456-7890.

Fixes issue CYAN-345.

Change-Id: I7b40dc6277f8e2dbfc4f6fe3319acc086c3f06fe
parent f5951668
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -54,8 +54,7 @@ public class CallStatsDetails implements CallDetailHeader.Data, Parcelable {
        this.geocode = geocode;
        this.date = date;

        this.inDuration = this.outDuration = 0;
        this.incomingCount = this.outgoingCount = this.missedCount = 0;
        reset();

        if (info != null) {
            updateFromInfo(info);
@@ -167,6 +166,11 @@ public class CallStatsDetails implements CallDetailHeader.Data, Parcelable {
        this.missedCount += other.missedCount;
    }

    public void reset() {
        this.inDuration = this.outDuration = 0;
        this.incomingCount = this.outgoingCount = this.missedCount = 0;
    }

    /* Parcelable interface */

    @Override
+4 −7
Original line number Diff line number Diff line
@@ -123,7 +123,7 @@ public class CallStatsQueryHandler extends AsyncQueryHandler {

        startQuery(QUERY_CALLS_TOKEN, null, Calls.CONTENT_URI, CallStatsQuery._PROJECTION,
                selection.toString(), selectionArgs.toArray(EMPTY_STRING_ARRAY),
                Calls.NUMBER + " DESC");
                Calls.NUMBER + " ASC");
    }

    @Override
@@ -194,24 +194,21 @@ public class CallStatsQueryHandler extends AsyncQueryHandler {
        final ArrayList<CallStatsDetails> callsToRemove = new ArrayList<CallStatsDetails>();
        final ArrayList<ContactInfo> infosToRemove = new ArrayList<ContactInfo>();

        // numbers in non-international format will be the first
        for (int i = 0; i < calls.size(); i++) {
            final CallStatsDetails outerItem = calls.get(i);
            final String currentFormattedNumber = outerItem.number.toString();

            if (currentFormattedNumber.startsWith("+")) {
                continue; // we don't check numbers starting with +, only removing from this point
            }

            for (int j = calls.size() - 1; j > i; j--) {
                final CallStatsDetails innerItem = calls.get(j);
                final String innerNumber = innerItem.number.toString();

                if (ContactsUtils.phoneNumbersEqual(currentFormattedNumber, innerNumber)) {
                    outerItem.mergeWith(innerItem);
                    //make sure we're not counting twice in case we're dealing with
                    //multiple different formats
                    innerItem.reset();
                    callsToRemove.add(innerItem);
                    infosToRemove.add(infos.get(j));
                    break; // we don't have multiple items with the same number, stop
                }
            }
        }