[Settings] Avoid rendering hidden preferences

Under dashboards with expand button, preferences are renderred even
not been expanded.
Avoid from rendering un-expanded preference can improve the performance
of dashboard display.

Bug: 141833767
Test: manual
Change-Id: I00c6f827a0b7b7cec6a6fd8c809b94ca1dce88bb
This commit is contained in:
Bonian Chen
2020-02-04 10:27:50 +08:00
parent d4e2f78d9a
commit 1b9bda3b05
3 changed files with 75 additions and 7 deletions

View File

@@ -258,6 +258,18 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
return 0;
}
/**
* Whether preference is allowing to be displayed to the user.
*
* @param preference to check if it can be displayed to the user (not hidding in expand area).
* @return {@code true} when preference is allowing to be displayed to the user.
* {@code false} when preference is hidden in expand area and not been displayed to the user.
*/
protected boolean isPreferenceExpanded(Preference preference) {
return ((mAdapter == null)
|| (mAdapter.getPreferenceAdapterPosition(preference) != RecyclerView.NO_POSITION));
}
protected void onDataSetChanged() {
highlightPreferenceIfNeeded();
updateEmptyView();