Bug 968170 - Factor out method to replace a PanelConfig in a list (r=margaret)

This commit is contained in:
Lucas Rocha 2014-02-13 11:46:25 +00:00
Родитель 61c41506af
Коммит 32b5207f11
1 изменённых файлов: 17 добавлений и 5 удалений

Просмотреть файл

@ -125,6 +125,22 @@ public class HomeConfigInvalidator implements GeckoEventListener {
Log.d(LOGTAG, "scheduleInvalidation: scheduled new invalidation");
}
/**
* Replace an element if a matching PanelConfig is
* present in the given list.
*/
private boolean replacePanelConfig(List<PanelConfig> panelConfigs, PanelConfig panelConfig) {
final int index = panelConfigs.indexOf(panelConfig);
if (index >= 0) {
panelConfigs.set(index, panelConfig);
Log.d(LOGTAG, "executePendingChanges: replaced position " + index + " with " + panelConfig.getId());
return true;
}
return false;
}
/**
* Runs in the background thread.
*/
@ -143,11 +159,7 @@ public class HomeConfigInvalidator implements GeckoEventListener {
break;
case INSTALL:
final int index = panelConfigs.indexOf(panelConfig);
if (index >= 0) {
panelConfigs.set(index, panelConfig);
Log.d(LOGTAG, "executePendingChanges: replaced position " + index + " with " + id);
} else {
if (!replacePanelConfig(panelConfigs, panelConfig)) {
panelConfigs.add(panelConfig);
Log.d(LOGTAG, "executePendingChanges: added panel " + id);
}