OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.download.ui; | |
6 | |
7 import org.chromium.chrome.browser.download.ui.DownloadHistoryAdapter.Subsection Header; | |
8 import org.chromium.chrome.browser.download.ui.DownloadHistoryItemWrapper.Offlin ePageItemWrapper; | |
9 import org.chromium.chrome.browser.widget.DateDividedAdapter; | |
10 import org.chromium.chrome.browser.widget.DateDividedAdapter.TimedItem; | |
11 | |
12 /** | |
13 * A bucket of downloaded items with the same date. It also holds the suggested offline items which | |
14 * are shown at the end of the list for that date. | |
15 */ | |
16 public class DownloadItemGroup extends DateDividedAdapter.ItemGroup { | |
17 public DownloadItemGroup(long timestamp) { | |
18 super(timestamp); | |
19 } | |
20 | |
21 private boolean isSuggestedOfflinePage(TimedItem timedItem) { | |
22 if (timedItem instanceof OfflinePageItemWrapper) { | |
23 return ((OfflinePageItemWrapper) timedItem).isSuggested(); | |
24 } | |
25 | |
26 return false; | |
27 } | |
28 | |
29 @Override | |
30 public int compareItem(TimedItem lhs, TimedItem rhs) { | |
31 int lhsOrder = order(lhs); | |
32 int rhsOrder = order(rhs); | |
33 | |
34 if (lhsOrder != rhsOrder) { | |
35 return lhsOrder < rhsOrder ? -1 : 1; | |
36 } | |
37 | |
38 return super.compareItem(lhs, rhs); | |
39 } | |
40 | |
41 /** | |
42 * A sorting helper function based on the item type. The items in the list v iew are placed from | |
43 * the top in the following order : download items, suggested pages header, suggested pages. | |
Theresa
2017/02/21 17:07:26
nit: s/order :/order:
shaktisahu
2017/02/21 21:17:13
Done.
| |
44 * @param timedItem The item to be displayed. | |
45 * @return An integer based on the item type which is to be used for sorting . | |
46 */ | |
47 private int order(TimedItem timedItem) { | |
48 if (isSuggestedOfflinePage(timedItem)) { | |
49 return 2; | |
50 } else if (timedItem instanceof SubsectionHeader) { | |
51 return 1; | |
52 } else { | |
53 return 0; | |
54 } | |
55 } | |
56 } | |
OLD | NEW |