Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 package org.mozilla.gecko.home;
8 import org.mozilla.gecko.db.BrowserContract.HomeItems;
9 import org.mozilla.gecko.home.HomeConfig.ViewConfig;
10 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
11 import org.mozilla.gecko.home.PanelLayout.FilterManager;
12 import org.mozilla.gecko.home.PanelLayout.OnItemOpenListener;
14 import android.database.Cursor;
16 import java.util.EnumSet;
18 class PanelViewItemHandler {
19 private final ViewConfig mViewConfig;
20 private OnItemOpenListener mItemOpenListener;
21 private FilterManager mFilterManager;
23 public PanelViewItemHandler(ViewConfig viewConfig) {
24 mViewConfig = viewConfig;
25 }
27 public void setOnItemOpenListener(OnItemOpenListener listener) {
28 mItemOpenListener = listener;
29 }
31 public void setFilterManager(FilterManager manager) {
32 mFilterManager = manager;
33 }
35 /**
36 * If item at this position is a back item, perform the go back action via the
37 * {@code FilterManager}. Otherwise, prepare the url to be opened by the
38 * {@code OnUrlOpenListener}.
39 */
40 public void openItemAtPosition(Cursor cursor, int position) {
41 if (mFilterManager != null && mFilterManager.canGoBack()) {
42 if (position == 0) {
43 mFilterManager.goBack();
44 return;
45 }
47 position--;
48 }
50 if (cursor == null || !cursor.moveToPosition(position)) {
51 throw new IllegalStateException("Couldn't move cursor to position " + position);
52 }
54 int urlIndex = cursor.getColumnIndexOrThrow(HomeItems.URL);
55 final String url = cursor.getString(urlIndex);
57 int titleIndex = cursor.getColumnIndexOrThrow(HomeItems.TITLE);
58 final String title = cursor.getString(titleIndex);
60 if (mItemOpenListener != null) {
61 mItemOpenListener.onItemOpen(url, title);
62 }
63 }
64 }