2014-02-25 02:41:57 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko.home;
|
|
|
|
|
|
|
|
import org.mozilla.gecko.db.BrowserContract.HomeItems;
|
|
|
|
import org.mozilla.gecko.home.HomeConfig.ViewConfig;
|
|
|
|
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
|
2014-03-04 15:15:44 -08:00
|
|
|
import org.mozilla.gecko.home.PanelLayout.FilterManager;
|
2014-02-24 15:23:29 -08:00
|
|
|
import org.mozilla.gecko.home.PanelLayout.OnItemOpenListener;
|
2014-02-25 02:41:57 -08:00
|
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
2014-02-24 15:23:29 -08:00
|
|
|
class PanelViewItemHandler {
|
2014-02-25 02:41:57 -08:00
|
|
|
private final ViewConfig mViewConfig;
|
2014-02-24 15:23:29 -08:00
|
|
|
private OnItemOpenListener mItemOpenListener;
|
2014-03-04 15:15:44 -08:00
|
|
|
private FilterManager mFilterManager;
|
2014-02-25 02:41:57 -08:00
|
|
|
|
2014-02-24 15:23:29 -08:00
|
|
|
public PanelViewItemHandler(ViewConfig viewConfig) {
|
2014-02-25 02:41:57 -08:00
|
|
|
mViewConfig = viewConfig;
|
|
|
|
}
|
|
|
|
|
2014-02-24 15:23:29 -08:00
|
|
|
public void setOnItemOpenListener(OnItemOpenListener listener) {
|
|
|
|
mItemOpenListener = listener;
|
2014-02-25 02:41:57 -08:00
|
|
|
}
|
|
|
|
|
2014-03-04 15:15:44 -08:00
|
|
|
public void setFilterManager(FilterManager manager) {
|
|
|
|
mFilterManager = manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If item at this position is a back item, perform the go back action via the
|
|
|
|
* {@code FilterManager}. Otherwise, prepare the url to be opened by the
|
|
|
|
* {@code OnUrlOpenListener}.
|
|
|
|
*/
|
2014-02-24 15:23:29 -08:00
|
|
|
public void openItemAtPosition(Cursor cursor, int position) {
|
2014-03-04 15:15:44 -08:00
|
|
|
if (mFilterManager != null && mFilterManager.canGoBack()) {
|
|
|
|
if (position == 0) {
|
|
|
|
mFilterManager.goBack();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
position--;
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:41:57 -08:00
|
|
|
if (cursor == null || !cursor.moveToPosition(position)) {
|
|
|
|
throw new IllegalStateException("Couldn't move cursor to position " + position);
|
|
|
|
}
|
|
|
|
|
|
|
|
int urlIndex = cursor.getColumnIndexOrThrow(HomeItems.URL);
|
|
|
|
final String url = cursor.getString(urlIndex);
|
|
|
|
|
2014-02-24 15:23:29 -08:00
|
|
|
int titleIndex = cursor.getColumnIndexOrThrow(HomeItems.TITLE);
|
|
|
|
final String title = cursor.getString(titleIndex);
|
2014-02-25 02:41:57 -08:00
|
|
|
|
2014-02-24 15:23:29 -08:00
|
|
|
if (mItemOpenListener != null) {
|
|
|
|
mItemOpenListener.onItemOpen(url, title);
|
2014-02-25 02:41:57 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|