Guard against flickering of dynamic injection items

The summary of injected items may flicker when the data is change from
URI.

Root cause:
If an external app injects an entry to Settings with a dynamic summary,
Settings will observe the summary change via the provideed URI. However,
sometimes when Settings observes the data change and then refreshes the
UI, the data doesn't really change and settings still gets the same
summary. If it happens in a short period, the summary will seem
flickering.

Solution:
Check if the data really changes before refresh UI. Guard both title and
summary.

Fixes: 168309941
Fixes: 166785977
Test: robotest
Change-Id: I137fc317dcfd8919195c10fa8cf7d2559fe1029d
This commit is contained in:
Jason Chiu
2020-09-23 11:00:21 +08:00
parent de28bc7c7e
commit a7d76af933

View File

@@ -248,7 +248,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
final Map<String, IContentProvider> providerMap = new ArrayMap<>();
final String titleFromUri = TileUtils.getTextFromUri(
mContext, uri, providerMap, META_DATA_PREFERENCE_TITLE);
if (!TextUtils.equals(titleFromUri, preference.getTitle())) {
ThreadUtils.postOnMainThread(() -> preference.setTitle(titleFromUri));
}
});
}
@@ -277,7 +279,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
final Map<String, IContentProvider> providerMap = new ArrayMap<>();
final String summaryFromUri = TileUtils.getTextFromUri(
mContext, uri, providerMap, META_DATA_PREFERENCE_SUMMARY);
if (!TextUtils.equals(summaryFromUri, preference.getSummary())) {
ThreadUtils.postOnMainThread(() -> preference.setSummary(summaryFromUri));
}
});
}