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

Commit 2916f658 authored by Svet Ganov's avatar Svet Ganov
Browse files

Sometimes historical printers not properly ordered.

We order printers based on past usage. In some cases the ordering
does not work. The reason for that was an incorrect assumption that
the entries in an ArrayMap are ordered in the order they are added.

bug:18109283

Change-Id: Ie367e4ca5e6bd79f335a060074c9211054e3a931
parent bd6fabe2
Loading
Loading
Loading
Loading
+7 −13
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -91,14 +92,14 @@ public final class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
        mPersistenceManager.addPrinterAndWritePrinterHistory(printer);
    }

    private void computeAndDeliverResult(ArrayMap<PrinterId, PrinterInfo> discoveredPrinters,
            ArrayMap<PrinterId, PrinterInfo> favoritePrinters) {
    private void computeAndDeliverResult(Map<PrinterId, PrinterInfo> discoveredPrinters,
            List<PrinterInfo> favoritePrinters) {
        List<PrinterInfo> printers = new ArrayList<>();

        // Add the updated favorite printers.
        final int favoritePrinterCount = favoritePrinters.size();
        for (int i = 0; i < favoritePrinterCount; i++) {
            PrinterInfo favoritePrinter = favoritePrinters.valueAt(i);
            PrinterInfo favoritePrinter = favoritePrinters.get(i);
            PrinterInfo updatedPrinter = discoveredPrinters.remove(
                    favoritePrinter.getId());
            if (updatedPrinter != null) {
@@ -215,21 +216,14 @@ public final class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
        // printer to use its current name instead of the historical one.
        mPersistenceManager.updatePrintersHistoricalNamesIfNeeded(printers);

        ArrayMap<PrinterId, PrinterInfo> printersMap = new ArrayMap<>();
        Map<PrinterId, PrinterInfo> printersMap = new LinkedHashMap<>();
        final int printerCount = printers.size();
        for (int i = 0; i < printerCount; i++) {
            PrinterInfo printer = printers.get(i);
            printersMap.put(printer.getId(), printer);
        }

        ArrayMap<PrinterId, PrinterInfo> favoritePrintersMap = new ArrayMap<>();
        final int favoritePrinterCount = favoritePrinters.size();
        for (int i = 0; i < favoritePrinterCount; i++) {
            PrinterInfo favoritePrinter = favoritePrinters.get(i);
            favoritePrintersMap.put(favoritePrinter.getId(), favoritePrinter);
        }

        computeAndDeliverResult(printersMap, favoritePrintersMap);
        computeAndDeliverResult(printersMap, favoritePrinters);
    }

    @Override
@@ -544,7 +538,7 @@ public final class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
                mReadHistoryCompleted = true;

                // Deliver the printers.
                updatePrinters(mDiscoverySession.getPrinters(), mHistoricalPrinters);
                updatePrinters(mDiscoverySession.getPrinters(), mFavoritePrinters);

                // Loading the available printers if needed.
                loadInternal();