Bug 877870 - Change BookmarkPage to use a listener to open URLs (r=sriram)
authorLucas Rocha <lucasr@mozilla.com>
Tue, 11 Jun 2013 17:57:45 +0100
changeset 151301 0496e60d608c89f4fbf9b15c0814f2b8cf8cdccf
parent 151300 7875f965bb4cee4381626de9b3d82b7768d3683d
child 151302 0807f3d71b68b3ed1b03bcd2b2a67feb298164f1
push idunknown
push userunknown
push dateunknown
reviewerssriram
bugs877870
milestone24.0a1
Bug 877870 - Change BookmarkPage to use a listener to open URLs (r=sriram)
mobile/android/base/BrowserApp.java
mobile/android/base/home/BookmarksPage.java
mobile/android/base/home/HomePager.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -69,17 +69,17 @@ import java.net.URL;
 import java.util.EnumSet;
 import java.util.Vector;
 
 abstract public class BrowserApp extends GeckoApp
                                  implements TabsPanel.TabsLayoutChangeListener,
                                             PropertyAnimator.PropertyAnimationListener,
                                             View.OnKeyListener,
                                             GeckoLayerClient.OnMetricsChangedListener,
-                                            AboutHome.UriLoadListener,
+                                            HomePager.OnUrlOpenListener,
                                             AboutHome.LoadCompleteListener {
     private static final String LOGTAG = "GeckoBrowserApp";
 
     private static final String PREF_CHROME_DYNAMICTOOLBAR = "browser.chrome.dynamictoolbar";
 
     private static final String ABOUT_HOME = "about:home";
 
     private static final int TABS_ANIMATION_DURATION = 450;
@@ -1769,18 +1769,19 @@ abstract public class BrowserApp extends
             public void onPostExecute(String url) {
                 // Don't bother sending a message if there is no URL.
                 if (url.length() > 0)
                     GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Feedback:LastUrl", url));
             }
         }).execute();
     }
 
+    // HomePager.OnUrlOpenListener
     @Override
-    public void onAboutHomeUriLoad(String url) {
+    public void onUrlOpen(String url) {
         openUrl(url);
     }
 
     @Override
     public void onAboutHomeLoadComplete() {
         mAboutHomeStartupTimer.stop();
     }
 
--- a/mobile/android/base/home/BookmarksPage.java
+++ b/mobile/android/base/home/BookmarksPage.java
@@ -7,16 +7,17 @@ package org.mozilla.gecko.home;
 
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.db.BrowserContract.Bookmarks;
 import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.BrowserDB.URLColumns;
+import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 import org.mozilla.gecko.util.GamepadUtils;
 import org.mozilla.gecko.util.ThreadUtils;
 
 import android.app.Activity;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.database.Cursor;
 import android.graphics.Bitmap;
@@ -52,28 +53,44 @@ public class BookmarksPage extends Fragm
     private BookmarksQueryTask mQueryTask = null;
 
     // The view shown by the fragment.
     private ListView mList;
 
     // Folder title for the currently shown list of bookmarks.
     private BookmarkFolderView mFolderView;
 
+    // On URL open listener
+    private OnUrlOpenListener mUrlOpenListener;
+
+    public BookmarksPage() {
+        mUrlOpenListener = null;
+    }
+
     @Override
     public void onAttach(Activity activity) {
         super.onAttach(activity);
 
+        try {
+            mUrlOpenListener = (OnUrlOpenListener) activity;
+        } catch (ClassCastException e) {
+            throw new ClassCastException(activity.toString()
+                    + " must implement HomePager.OnUrlOpenListener");
+        }
+
         // Intialize the adapter.
         mCursorAdapter = new BookmarksListAdapter(getActivity());
     }
 
     @Override
     public void onDetach() {
         super.onDetach();
 
+        mUrlOpenListener = null;
+
         // Can't use getters for adapter. It will create one if null.
         if (mCursorAdapter != null) {
             final Cursor cursor = mCursorAdapter.getCursor();
             mCursorAdapter = null;
 
             // Gingerbread locks the DB when closing a cursor, so do it in the background.
             ThreadUtils.postToBackgroundThread(new Runnable() {
                 @Override
@@ -201,17 +218,19 @@ public class BookmarksPage extends Fragm
             if (type == Bookmarks.TYPE_FOLDER) {
                 // If we're clicking on a folder, update adapter to move to that folder
                 int folderId = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID));
                 String folderTitle = mCursorAdapter.getFolderTitle(position);
                 mCursorAdapter.moveToChildFolder(folderId, folderTitle);
              } else {
                 // Otherwise, just open the URL
                 String url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL));
-                Tabs.getInstance().loadUrl(url);
+                if (mUrlOpenListener != null) {
+                    mUrlOpenListener.onUrlOpen(url);
+                }
              }
          }
 
         @Override
         public boolean onTouch(View view, MotionEvent event) {
             if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                 // take focus away from awesome bar to hide the keyboard
                 view.requestFocus();
--- a/mobile/android/base/home/HomePager.java
+++ b/mobile/android/base/home/HomePager.java
@@ -27,16 +27,20 @@ public class HomePager extends ViewPager
 
     // List of pages in order.
     private enum Page {
         BOOKMARKS
     }
 
     private EnumMap<Page, Fragment> mPages = new EnumMap<Page, Fragment>(Page.class);
 
+    public interface OnUrlOpenListener {
+        public void onUrlOpen(String url);
+    }
+
     public HomePager(Context context) {
         super(context);
         mContext = context;
     }
 
     public HomePager(Context context, AttributeSet attrs) {
         super(context, attrs);
         mContext = context;