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