Bug 1325380 - Use provider name for AS highlights. r=Grisha

MozReview-Commit-ID: 2vPk2DdrYed

--HG--
extra : rebase_source : e7de82507816ad026917b281c1d97a0a07e6289e
This commit is contained in:
Sebastian Kaspari 2016-12-22 16:17:28 +01:00
Родитель 6629c9887c
Коммит 3f306fc9d4
3 изменённых файлов: 43 добавлений и 4 удалений

Просмотреть файл

@ -606,6 +606,7 @@ public class BrowserContract {
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "highlights");
public static final String DATE = "date";
public static final String METADATA = "metadata";
}
@RobocopTarget

Просмотреть файл

@ -1192,11 +1192,16 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.POSITION) + " AS " + Bookmarks.POSITION + ", " +
DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.URL) + ", " +
DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.TITLE) + ", " +
DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.DATE_CREATED) + " AS " + Highlights.DATE + " " +
DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.DATE_CREATED) + " AS " + Highlights.DATE + ", " +
DBUtils.qualifyColumn(PageMetadata.TABLE_NAME, PageMetadata.JSON) + " AS " + Highlights.METADATA + " " +
"FROM " + Bookmarks.TABLE_NAME + " " +
"LEFT JOIN " + History.TABLE_NAME + " ON " +
DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.URL) + " = " +
DBUtils.qualifyColumn(History.TABLE_NAME, History.URL) + " " +
// 1:1 relationship (Metadata is added via INSERT OR REPLACE)
"LEFT JOIN " + PageMetadata.TABLE_NAME + " ON " +
DBUtils.qualifyColumn(History.TABLE_NAME, History.GUID) + " = " +
DBUtils.qualifyColumn(PageMetadata.TABLE_NAME, PageMetadata.HISTORY_GUID) + " " +
"WHERE " + DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.DATE_CREATED) + " > " + threeDaysAgo + " " +
"AND (" + DBUtils.qualifyColumn(History.TABLE_NAME, History.VISITS) + " <= 3 " +
"OR " + DBUtils.qualifyColumn(History.TABLE_NAME, History.VISITS) + " IS NULL) " +
@ -1218,11 +1223,16 @@ public class BrowserProvider extends SharedBrowserDatabaseProvider {
DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.POSITION) + " AS " + Bookmarks.POSITION + ", " +
DBUtils.qualifyColumn(History.TABLE_NAME, History.URL) + ", " +
DBUtils.qualifyColumn(History.TABLE_NAME, History.TITLE) + ", " +
DBUtils.qualifyColumn(History.TABLE_NAME, History.DATE_LAST_VISITED) + " AS " + Highlights.DATE + " " +
DBUtils.qualifyColumn(History.TABLE_NAME, History.DATE_LAST_VISITED) + " AS " + Highlights.DATE + ", " +
DBUtils.qualifyColumn(PageMetadata.TABLE_NAME, PageMetadata.JSON) + " AS " + Highlights.METADATA + " " +
"FROM " + History.TABLE_NAME + " " +
"LEFT JOIN " + Bookmarks.TABLE_NAME + " ON " +
DBUtils.qualifyColumn(History.TABLE_NAME, History.URL) + " = " +
DBUtils.qualifyColumn(Bookmarks.TABLE_NAME, Bookmarks.URL) + " " +
// 1:1 relationship (Metadata is added via INSERT OR REPLACE)
"LEFT JOIN " + PageMetadata.TABLE_NAME + " ON " +
DBUtils.qualifyColumn(History.TABLE_NAME, History.GUID) + " = " +
DBUtils.qualifyColumn(PageMetadata.TABLE_NAME, PageMetadata.HISTORY_GUID) + " " +
"WHERE " + DBUtils.qualifyColumn(History.TABLE_NAME, History.DATE_LAST_VISITED) + " < " + last30Minutes + " " +
"AND " + DBUtils.qualifyColumn(History.TABLE_NAME, History.VISITS) + " <= 3 " +
"AND " + DBUtils.qualifyColumn(History.TABLE_NAME, History.TITLE) + " NOT NULL AND " + DBUtils.qualifyColumn(History.TABLE_NAME, History.TITLE) + " != '' " +

Просмотреть файл

@ -14,6 +14,7 @@ import android.support.v4.view.ViewPager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
@ -21,6 +22,8 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Telemetry;
@ -46,6 +49,8 @@ import java.util.concurrent.Future;
import static org.mozilla.gecko.activitystream.ActivityStream.extractLabel;
public abstract class StreamItem extends RecyclerView.ViewHolder {
private static final String LOGTAG = "GeckoStreamItem";
public StreamItem(View itemView) {
super(itemView);
}
@ -141,6 +146,7 @@ public abstract class StreamItem extends RecyclerView.ViewHolder {
String title;
String url;
JSONObject metadata;
@Nullable Boolean isPinned;
@Nullable Boolean isBookmarked;
@ -212,6 +218,15 @@ public abstract class StreamItem extends RecyclerView.ViewHolder {
url = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.URL));
source = Utils.highlightSource(cursor);
try {
final String rawMetadata = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Highlights.METADATA));
if (rawMetadata != null) {
metadata = new JSONObject(rawMetadata);
}
} catch (JSONException e) {
Log.w(LOGTAG, "JSONException while parsing page metadata", e);
}
vLabel.setText(title);
vTimeSince.setText(ago);
@ -222,7 +237,7 @@ public abstract class StreamItem extends RecyclerView.ViewHolder {
updateStateForSource(source);
updateUiForSource(source);
updatePage(url);
updatePage(metadata, url);
if (ongoingIconLoad != null) {
ongoingIconLoad.cancel(true);
@ -272,7 +287,20 @@ public abstract class StreamItem extends RecyclerView.ViewHolder {
}
}
private void updatePage(final String url) {
private void updatePage(final JSONObject metadata, final String url) {
// First try to set the provider name from the page's metadata.
try {
if (metadata != null && metadata.has("provider")) {
vPageView.setText(metadata.getString("provider"));
return;
}
} catch (JSONException e) {
// Broken JSON? Continue with fallback.
}
// If there's no provider name available then let's try to extract one from the URL.
extractLabel(itemView.getContext(), url, false, new LabelCallback() {
@Override
public void onLabelExtracted(String label) {