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

Commit f64dc765 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "PBAP: Apply listStartOffset in the final list."

parents d03e39ff b584b965
Loading
Loading
Loading
Loading
+31 −16
Original line number Diff line number Diff line
@@ -817,50 +817,65 @@ public class BluetoothPbapObexServer extends ServerRequestHandler {
        }

        if (type.equals("number")) {
            ArrayList<Integer> savedPosList = new ArrayList<>();
            ArrayList<String> selectedNameList = new ArrayList<String>();
            // query the number, to get the names
            ArrayList<String> names =
                    mVcardManager.getContactNamesByNumber(appParamValue.searchValue);
            if (mOrderBy == ORDER_BY_ALPHABETICAL) Collections.sort(names);
            for (int i = 0; i < names.size(); i++) {
                compareValue = names.get(i).trim();
                if (D) {
                    Log.d(TAG, "compareValue=" + compareValue);
                }
                for (int pos = appParamValue.listStartOffset;
                        pos < listSize && itemsFound < requestSize; pos++) {
                if (D) Log.d(TAG, "compareValue=" + compareValue);
                for (int pos = 0; pos < listSize; pos++) {
                    currentValue = nameList.get(pos);
                    if (V) {
                        Log.d(TAG, "currentValue=" + currentValue);
                    }
                    if (currentValue.equals(compareValue)) {
                        itemsFound++;
                        if (currentValue.contains(",")) {
                            currentValue = currentValue.substring(0, currentValue.lastIndexOf(','));
                        }
                        writeVCardEntry(pos, currentValue, result);
                        selectedNameList.add(currentValue);
                        savedPosList.add(pos);
                    }
                }
                if (itemsFound >= requestSize) {
                    break;
            }

            for (int j = appParamValue.listStartOffset;
                    j < selectedNameList.size() && itemsFound < requestSize; j++) {
                itemsFound++;
                writeVCardEntry(savedPosList.get(j), selectedNameList.get(j), result);
            }

        } else {
            ArrayList<Integer> savedPosList = new ArrayList<>();
            ArrayList<String> selectedNameList = new ArrayList<String>();
            if (appParamValue.searchValue != null) {
                compareValue = appParamValue.searchValue.trim().toLowerCase();
            }
            for (int pos = appParamValue.listStartOffset;
                    pos < listSize && itemsFound < requestSize; pos++) {

            for (int pos = 0; pos < listSize; pos++) {
                currentValue = nameList.get(pos);

                if (currentValue.contains(",")) {
                    currentValue = currentValue.substring(0, currentValue.lastIndexOf(','));
                }

                if (appParamValue.searchValue.isEmpty() || ((currentValue.toLowerCase()).startsWith(
                        compareValue))) {
                    itemsFound++;
                    writeVCardEntry(pos, currentValue, result);
                if (appParamValue.searchValue != null) {
                    if (appParamValue.searchValue.isEmpty()
                            || ((currentValue.toLowerCase())
                                               .startsWith(compareValue.toLowerCase()))) {
                        selectedNameList.add(currentValue);
                        savedPosList.add(pos);
                    }
                }
            }

            for (int i = appParamValue.listStartOffset;
                    i < selectedNameList.size() && itemsFound < requestSize; i++) {
                itemsFound++;
                writeVCardEntry(savedPosList.get(i), selectedNameList.get(i), result);
            }
        }
        return itemsFound;
    }
+8 −1
Original line number Diff line number Diff line
@@ -332,12 +332,18 @@ public class BluetoothPbapVcardManager {
            contactCursor = mResolver.query(myUri, PHONES_CONTACTS_PROJECTION, null, null,
                    Phone.CONTACT_ID);

            ArrayList<String> contactNameIdList = new ArrayList<String>();
            appendDistinctNameIdList(contactNameIdList,
                    mContext.getString(android.R.string.unknownName), contactCursor);

            if (contactCursor != null) {
                if (!composer.initWithCallback(contactCursor,
                        new EnterpriseRawContactEntitlesInfoCallback())) {
                    return nameList;
                }

                int i = 0;
                contactCursor.moveToFirst();
                while (!composer.isAfterLast()) {
                    String vcard = composer.createOneEntry();
                    if (vcard == null) {
@@ -362,8 +368,9 @@ public class BluetoothPbapVcardManager {
                        if (TextUtils.isEmpty(name)) {
                            name = mContext.getString(android.R.string.unknownName);
                        }
                        nameList.add(name);
                        nameList.add(contactNameIdList.get(i));
                    }
                    i++;
                }
                if (orderByWhat == BluetoothPbapObexServer.ORDER_BY_INDEXED) {
                    if (V) {