Bug 892947 - [fig] Update ReaderList Status when removed via ContextMenu, r=lucasr
authorMark Capella <markcapella@twcny.rr.com>
Fri, 12 Jul 2013 13:34:54 -0400
changeset 143401 f3f76c0ea2ce93ec8787afc7955c3d28ee1ecadf
parent 143400 a0658f1018a65f5fd2d9d5c7e6d93b1e0182a822
child 143402 84d09b3378b4ab720df8cfd32be036b08470e529
push id25130
push userlrocha@mozilla.com
push dateWed, 21 Aug 2013 09:41:27 +0000
treeherdermozilla-central@b2486721572e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs892947
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 892947 - [fig] Update ReaderList Status when removed via ContextMenu, r=lucasr
mobile/android/base/home/HomeFragment.java
mobile/android/base/home/HomeListView.java
--- a/mobile/android/base/home/HomeFragment.java
+++ b/mobile/android/base/home/HomeFragment.java
@@ -1,16 +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.home;
 
 import org.mozilla.gecko.EditBookmarkDialog;
+import org.mozilla.gecko.GeckoEvent;
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.gfx.BitmapUtils;
 import org.mozilla.gecko.home.HomeListView.HomeContextMenuInfo;
 import org.mozilla.gecko.util.ThreadUtils;
@@ -142,26 +143,40 @@ class HomeFragment extends Fragment {
 
             case R.id.edit_bookmark: {
                 new EditBookmarkDialog(activity).show(info.url);
                 return true;
             }
 
             case R.id.remove_bookmark: {
                 final int rowId = info.rowId;
-                (new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
+                final String url = info.url;
+                final boolean inReadingList = info.inReadingList;
+
+                (new UiAsyncTask<Void, Void, Integer>(ThreadUtils.getBackgroundHandler()) {
                     @Override
-                    public Void doInBackground(Void... params) {
+                    public Integer doInBackground(Void... params) {
                         BrowserDB.removeBookmark(activity.getContentResolver(), rowId);
-                        return null;
+                        return BrowserDB.getReadingListCount(activity.getContentResolver());
                     }
 
                     @Override
-                    public void onPostExecute(Void result) {
-                        Toast.makeText(activity, R.string.bookmark_removed, Toast.LENGTH_SHORT).show();
+                    public void onPostExecute(Integer aCount) {
+                        int messageId = R.string.bookmark_removed;
+                        if (inReadingList) {
+                            messageId = R.string.reading_list_removed;
+
+                            GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Remove", url);
+                            GeckoAppShell.sendEventToGecko(e);
+
+                            e = GeckoEvent.createBroadcastEvent("Reader:ListCountUpdated", Integer.toString(aCount));
+                            GeckoAppShell.sendEventToGecko(e);
+                        }
+
+                        Toast.makeText(activity, messageId, Toast.LENGTH_SHORT).show();
                     }
                 }).execute();
                 return true;
             }
         }
         return false;
     }
 }
--- a/mobile/android/base/home/HomeListView.java
+++ b/mobile/android/base/home/HomeListView.java
@@ -92,16 +92,17 @@ public class HomeListView extends ListVi
     public static class HomeContextMenuInfo extends AdapterContextMenuInfo {
         public int rowId;
         public String url;
         public byte[] favicon;
         public String title;
         public String keyword;
         public int display;
         public boolean isFolder;
+        public boolean inReadingList;
 
         public HomeContextMenuInfo(View targetView, int position, long id, Cursor cursor) {
             super(targetView, position, id);
 
             if (cursor == null) {
                 return;
             }
 
@@ -128,12 +129,20 @@ public class HomeListView extends ListVi
                 favicon = cursor.getBlob(faviconCol);
             } else {
                 favicon = null;
             }
 
             rowId = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID));
             url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL));
             title = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE));
+
+            final int parentCol = cursor.getColumnIndex(Bookmarks.PARENT);
+            if (parentCol != -1) {
+                inReadingList = (cursor.getInt(parentCol) == Bookmarks.FIXED_READING_LIST_ID);
+            } else {
+                inReadingList = false;
+            }
+
             display = Combined.DISPLAY_NORMAL;
         }
     }
 }