Bug 1380808 - Rename some "Item" classes to be more descriptive. r=mcomella

MozReview-Commit-ID: GlPbKuQPr8g

--HG--
rename : mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/model/Item.java => mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/model/WebpageModel.java
rename : mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/StreamItem.java => mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/stream/StreamViewHolder.java
extra : rebase_source : 851810edc353ec9f855aaf303752be49d8cf7e4b
This commit is contained in:
Chenxia Liu 2017-08-16 18:38:50 -07:00
parent 2f49040f78
commit bf08abec1c
15 changed files with 52 additions and 38 deletions

View File

@ -17,11 +17,12 @@ import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
import org.mozilla.gecko.activitystream.homepanel.menu.ActivityStreamContextMenu;
import org.mozilla.gecko.activitystream.homepanel.model.RowModel;
import org.mozilla.gecko.home.HomePager;
import org.mozilla.gecko.activitystream.homepanel.model.Highlight;
import org.mozilla.gecko.activitystream.homepanel.stream.HighlightItem;
import org.mozilla.gecko.activitystream.homepanel.stream.HighlightsTitle;
import org.mozilla.gecko.activitystream.homepanel.stream.StreamItem;
import org.mozilla.gecko.activitystream.homepanel.stream.StreamViewHolder;
import org.mozilla.gecko.activitystream.homepanel.stream.TopPanel;
import org.mozilla.gecko.activitystream.homepanel.stream.WelcomePanel;
import org.mozilla.gecko.util.StringUtils;
@ -36,13 +37,13 @@ import java.util.List;
*
* Every item is in a single adapter: Top Sites, Welcome panel, Highlights.
*/
public class StreamRecyclerAdapter extends RecyclerView.Adapter<StreamItem> implements RecyclerViewClickSupport.OnItemClickListener,
public class StreamRecyclerAdapter extends RecyclerView.Adapter<StreamViewHolder> implements RecyclerViewClickSupport.OnItemClickListener,
RecyclerViewClickSupport.OnItemLongClickListener, StreamHighlightItemContextMenuListener {
private static final String LOGTAG = StringUtils.safeSubstring("Gecko" + StreamRecyclerAdapter.class.getSimpleName(), 0, 23);
private Cursor topSitesCursor;
private List<RowItem> recyclerViewModel; // List of item types backing this RecyclerView.
private List<RowModel> recyclerViewModel; // List of item types backing this RecyclerView.
private final RowItemType[] FIXED_ROWS = {RowItemType.TOP_PANEL, RowItemType.WELCOME, RowItemType.HIGHLIGHTS_TITLE};
private static final int HIGHLIGHTS_OFFSET = 3; // Topsites, Welcome, Highlights Title
@ -53,10 +54,6 @@ public class StreamRecyclerAdapter extends RecyclerView.Adapter<StreamItem> impl
private int tiles;
private int tilesSize;
public interface RowItem {
RowItemType getRowItemType();
}
public enum RowItemType {
TOP_PANEL (-2), // RecyclerView.NO_ID is -1, so start hard-coded stableIds at -2.
WELCOME (-3),
@ -74,8 +71,8 @@ public class StreamRecyclerAdapter extends RecyclerView.Adapter<StreamItem> impl
}
}
private static RowItem makeRowItemFromType(final RowItemType type) {
return new RowItem() {
private static RowModel makeRowModelFromType(final RowItemType type) {
return new RowModel() {
@Override
public RowItemType getRowItemType() {
return type;
@ -87,7 +84,7 @@ public class StreamRecyclerAdapter extends RecyclerView.Adapter<StreamItem> impl
setHasStableIds(true);
recyclerViewModel = new LinkedList<>();
for (RowItemType type : FIXED_ROWS) {
recyclerViewModel.add(makeRowItemFromType(type));
recyclerViewModel.add(makeRowModelFromType(type));
}
}
@ -112,7 +109,7 @@ public class StreamRecyclerAdapter extends RecyclerView.Adapter<StreamItem> impl
}
@Override
public StreamItem onCreateViewHolder(ViewGroup parent, final int type) {
public StreamViewHolder onCreateViewHolder(ViewGroup parent, final int type) {
final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
if (type == RowItemType.TOP_PANEL.getViewType()) {
@ -133,7 +130,7 @@ public class StreamRecyclerAdapter extends RecyclerView.Adapter<StreamItem> impl
}
@Override
public void onBindViewHolder(StreamItem holder, int position) {
public void onBindViewHolder(StreamViewHolder holder, int position) {
int type = getItemViewType(position);
if (type == RowItemType.HIGHLIGHT_ITEM.getViewType()) {
final Highlight highlight = (Highlight) recyclerViewModel.get(position);

View File

@ -17,10 +17,10 @@ import org.mozilla.gecko.R;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
import org.mozilla.gecko.activitystream.homepanel.model.WebpageModel;
import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.home.HomePager;
import org.mozilla.gecko.activitystream.homepanel.model.Item;
import org.mozilla.gecko.reader.SavedReaderViewHelper;
import org.mozilla.gecko.util.Clipboard;
import org.mozilla.gecko.util.HardwareUtils;
@ -39,7 +39,7 @@ public abstract class ActivityStreamContextMenu
}
private final Context context;
private final Item item;
private final WebpageModel item;
private final ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder;
@ -57,7 +57,7 @@ public abstract class ActivityStreamContextMenu
/* package-private */ ActivityStreamContextMenu(final Context context,
final ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
final MenuMode mode,
final Item item,
final WebpageModel item,
HomePager.OnUrlOpenListener onUrlOpenListener,
HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
this.context = context;
@ -148,7 +148,7 @@ public abstract class ActivityStreamContextMenu
(new UIAsyncTask.WithoutParams<Boolean>(ThreadUtils.getBackgroundHandler()) {
@Override
protected Boolean doInBackground() {
final Item item = ActivityStreamContextMenu.this.item;
final WebpageModel item = ActivityStreamContextMenu.this.item;
final Cursor cursor = BrowserDB.from(context).getHistoryForURL(context.getContentResolver(), item.getUrl());
// It's tempting to throw here, but crashing because of a (hopefully) inconsequential
@ -314,7 +314,7 @@ public abstract class ActivityStreamContextMenu
@RobocopTarget
public static ActivityStreamContextMenu show(Context context,
View anchor, ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
final MenuMode menuMode, final Item item,
final MenuMode menuMode, final WebpageModel item,
final boolean shouldOverrideIconWithImageProvider,
HomePager.OnUrlOpenListener onUrlOpenListener,
HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener,

View File

@ -21,8 +21,8 @@ import android.view.accessibility.AccessibilityEvent;
import android.widget.TextView;
import org.mozilla.gecko.R;
import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
import org.mozilla.gecko.activitystream.homepanel.model.Item;
import org.mozilla.gecko.activitystream.homepanel.stream.StreamOverridablePageIconLayout;
import org.mozilla.gecko.activitystream.homepanel.model.WebpageModel;
import org.mozilla.gecko.home.HomePager;
import org.mozilla.gecko.util.StringUtils;
import org.mozilla.gecko.util.URIUtils;
@ -49,7 +49,7 @@ import java.net.URISyntaxException;
public BottomSheetContextMenu(final Context context,
final ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
final MenuMode mode,
final Item item,
final WebpageModel item,
final boolean shouldOverrideIconWithImageProvider,
HomePager.OnUrlOpenListener onUrlOpenListener,
HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener,

View File

@ -18,7 +18,7 @@ import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.R;
import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
import org.mozilla.gecko.home.HomePager;
import org.mozilla.gecko.activitystream.homepanel.model.Item;
import org.mozilla.gecko.activitystream.homepanel.model.WebpageModel;
/* package-private */ class PopupContextMenu
extends ActivityStreamContextMenu {
@ -32,7 +32,7 @@ import org.mozilla.gecko.activitystream.homepanel.model.Item;
View anchor,
final ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
final MenuMode mode,
final Item item,
final WebpageModel item,
HomePager.OnUrlOpenListener onUrlOpenListener,
HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
super(context,

View File

@ -18,7 +18,7 @@ import org.mozilla.gecko.activitystream.ranking.HighlightsRanking;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Highlight implements Item, StreamRecyclerAdapter.RowItem {
public class Highlight implements WebpageModel, RowModel {
/**
* A pattern matching a json object containing the key "image_url" and extracting the value. afaik, these urls

View File

@ -0,0 +1,11 @@
/* -*- 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.activitystream.homepanel.model;
import org.mozilla.gecko.activitystream.homepanel.StreamRecyclerAdapter;
public interface RowModel {
StreamRecyclerAdapter.RowItemType getRowItemType();
}

View File

@ -11,7 +11,7 @@ import android.support.annotation.Nullable;
import org.mozilla.gecko.db.BrowserContract;
public class TopSite implements Item {
public class TopSite implements WebpageModel {
private final long id;
private final String url;
private final String title;

View File

@ -1,12 +1,17 @@
/* -*- 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.activitystream.homepanel.model;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
/**
* Shared interface for activity stream item models.
* Shared interface for activity stream items that model a url/link item.
*/
public interface Item {
public interface WebpageModel {
String getTitle();
String getUrl();

View File

@ -28,7 +28,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.UUID;
public class HighlightItem extends StreamItem {
public class HighlightItem extends StreamViewHolder {
private static final String LOGTAG = "GeckoHighlightItem";
public static final int LAYOUT_ID = R.layout.activity_stream_card_history_item;

View File

@ -9,7 +9,7 @@ import android.view.View;
import org.mozilla.gecko.R;
public class HighlightsTitle extends StreamItem {
public class HighlightsTitle extends StreamViewHolder {
public static final int LAYOUT_ID = R.layout.activity_stream_main_highlightstitle;
public HighlightsTitle(final View itemView) {

View File

@ -8,8 +8,8 @@ package org.mozilla.gecko.activitystream.homepanel.stream;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public abstract class StreamItem extends RecyclerView.ViewHolder {
public StreamItem(View itemView) {
public abstract class StreamViewHolder extends RecyclerView.ViewHolder {
public StreamViewHolder(View itemView) {
super(itemView);
}
}

View File

@ -17,7 +17,7 @@ import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.activitystream.homepanel.topsites.TopSitesPagerAdapter;
import org.mozilla.gecko.home.HomePager;
public class TopPanel extends StreamItem {
public class TopPanel extends StreamViewHolder {
public static final int LAYOUT_ID = R.layout.activity_stream_main_toppanel;
private final ViewPager topSitesPager;

View File

@ -15,15 +15,15 @@ import android.widget.Button;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.R;
public class WelcomePanel extends StreamItem implements View.OnClickListener {
public class WelcomePanel extends StreamViewHolder implements View.OnClickListener {
public static final int LAYOUT_ID = R.layout.activity_stream_main_welcomepanel;
public static final String PREF_WELCOME_DISMISSED = "activitystream.welcome_dismissed";
private final RecyclerView.Adapter<StreamItem> adapter;
private final RecyclerView.Adapter<StreamViewHolder> adapter;
private final Context context;
public WelcomePanel(final View itemView, final RecyclerView.Adapter<StreamItem> adapter) {
public WelcomePanel(final View itemView, final RecyclerView.Adapter<StreamViewHolder> adapter) {
super(itemView);
this.adapter = adapter;
@ -47,7 +47,7 @@ public class WelcomePanel extends StreamItem implements View.OnClickListener {
// To animate between item changes, RecyclerView keeps around the old version of the view,
// and creates a new equivalent item (which is bound using the new data) - followed by
// animating between those two versions. Hence we just need to make sure that
// any future calls to onCreateViewHolder create a version of the Header Item
// any future calls to onCreateViewHolder create a version of the Header StreamViewHolder
// with the welcome panel hidden (i.e. we don't need to care about animations ourselves).
// We communicate this state change via the pref.

View File

@ -513,13 +513,14 @@ gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [
'activitystream/homepanel/menu/BottomSheetContextMenu.java',
'activitystream/homepanel/menu/PopupContextMenu.java',
'activitystream/homepanel/model/Highlight.java',
'activitystream/homepanel/model/Item.java',
'activitystream/homepanel/model/Metadata.java',
'activitystream/homepanel/model/RowModel.java',
'activitystream/homepanel/model/TopSite.java',
'activitystream/homepanel/model/WebpageModel.java',
'activitystream/homepanel/stream/HighlightItem.java',
'activitystream/homepanel/stream/HighlightsTitle.java',
'activitystream/homepanel/stream/StreamItem.java',
'activitystream/homepanel/stream/StreamOverridablePageIconLayout.java',
'activitystream/homepanel/stream/StreamViewHolder.java',
'activitystream/homepanel/stream/TopPanel.java',
'activitystream/homepanel/stream/WelcomePanel.java',
'activitystream/homepanel/StreamHighlightItemContextMenuListener.java',

View File

@ -17,13 +17,13 @@ import com.robotium.solo.Condition;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.R;
import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
import org.mozilla.gecko.activitystream.homepanel.model.WebpageModel;
import org.mozilla.gecko.activitystream.ranking.HighlightCandidateCursorIndices;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.DBUtils;
import org.mozilla.gecko.activitystream.homepanel.menu.ActivityStreamContextMenu;
import org.mozilla.gecko.activitystream.homepanel.model.Highlight;
import org.mozilla.gecko.activitystream.homepanel.model.Item;
import org.mozilla.gecko.activitystream.homepanel.model.TopSite;
/**
@ -228,7 +228,7 @@ public class testActivityStreamContextMenu extends BaseTest {
* Test that the menu shows the expected menu items for a given URL, and that these items have
* the correct state.
*/
private void testMenuForItem(Item item, boolean bookmarked, boolean pinned, boolean visited) {
private void testMenuForItem(WebpageModel item, boolean bookmarked, boolean pinned, boolean visited) {
final View anchor = new View(getActivity());
final ActivityStreamContextMenu menu = ActivityStreamContextMenu.show(
getActivity(), anchor, ActivityStreamTelemetry.Extras.builder(),