Bug 877870 - Change BookmarkPage to use a listener to open URLs (r=sriram)

This commit is contained in:
Lucas Rocha 2013-06-11 17:57:45 +01:00
parent 8905d1fd02
commit aaa8a88ce4
3 changed files with 27 additions and 3 deletions

View File

@ -74,7 +74,7 @@ abstract public class BrowserApp extends GeckoApp
PropertyAnimator.PropertyAnimationListener,
View.OnKeyListener,
GeckoLayerClient.OnMetricsChangedListener,
AboutHome.UriLoadListener,
HomePager.OnUrlOpenListener,
AboutHome.LoadCompleteListener {
private static final String LOGTAG = "GeckoBrowserApp";
@ -1774,8 +1774,9 @@ abstract public class BrowserApp extends GeckoApp
}).execute();
}
// HomePager.OnUrlOpenListener
@Override
public void onAboutHomeUriLoad(String url) {
public void onUrlOpen(String url) {
openUrl(url);
}

View File

@ -12,6 +12,7 @@ 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;
@ -57,10 +58,24 @@ public class BookmarksPage extends Fragment {
// 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());
}
@ -69,6 +84,8 @@ public class BookmarksPage extends Fragment {
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();
@ -206,7 +223,9 @@ public class BookmarksPage extends Fragment {
} else {
// Otherwise, just open the URL
String url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL));
Tabs.getInstance().loadUrl(url);
if (mUrlOpenListener != null) {
mUrlOpenListener.onUrlOpen(url);
}
}
}

View File

@ -32,6 +32,10 @@ public class HomePager extends ViewPager {
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;