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.app.Activity; |
| 8 import android.support.v7.widget.Toolbar.OnMenuItemClickListener; |
| 9 import android.view.LayoutInflater; |
| 10 import android.view.MenuItem; |
| 11 import android.view.ViewGroup; |
| 12 |
| 13 import org.chromium.chrome.R; |
| 14 import org.chromium.chrome.browser.widget.TintedDrawable; |
| 15 import org.chromium.chrome.browser.widget.selection.SelectableListLayout; |
| 16 import org.chromium.chrome.browser.widget.selection.SelectionDelegate; |
| 17 import org.chromium.ui.base.DeviceFormFactor; |
| 18 |
| 19 /** |
| 20 * Displays and manages the UI for browsing history. |
| 21 */ |
| 22 public class HistoryManager implements OnMenuItemClickListener { |
| 23 private final Activity mActivity; |
| 24 private final SelectableListLayout mSelectableListLayout; |
| 25 private final HistoryAdapter mHistoryAdapter; |
| 26 private final SelectionDelegate<HistoryItem> mSelectionDelegate; |
| 27 |
| 28 /** |
| 29 * Creates a new HistoryManager. |
| 30 * @param activity The Activity associated with the HistoryManager. |
| 31 */ |
| 32 public HistoryManager(Activity activity) { |
| 33 mActivity = activity; |
| 34 |
| 35 mSelectionDelegate = new SelectionDelegate<>(); |
| 36 mHistoryAdapter = new HistoryAdapter(mSelectionDelegate); |
| 37 |
| 38 mSelectableListLayout = |
| 39 (SelectableListLayout) LayoutInflater.from(activity).inflate( |
| 40 R.layout.history_main, null); |
| 41 mSelectableListLayout.initializeRecyclerView(mHistoryAdapter); |
| 42 mSelectableListLayout.initializeToolbar(R.layout.history_toolbar, mSelec
tionDelegate, |
| 43 R.string.menu_history, null, R.id.normal_menu_group, |
| 44 R.id.selection_mode_menu_group, this); |
| 45 mSelectableListLayout.initializeEmptyView( |
| 46 TintedDrawable.constructTintedDrawable(mActivity.getResources(), |
| 47 R.drawable.history_large), |
| 48 R.string.history_manager_empty); |
| 49 |
| 50 mHistoryAdapter.initialize(); |
| 51 |
| 52 // TODO(twellington): add a scroll listener to the RecyclerView that loa
ds more items when |
| 53 // the scroll position is near the end. |
| 54 } |
| 55 |
| 56 @Override |
| 57 public boolean onMenuItemClick(MenuItem item) { |
| 58 if (item.getItemId() == R.id.close_menu_id && !DeviceFormFactor.isTablet
(mActivity)) { |
| 59 mActivity.finish(); |
| 60 return true; |
| 61 } |
| 62 return false; |
| 63 } |
| 64 |
| 65 /** |
| 66 * @return The view that shows the main browsing history UI. |
| 67 */ |
| 68 public ViewGroup getView() { |
| 69 return mSelectableListLayout; |
| 70 } |
| 71 |
| 72 /** |
| 73 * Called when the activity/native page is destroyed. |
| 74 */ |
| 75 public void onDestroyed() { |
| 76 mSelectableListLayout.onDestroyed(); |
| 77 mHistoryAdapter.onDestroyed(); |
| 78 } |
| 79 } |
OLD | NEW |