OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chrome.browser.history; | |
6 | |
7 import android.support.v7.widget.RecyclerView.ViewHolder; | |
8 import android.view.LayoutInflater; | |
9 import android.view.View; | |
10 import android.view.ViewGroup; | |
11 | |
12 import org.chromium.base.Callback; | |
13 import org.chromium.chrome.R; | |
14 import org.chromium.chrome.browser.widget.DateDividedAdapter; | |
15 import org.chromium.chrome.browser.widget.selection.SelectableItemViewHolder; | |
16 import org.chromium.chrome.browser.widget.selection.SelectionDelegate; | |
17 | |
18 import java.util.List; | |
19 | |
20 /** | |
21 * Bridges the user's browsing history and the UI used to display it. | |
22 */ | |
23 public class HistoryAdapter extends DateDividedAdapter { | |
24 private static final String EMPTY_QUERY = ""; | |
25 | |
26 private SelectionDelegate<HistoryItem> mSelectionDelegate; | |
gone
2016/12/02 19:34:37
finals?
Theresa
2016/12/02 20:49:32
Done.
| |
27 private BrowsingHistoryBridge mBridge; | |
28 | |
29 public HistoryAdapter(SelectionDelegate<HistoryItem> delegate) { | |
30 setHasStableIds(true); | |
31 mSelectionDelegate = delegate; | |
32 mBridge = new BrowsingHistoryBridge(); | |
33 } | |
34 | |
35 /** | |
36 * Called when the activity/native page is destroyed. | |
37 */ | |
38 public void onDestroyed() { | |
39 mBridge.destroy(); | |
40 } | |
41 | |
42 /** | |
43 * Initializes the HistoryAdapter and loads the first set of browsing histor y items. | |
44 */ | |
45 public void initialize() { | |
46 mBridge.queryHistory(new Callback<List<HistoryItem>>() { | |
47 @Override | |
48 public void onResult(List<HistoryItem> result) { | |
49 loadItems(result); | |
gone
2016/12/02 19:34:37
What happens if this class (or the bridge) is dest
Theresa
2016/12/02 20:49:32
I don't think it's technically possible (see comme
| |
50 } | |
51 }, EMPTY_QUERY, 0); | |
52 } | |
53 | |
54 @Override | |
55 protected ViewHolder createViewHolder(ViewGroup parent) { | |
56 View v = LayoutInflater.from(parent.getContext()).inflate( | |
57 R.layout.history_item_view, parent, false); | |
58 return new SelectableItemViewHolder<HistoryItem>(v, mSelectionDelegate); | |
59 } | |
60 | |
61 @Override | |
62 protected void bindViewHolderForTimedItem(ViewHolder current, TimedItem time dItem) { | |
63 final HistoryItem item = (HistoryItem) timedItem; | |
64 @SuppressWarnings("unchecked") | |
65 SelectableItemViewHolder<HistoryItem> holder = | |
66 (SelectableItemViewHolder<HistoryItem>) current; | |
67 holder.displayItem(item); | |
68 } | |
69 | |
70 @Override | |
71 protected int getTimedItemViewResId() { | |
72 return R.layout.date_view; | |
73 } | |
74 | |
75 } | |
OLD | NEW |