Bug 1026715 - Add "Open all" item to recent tabs lists. r=lucasr

This commit is contained in:
Margaret Leibovic 2014-06-23 14:13:05 -07:00
parent 332a546ab2
commit 943fb5aa9a
7 changed files with 74 additions and 12 deletions

View File

@ -9,6 +9,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.net.URLEncoder;
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.Vector;
@ -2746,7 +2747,7 @@ abstract public class BrowserApp extends GeckoApp
// HomePager.OnNewTabsListener
@Override
public void onNewTabs(String[] urls) {
public void onNewTabs(List<String> urls) {
final EnumSet<OnUrlOpenListener.Flags> flags = EnumSet.of(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB);
for (String url : urls) {

View File

@ -81,7 +81,7 @@ public class HomePager extends ViewPager {
}
public interface OnNewTabsListener {
public void onNewTabs(String[] urls);
public void onNewTabs(List<String> urls);
}
/**

View File

@ -5,6 +5,9 @@
package org.mozilla.gecko.home;
import java.util.ArrayList;
import java.util.List;
import org.mozilla.gecko.AboutPages;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoAppShell;
@ -86,6 +89,8 @@ public class RecentTabsPanel extends HomeFragment
public static final int TYPE_HEADER = 0;
public static final int TYPE_LAST_TIME = 1;
public static final int TYPE_CLOSED = 2;
public static final int TYPE_OPEN_ALL_LAST_TIME = 3;
public static final int TYPE_OPEN_ALL_CLOSED = 4;
}
@Override
@ -125,16 +130,36 @@ public class RecentTabsPanel extends HomeFragment
return;
}
final int itemType = c.getInt(c.getColumnIndexOrThrow(RecentTabs.TYPE));
if (itemType == RecentTabs.TYPE_OPEN_ALL_LAST_TIME) {
openTabsWithType(RecentTabs.TYPE_LAST_TIME);
return;
}
if (itemType == RecentTabs.TYPE_OPEN_ALL_CLOSED) {
openTabsWithType(RecentTabs.TYPE_CLOSED);
return;
}
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL);
final String url = c.getString(c.getColumnIndexOrThrow(RecentTabs.URL));
mNewTabsListener.onNewTabs(new String[] { url });
final ArrayList<String> urls = new ArrayList<String>();
urls.add(c.getString(c.getColumnIndexOrThrow(RecentTabs.URL)));
mNewTabsListener.onNewTabs(urls);
}
});
mList.setContextMenuInfoFactory(new HomeContextMenuInfo.Factory() {
@Override
public HomeContextMenuInfo makeInfoForCursor(View view, int position, long id, Cursor cursor) {
// Don't show context menus for the "Open all" rows.
final int itemType = cursor.getInt(cursor.getColumnIndexOrThrow(RecentTabs.TYPE));
if (itemType == RecentTabs.TYPE_OPEN_ALL_LAST_TIME || itemType == RecentTabs.TYPE_OPEN_ALL_CLOSED) {
return null;
}
final HomeContextMenuInfo info = new HomeContextMenuInfo(view, position, id);
info.url = cursor.getString(cursor.getColumnIndexOrThrow(RecentTabs.URL));
info.title = cursor.getString(cursor.getColumnIndexOrThrow(RecentTabs.TITLE));
@ -234,16 +259,17 @@ public class RecentTabsPanel extends HomeFragment
});
}
private void openAllTabs() {
private void openTabsWithType(int type) {
final Cursor c = mAdapter.getCursor();
if (c == null || !c.moveToFirst()) {
return;
}
final String[] urls = new String[c.getCount()];
final List<String> urls = new ArrayList<String>();
do {
urls[c.getPosition()] = c.getString(c.getColumnIndexOrThrow(RecentTabs.URL));
if (c.getInt(c.getColumnIndexOrThrow(RecentTabs.TYPE)) == type) {
urls.add(c.getString(c.getColumnIndexOrThrow(RecentTabs.URL)));
}
} while (c.moveToNext());
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.BUTTON);
@ -288,6 +314,11 @@ public class RecentTabsPanel extends HomeFragment
addRow(c, url, closedTabs[i].title, RecentTabs.TYPE_CLOSED);
}
}
// Add an "Open all" button if more than 2 tabs were added to the list.
if (length > 1) {
addRow(c, null, null, RecentTabs.TYPE_OPEN_ALL_CLOSED);
}
}
final String jsonString = GeckoProfile.get(context).readSessionFile(true);
@ -317,6 +348,11 @@ public class RecentTabsPanel extends HomeFragment
}
}.parse(jsonString);
// Add an "Open all" button if more than 2 tabs were added to the list (account for the header)
if (c.getCount() - count > 2) {
addRow(c, null, null, RecentTabs.TYPE_OPEN_ALL_LAST_TIME);
}
return c;
}
}
@ -324,9 +360,11 @@ public class RecentTabsPanel extends HomeFragment
private static class RecentTabsAdapter extends MultiTypeCursorAdapter {
private static final int ROW_HEADER = 0;
private static final int ROW_STANDARD = 1;
private static final int ROW_OPEN_ALL = 2;
private static final int[] VIEW_TYPES = new int[] { ROW_STANDARD, ROW_HEADER };
private static final int[] LAYOUT_TYPES = new int[] { R.layout.home_item_row, R.layout.home_header_row };
private static final int[] VIEW_TYPES = new int[] { ROW_STANDARD, ROW_HEADER, ROW_OPEN_ALL };
private static final int[] LAYOUT_TYPES =
new int[] { R.layout.home_item_row, R.layout.home_header_row, R.layout.home_open_all_row };
public RecentTabsAdapter(Context context) {
super(context, null, VIEW_TYPES, LAYOUT_TYPES);
@ -340,6 +378,10 @@ public class RecentTabsPanel extends HomeFragment
return ROW_HEADER;
}
if (type == RecentTabs.TYPE_OPEN_ALL_LAST_TIME || type == RecentTabs.TYPE_OPEN_ALL_CLOSED) {
return ROW_OPEN_ALL;
}
return ROW_STANDARD;
}
@ -350,6 +392,10 @@ public class RecentTabsPanel extends HomeFragment
@Override
public void bindView(View view, Context context, int position) {
final int itemType = getItemViewType(position);
if (itemType == ROW_OPEN_ALL) {
return;
}
final Cursor c = getCursor(position);
if (itemType == ROW_HEADER) {

View File

@ -352,8 +352,8 @@ size. -->
<!ENTITY home_bookmarks_empty "Bookmarks you save show up here.">
<!ENTITY home_closed_tabs_title "Recently closed tabs">
<!ENTITY home_last_tabs_title "Tabs from last time">
<!ENTITY home_last_tabs_open "Open all tabs from last time">
<!ENTITY home_last_tabs_empty "Your recent tabs show up here.">
<!ENTITY home_open_all "Open all">
<!ENTITY home_most_recent_empty "Websites you visited most recently show up here.">
<!ENTITY home_reading_list_empty "Articles you save for later show up here.">
<!-- Localization note (home_reading_list_hint): The "TIP" string is synonymous to "hint", "clue", etc. This string is displayed

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:text="@string/home_open_all"
style="@style/Widget.Home.ActionItem"/>

View File

@ -233,6 +233,13 @@
<item name="android:textAppearance">@style/TextAppearance.Widget.Home.PageAction</item>
</style>
<style name="Widget.Home.ActionItem">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">40dip</item>
<item name="android:textColor">#000000</item>
<item name="android:gravity">center</item>
</style>
<style name="Widget.Home.HistoryTabIndicator">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">32dp</item>

View File

@ -316,8 +316,8 @@
<string name="home_bookmarks_empty">&home_bookmarks_empty;</string>
<string name="home_closed_tabs_title">&home_closed_tabs_title;</string>
<string name="home_last_tabs_title">&home_last_tabs_title;</string>
<string name="home_last_tabs_open">&home_last_tabs_open;</string>
<string name="home_last_tabs_empty">&home_last_tabs_empty;</string>
<string name="home_open_all">&home_open_all;</string>
<string name="home_most_recent_empty">&home_most_recent_empty;</string>
<string name="home_reading_list_empty">&home_reading_list_empty;</string>
<string name="home_reading_list_hint">&home_reading_list_hint2;</string>