Bug 1317632 - If the bookmark to add is a reader mode page, defer db action till it cache completely and save the same url in bookmarks and uriannotations table to avoid URL chagne between two http requests. r?ahunt,sebastian
draft
Bug 1317632 - If the bookmark to add is a reader mode page, defer db action till it cache completely and save the same url in bookmarks and uriannotations table to avoid URL chagne between two http requests. r?ahunt,sebastian
MozReview-Commit-ID: 8ZwteTOKe1G
--- a/mobile/android/base/java/org/mozilla/gecko/Tab.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tab.java
@@ -505,26 +505,28 @@ public class Tab {
public void addBookmark() {
final String url = getURL();
if (url == null) {
return;
}
final String pageUrl = ReaderModeUtils.stripAboutReaderUrl(getURL());
- ThreadUtils.postToBackgroundThread(new Runnable() {
- @Override
- public void run() {
- mDB.addBookmark(getContentResolver(), mTitle, pageUrl);
- Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.BOOKMARK_ADDED);
- }
- });
-
if (AboutPages.isAboutReader(url)) {
ReadingListHelper.cacheReaderItem(pageUrl, mId, mAppContext);
+ // defer bookmarking after completely added to cache.
+ } else {
+ ThreadUtils.postToBackgroundThread(new Runnable() {
+ @Override
+ public void run() {
+ mDB.addBookmark(getContentResolver(), mTitle, pageUrl);
+ Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.BOOKMARK_ADDED);
+ }
+ });
+
}
}
public void removeBookmark() {
final String url = getURL();
if (url == null) {
return;
}
--- a/mobile/android/base/java/org/mozilla/gecko/reader/SavedReaderViewHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/reader/SavedReaderViewHelper.java
@@ -1,22 +1,25 @@
/* -*- 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.reader;
+import android.content.ContentResolver;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.GeckoProfile;
+import org.mozilla.gecko.Tab;
+import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.UrlAnnotations;
import org.mozilla.gecko.util.ThreadUtils;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
@@ -141,18 +144,23 @@ public class SavedReaderViewHelper {
Log.w(LOG_TAG, "Item insertion failed:", e);
// This should never happen, absent any errors in our own implementation
throw new IllegalStateException("Failure inserting into SavedReaderViewHelper json");
}
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
- UrlAnnotations annotations = BrowserDB.from(mContext).getUrlAnnotations();
- annotations.insertReaderViewUrl(mContext.getContentResolver(), pageURL);
+ final UrlAnnotations annotations = BrowserDB.from(mContext).getUrlAnnotations();
+ final ContentResolver contentResolver = mContext.getContentResolver();
+ final Tab selectedTab = Tabs.getInstance().getSelectedTab();
+
+ annotations.insertReaderViewUrl(contentResolver, pageURL);
+ BrowserDB.from(mContext).addBookmark(contentResolver, selectedTab.getTitle(), pageURL);
+ Tabs.getInstance().notifyListeners(selectedTab, Tabs.TabEvents.BOOKMARK_ADDED);
commit();
}
});
}
protected synchronized void remove(@NonNull final String pageURL) {
assertItemsLoaded();