Commit d749ac4f authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Added toolbar and tab text for offline home

This CL sets offline home title and tab texts.

Bug: 1012619
Change-Id: Ic105869e5d26467ae552982cb84691beed0fdf52
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1849451
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705764}
parent b9683d17
......@@ -58,10 +58,12 @@ public class DownloadActivity extends SnackbarActivity implements ModalDialogMan
getIntent(), IntentHandler.EXTRA_PARENT_COMPONENT);
mPermissionDelegate =
new ActivityAndroidPermissionDelegate(new WeakReference<Activity>(this));
DownloadManagerUiConfig config = new DownloadManagerUiConfig.Builder()
.setIsOffTheRecord(isOffTheRecord)
.setIsSeparateActivity(true)
.build();
DownloadManagerUiConfig config =
new DownloadManagerUiConfig.Builder()
.setIsOffTheRecord(isOffTheRecord)
.setIsSeparateActivity(true)
.setShowOfflineHome(DownloadUtils.shouldShowOfflineHome())
.build();
mModalDialogManager = new ModalDialogManager(
new AppModalPresenter(this), ModalDialogManager.ModalDialogType.APP);
......
......@@ -42,10 +42,12 @@ public class DownloadPage extends BasicNativePage implements DownloadManagerCoor
protected void initialize(ChromeActivity activity, final NativePageHost host) {
ThreadUtils.assertOnUiThread();
DownloadManagerUiConfig config = new DownloadManagerUiConfig.Builder()
.setIsOffTheRecord(host.isIncognito())
.setIsSeparateActivity(false)
.build();
DownloadManagerUiConfig config =
new DownloadManagerUiConfig.Builder()
.setIsOffTheRecord(host.isIncognito())
.setIsSeparateActivity(false)
.setShowOfflineHome(DownloadUtils.shouldShowOfflineHome())
.build();
mDownloadCoordinator = DownloadManagerCoordinatorFactory.create(activity, config,
((SnackbarManageable) activity).getSnackbarManager(), activity.getComponentName(),
activity.getModalDialogManager());
......
......@@ -64,7 +64,7 @@ class DownloadManagerCoordinatorImpl
mSelectionDelegate, this::notifyFilterChanged, createDateOrderedListObserver(),
modalDialogManager);
mToolbarCoordinator = new ToolbarCoordinator(mActivity, this, mListCoordinator,
mSelectionDelegate, config.isSeparateActivity, profile);
mSelectionDelegate, config.showOfflineHome, config.isSeparateActivity, profile);
initializeView();
RecordUserAction.record("Android.DownloadManager.Open");
......
......@@ -19,6 +19,9 @@ public class DownloadManagerUiConfig {
/** Whether or not the UI should be shown as part of a separate activity. */
public final boolean isSeparateActivity;
/** Whether or not to show the Offline Home UI. */
public final boolean showOfflineHome;
/** Whether generic view types should be used wherever possible. Used for low end devices. */
public final boolean useGenericViewTypes;
......@@ -58,6 +61,7 @@ public class DownloadManagerUiConfig {
private DownloadManagerUiConfig(Builder builder) {
isOffTheRecord = builder.mIsOffTheRecord;
isSeparateActivity = builder.mIsSeparateActivity;
showOfflineHome = builder.mShowOfflineHome;
useGenericViewTypes = builder.mUseGenericViewTypes;
supportFullWidthImages = builder.mSupportFullWidthImages;
useNewDownloadPath = builder.mUseNewDownloadPath;
......@@ -77,6 +81,7 @@ public class DownloadManagerUiConfig {
private boolean mIsOffTheRecord;
private boolean mIsSeparateActivity;
private boolean mShowOfflineHome;
private boolean mUseGenericViewTypes;
private boolean mSupportFullWidthImages;
private boolean mUseNewDownloadPath;
......@@ -105,6 +110,11 @@ public class DownloadManagerUiConfig {
return this;
}
public Builder setShowOfflineHome(boolean showOfflineHome) {
mShowOfflineHome = showOfflineHome;
return this;
}
public Builder setUseGenericViewTypes(boolean useGenericViewTypes) {
mUseGenericViewTypes = useGenericViewTypes;
return this;
......
......@@ -10,11 +10,13 @@ import android.view.View;
import androidx.annotation.IntDef;
import org.chromium.base.ObserverList;
import org.chromium.chrome.browser.download.home.DownloadManagerUiConfig;
import org.chromium.chrome.browser.download.home.filter.Filters.FilterType;
import org.chromium.chrome.browser.download.home.filter.chips.ChipsCoordinator;
import org.chromium.chrome.browser.offlinepages.prefetch.PrefetchConfiguration;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefChangeRegistrar;
import org.chromium.chrome.download.R;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
......@@ -51,7 +53,8 @@ public class FilterCoordinator {
* Builds a new FilterCoordinator.
* @param context The context to build the views and pull parameters from.
*/
public FilterCoordinator(Context context, OfflineItemFilterSource chipFilterSource) {
public FilterCoordinator(Context context, OfflineItemFilterSource chipFilterSource,
DownloadManagerUiConfig config) {
mChipsProvider =
new FilterChipsProvider(context, type -> handleChipSelected(), chipFilterSource);
mChipsCoordinator = new ChipsCoordinator(context, mChipsProvider);
......@@ -63,6 +66,7 @@ public class FilterCoordinator {
selectTab(TabType.FILES);
mModel.set(FilterProperties.SHOW_TABS, isPrefetchTabEnabled());
setTabTitles(context, config.showOfflineHome);
addPrefetchUserSettingsObserver();
}
......@@ -125,6 +129,17 @@ public class FilterCoordinator {
handleTabSelected(tabSelected);
}
/** Sets the tab titles. */
private void setTabTitles(Context context, boolean showOfflineHomeTabs) {
mModel.set(FilterProperties.FILES_TAB_TITLE,
context.getString(showOfflineHomeTabs ? R.string.menu_downloads
: R.string.download_manager_files_tab));
mModel.set(FilterProperties.PREFETCH_TAB_TITLE,
context.getString(showOfflineHomeTabs
? R.string.download_manager_explore_offline
: R.string.ntp_article_suggestions_section_header));
}
private void selectTab(@TabType int selectedTab) {
mModel.set(FilterProperties.SELECTED_TAB, selectedTab);
......
......@@ -15,19 +15,24 @@ import org.chromium.ui.modelutil.PropertyModel.WritableObjectPropertyKey;
/** The properties needed to render the download home filter view. */
public interface FilterProperties {
/** The {@link View} to show in the content area. */
public static final WritableObjectPropertyKey<View> CONTENT_VIEW =
new WritableObjectPropertyKey<>();
WritableObjectPropertyKey<View> CONTENT_VIEW = new WritableObjectPropertyKey<>();
/** Which {@code TabType} should be selected. */
public static final WritableIntPropertyKey SELECTED_TAB = new WritableIntPropertyKey();
WritableIntPropertyKey SELECTED_TAB = new WritableIntPropertyKey();
/** The callback listener for {@code TabType} selection changes. */
public static final WritableObjectPropertyKey<Callback</* @TabType */ Integer>>
CHANGE_LISTENER = new WritableObjectPropertyKey<>();
WritableObjectPropertyKey<Callback</* @TabType */ Integer>> CHANGE_LISTENER =
new WritableObjectPropertyKey<>();
/** Whether or not to show the tabs or just show the content. */
public static final WritableBooleanPropertyKey SHOW_TABS = new WritableBooleanPropertyKey();
WritableBooleanPropertyKey SHOW_TABS = new WritableBooleanPropertyKey();
/** The title for the files tab. */
WritableObjectPropertyKey<String> FILES_TAB_TITLE = new WritableObjectPropertyKey<>();
/** The title for the prefetch tab. */
WritableObjectPropertyKey<String> PREFETCH_TAB_TITLE = new WritableObjectPropertyKey<>();
public static final PropertyKey[] ALL_KEYS =
new PropertyKey[] {CONTENT_VIEW, SELECTED_TAB, CHANGE_LISTENER, SHOW_TABS};
}
\ No newline at end of file
PropertyKey[] ALL_KEYS = new PropertyKey[] {CONTENT_VIEW, SELECTED_TAB, CHANGE_LISTENER,
SHOW_TABS, FILES_TAB_TITLE, PREFETCH_TAB_TITLE};
}
......@@ -84,4 +84,14 @@ class FilterView {
public void setShowTabs(boolean show) {
mTabsView.setVisibility(show ? View.VISIBLE : View.GONE);
}
/** Sets the title for the files tab. */
public void setFilesTabTitle(String title) {
mTabsView.getTabAt(0).setText(title);
}
/** Sets the title for the prefetch tab. */
public void setPrefetchTabTitle(String title) {
mTabsView.getTabAt(1).setText(title);
}
}
\ No newline at end of file
......@@ -23,6 +23,10 @@ class FilterViewBinder implements ViewBinder<PropertyModel, FilterView, Property
view.setTabSelectedCallback(model.get(FilterProperties.CHANGE_LISTENER));
} else if (propertyKey == FilterProperties.SHOW_TABS) {
view.setShowTabs(model.get(FilterProperties.SHOW_TABS));
} else if (propertyKey == FilterProperties.FILES_TAB_TITLE) {
view.setFilesTabTitle(model.get(FilterProperties.FILES_TAB_TITLE));
} else if (propertyKey == FilterProperties.PREFETCH_TAB_TITLE) {
view.setPrefetchTabTitle(model.get(FilterProperties.PREFETCH_TAB_TITLE));
}
}
}
\ No newline at end of file
......@@ -118,7 +118,7 @@ public class DateOrderedListCoordinator implements ToolbarCoordinator.ToolbarLis
mStorageCoordinator = new StorageCoordinator(context, mMediator.getFilterSource());
mFilterCoordinator = new FilterCoordinator(context, mMediator.getFilterSource());
mFilterCoordinator = new FilterCoordinator(context, mMediator.getFilterSource(), config);
mFilterCoordinator.addObserver(mMediator::onFilterTypeSelected);
mFilterCoordinator.addObserver(filterObserver);
mFilterCoordinator.addObserver(mEmptyCoordinator);
......
......@@ -91,8 +91,8 @@ public class ToolbarCoordinator implements SelectionObserver<ListItem> {
public ToolbarCoordinator(Context context, ToolbarActionDelegate delegate,
ToolbarListActionDelegate listActionDelegate,
SelectionDelegate<ListItem> selectionDelegate, boolean hasCloseButton,
Profile profile) {
SelectionDelegate<ListItem> selectionDelegate, boolean showOfflineHome,
boolean hasCloseButton, Profile profile) {
mDelegate = delegate;
mListActionDelegate = listActionDelegate;
......@@ -101,7 +101,9 @@ public class ToolbarCoordinator implements SelectionObserver<ListItem> {
mToolbar = mView.findViewById(R.id.download_toolbar);
mShadow = mView.findViewById(R.id.shadow);
mToolbar.initialize(selectionDelegate, R.string.menu_downloads, R.id.normal_menu_group,
int titleResId =
showOfflineHome ? R.string.download_manager_offline_home : R.string.menu_downloads;
mToolbar.initialize(selectionDelegate, titleResId, R.id.normal_menu_group,
R.id.selection_mode_menu_group, hasCloseButton);
mToolbar.setOnMenuItemClickListener(this ::onMenuItemClick);
......
......@@ -2540,6 +2540,12 @@ To change this setting, <ph name="BEGIN_LINK">&lt;resetlink&gt;</ph>reset sync<p
<message name="IDS_DOWNLOAD_MANAGER_JUST_NOW" desc="Text on a label describing that the associated download event happened just now.">
Just Now
</message>
<message name="IDS_DOWNLOAD_MANAGER_OFFLINE_HOME" desc="The title text on download home indicating that we are in offline mode.">
Offline Home
</message>
<message name="IDS_DOWNLOAD_MANAGER_EXPLORE_OFFLINE" desc="Tab text for the offline content in download home which contains recommended offline content for the user.">
Explore Offline
</message>
<!-- Browsing History UI -->
<message name="IDS_HISTORY_MANAGER_EMPTY" desc="Indicates that there are no browsing history items.">
......
c226c7bcd98ef3e02ea0b93d83c2448f0fffc2eb
\ No newline at end of file
c226c7bcd98ef3e02ea0b93d83c2448f0fffc2eb
\ No newline at end of file
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