Commit aefa4487 authored by Joy Ming's avatar Joy Ming Committed by Commit Bot

[Downloads location] Add option to go to settings in downloads home.

Currently the only way to get to the Downloads-related settings is by
navigating through Chrome Settings. This CL adds a button into the
downloads home top toolbar that allows the user to go directly to
the Downloads-related settings.

Screenshots:
https://drive.google.com/file/d/1KDZJF8XoKpaBjj7jNZmgiHubEokGqHc6/view
https://drive.google.com/file/d/1pV2M05Kpqh-xa3XcerZYDHHLbgW6rwqB/view
https://drive.google.com/file/d/1mb6jOUZbPYVWvy2z5vATY4BrA6-a2LH6/view
https://drive.google.com/file/d/1sBKowuMVTkY62dalrRGEDHX-DP6Tt3ky/view

Bug: 792775
Change-Id: Ib92393fd30a231597bbda9a1d2c610fc46718cda
Reviewed-on: https://chromium-review.googlesource.com/998827Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Joy Ming <jming@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551060}
parent 96267473
......@@ -6,7 +6,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:chrome="http://schemas.android.com/apk/res-auto" >
<group android:id="@+id/normal_menu_group" >
<group android:id="@+id/normal_menu_group"
android:visible="false" >
<item
android:id="@+id/info_menu_id"
android:icon="@drawable/btn_info"
......@@ -25,6 +26,37 @@
android:title="@string/close"
chrome:showAsAction="ifRoom" />
</group>
<group android:id="@+id/with_settings_normal_menu_group"
android:visible="false" >
<item
android:id="@+id/with_settings_search_menu_id"
android:icon="@drawable/ic_search"
android:title="@string/search"
android:visible="false"
chrome:showAsAction="ifRoom" />
<item
android:id="@+id/extra_menu_id"
android:icon="@drawable/ic_more_vert_black_24dp"
android:title=""
chrome:showAsAction="ifRoom" >
<menu>
<item
android:id="@+id/with_settings_info_menu_id"
android:title="@string/download_manager_ui_show_storage"
android:visible="false"
chrome:showAsAction="never" />
<item
android:id="@+id/settings_menu_id"
android:title="@string/preferences"
chrome:showAsAction="never" />
</menu>
</item>
<item
android:id="@+id/with_settings_close_menu_id"
android:icon="@drawable/btn_close"
android:title="@string/close"
chrome:showAsAction="ifRoom" />
</group>
<group
android:id="@+id/selection_mode_menu_group"
android:visible="false" >
......
......@@ -26,6 +26,8 @@ public class DownloadManagerToolbar extends SelectableListToolbar<DownloadHistor
private Spinner mSpinner;
private DownloadManagerUi mManager;
private int mInfoMenuItemId;
public DownloadManagerToolbar(Context context, AttributeSet attrs) {
super(context, attrs);
inflateMenu(R.menu.download_manager_menu);
......@@ -96,7 +98,7 @@ public class DownloadManagerToolbar extends SelectableListToolbar<DownloadHistor
protected void onDataChanged(int numItems) {
super.onDataChanged(numItems);
getMenu()
.findItem(R.id.info_menu_id)
.findItem(mInfoMenuItemId)
.setVisible(!mIsSearching && !mIsSelectionEnabled && numItems > 0);
}
......@@ -123,6 +125,12 @@ public class DownloadManagerToolbar extends SelectableListToolbar<DownloadHistor
mSpinner.setVisibility(VISIBLE);
}
@Override
public void setInfoMenuItem(int infoMenuItemId) {
super.setInfoMenuItem(infoMenuItemId);
mInfoMenuItemId = infoMenuItemId;
}
/** Returns the {@link Spinner}. */
@VisibleForTesting
public Spinner getSpinnerForTests() {
......
......@@ -30,9 +30,12 @@ import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.BasicNativePage;
import org.chromium.chrome.browser.ChromeApplication;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.download.DownloadManagerService;
import org.chromium.chrome.browser.download.DownloadUtils;
import org.chromium.chrome.browser.download.items.OfflineContentAggregatorFactory;
import org.chromium.chrome.browser.preferences.PreferencesLauncher;
import org.chromium.chrome.browser.preferences.download.DownloadPreferences;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.snackbar.Snackbar;
import org.chromium.chrome.browser.snackbar.SnackbarManager;
......@@ -199,6 +202,9 @@ public class DownloadManagerUi
private SelectableListLayout<DownloadHistoryItemWrapper> mSelectableListLayout;
private boolean mIsSeparateActivity;
private int mSearchMenuId;
private int mInfoMenuId;
/**
* Constructs a new DownloadManagerUi.
* @param activity The {@link Activity} associated with the download manager.
......@@ -247,16 +253,33 @@ public class DownloadManagerUi
mFilterAdapter.initialize(this);
addObserver(mFilterAdapter);
boolean isLocationEnabled =
ChromeFeatureList.isEnabled(ChromeFeatureList.DOWNLOADS_LOCATION_CHANGE);
int normalGroupId =
isLocationEnabled ? R.id.with_settings_normal_menu_group : R.id.normal_menu_group;
mSearchMenuId = isLocationEnabled ? R.id.with_settings_search_menu_id : R.id.search_menu_id;
mInfoMenuId = isLocationEnabled ? R.id.with_settings_info_menu_id : R.id.info_menu_id;
mToolbar = (DownloadManagerToolbar) mSelectableListLayout.initializeToolbar(
R.layout.download_manager_toolbar, mBackendProvider.getSelectionDelegate(), 0, null,
R.id.normal_menu_group, R.id.selection_mode_menu_group,
R.color.modern_primary_color, this, true);
normalGroupId, R.id.selection_mode_menu_group, R.color.modern_primary_color, this,
true);
mToolbar.getMenu().setGroupVisible(normalGroupId, true);
mToolbar.setManager(this);
mToolbar.initializeFilterSpinner(mFilterAdapter);
mToolbar.initializeSearchView(this, R.string.download_manager_search, R.id.search_menu_id);
mToolbar.setInfoMenuItem(R.id.info_menu_id);
mToolbar.initializeSearchView(this, R.string.download_manager_search, mSearchMenuId);
mToolbar.setInfoMenuItem(mInfoMenuId);
addObserver(mToolbar);
if (isLocationEnabled) {
mToolbar.setExtraMenuItem(R.id.extra_menu_id);
mToolbar.setInfoButtonText(R.string.download_manager_ui_show_storage,
R.string.download_manager_ui_hide_storage);
mToolbar.setShowInfoIcon(false);
}
mSelectableListLayout.configureWideDisplayStyle();
mHistoryAdapter.initialize(mBackendProvider, mSelectableListLayout.getUiConfig());
addObserver(mHistoryAdapter);
......@@ -342,7 +365,9 @@ public class DownloadManagerUi
@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.close_menu_id && mIsSeparateActivity) {
if ((item.getItemId() == R.id.close_menu_id
|| item.getItemId() == R.id.with_settings_close_menu_id)
&& mIsSeparateActivity) {
recordMenuActionHistogram(MENU_ACTION_CLOSE);
mActivity.finish();
return true;
......@@ -371,12 +396,12 @@ public class DownloadManagerUi
shareItems(items);
return true;
} else if (item.getItemId() == R.id.info_menu_id) {
} else if (item.getItemId() == mInfoMenuId) {
boolean showInfo = !mHistoryAdapter.shouldShowStorageInfoHeader();
recordMenuActionHistogram(showInfo ? MENU_ACTION_SHOW_INFO : MENU_ACTION_HIDE_INFO);
enableStorageInfoHeader(showInfo);
return true;
} else if (item.getItemId() == R.id.search_menu_id) {
} else if (item.getItemId() == mSearchMenuId) {
recordMenuActionHistogram(MENU_ACTION_SEARCH);
// The header should be removed as soon as a search is started. It will be added back in
// DownloadHistoryAdatper#filter() when the search is ended.
......@@ -385,6 +410,12 @@ public class DownloadManagerUi
mToolbar.showSearchView();
RecordUserAction.record("Android.DownloadManager.Search");
return true;
} else if (item.getItemId() == R.id.settings_menu_id) {
Intent intent = PreferencesLauncher.createIntentForSettingsPage(
mActivity, DownloadPreferences.class.getName());
mActivity.startActivity(intent);
RecordUserAction.record("Android.DownloadManager.Settings");
return true;
}
return false;
}
......
......@@ -125,6 +125,11 @@ public class SelectableListToolbar<E>
private boolean mShowInfoItem;
private boolean mInfoShowing;
private boolean mShowInfoIcon;
private int mShowInfoStringId;
private int mHideInfoStringId;
private int mExtraMenuItemId;
/**
* Constructor for inflating from XML.
*/
......@@ -205,6 +210,19 @@ public class SelectableListToolbar<E>
VrShellDelegate.registerVrModeObserver(this);
if (VrShellDelegate.isInVr()) onEnterVr();
mShowInfoIcon = true;
mShowInfoStringId = R.string.show_info;
mHideInfoStringId = R.string.hide_info;
// Used only for the case of DownloadManagerToolbar.
// Will not be needed after a tint is applied to all toolbar buttons.
MenuItem extraMenuItem = getMenu().findItem(mExtraMenuItemId);
if (extraMenuItem != null) {
Drawable iconDrawable = TintedDrawable.constructTintedDrawable(
getResources(), R.drawable.ic_more_vert_black_24dp, R.color.light_normal_color);
extraMenuItem.setIcon(iconDrawable);
}
}
@Override
......@@ -635,21 +653,61 @@ public class SelectableListToolbar<E>
mInfoMenuItemId = infoMenuItemId;
}
/**
* Set ID of menu item that is displayed to hold any extra actions.
* Needs to be called before {@link #initialize}.
*
* @param extraMenuItemId The menu item.
*/
public void setExtraMenuItem(int extraMenuItemId) {
mExtraMenuItemId = extraMenuItemId;
}
/**
* Sets the parameter that determines whether to show the info icon.
* This is useful when the info menu option is being shown in a sub-menu, where only the text is
* necessary, versus being shown as an icon in the toolbar.
* Needs to be called before {@link #initialize}.
*
* @param shouldShow Whether to show the icon for the info menu item. Defaults to true.
*/
public void setShowInfoIcon(boolean shouldShow) {
mShowInfoIcon = shouldShow;
}
/**
* Set the IDs of the string resources to be shown for the info button text if different from
* the default "Show info"/"Hide info" text.
* Needs to be called before {@link #initialize}.
*
* @param showInfoStringId Resource ID of string for the info button text that, when clicked,
* will show info.
* @param hideInfoStringId Resource ID of the string that will hide the info.
*/
public void setInfoButtonText(int showInfoStringId, int hideInfoStringId) {
mShowInfoStringId = showInfoStringId;
mHideInfoStringId = hideInfoStringId;
}
/**
* Update icon, title, and visibility of info menu item.
* @param showItem Whether or not info menu item should show.
* @param infoShowing Whether or not info header is currently showing.
* @param showItem Whether or not info menu item should show.
* @param infoShowing Whether or not info header is currently showing.
*/
public void updateInfoMenuItem(boolean showItem, boolean infoShowing) {
mShowInfoItem = showItem;
mInfoShowing = infoShowing;
MenuItem infoMenuItem = getMenu().findItem(mInfoMenuItemId);
if (infoMenuItem != null) {
Drawable iconDrawable =
TintedDrawable.constructTintedDrawable(getResources(), R.drawable.btn_info,
infoShowing ? R.color.light_active_color : R.color.light_normal_color);
if (mShowInfoIcon) {
Drawable iconDrawable = TintedDrawable.constructTintedDrawable(getResources(),
R.drawable.btn_info,
infoShowing ? R.color.light_active_color : R.color.light_normal_color);
infoMenuItem.setIcon(iconDrawable);
}
infoMenuItem.setIcon(iconDrawable);
if (VrShellDelegate.isInVr()) {
// There seems to be a bug with the support library, only on Android N, where the
// toast showing the title shows up every time the info menu item is clicked or
......@@ -658,7 +716,7 @@ public class SelectableListToolbar<E>
// disable it.
infoMenuItem.setTitle("");
} else {
infoMenuItem.setTitle(infoShowing ? R.string.hide_info : R.string.show_info);
infoMenuItem.setTitle(infoShowing ? mHideInfoStringId : mShowInfoStringId);
}
infoMenuItem.setVisible(showItem);
}
......
......@@ -2225,6 +2225,12 @@ To obtain new licenses, connect to the internet and play your downloaded content
<message name="IDS_DOWNLOAD_MANAGER_LIST_ITEM_DESCRIPTION" desc="Text containing the download list item description.">
<ph name="FILE_SIZE">%1$s<ex>1.56 MB</ex></ph> - <ph name="DESCRIPTION">%2$s<ex>www.example.com</ex></ph>
</message>
<message name="IDS_DOWNLOAD_MANAGER_UI_SHOW_STORAGE" desc="Text that tells the user to show the storage information in downloads home.">
Show storage
</message>
<message name="IDS_DOWNLOAD_MANAGER_UI_HIDE_STORAGE" desc="Text that tells the user to hide the storage information in downloads home.">
Hide storage
</message>
<!-- Browsing History UI -->
<message name="IDS_HISTORY_MANAGER_EMPTY" desc="Indicates that there are no browsing history items.">
......
86199850f71f7549080fbac10d865d243bfdc950
\ No newline at end of file
68c8dff06fca220ad3e2000d6849a8f443368a25
\ No newline at end of file
......@@ -1555,6 +1555,15 @@ should be able to be added at any place in this file.
</description>
</action>
<action name="Android.DownloadManager.Settings">
<owner>jming@chromium.org</owner>
<owner>twellington@chromium.org</owner>
<description>
User selected the settings option in the download manager to open up the
settings page to download preferences.
</description>
</action>
<action name="Android.DownloadManager.UndoDelete">
<owner>dfalcantara@chromium.org</owner>
<owner>twellington@chromium.org</owner>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment