Bug 1022238 - Part 2: Handle removal correctly. r=margaret

This commit is contained in:
Chenxia Liu 2014-06-10 15:03:49 -07:00
parent 330aca79c6
commit c53883bfee
4 changed files with 25 additions and 12 deletions

View File

@ -422,9 +422,6 @@ abstract public class BrowserApp extends GeckoApp
public void run() {
BrowserDB.removeReadingListItemWithURL(getContentResolver(), url);
showToast(R.string.page_removed, Toast.LENGTH_SHORT);
final int count = BrowserDB.getReadingListCount(getContentResolver());
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Reader:ListCountUpdated", Integer.toString(count)));
}
});
}

View File

@ -5,6 +5,8 @@
package org.mozilla.gecko.home;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.EditBookmarkDialog;
import org.mozilla.gecko.GeckoApp;
import org.mozilla.gecko.GeckoAppShell;
@ -340,7 +342,16 @@ abstract class HomeFragment extends Fragment {
BrowserDB.removeHistoryEntry(cr, mUrl);
BrowserDB.removeReadingListItemWithURL(cr, mUrl);
GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Remove", mUrl);
final JSONObject json = new JSONObject();
try {
json.put("url", mUrl);
json.put("notify", false);
} catch (JSONException e) {
Log.e(LOGTAG, "error building JSON arguments");
}
GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Remove", json.toString());
GeckoAppShell.sendEventToGecko(e);
return null;

View File

@ -196,9 +196,9 @@ AboutReader.prototype = {
}
break;
}
case "Reader:Remove": {
if (aData == this._article.url) {
let args = JSON.parse(aData);
if (args.url == this._article.url) {
if (this._isReadingListItem != 0) {
this._isReadingListItem = 0;
this._updateToggleButton();
@ -316,7 +316,8 @@ AboutReader.prototype = {
// In addition to removing the article from the cache (handled in
// browser.js), sending this message will cause the toggle button to be
// updated (handled in this file).
Services.obs.notifyObservers(null, "Reader:Remove", this._article.url);
let json = JSON.stringify({ url: this._article.url, notify: true });
Services.obs.notifyObservers(null, "Reader:Remove", json);
UITelemetry.addEvent("unsave.1", "button", null, "reader");
}

View File

@ -7320,14 +7320,18 @@ let Reader = {
}
case "Reader:Remove": {
let url = aData;
this.removeArticleFromCache(url, function(success) {
this.log("Reader:Remove success=" + success + ", url=" + url);
let args = JSON.parse(aData);
if (success) {
if (!("url" in args)) {
throw new Error("Reader:Remove requires URL as an argument");
}
this.removeArticleFromCache(args.url, function(success) {
this.log("Reader:Remove success=" + success + ", url=" + args.url);
if (success && args.notify) {
sendMessageToJava({
type: "Reader:Removed",
url: url
url: args.url
});
}
}.bind(this));