Bug 1024145 - Display bookmarked toast only after bookmark has been added / removed. r=mcomella
authorTristan Pollitt <treemantris@googlemail.com>
Tue, 12 Aug 2014 10:35:00 +0200
changeset 203162 4243b005e874b97b5b0295166447b2dbf33fefcf
parent 203161 4567aa2ed95bbe6634cabd8d170e2c283206c4e2
child 203163 df679bea2e78fbd62e9836ad52991a06ab012d42
push id8521
push usercbook@mozilla.com
push dateWed, 03 Sep 2014 10:18:35 +0000
treeherderfx-team@df679bea2e78 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1024145
milestone35.0a1
Bug 1024145 - Display bookmarked toast only after bookmark has been added / removed. r=mcomella
mobile/android/base/BrowserApp.java
mobile/android/base/Tab.java
mobile/android/base/Tabs.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -275,20 +275,47 @@ public class BrowserApp extends GeckoApp
                 // If tab is not loading and the favicon is updated, we
                 // want to load the image straight away. If tab is still
                 // loading, we only load the favicon once the page's content
                 // is fully loaded.
                 if (tab.getState() != Tab.STATE_LOADING) {
                     loadFavicon(tab);
                 }
                 break;
+            case BOOKMARK_ADDED:
+                showBookmarkAddedToast();
+                break;
+            case BOOKMARK_REMOVED:
+                showBookmarkRemovedToast();
+                break;
         }
         super.onTabChanged(tab, msg, data);
     }
 
+    private void showBookmarkAddedToast() {
+        getButtonToast().show(false,
+                getResources().getString(R.string.bookmark_added),
+                ButtonToast.LENGTH_SHORT,
+                getResources().getString(R.string.bookmark_options),
+                null,
+                new ButtonToast.ToastListener() {
+                    @Override
+                    public void onButtonClicked() {
+                        showBookmarkDialog();
+                    }
+
+                    @Override
+                    public void onToastHidden(ButtonToast.ReasonHidden reason) { }
+                });
+    }
+
+    private void showBookmarkRemovedToast() {
+        Toast.makeText(this, R.string.bookmark_removed, Toast.LENGTH_SHORT).show();
+    }
+
     @Override
     public boolean onKey(View v, int keyCode, KeyEvent event) {
         if (AndroidGamepadManager.handleKeyEvent(event)) {
             return true;
         }
 
         // Global onKey handler. This is called if the focused UI doesn't
         // handle the key event, and before Gecko swallows the events.
@@ -2616,35 +2643,20 @@ public class BrowserApp extends GeckoApp
         Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.MENU, getResources().getResourceEntryName(itemId));
 
         if (itemId == R.id.bookmark) {
             tab = Tabs.getInstance().getSelectedTab();
             if (tab != null) {
                 if (item.isChecked()) {
                     Telemetry.sendUIEvent(TelemetryContract.Event.UNSAVE, TelemetryContract.Method.MENU, "bookmark");
                     tab.removeBookmark();
-                    Toast.makeText(this, R.string.bookmark_removed, Toast.LENGTH_SHORT).show();
                     item.setIcon(R.drawable.ic_menu_bookmark_add);
                 } else {
                     Telemetry.sendUIEvent(TelemetryContract.Event.SAVE, TelemetryContract.Method.MENU, "bookmark");
                     tab.addBookmark();
-                    getButtonToast().show(false,
-                        getResources().getString(R.string.bookmark_added),
-                        ButtonToast.LENGTH_SHORT,
-                        getResources().getString(R.string.bookmark_options),
-                        null,
-                        new ButtonToast.ToastListener() {
-                            @Override
-                            public void onButtonClicked() {
-                                showBookmarkDialog();
-                            }
-
-                            @Override
-                            public void onToastHidden(ButtonToast.ReasonHidden reason) { }
-                        });
                     item.setIcon(R.drawable.ic_menu_bookmark_remove);
                 }
             }
             return true;
         }
 
         if (itemId == R.id.share) {
             shareCurrentUrl();
--- a/mobile/android/base/Tab.java
+++ b/mobile/android/base/Tab.java
@@ -454,29 +454,31 @@ public class Tab {
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
                 String url = getURL();
                 if (url == null)
                     return;
 
                 BrowserDB.addBookmark(getContentResolver(), mTitle, url);
+                Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.BOOKMARK_ADDED);
             }
         });
     }
 
     public void removeBookmark() {
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
             public void run() {
                 String url = getURL();
                 if (url == null)
                     return;
 
                 BrowserDB.removeBookmarksWithURL(getContentResolver(), url);
+                Tabs.getInstance().notifyListeners(Tab.this, Tabs.TabEvents.BOOKMARK_REMOVED);
             }
         });
     }
 
     public void addToReadingList() {
         if (!mReaderEnabled)
             return;
 
--- a/mobile/android/base/Tabs.java
+++ b/mobile/android/base/Tabs.java
@@ -592,17 +592,19 @@ public class Tabs implements GeckoEventL
         MENU_UPDATED,
         PAGE_SHOW,
         LINK_FAVICON,
         LINK_FEED,
         SECURITY_CHANGE,
         READER_ENABLED,
         DESKTOP_MODE_CHANGE,
         VIEWPORT_CHANGE,
-        RECORDING_CHANGE
+        RECORDING_CHANGE,
+        BOOKMARK_ADDED,
+        BOOKMARK_REMOVED
     }
 
     public void notifyListeners(Tab tab, TabEvents msg) {
         notifyListeners(tab, msg, "");
     }
 
     public void notifyListeners(final Tab tab, final TabEvents msg, final Object data) {
         if (tab == null &&