| Index: chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapter.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapter.java
|
| index 898d6bdce140b377122961de165907967cd7f570..a9e02658ecef49e71641e877c11869761c5f1e78 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapter.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryAdapter.java
|
| @@ -6,8 +6,6 @@ package org.chromium.chrome.browser.download.ui;
|
|
|
| import android.content.ComponentName;
|
| import android.content.Context;
|
| -import android.content.res.Resources;
|
| -import android.graphics.Paint;
|
| import android.support.v7.widget.RecyclerView;
|
| import android.support.v7.widget.RecyclerView.ViewHolder;
|
| import android.text.TextUtils;
|
| @@ -18,8 +16,8 @@ import android.view.ViewGroup;
|
| import android.widget.ImageView;
|
| import android.widget.TextView;
|
|
|
| -import org.chromium.base.ApiCompatibilityUtils;
|
| import org.chromium.base.metrics.RecordHistogram;
|
| +import org.chromium.base.metrics.RecordUserAction;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.download.DownloadItem;
|
| import org.chromium.chrome.browser.download.ui.BackendProvider.DownloadDelegate;
|
| @@ -34,7 +32,9 @@ import org.chromium.chrome.browser.widget.DateDividedAdapter;
|
| import org.chromium.chrome.browser.widget.selection.SelectionDelegate;
|
|
|
| import java.util.ArrayList;
|
| +import java.util.HashMap;
|
| import java.util.List;
|
| +import java.util.Map;
|
|
|
| /** Bridges the user's download history and the UI used to display it. */
|
| public class DownloadHistoryAdapter extends DateDividedAdapter implements DownloadUiObserver {
|
| @@ -63,6 +63,12 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
| /** See {@link #findItemIndex}. */
|
| private static final int INVALID_INDEX = -1;
|
|
|
| + /**
|
| + * Externally deleted items that have been removed from downloads history.
|
| + * Shared across instances.
|
| + */
|
| + private static final Map<String, Boolean> sExternallyDeletedItems = new HashMap<>();
|
| +
|
| private final List<DownloadItemWrapper> mDownloadItems = new ArrayList<>();
|
| private final List<DownloadItemWrapper> mDownloadOffTheRecordItems = new ArrayList<>();
|
| private final List<OfflinePageItemWrapper> mOfflinePageItems = new ArrayList<>();
|
| @@ -73,7 +79,6 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
| private BackendProvider mBackendProvider;
|
| private OfflinePageDownloadBridge.Observer mOfflinePageObserver;
|
| private int mFilter = DownloadFilter.FILTER_ALL;
|
| - private int mFilenameViewTextColor;
|
|
|
| DownloadHistoryAdapter(boolean showOffTheRecord, ComponentName parentComponent) {
|
| mShowOffTheRecord = showOffTheRecord;
|
| @@ -100,11 +105,21 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
| List<DownloadItemWrapper> list = getDownloadItemList(isOffTheRecord);
|
| list.clear();
|
| int[] mItemCounts = new int[DownloadFilter.FILTER_BOUNDARY];
|
| +
|
| for (DownloadItem item : result) {
|
| DownloadItemWrapper wrapper = new DownloadItemWrapper(item, isOffTheRecord);
|
| - list.add(wrapper);
|
| - mItemCounts[wrapper.getFilterType()]++;
|
| +
|
| + // TODO(twellington): The native downloads service should remove externally deleted
|
| + // downloads rather than passing them to Java.
|
| + if (sExternallyDeletedItems.containsKey(wrapper.getId())) continue;
|
| + if (wrapper.hasBeenExternallyRemoved()) {
|
| + removeExternallyDeletedItem(wrapper);
|
| + } else {
|
| + list.add(wrapper);
|
| + mItemCounts[wrapper.getFilterType()]++;
|
| + }
|
| }
|
| +
|
| filter(DownloadFilter.FILTER_ALL);
|
| if (!isOffTheRecord) recordDownloadCountHistograms(mItemCounts, result.size());
|
| }
|
| @@ -156,7 +171,6 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
| final DownloadHistoryItemWrapper item = (DownloadHistoryItemWrapper) timedItem;
|
|
|
| ItemViewHolder holder = (ItemViewHolder) current;
|
| - DownloadHistoryItemWrapper previousItem = holder.mItemView.mItem;
|
| Context context = holder.mFilesizeView.getContext();
|
| holder.mFilenameView.setText(item.getDisplayFileName());
|
| holder.mHostnameView.setText(
|
| @@ -188,12 +202,6 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
| }
|
|
|
| holder.mIconView.setImageResource(iconResource);
|
| -
|
| - // Externally removed items have a different style. Update the item's style if necessary.
|
| - if (previousItem == null
|
| - || previousItem.hasBeenExternallyRemoved() != item.hasBeenExternallyRemoved()) {
|
| - setItemViewStyle(holder, item);
|
| - }
|
| }
|
|
|
| /**
|
| @@ -204,12 +212,24 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
|
|
| List<DownloadItemWrapper> list = getDownloadItemList(isOffTheRecord);
|
| int index = findItemIndex(list, item.getId());
|
| +
|
| + DownloadItemWrapper wrapper = new DownloadItemWrapper(item, isOffTheRecord);
|
| +
|
| + // If an externally deleted item has already been removed from the history service, it
|
| + // shouldn't be removed again.
|
| + if (sExternallyDeletedItems.containsKey(wrapper.getId())) return;
|
| +
|
| + if (wrapper.hasBeenExternallyRemoved()) {
|
| + removeExternallyDeletedItem(wrapper);
|
| + return;
|
| + }
|
| +
|
| if (index == INVALID_INDEX) {
|
| // Add a new entry.
|
| - list.add(new DownloadItemWrapper(item, isOffTheRecord));
|
| + list.add(wrapper);
|
| } else {
|
| // Update the old one.
|
| - list.set(index, new DownloadItemWrapper(item, isOffTheRecord));
|
| + list.set(index, wrapper);
|
| }
|
|
|
| filter(mFilter);
|
| @@ -327,36 +347,6 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
| return INVALID_INDEX;
|
| }
|
|
|
| - private void setItemViewStyle(ItemViewHolder holder, DownloadHistoryItemWrapper item) {
|
| - if (mFilenameViewTextColor == 0) {
|
| - // The color is not explicitly set in the XML. Programmatically retrieve the original
|
| - // color so that the color can be reset if it's changed due to the contained item
|
| - // being externally removed.
|
| - mFilenameViewTextColor = holder.mFilenameView.getTextColors().getDefaultColor();
|
| - }
|
| -
|
| - Context context = holder.itemView.getContext();
|
| - Resources res = context.getResources();
|
| - if (item.hasBeenExternallyRemoved()) {
|
| - int disabledColor = ApiCompatibilityUtils.getColor(res, R.color.google_grey_300);
|
| -
|
| - holder.mHostnameView.setTextColor(disabledColor);
|
| - holder.mIconView.setBackgroundColor(disabledColor);
|
| - holder.mFilenameView.setTextColor(disabledColor);
|
| - holder.mFilenameView.setPaintFlags(holder.mFilenameView.getPaintFlags()
|
| - | Paint.STRIKE_THRU_TEXT_FLAG);
|
| - holder.mFilesizeView.setText(context.getString(R.string.download_manager_ui_deleted));
|
| - } else {
|
| - holder.mHostnameView.setTextColor(mFilenameViewTextColor);
|
| - holder.mIconView.setBackgroundColor(ApiCompatibilityUtils.getColor(res,
|
| - R.color.light_active_color));
|
| - holder.mFilenameView.setTextColor(ApiCompatibilityUtils.getColor(res,
|
| - R.color.default_text_color));
|
| - holder.mFilenameView.setPaintFlags(holder.mFilenameView.getPaintFlags()
|
| - & ~Paint.STRIKE_THRU_TEXT_FLAG);
|
| - }
|
| - }
|
| -
|
| /**
|
| * Removes the item matching the given |guid|.
|
| * @param list List of the users downloads of a specific type.
|
| @@ -394,4 +384,10 @@ public class DownloadHistoryAdapter extends DateDividedAdapter implements Downlo
|
| RecordHistogram.recordCountHistogram("Android.DownloadManager.InitialCount.Total",
|
| totalCount);
|
| }
|
| +
|
| + private void removeExternallyDeletedItem(DownloadItemWrapper wrapper) {
|
| + sExternallyDeletedItems.put(wrapper.getId(), true);
|
| + wrapper.delete(null);
|
| + RecordUserAction.record("Android.DownloadManager.Item.ExternallyDeleted");
|
| + }
|
| }
|
|
|