Bug 1234328 - Pass OnUrlOpenListener through to TwoLinePageRow to allow direct url opening draft
authorAndrzej Hunt <ahunt@mozilla.com>
Tue, 23 Feb 2016 18:14:20 -0800
changeset 336565 e472afd4731bcf267dee9e9d9c51bcac7f1073c0
parent 336564 bf602203bdadb641bc8f2f2d610885ccf763cb56
child 336566 d4b4317db9c900a1bc613d4b00579134ce28593b
push id12121
push userahunt@mozilla.com
push dateThu, 03 Mar 2016 19:16:47 +0000
bugs1234328
milestone47.0a1
Bug 1234328 - Pass OnUrlOpenListener through to TwoLinePageRow to allow direct url opening We'll need this to be able to open about:reader urls directly from here. MozReview-Commit-ID: ElnZwXFPnzD
mobile/android/base/java/org/mozilla/gecko/home/BookmarksListAdapter.java
mobile/android/base/java/org/mozilla/gecko/home/BookmarksPanel.java
mobile/android/base/java/org/mozilla/gecko/home/TwoLinePageRow.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/BookmarksListAdapter.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/BookmarksListAdapter.java
@@ -24,16 +24,18 @@ import android.view.View;
  */
 class BookmarksListAdapter extends MultiTypeCursorAdapter {
     private static final int VIEW_TYPE_ITEM = 0;
     private static final int VIEW_TYPE_FOLDER = 1;
 
     private static final int[] VIEW_TYPES = new int[] { VIEW_TYPE_ITEM, VIEW_TYPE_FOLDER };
     private static final int[] LAYOUT_TYPES = new int[] { R.layout.bookmark_item_row, R.layout.bookmark_folder_row };
 
+    private HomePager.OnUrlOpenListener mUrlOpenListener = null;
+
     public enum RefreshType implements Parcelable {
         PARENT,
         CHILD;
 
         @Override
         public int describeContents() {
             return 0;
         }
@@ -262,16 +264,20 @@ class BookmarksListAdapter extends Multi
         return (mParentStack.peek().id != Bookmarks.FIXED_ROOT_ID);
     }
 
     @Override
     public int getCount() {
         return super.getCount() + (isShowingChildFolder() ? 1 : 0);
     }
 
+    public void setOnUrlOpenListener(HomePager.OnUrlOpenListener listener) {
+        mUrlOpenListener = listener;
+    }
+
     @Override
     public void bindView(View view, Context context, int position) {
         final int viewType = getItemViewType(position);
 
         final Cursor cursor;
         if (isShowingChildFolder()) {
             if (position == 0) {
                 cursor = null;
@@ -282,16 +288,17 @@ class BookmarksListAdapter extends Multi
             }
         } else {
             cursor = getCursor(position);
         }
 
         if (viewType == VIEW_TYPE_ITEM) {
             final TwoLinePageRow row = (TwoLinePageRow) view;
             row.updateFromCursor(cursor);
+            row.setOnUrlOpenListener(mUrlOpenListener);
         } else {
             final BookmarkFolderView row = (BookmarkFolderView) view;
             if (cursor == null) {
                 final Resources res = context.getResources();
                 row.setText(res.getString(R.string.home_move_up_to_filter, mParentStack.get(1).title));
                 row.open();
             } else {
                 row.setText(getFolderTitle(context, cursor));
--- a/mobile/android/base/java/org/mozilla/gecko/home/BookmarksPanel.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/BookmarksPanel.java
@@ -117,16 +117,17 @@ public class BookmarksPanel extends Home
             public void onRefreshFolder(FolderInfo folderInfo, RefreshType refreshType) {
                 // Restart the loader with folder as the argument.
                 Bundle bundle = new Bundle();
                 bundle.putParcelable(BOOKMARKS_FOLDER_INFO, folderInfo);
                 bundle.putParcelable(BOOKMARKS_REFRESH_TYPE, refreshType);
                 getLoaderManager().restartLoader(LOADER_ID_BOOKMARKS_LIST, bundle, mLoaderCallbacks);
             }
         });
+        mListAdapter.setOnUrlOpenListener(mUrlOpenListener);
         mList.setAdapter(mListAdapter);
 
         // Create callbacks before the initial loader is started.
         mLoaderCallbacks = new CursorLoaderCallbacks();
         loadIfVisible();
     }
 
     @Override
--- a/mobile/android/base/java/org/mozilla/gecko/home/TwoLinePageRow.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/TwoLinePageRow.java
@@ -11,16 +11,17 @@ import org.mozilla.gecko.AboutPages;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.reader.ReaderModeUtils;
 import org.mozilla.gecko.Tab;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.db.BrowserContract.Combined;
 import org.mozilla.gecko.db.BrowserContract.URLColumns;
 import org.mozilla.gecko.favicons.Favicons;
 import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
+import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 import org.mozilla.gecko.widget.FaviconView;
 
 import android.content.Context;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.text.TextUtils;
 import android.util.AttributeSet;
 import android.view.Gravity;
@@ -39,16 +40,18 @@ public class TwoLinePageRow extends Line
     private int mSwitchToTabIconId;
     private int mPageTypeIconId;
 
     private final FaviconView mFavicon;
 
     private boolean mShowIcons;
     private int mLoadFaviconJobId = Favicons.NOT_LOADING;
 
+    private OnUrlOpenListener mUrlOpenListener = null;
+
     // Only holds a reference to the FaviconView itself, so if the row gets
     // discarded while a task is outstanding, we'll leak less memory.
     private static class UpdateViewFaviconLoadedListener implements OnFaviconLoadedListener {
         private final WeakReference<FaviconView> view;
         public UpdateViewFaviconLoadedListener(FaviconView view) {
             this.view = new WeakReference<FaviconView>(view);
         }
 
@@ -96,16 +99,20 @@ public class TwoLinePageRow extends Line
         mSwitchToTabIconId = NO_ICON;
         mPageTypeIconId = NO_ICON;
         mShowIcons = true;
 
         mFavicon = (FaviconView) findViewById(R.id.icon);
         mFaviconListener = new UpdateViewFaviconLoadedListener(mFavicon);
     }
 
+    public void setOnUrlOpenListener(OnUrlOpenListener listener) {
+        mUrlOpenListener = listener;
+    }
+
     @Override
     protected void onAttachedToWindow() {
         super.onAttachedToWindow();
 
         Tabs.registerOnTabsChangedListener(this);
     }
 
     @Override