Small corrections to the code that generates the print summary in the settings.
- Optimize when the listener is active and rely on it to be cleaned up automatically - Only count print jobs that should be shown (i.e. not ones that are already finished.) Change-Id: Idba995f1036e736f47ca7402d493210600eae91c
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user