mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 975055 - Show filter title in back row. r=lucasr
This commit is contained in:
parent
766efc96ab
commit
6b4845d232
@ -6,8 +6,10 @@
|
||||
package org.mozilla.gecko.home;
|
||||
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.home.PanelLayout.FilterDetail;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
@ -24,7 +26,9 @@ class PanelBackItemView extends LinearLayout {
|
||||
title = (TextView) findViewById(R.id.title);
|
||||
}
|
||||
|
||||
public void updateFromFilter(String filter) {
|
||||
title.setText(filter);
|
||||
public void updateFromFilter(FilterDetail filter) {
|
||||
final String backText = getResources()
|
||||
.getString(R.string.home_move_up_to_filter, filter.title);
|
||||
title.setText(backText);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import org.mozilla.gecko.home.HomeConfig.ViewConfig;
|
||||
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
|
||||
import org.mozilla.gecko.home.PanelLayout.DatasetBacked;
|
||||
import org.mozilla.gecko.home.PanelLayout.FilterManager;
|
||||
import org.mozilla.gecko.home.PanelLayout.OnItemOpenListener;
|
||||
import org.mozilla.gecko.home.PanelLayout.PanelView;
|
||||
|
||||
import android.content.Context;
|
||||
@ -28,13 +29,13 @@ public class PanelGridView extends GridView
|
||||
|
||||
private final ViewConfig mViewConfig;
|
||||
private final PanelViewAdapter mAdapter;
|
||||
private PanelViewUrlHandler mUrlHandler;
|
||||
private PanelViewItemHandler mItemHandler;
|
||||
|
||||
public PanelGridView(Context context, ViewConfig viewConfig) {
|
||||
super(context, null, R.attr.panelGridViewStyle);
|
||||
|
||||
mViewConfig = viewConfig;
|
||||
mUrlHandler = new PanelViewUrlHandler(viewConfig);
|
||||
mItemHandler = new PanelViewItemHandler(viewConfig);
|
||||
|
||||
mAdapter = new PanelViewAdapter(context, viewConfig.getItemType());
|
||||
setAdapter(mAdapter);
|
||||
@ -45,7 +46,7 @@ public class PanelGridView extends GridView
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mUrlHandler.setOnUrlOpenListener(null);
|
||||
mItemHandler.setOnItemOpenListener(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -54,20 +55,20 @@ public class PanelGridView extends GridView
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnUrlOpenListener(OnUrlOpenListener listener) {
|
||||
mUrlHandler.setOnUrlOpenListener(listener);
|
||||
public void setOnItemOpenListener(OnItemOpenListener listener) {
|
||||
mItemHandler.setOnItemOpenListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFilterManager(FilterManager filterManager) {
|
||||
mAdapter.setFilterManager(filterManager);
|
||||
mUrlHandler.setFilterManager(filterManager);
|
||||
mItemHandler.setFilterManager(filterManager);
|
||||
}
|
||||
|
||||
private class PanelGridItemClickListener implements AdapterView.OnItemClickListener {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
mUrlHandler.openUrlAtPosition(mAdapter.getCursor(), position);
|
||||
mItemHandler.openItemAtPosition(mAdapter.getCursor(), position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,9 @@
|
||||
|
||||
package org.mozilla.gecko.home;
|
||||
|
||||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
|
||||
import org.mozilla.gecko.home.HomeConfig.ItemHandler;
|
||||
import org.mozilla.gecko.home.HomeConfig.PanelConfig;
|
||||
import org.mozilla.gecko.home.HomeConfig.ViewConfig;
|
||||
import org.mozilla.gecko.util.StringUtils;
|
||||
@ -64,6 +66,7 @@ abstract class PanelLayout extends FrameLayout {
|
||||
private static final String LOGTAG = "GeckoPanelLayout";
|
||||
|
||||
protected final Map<View, ViewState> mViewStateMap;
|
||||
private final PanelConfig mPanelConfig;
|
||||
private final DatasetHandler mDatasetHandler;
|
||||
private final OnUrlOpenListener mUrlOpenListener;
|
||||
|
||||
@ -140,11 +143,12 @@ abstract class PanelLayout extends FrameLayout {
|
||||
}
|
||||
|
||||
public interface PanelView {
|
||||
public void setOnUrlOpenListener(OnUrlOpenListener listener);
|
||||
public void setOnItemOpenListener(OnItemOpenListener listener);
|
||||
public void setOnKeyListener(OnKeyListener listener);
|
||||
}
|
||||
|
||||
public interface FilterManager {
|
||||
public String getPreviousFilter();
|
||||
public FilterDetail getPreviousFilter();
|
||||
public boolean canGoBack();
|
||||
public void goBack();
|
||||
}
|
||||
@ -152,6 +156,7 @@ abstract class PanelLayout extends FrameLayout {
|
||||
public PanelLayout(Context context, PanelConfig panelConfig, DatasetHandler datasetHandler, OnUrlOpenListener urlOpenListener) {
|
||||
super(context);
|
||||
mViewStateMap = new WeakHashMap<View, ViewState>();
|
||||
mPanelConfig = panelConfig;
|
||||
mDatasetHandler = datasetHandler;
|
||||
mUrlOpenListener = urlOpenListener;
|
||||
}
|
||||
@ -220,8 +225,9 @@ abstract class PanelLayout extends FrameLayout {
|
||||
// TODO: Push initial filter here onto ViewState
|
||||
mViewStateMap.put(view, state);
|
||||
|
||||
((PanelView) view).setOnUrlOpenListener(new PanelUrlOpenListener(state));
|
||||
view.setOnKeyListener(new PanelKeyListener(state));
|
||||
PanelView panelView = (PanelView) view;
|
||||
panelView.setOnItemOpenListener(new PanelOnItemOpenListener(state));
|
||||
panelView.setOnKeyListener(new PanelKeyListener(state));
|
||||
|
||||
if (view instanceof DatasetBacked) {
|
||||
DatasetBacked datasetBacked = (DatasetBacked) view;
|
||||
@ -277,9 +283,9 @@ abstract class PanelLayout extends FrameLayout {
|
||||
* Represents a 'live' instance of a panel view associated with
|
||||
* the {@code PanelLayout}. Is responsible for tracking the history stack of filters.
|
||||
*/
|
||||
protected static class ViewState {
|
||||
protected class ViewState {
|
||||
private final ViewConfig mViewConfig;
|
||||
private LinkedList<String> mFilterStack;
|
||||
private LinkedList<FilterDetail> mFilterStack;
|
||||
|
||||
public ViewState(ViewConfig viewConfig) {
|
||||
mViewConfig = viewConfig;
|
||||
@ -289,10 +295,14 @@ abstract class PanelLayout extends FrameLayout {
|
||||
return mViewConfig.getDatasetId();
|
||||
}
|
||||
|
||||
public ItemHandler getItemHandler() {
|
||||
return mViewConfig.getItemHandler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current filter that this view is displaying, or null if none.
|
||||
*/
|
||||
public String getCurrentFilter() {
|
||||
public FilterDetail getCurrentFilter() {
|
||||
if (mFilterStack == null) {
|
||||
return null;
|
||||
} else {
|
||||
@ -303,7 +313,7 @@ abstract class PanelLayout extends FrameLayout {
|
||||
/**
|
||||
* Get the previous filter that this view was displaying, or null if none.
|
||||
*/
|
||||
public String getPreviousFilter() {
|
||||
public FilterDetail getPreviousFilter() {
|
||||
if (!canPopFilter()) {
|
||||
return null;
|
||||
}
|
||||
@ -314,13 +324,13 @@ abstract class PanelLayout extends FrameLayout {
|
||||
/**
|
||||
* Adds a filter to the history stack for this view.
|
||||
*/
|
||||
public void pushFilter(String filter) {
|
||||
public void pushFilter(FilterDetail filter) {
|
||||
if (mFilterStack == null) {
|
||||
mFilterStack = new LinkedList<String>();
|
||||
mFilterStack = new LinkedList<FilterDetail>();
|
||||
|
||||
// Initialize with a null filter.
|
||||
// TODO: use initial filter from ViewConfig
|
||||
mFilterStack.push(null);
|
||||
mFilterStack.push(new FilterDetail(null, mPanelConfig.getTitle()));
|
||||
}
|
||||
|
||||
mFilterStack.push(filter);
|
||||
@ -345,12 +355,25 @@ abstract class PanelLayout extends FrameLayout {
|
||||
}
|
||||
}
|
||||
|
||||
static class FilterDetail {
|
||||
final String filter;
|
||||
final String title;
|
||||
|
||||
public FilterDetail(String filter, String title) {
|
||||
this.filter = filter;
|
||||
this.title = title;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pushes filter to {@code ViewState}'s stack and makes request for new filter value.
|
||||
*/
|
||||
private void pushFilterOnView(ViewState viewState, String filter) {
|
||||
viewState.pushFilter(filter);
|
||||
mDatasetHandler.requestDataset(new DatasetRequest(viewState.getDatasetId(), filter));
|
||||
private void pushFilterOnView(ViewState viewState, FilterDetail filterDetail) {
|
||||
viewState.pushFilter(filterDetail);
|
||||
|
||||
final String filter = filterDetail.filter;
|
||||
final String datasetId = viewState.getDatasetId();
|
||||
mDatasetHandler.requestDataset(new DatasetRequest(datasetId, filter));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -360,30 +383,39 @@ abstract class PanelLayout extends FrameLayout {
|
||||
*/
|
||||
private boolean popFilterOnView(ViewState viewState) {
|
||||
if (viewState.popFilter()) {
|
||||
final String filter = viewState.getCurrentFilter();
|
||||
mDatasetHandler.requestDataset(new DatasetRequest(viewState.getDatasetId(), filter));
|
||||
final FilterDetail current = viewState.getCurrentFilter();
|
||||
|
||||
final String filter = (current == null ? null : current.filter);
|
||||
final String datasetId = viewState.getDatasetId();
|
||||
mDatasetHandler.requestDataset(new DatasetRequest(datasetId, filter));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom listener so that we can intercept any filter URLs and make a new dataset request
|
||||
* rather than forwarding them to the default listener.
|
||||
*/
|
||||
private class PanelUrlOpenListener implements OnUrlOpenListener {
|
||||
public interface OnItemOpenListener {
|
||||
public void onItemOpen(String url, String title);
|
||||
}
|
||||
|
||||
private class PanelOnItemOpenListener implements OnItemOpenListener {
|
||||
private ViewState mViewState;
|
||||
|
||||
public PanelUrlOpenListener(ViewState viewState) {
|
||||
public PanelOnItemOpenListener(ViewState viewState) {
|
||||
mViewState = viewState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUrlOpen(String url, EnumSet<Flags> flags) {
|
||||
public void onItemOpen(String url, String title) {
|
||||
if (StringUtils.isFilterUrl(url)) {
|
||||
pushFilterOnView(mViewState, StringUtils.getFilterFromUrl(url));
|
||||
FilterDetail filterDetail = new FilterDetail(StringUtils.getFilterFromUrl(url), title);
|
||||
pushFilterOnView(mViewState, filterDetail);
|
||||
} else {
|
||||
EnumSet<OnUrlOpenListener.Flags> flags = EnumSet.noneOf(OnUrlOpenListener.Flags.class);
|
||||
if (mViewState.getItemHandler() == ItemHandler.INTENT) {
|
||||
flags.add(OnUrlOpenListener.Flags.OPEN_WITH_INTENT);
|
||||
}
|
||||
|
||||
mUrlOpenListener.onUrlOpen(url, flags);
|
||||
}
|
||||
}
|
||||
@ -414,7 +446,7 @@ abstract class PanelLayout extends FrameLayout {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreviousFilter() {
|
||||
public FilterDetail getPreviousFilter() {
|
||||
return mViewState.getPreviousFilter();
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import org.mozilla.gecko.home.HomeConfig.ViewConfig;
|
||||
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
|
||||
import org.mozilla.gecko.home.PanelLayout.DatasetBacked;
|
||||
import org.mozilla.gecko.home.PanelLayout.FilterManager;
|
||||
import org.mozilla.gecko.home.PanelLayout.OnItemOpenListener;
|
||||
import org.mozilla.gecko.home.PanelLayout.PanelView;
|
||||
|
||||
import android.content.Context;
|
||||
@ -28,13 +29,13 @@ public class PanelListView extends HomeListView
|
||||
|
||||
private final PanelViewAdapter mAdapter;
|
||||
private final ViewConfig mViewConfig;
|
||||
private final PanelViewUrlHandler mUrlHandler;
|
||||
private final PanelViewItemHandler mItemHandler;
|
||||
|
||||
public PanelListView(Context context, ViewConfig viewConfig) {
|
||||
super(context);
|
||||
|
||||
mViewConfig = viewConfig;
|
||||
mUrlHandler = new PanelViewUrlHandler(viewConfig);
|
||||
mItemHandler = new PanelViewItemHandler(viewConfig);
|
||||
|
||||
mAdapter = new PanelViewAdapter(context, viewConfig.getItemType());
|
||||
setAdapter(mAdapter);
|
||||
@ -42,6 +43,12 @@ public class PanelListView extends HomeListView
|
||||
setOnItemClickListener(new PanelListItemClickListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mItemHandler.setOnItemOpenListener(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDataset(Cursor cursor) {
|
||||
Log.d(LOGTAG, "Setting dataset: " + mViewConfig.getDatasetId());
|
||||
@ -49,21 +56,20 @@ public class PanelListView extends HomeListView
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnUrlOpenListener(OnUrlOpenListener listener) {
|
||||
super.setOnUrlOpenListener(listener);
|
||||
mUrlHandler.setOnUrlOpenListener(listener);
|
||||
public void setOnItemOpenListener(OnItemOpenListener listener) {
|
||||
mItemHandler.setOnItemOpenListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFilterManager(FilterManager filterManager) {
|
||||
mAdapter.setFilterManager(filterManager);
|
||||
mUrlHandler.setFilterManager(filterManager);
|
||||
mItemHandler.setFilterManager(filterManager);
|
||||
}
|
||||
|
||||
private class PanelListItemClickListener implements AdapterView.OnItemClickListener {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
mUrlHandler.openUrlAtPosition(mAdapter.getCursor(), position);
|
||||
mItemHandler.openItemAtPosition(mAdapter.getCursor(), position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,26 +6,26 @@
|
||||
package org.mozilla.gecko.home;
|
||||
|
||||
import org.mozilla.gecko.db.BrowserContract.HomeItems;
|
||||
import org.mozilla.gecko.home.HomeConfig.ItemHandler;
|
||||
import org.mozilla.gecko.home.HomeConfig.ViewConfig;
|
||||
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
|
||||
import org.mozilla.gecko.home.PanelLayout.FilterManager;
|
||||
import org.mozilla.gecko.home.PanelLayout.OnItemOpenListener;
|
||||
|
||||
import android.database.Cursor;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
class PanelViewUrlHandler {
|
||||
class PanelViewItemHandler {
|
||||
private final ViewConfig mViewConfig;
|
||||
private OnUrlOpenListener mUrlOpenListener;
|
||||
private OnItemOpenListener mItemOpenListener;
|
||||
private FilterManager mFilterManager;
|
||||
|
||||
public PanelViewUrlHandler(ViewConfig viewConfig) {
|
||||
public PanelViewItemHandler(ViewConfig viewConfig) {
|
||||
mViewConfig = viewConfig;
|
||||
}
|
||||
|
||||
public void setOnUrlOpenListener(OnUrlOpenListener listener) {
|
||||
mUrlOpenListener = listener;
|
||||
public void setOnItemOpenListener(OnItemOpenListener listener) {
|
||||
mItemOpenListener = listener;
|
||||
}
|
||||
|
||||
public void setFilterManager(FilterManager manager) {
|
||||
@ -37,7 +37,7 @@ class PanelViewUrlHandler {
|
||||
* {@code FilterManager}. Otherwise, prepare the url to be opened by the
|
||||
* {@code OnUrlOpenListener}.
|
||||
*/
|
||||
public void openUrlAtPosition(Cursor cursor, int position) {
|
||||
public void openItemAtPosition(Cursor cursor, int position) {
|
||||
if (mFilterManager != null && mFilterManager.canGoBack()) {
|
||||
if (position == 0) {
|
||||
mFilterManager.goBack();
|
||||
@ -54,13 +54,11 @@ class PanelViewUrlHandler {
|
||||
int urlIndex = cursor.getColumnIndexOrThrow(HomeItems.URL);
|
||||
final String url = cursor.getString(urlIndex);
|
||||
|
||||
EnumSet<OnUrlOpenListener.Flags> flags = EnumSet.noneOf(OnUrlOpenListener.Flags.class);
|
||||
if (mViewConfig.getItemHandler() == ItemHandler.INTENT) {
|
||||
flags.add(OnUrlOpenListener.Flags.OPEN_WITH_INTENT);
|
||||
}
|
||||
int titleIndex = cursor.getColumnIndexOrThrow(HomeItems.TITLE);
|
||||
final String title = cursor.getString(titleIndex);
|
||||
|
||||
if (mUrlOpenListener != null) {
|
||||
mUrlOpenListener.onUrlOpen(url, flags);
|
||||
if (mItemOpenListener != null) {
|
||||
mItemOpenListener.onItemOpen(url, title);
|
||||
}
|
||||
}
|
||||
}
|
@ -339,6 +339,10 @@ size. -->
|
||||
is no data to show in an about:home panel that was created by an add-on. -->
|
||||
<!ENTITY home_default_empty "No content could be found for this panel.">
|
||||
|
||||
<!-- Localization note (home_move_up_to_filter): The variable is replaced by the name of the
|
||||
previous location in the navigation, such as the previous folder -->
|
||||
<!ENTITY home_move_up_to_filter "Up to &formatS;">
|
||||
|
||||
<!ENTITY pin_site_dialog_hint "Enter a search keyword">
|
||||
|
||||
<!ENTITY filepicker_title "Choose File">
|
||||
|
@ -253,7 +253,7 @@ gbjar.sources += [
|
||||
'home/PanelListView.java',
|
||||
'home/PanelManager.java',
|
||||
'home/PanelViewAdapter.java',
|
||||
'home/PanelViewUrlHandler.java',
|
||||
'home/PanelViewItemHandler.java',
|
||||
'home/PinSiteDialog.java',
|
||||
'home/ReadingListPanel.java',
|
||||
'home/SearchEngine.java',
|
||||
|
@ -305,6 +305,7 @@
|
||||
<string name="home_reading_list_hint">&home_reading_list_hint2;</string>
|
||||
<string name="home_reading_list_hint_accessible">&home_reading_list_hint_accessible;</string>
|
||||
<string name="home_default_empty">&home_default_empty;</string>
|
||||
<string name="home_move_up_to_filter">&home_move_up_to_filter;</string>
|
||||
<string name="pin_site_dialog_hint">&pin_site_dialog_hint;</string>
|
||||
|
||||
<string name="filepicker_title">&filepicker_title;</string>
|
||||
|
Loading…
Reference in New Issue
Block a user