зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset 1d0bc7e990fe (bug 1328937)
This commit is contained in:
Родитель
c1a0c67e9e
Коммит
1851a07b40
|
@ -144,7 +144,7 @@ public class ActivityStreamTelemetry {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder forTopSiteType(@BrowserContract.TopSites.TopSiteType int type) {
|
||||
public Builder forTopSiteType(int type) {
|
||||
switch (type) {
|
||||
case BrowserContract.TopSites.TYPE_PINNED:
|
||||
this.set(Contract.SOURCE_SUBTYPE, Contract.SUBTYPE_PINNED);
|
||||
|
@ -156,7 +156,6 @@ public class ActivityStreamTelemetry {
|
|||
this.set(Contract.SOURCE_SUBTYPE, Contract.SUBTYPE_TOP);
|
||||
break;
|
||||
// While we also have a "blank" type, it is not used by Activity Stream.
|
||||
case BrowserContract.TopSites.TYPE_BLANK:
|
||||
default:
|
||||
throw new IllegalStateException("Unknown top site type: " + type);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.mozilla.gecko.db;
|
|||
import org.mozilla.gecko.AppConstants;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.mozilla.gecko.annotation.RobocopTarget;
|
||||
|
@ -596,9 +595,6 @@ public class BrowserContract {
|
|||
public static final int TYPE_PINNED = 2;
|
||||
public static final int TYPE_SUGGESTED = 3;
|
||||
|
||||
@IntDef({TYPE_BLANK, TYPE_TOP, TYPE_PINNED, TYPE_SUGGESTED})
|
||||
public @interface TopSiteType {}
|
||||
|
||||
public static final String BOOKMARK_ID = "bookmark_id";
|
||||
public static final String HISTORY_ID = "history_id";
|
||||
public static final String TYPE = "type";
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
/* -*- 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.activitystream.model;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
|
||||
public class TopSite {
|
||||
private final long id;
|
||||
private final String url;
|
||||
private final String title;
|
||||
private @Nullable final Boolean isBookmarked;
|
||||
private @BrowserContract.TopSites.TopSiteType final int type;
|
||||
|
||||
public static TopSite fromCursor(Cursor cursor) {
|
||||
// The Combined View only contains pages that have been visited at least once, i.e. any
|
||||
// page in the TopSites query will contain a HISTORY_ID. _ID however will be 0 for all rows.
|
||||
final long id = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.Combined.HISTORY_ID));
|
||||
final String url = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.URL));
|
||||
final String title = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.TITLE));
|
||||
final int type = cursor.getInt(cursor.getColumnIndexOrThrow(BrowserContract.TopSites.TYPE));
|
||||
|
||||
// We can't figure out bookmark state of a pin, so we leave it as unknown to be queried later.
|
||||
Boolean isBookmarked = null;
|
||||
if (type != BrowserContract.TopSites.TYPE_PINNED) {
|
||||
isBookmarked = !cursor.isNull(cursor.getColumnIndexOrThrow(BrowserContract.Combined.BOOKMARK_ID));
|
||||
}
|
||||
|
||||
return new TopSite(id, url, title, isBookmarked, type);
|
||||
}
|
||||
|
||||
private TopSite(long id, String url, String title, @Nullable Boolean isBookmarked, int type) {
|
||||
this.id = id;
|
||||
this.url = url;
|
||||
this.title = title;
|
||||
this.isBookmarked = isBookmarked;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Boolean isBookmarked() {
|
||||
return isBookmarked;
|
||||
}
|
||||
|
||||
@BrowserContract.TopSites.TopSiteType
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean isPinned() {
|
||||
return type == BrowserContract.TopSites.TYPE_PINNED;
|
||||
}
|
||||
}
|
|
@ -21,7 +21,6 @@ import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
|
|||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.home.HomePager;
|
||||
import org.mozilla.gecko.home.activitystream.menu.ActivityStreamContextMenu;
|
||||
import org.mozilla.gecko.home.activitystream.model.TopSite;
|
||||
import org.mozilla.gecko.icons.IconCallback;
|
||||
import org.mozilla.gecko.icons.IconResponse;
|
||||
import org.mozilla.gecko.icons.Icons;
|
||||
|
@ -41,7 +40,9 @@ class TopSitesCard extends RecyclerView.ViewHolder
|
|||
private final ImageView menuButton;
|
||||
private Future<IconResponse> ongoingIconLoad;
|
||||
|
||||
private TopSite topSite;
|
||||
private String url;
|
||||
private int type;
|
||||
@Nullable private Boolean isBookmarked;
|
||||
|
||||
private final HomePager.OnUrlOpenListener onUrlOpenListener;
|
||||
private final HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener;
|
||||
|
@ -65,27 +66,29 @@ class TopSitesCard extends RecyclerView.ViewHolder
|
|||
ViewUtil.enableTouchRipple(menuButton);
|
||||
}
|
||||
|
||||
void bind(final TopSite topSite) {
|
||||
this.topSite = topSite;
|
||||
|
||||
ActivityStream.extractLabel(itemView.getContext(), topSite.getUrl(), true, new ActivityStream.LabelCallback() {
|
||||
void bind(final TopSitesPageAdapter.TopSite topSite) {
|
||||
ActivityStream.extractLabel(itemView.getContext(), topSite.url, true, new ActivityStream.LabelCallback() {
|
||||
@Override
|
||||
public void onLabelExtracted(String label) {
|
||||
title.setText(label);
|
||||
}
|
||||
});
|
||||
|
||||
this.url = topSite.url;
|
||||
this.type = topSite.type;
|
||||
this.isBookmarked = topSite.isBookmarked;
|
||||
|
||||
if (ongoingIconLoad != null) {
|
||||
ongoingIconLoad.cancel(true);
|
||||
}
|
||||
|
||||
ongoingIconLoad = Icons.with(itemView.getContext())
|
||||
.pageUrl(topSite.getUrl())
|
||||
.pageUrl(topSite.url)
|
||||
.skipNetwork()
|
||||
.build()
|
||||
.execute(this);
|
||||
|
||||
final int pinResourceId = (topSite.isPinned() ? R.drawable.pin : 0);
|
||||
final int pinResourceId = (isPinned(this.type) ? R.drawable.pin : 0);
|
||||
TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(title, pinResourceId, 0, 0, 0);
|
||||
}
|
||||
|
||||
|
@ -103,10 +106,10 @@ class TopSitesCard extends RecyclerView.ViewHolder
|
|||
public void onClick(View clickedView) {
|
||||
ActivityStreamTelemetry.Extras.Builder extras = ActivityStreamTelemetry.Extras.builder()
|
||||
.set(ActivityStreamTelemetry.Contract.SOURCE_TYPE, ActivityStreamTelemetry.Contract.TYPE_TOPSITES)
|
||||
.forTopSiteType(topSite.getType());
|
||||
.forTopSiteType(type);
|
||||
|
||||
if (clickedView == itemView) {
|
||||
onUrlOpenListener.onUrlOpen(topSite.getUrl(), EnumSet.noneOf(HomePager.OnUrlOpenListener.Flags.class));
|
||||
onUrlOpenListener.onUrlOpen(url, EnumSet.noneOf(HomePager.OnUrlOpenListener.Flags.class));
|
||||
|
||||
Telemetry.sendUIEvent(
|
||||
TelemetryContract.Event.LOAD_URL,
|
||||
|
@ -118,9 +121,9 @@ class TopSitesCard extends RecyclerView.ViewHolder
|
|||
menuButton,
|
||||
extras,
|
||||
ActivityStreamContextMenu.MenuMode.TOPSITE,
|
||||
title.getText().toString(), topSite.getUrl(),
|
||||
title.getText().toString(), url,
|
||||
|
||||
topSite.isBookmarked(), topSite.isPinned(),
|
||||
isBookmarked, isPinned(type),
|
||||
|
||||
onUrlOpenListener, onUrlOpenInBackgroundListener,
|
||||
faviconView.getWidth(), faviconView.getHeight());
|
||||
|
@ -132,4 +135,8 @@ class TopSitesCard extends RecyclerView.ViewHolder
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPinned(int type) {
|
||||
return type == BrowserContract.TopSites.TYPE_PINNED;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,27 @@ import android.widget.FrameLayout;
|
|||
import org.mozilla.gecko.R;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.home.HomePager;
|
||||
import org.mozilla.gecko.home.activitystream.model.TopSite;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TopSitesPageAdapter extends RecyclerView.Adapter<TopSitesCard> {
|
||||
static final class TopSite {
|
||||
public final long id;
|
||||
public final String url;
|
||||
public final String title;
|
||||
@Nullable public final Boolean isBookmarked;
|
||||
public final int type;
|
||||
|
||||
TopSite(long id, String url, String title, @Nullable Boolean isBookmarked, int type) {
|
||||
this.id = id;
|
||||
this.url = url;
|
||||
this.title = title;
|
||||
this.isBookmarked = isBookmarked;
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
|
||||
private List<TopSite> topSites;
|
||||
private int tiles;
|
||||
private int tilesWidth;
|
||||
|
@ -47,6 +62,8 @@ public class TopSitesPageAdapter extends RecyclerView.Adapter<TopSitesCard> {
|
|||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cursor
|
||||
* @param startIndex The first item that this topsites group should show. This item, and the following
|
||||
* 3 items will be displayed by this adapter.
|
||||
*/
|
||||
|
@ -60,7 +77,19 @@ public class TopSitesPageAdapter extends RecyclerView.Adapter<TopSitesCard> {
|
|||
for (int i = 0; i < tiles && startIndex + i < cursor.getCount(); i++) {
|
||||
cursor.moveToPosition(startIndex + i);
|
||||
|
||||
topSites.add(TopSite.fromCursor(cursor));
|
||||
// The Combined View only contains pages that have been visited at least once, i.e. any
|
||||
// page in the TopSites query will contain a HISTORY_ID. _ID however will be 0 for all rows.
|
||||
final long id = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.Combined.HISTORY_ID));
|
||||
final String url = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.URL));
|
||||
final String title = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.TITLE));
|
||||
final int type = cursor.getInt(cursor.getColumnIndexOrThrow(BrowserContract.TopSites.TYPE));
|
||||
|
||||
// We can't figure out bookmark state of a pin, so we leave it as unknown to be queried later.
|
||||
Boolean isBookmarked = null;
|
||||
if (type != BrowserContract.TopSites.TYPE_PINNED) {
|
||||
isBookmarked = !cursor.isNull(cursor.getColumnIndexOrThrow(BrowserContract.Combined.BOOKMARK_ID));
|
||||
}
|
||||
topSites.add(new TopSite(id, url, title, isBookmarked, type));
|
||||
}
|
||||
|
||||
notifyDataSetChanged();
|
||||
|
@ -94,6 +123,6 @@ public class TopSitesPageAdapter extends RecyclerView.Adapter<TopSitesCard> {
|
|||
@Override
|
||||
@UiThread
|
||||
public long getItemId(int position) {
|
||||
return topSites.get(position).getId();
|
||||
return topSites.get(position).id;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -472,7 +472,6 @@ gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [
|
|||
'home/activitystream/menu/PopupContextMenu.java',
|
||||
'home/activitystream/model/Highlight.java',
|
||||
'home/activitystream/model/Metadata.java',
|
||||
'home/activitystream/model/TopSite.java',
|
||||
'home/activitystream/stream/HighlightItem.java',
|
||||
'home/activitystream/stream/HighlightsTitle.java',
|
||||
'home/activitystream/stream/StreamItem.java',
|
||||
|
|
Загрузка…
Ссылка в новой задаче