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

Commit cfab2457 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Printers in the list of printers change position.

While the logic was correct the array map that holds the list of pritners
does not keep the position of the items constant. Switched to linked hash
map which gives this guarantee.

bug:10955751

Change-Id: Idbbe14d753e6a1ad1002f2289b10cb62d7f9f040
parent c6568719
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.util.Log;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;

/**
@@ -40,8 +41,8 @@ public final class PrinterDiscoverySession {
    private static final int MSG_PRINTERS_ADDED = 1;
    private static final int MSG_PRINTERS_REMOVED = 2;

    private final ArrayMap<PrinterId, PrinterInfo> mPrinters =
            new ArrayMap<PrinterId, PrinterInfo>();
    private final LinkedHashMap<PrinterId, PrinterInfo> mPrinters =
            new LinkedHashMap<PrinterId, PrinterInfo>();

    private final IPrintManager mPrintManager;

@@ -218,9 +219,7 @@ public final class PrinterDiscoverySession {
        }

        // Update printers we already have.
        final int oldPrinterCount = mPrinters.size();
        for (int i = 0; i < oldPrinterCount; i++) {
            PrinterId oldPrinterId = mPrinters.keyAt(i);
        for (PrinterId oldPrinterId : mPrinters.keySet()) {
            PrinterInfo updatedPrinter = addedPrintersMap.remove(oldPrinterId);
            if (updatedPrinter != null) {
                mPrinters.put(oldPrinterId, updatedPrinter);