Commit 7b971535 authored by twellington's avatar twellington Committed by Commit bot

[Downloads UI] Fix selection toggle for updated items

When a download item is updated, its toggle state should carry over
from the previous DownloadHistoryItemWrapper. This fixes a bug
where a selection remained established if it the Download UI was
opened in two windows and a selected item in one window was
removed from the other window.

Also fixes some variable naming in SelectionDelegate.java

BUG=648938

Review-Url: https://codereview.chromium.org/2361163004
Cr-Commit-Position: refs/heads/master@{#420788}
parent ba0546f0
......@@ -206,6 +206,12 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
list.add(wrapper);
mFilePathsToItemsMap.addItem(wrapper);
} else {
DownloadItemWrapper previousWrapper = list.get(index);
// If the previous item was selected, the updated item should be selected as well.
if (getSelectionDelegate().isItemSelected(previousWrapper)) {
getSelectionDelegate().toggleSelectionForItem(previousWrapper);
getSelectionDelegate().toggleSelectionForItem(wrapper);
}
// Update the old one.
list.set(index, wrapper);
mFilePathsToItemsMap.replaceItem(wrapper);
......
......@@ -34,25 +34,25 @@ public class SelectionDelegate<E> {
/**
* Toggles the selected state for the given item.
* @param itemId The id of the item to toggle.
* @param item The item to toggle.
* @return Whether the item is selected.
*/
public boolean toggleSelectionForItem(E itemId) {
if (mSelectedItems.contains(itemId)) mSelectedItems.remove(itemId);
else mSelectedItems.add(itemId);
public boolean toggleSelectionForItem(E item) {
if (mSelectedItems.contains(item)) mSelectedItems.remove(item);
else mSelectedItems.add(item);
notifyObservers();
return isItemSelected(itemId);
return isItemSelected(item);
}
/**
* True if the bookmark is selected. False otherwise.
* @param itemId The id of the item.
* True if the item is selected. False otherwise.
* @param item The item.
* @return Whether the item is selected.
*/
public boolean isItemSelected(E itemId) {
return mSelectedItems.contains(itemId);
public boolean isItemSelected(E item) {
return mSelectedItems.contains(item);
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment