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

Commit ef7c7fe1 authored by Philip P. Moltmann's avatar Philip P. Moltmann Committed by Android (Google) Code Review
Browse files

Merge "Small corrections to the code that generates the print summary in the settings."

parents c6e7d300 43335444
Loading
Loading
Loading
Loading
+29 −20
Original line number Diff line number Diff line
@@ -590,7 +590,14 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment
            }
            return printJobInfos;
        }
    }

    /**
     * Should the print job the shown to the user in the settings app.
     *
     * @param printJob The print job in question.
     * @return true iff the print job should be shown.
     */
    private static boolean shouldShowToUser(PrintJobInfo printJob) {
        switch (printJob.getState()) {
            case PrintJobInfo.STATE_QUEUED:
@@ -602,7 +609,6 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment
        }
        return false;
    }
    }

    /**
     * Provider for the print settings summary
@@ -624,29 +630,32 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment
            mSummaryLoader = summaryLoader;
            mPrintManager = ((PrintManager) context.getSystemService(Context.PRINT_SERVICE))
                    .getGlobalPrintManagerForUser(context.getUserId());
            mPrintManager.addPrintJobStateChangeListener(this);
        }

        @Override
        public void setListening(boolean isListening) {
            mPrintManager.removePrintJobStateChangeListener(this);

            if (isListening) {
                mPrintManager.addPrintJobStateChangeListener(this);
            }
                onPrintJobStateChanged(null);
            } else {
                mPrintManager.removePrintJobStateChangeListener(this);
            }
        }

        @Override
        public void onPrintJobStateChanged(PrintJobId printJobId) {
            int numPrintJobs = mPrintManager.getPrintJobs().size();
            mSummaryLoader.setSummary(this, mContext.getResources().getQuantityString(
                    R.plurals.print_settings_title, numPrintJobs, numPrintJobs));
            List<PrintJob> printJobs = mPrintManager.getPrintJobs();

            int numActivePrintJobs = 0;
            final int numPrintJobs = printJobs.size();
            for (int i = 0; i < numPrintJobs; i++) {
                if (shouldShowToUser(printJobs.get(i).getInfo())) {
                    numActivePrintJobs++;
                }
            }

        @Override
        protected void finalize() {
            mPrintManager.removePrintJobStateChangeListener(this);
            mSummaryLoader.setSummary(this, mContext.getResources().getQuantityString(
                    R.plurals.print_settings_title, numActivePrintJobs, numActivePrintJobs));
        }
    }