Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Android] Prevent duplicate duplicate items from being in the game li…
…st at one time.

Previously it was possible for a game with the same path and name to be in the list as another. This is annoying because duplicates ae (obviously) no different from the initial item.

This prevents duplicates from entering the list.

The way this works is:

1. We get the final list of items to add to the list.

2. Loop through it using two indices, which, for this explanation I'll call [item] and [itemAfter]

We compare path name at item with index [item] and the path name at item with index [itemAfter]
To phrase this numerically comparison works like so:

for (int i = 0; i < listSize; i++)
{
    if (i+1 < listSize)
        item[i].getPath().equals(item[i+1].getPath())
}

3. For each path comparison that is true, remove item at [indexNext].
  • Loading branch information
lioncash committed Aug 17, 2013
1 parent a9d6340 commit 07d729d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Source/Android/src/org/dolphinemu/dolphinemu/GameListFragment.java
Expand Up @@ -76,6 +76,21 @@ private void Fill()
}
}
Collections.sort(fls);

// Remove any duplicate items from the list.
// We don't need to index these in the game list more than once.
//
// This works by comparing the paths of items in the file list for equality,
// so there should be no worries about accidentally removing a valid game.
for (int i = 0; i < fls.size(); i++)
{
int indexNext = i+1;

if (indexNext < fls.size() && fls.get(indexNext).getPath().contains(fls.get(i).getPath()))
{
fls.remove(indexNext);
}
}

mGameAdapter = new GameListAdapter(mMe, R.layout.gamelist_layout, fls);
mMainList.setAdapter(mGameAdapter);
Expand Down

0 comments on commit 07d729d

Please sign in to comment.