Remove tiles pointing to same intent within same category.
Bug: 32874082 Test: RunSettingsLibRoboTests Change-Id: I155495882663ed60cbf21c9a5651709ac3cbd137
This commit is contained in:
@@ -20,6 +20,7 @@ import android.content.Context;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
@@ -116,6 +117,7 @@ public class CategoryManager {
|
||||
}
|
||||
backwardCompatCleanupForCategory(mTileByComponentCache, mCategoryByKeyMap);
|
||||
normalizePriority(context, mCategoryByKeyMap);
|
||||
filterDuplicateTiles(mCategoryByKeyMap);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,6 +186,31 @@ public class CategoryManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter out duplicate tiles from category. Duplicate tiles are the ones pointing to the
|
||||
* same intent.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
synchronized void filterDuplicateTiles(Map<String, DashboardCategory> categoryByKeyMap) {
|
||||
for (Entry<String, DashboardCategory> categoryEntry : categoryByKeyMap.entrySet()) {
|
||||
final DashboardCategory category = categoryEntry.getValue();
|
||||
final int count = category.tiles.size();
|
||||
final Set<ComponentName> components = new ArraySet<>();
|
||||
for (int i = count - 1; i >= 0; i--) {
|
||||
final Tile tile = category.tiles.get(i);
|
||||
if (tile.intent == null) {
|
||||
continue;
|
||||
}
|
||||
final ComponentName tileComponent = tile.intent.getComponent();
|
||||
if (components.contains(tileComponent)) {
|
||||
category.tiles.remove(i);
|
||||
} else {
|
||||
components.add(tileComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize priority value for tiles within a single {@code DashboardCategory}.
|
||||
*
|
||||
@@ -218,7 +245,6 @@ public class CategoryManager {
|
||||
continue;
|
||||
}
|
||||
dashboardCategory.tiles.get(i).priority = i;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,4 +228,60 @@ public class CategoryManagerTest {
|
||||
assertThat(category.tiles.get(1).priority).isEqualTo(100);
|
||||
assertThat(category.tiles.get(2).priority).isEqualTo(50);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterTiles_noDuplicate_noChange() {
|
||||
// Create some unique tiles
|
||||
final String testPackage =
|
||||
ShadowApplication.getInstance().getApplicationContext().getPackageName();
|
||||
final DashboardCategory category = new DashboardCategory();
|
||||
final Tile tile1 = new Tile();
|
||||
tile1.intent =
|
||||
new Intent().setComponent(new ComponentName(testPackage, "class1"));
|
||||
tile1.priority = 100;
|
||||
final Tile tile2 = new Tile();
|
||||
tile2.intent =
|
||||
new Intent().setComponent(new ComponentName(testPackage, "class2"));
|
||||
tile2.priority = 100;
|
||||
final Tile tile3 = new Tile();
|
||||
tile3.intent =
|
||||
new Intent().setComponent(new ComponentName(testPackage, "class3"));
|
||||
tile3.priority = 50;
|
||||
category.tiles.add(tile1);
|
||||
category.tiles.add(tile2);
|
||||
category.tiles.add(tile3);
|
||||
mCategoryByKeyMap.put(CategoryKey.CATEGORY_HOMEPAGE, category);
|
||||
|
||||
mCategoryManager.filterDuplicateTiles(mCategoryByKeyMap);
|
||||
|
||||
assertThat(category.tiles.size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterTiles_hasDuplicate_shouldOnlyKeepUniqueTiles() {
|
||||
// Create tiles pointing to same intent.
|
||||
final String testPackage =
|
||||
ShadowApplication.getInstance().getApplicationContext().getPackageName();
|
||||
final DashboardCategory category = new DashboardCategory();
|
||||
final Tile tile1 = new Tile();
|
||||
tile1.intent =
|
||||
new Intent().setComponent(new ComponentName(testPackage, "class1"));
|
||||
tile1.priority = 100;
|
||||
final Tile tile2 = new Tile();
|
||||
tile2.intent =
|
||||
new Intent().setComponent(new ComponentName(testPackage, "class1"));
|
||||
tile2.priority = 100;
|
||||
final Tile tile3 = new Tile();
|
||||
tile3.intent =
|
||||
new Intent().setComponent(new ComponentName(testPackage, "class1"));
|
||||
tile3.priority = 50;
|
||||
category.tiles.add(tile1);
|
||||
category.tiles.add(tile2);
|
||||
category.tiles.add(tile3);
|
||||
mCategoryByKeyMap.put(CategoryKey.CATEGORY_HOMEPAGE, category);
|
||||
|
||||
mCategoryManager.filterDuplicateTiles(mCategoryByKeyMap);
|
||||
|
||||
assertThat(category.tiles.size()).isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user