| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.download.ui; | 5 package org.chromium.chrome.browser.download.ui; |
| 6 | 6 |
| 7 import android.content.ComponentName; | 7 import android.content.ComponentName; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.text.TextUtils; | 9 import android.text.TextUtils; |
| 10 | 10 |
| 11 import org.chromium.base.ContextUtils; | 11 import org.chromium.base.ContextUtils; |
| 12 import org.chromium.base.metrics.RecordHistogram; | 12 import org.chromium.base.metrics.RecordHistogram; |
| 13 import org.chromium.chrome.R; | 13 import org.chromium.chrome.R; |
| 14 import org.chromium.chrome.browser.download.DownloadInfo; | 14 import org.chromium.chrome.browser.download.DownloadInfo; |
| 15 import org.chromium.chrome.browser.download.DownloadItem; | 15 import org.chromium.chrome.browser.download.DownloadItem; |
| 16 import org.chromium.chrome.browser.download.DownloadNotificationService; | 16 import org.chromium.chrome.browser.download.DownloadNotificationService; |
| 17 import org.chromium.chrome.browser.download.DownloadUtils; | 17 import org.chromium.chrome.browser.download.DownloadUtils; |
| 18 import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadIte
m; | 18 import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadIte
m; |
| 19 import org.chromium.chrome.browser.widget.DateDividedAdapter.TimedItem; | 19 import org.chromium.chrome.browser.widget.DateDividedAdapter.TimedItem; |
| 20 import org.chromium.components.offline_items_collection.OfflineItem.Progress; |
| 21 import org.chromium.components.offline_items_collection.OfflineItemProgressUnit; |
| 20 import org.chromium.components.url_formatter.UrlFormatter; | 22 import org.chromium.components.url_formatter.UrlFormatter; |
| 21 import org.chromium.content_public.browser.DownloadState; | 23 import org.chromium.content_public.browser.DownloadState; |
| 22 import org.chromium.ui.widget.Toast; | 24 import org.chromium.ui.widget.Toast; |
| 23 | 25 |
| 24 import java.io.File; | 26 import java.io.File; |
| 25 import java.util.Collections; | 27 import java.util.Collections; |
| 26 import java.util.HashMap; | 28 import java.util.HashMap; |
| 27 import java.util.Locale; | 29 import java.util.Locale; |
| 28 import java.util.Map; | 30 import java.util.Map; |
| 29 | 31 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 143 |
| 142 /** @return {@link DownloadFilter} that represents the file type. */ | 144 /** @return {@link DownloadFilter} that represents the file type. */ |
| 143 public abstract int getFilterType(); | 145 public abstract int getFilterType(); |
| 144 | 146 |
| 145 /** @return The mime type or null if the item doesn't have one. */ | 147 /** @return The mime type or null if the item doesn't have one. */ |
| 146 public abstract String getMimeType(); | 148 public abstract String getMimeType(); |
| 147 | 149 |
| 148 /** @return The file extension type. See list at the top of the file. */ | 150 /** @return The file extension type. See list at the top of the file. */ |
| 149 public abstract int getFileExtensionType(); | 151 public abstract int getFileExtensionType(); |
| 150 | 152 |
| 151 /** @return How much of the download has completed, or -1 if there is no pro
gress. */ | 153 /** @return How much of the download has completed, or null if there is no p
rogress. */ |
| 152 abstract int getDownloadProgress(); | 154 abstract Progress getDownloadProgress(); |
| 153 | 155 |
| 154 /** @return Whether the download has an unknown file size. */ | 156 /** @return Whether the download has an unknown file size. */ |
| 155 abstract boolean isIndeterminate(); | 157 abstract boolean isIndeterminate(); |
| 156 | 158 |
| 157 /** @return String indicating the status of the download. */ | 159 /** @return String indicating the status of the download. */ |
| 158 abstract String getStatusString(); | 160 abstract String getStatusString(); |
| 159 | 161 |
| 160 /** @return Whether the file for this item has been removed through an exter
nal action. */ | 162 /** @return Whether the file for this item has been removed through an exter
nal action. */ |
| 161 abstract boolean hasBeenExternallyRemoved(); | 163 abstract boolean hasBeenExternallyRemoved(); |
| 162 | 164 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 extension.toLowerCase(Locale.getDefault())); | 300 extension.toLowerCase(Locale.getDefault())); |
| 299 } else { | 301 } else { |
| 300 mFileExtensionType = FILE_EXTENSION_OTHER; | 302 mFileExtensionType = FILE_EXTENSION_OTHER; |
| 301 } | 303 } |
| 302 } | 304 } |
| 303 | 305 |
| 304 return mFileExtensionType; | 306 return mFileExtensionType; |
| 305 } | 307 } |
| 306 | 308 |
| 307 @Override | 309 @Override |
| 308 public int getDownloadProgress() { | 310 public Progress getDownloadProgress() { |
| 309 return mItem.getDownloadInfo().getPercentCompleted(); | 311 return mItem.getDownloadInfo().getProgress(); |
| 310 } | 312 } |
| 311 | 313 |
| 312 @Override | 314 @Override |
| 313 public boolean isIndeterminate() { | 315 public boolean isIndeterminate() { |
| 314 return mItem.isIndeterminate(); | 316 return mItem.isIndeterminate(); |
| 315 } | 317 } |
| 316 | 318 |
| 317 @Override | 319 @Override |
| 318 public String getStatusString() { | 320 public String getStatusString() { |
| 319 return DownloadUtils.getStatusString(mItem); | 321 return DownloadUtils.getStatusString(mItem); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 401 } |
| 400 | 402 |
| 401 return true; | 403 return true; |
| 402 } | 404 } |
| 403 | 405 |
| 404 /** @return whether the given DownloadItem is visibly different from the
current one. */ | 406 /** @return whether the given DownloadItem is visibly different from the
current one. */ |
| 405 private boolean isNewItemVisiblyDifferent(DownloadItem newItem) { | 407 private boolean isNewItemVisiblyDifferent(DownloadItem newItem) { |
| 406 DownloadInfo oldInfo = mItem.getDownloadInfo(); | 408 DownloadInfo oldInfo = mItem.getDownloadInfo(); |
| 407 DownloadInfo newInfo = newItem.getDownloadInfo(); | 409 DownloadInfo newInfo = newItem.getDownloadInfo(); |
| 408 | 410 |
| 409 if (oldInfo.getPercentCompleted() != newInfo.getPercentCompleted())
return true; | 411 if (oldInfo.getProgress().equals(newInfo.getProgress())) return true
; |
| 410 if (oldInfo.getBytesReceived() != newInfo.getBytesReceived()) return
true; | 412 if (oldInfo.getBytesReceived() != newInfo.getBytesReceived()) return
true; |
| 411 if (oldInfo.state() != newInfo.state()) return true; | 413 if (oldInfo.state() != newInfo.state()) return true; |
| 412 if (oldInfo.isPaused() != newInfo.isPaused()) return true; | 414 if (oldInfo.isPaused() != newInfo.isPaused()) return true; |
| 413 if (!TextUtils.equals(oldInfo.getFilePath(), newInfo.getFilePath()))
return true; | 415 if (!TextUtils.equals(oldInfo.getFilePath(), newInfo.getFilePath()))
return true; |
| 414 | 416 |
| 415 return false; | 417 return false; |
| 416 } | 418 } |
| 417 } | 419 } |
| 418 | 420 |
| 419 /** Wraps a {@link OfflinePageDownloadItem}. */ | 421 /** Wraps a {@link OfflinePageDownloadItem}. */ |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 public String getMimeType() { | 488 public String getMimeType() { |
| 487 return "text/html"; | 489 return "text/html"; |
| 488 } | 490 } |
| 489 | 491 |
| 490 @Override | 492 @Override |
| 491 public int getFileExtensionType() { | 493 public int getFileExtensionType() { |
| 492 return FILE_EXTENSION_OTHER; | 494 return FILE_EXTENSION_OTHER; |
| 493 } | 495 } |
| 494 | 496 |
| 495 @Override | 497 @Override |
| 496 public int getDownloadProgress() { | 498 public Progress getDownloadProgress() { |
| 497 // Only completed offline page downloads are shown. | 499 // Only completed offline page downloads are shown. |
| 498 return 100; | 500 return new Progress(100, 100L, OfflineItemProgressUnit.PERCENTAGE); |
| 499 } | 501 } |
| 500 | 502 |
| 501 @Override | 503 @Override |
| 502 public boolean isIndeterminate() { | 504 public boolean isIndeterminate() { |
| 503 return true; | 505 return true; |
| 504 } | 506 } |
| 505 | 507 |
| 506 @Override | 508 @Override |
| 507 public String getStatusString() { | 509 public String getStatusString() { |
| 508 Context context = ContextUtils.getApplicationContext(); | 510 Context context = ContextUtils.getApplicationContext(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 == org.chromium.components.offlinepages.downloads.DownloadSt
ate.COMPLETE; | 580 == org.chromium.components.offlinepages.downloads.DownloadSt
ate.COMPLETE; |
| 579 } | 581 } |
| 580 | 582 |
| 581 @Override | 583 @Override |
| 582 public boolean isPaused() { | 584 public boolean isPaused() { |
| 583 return mItem.getDownloadState() | 585 return mItem.getDownloadState() |
| 584 == org.chromium.components.offlinepages.downloads.DownloadSt
ate.PAUSED; | 586 == org.chromium.components.offlinepages.downloads.DownloadSt
ate.PAUSED; |
| 585 } | 587 } |
| 586 } | 588 } |
| 587 } | 589 } |
| OLD | NEW |