Commit 66058fec authored by Shakti Sahu's avatar Shakti Sahu Committed by Commit Bot

Update Download Home FilterCoordinator.

- Move FilterModel to FilterProperties.
- Incorporate showing/hiding the tabs as a new property on the model.

Change-Id: I0711ab244aada2ee27d8693408551261911df41e
Reviewed-on: https://chromium-review.googlesource.com/1149268
Commit-Queue: Shakti Sahu <shaktisahu@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579386}
parent 0914b598
......@@ -11,6 +11,8 @@ import android.view.View;
import org.chromium.base.ObserverList;
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.modelutil.PropertyKey;
import org.chromium.chrome.browser.modelutil.PropertyModel;
import org.chromium.chrome.browser.modelutil.PropertyModelChangeProcessor;
import java.lang.annotation.Retention;
......@@ -32,15 +34,12 @@ public class FilterCoordinator {
}
private final ObserverList<Observer> mObserverList = new ObserverList<>();
private FilterModel mModel;
private FilterViewBinder mViewBinder;
private FilterView mView;
private final PropertyModel mModel;
private final FilterViewBinder mViewBinder;
private final FilterView mView;
private ChipsCoordinator mChipsCoordinator;
private FilterChipsProvider mChipsProvider;
/** No-args constructor to be used by subclasses. */
protected FilterCoordinator() {}
private final ChipsCoordinator mChipsCoordinator;
private final FilterChipsProvider mChipsProvider;
/**
* Builds a new FilterCoordinator.
......@@ -50,13 +49,18 @@ public class FilterCoordinator {
mChipsProvider = new FilterChipsProvider(type -> handleChipSelected(), chipFilterSource);
mChipsCoordinator = new ChipsCoordinator(context, mChipsProvider);
mModel = new FilterModel();
mModel = new PropertyModel(FilterProperties.ALL_KEYS);
mViewBinder = new FilterViewBinder();
mView = new FilterView(context);
mModel.addObserver(new PropertyModelChangeProcessor<>(mModel, mView, mViewBinder));
mModel.addObserver(new PropertyModelChangeProcessor<PropertyModel, FilterView, PropertyKey>(
mModel, mView, mViewBinder));
mModel.setChangeListener(selectedTab -> handleTabSelected(selectedTab));
mModel.setValue(
FilterProperties.CHANGE_LISTENER, selectedTab -> handleTabSelected(selectedTab));
selectTab(TabType.FILES);
// TODO(shaktisahu): Check if prefetch UI is enabled.
mModel.setValue(FilterProperties.SHOW_TABS, true);
}
/** @return The {@link View} representing this widget. */
......@@ -88,12 +92,12 @@ public class FilterCoordinator {
}
private void selectTab(@TabType int selectedTab) {
mModel.setSelectedTab(selectedTab);
mModel.setValue(FilterProperties.SELECTED_TAB, selectedTab);
if (selectedTab == TabType.FILES) {
mModel.setContentView(mChipsCoordinator.getView());
mModel.setValue(FilterProperties.CONTENT_VIEW, mChipsCoordinator.getView());
} else if (selectedTab == TabType.PREFETCH) {
mModel.setContentView(null);
mModel.setValue(FilterProperties.CONTENT_VIEW, null);
}
}
......@@ -111,11 +115,11 @@ public class FilterCoordinator {
notifyFilterChanged(filterType);
}
protected void notifyFilterChanged(@FilterType int filter) {
private void notifyFilterChanged(@FilterType int filter) {
for (Observer observer : mObserverList) observer.onFilterChanged(filter);
}
private void handleChipSelected() {
handleTabSelected(mModel.getSelectedTab());
handleTabSelected(mModel.getValue(FilterProperties.SELECTED_TAB));
}
}
\ No newline at end of file
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.download.home.filter;
import android.content.Context;
import android.view.View;
import org.chromium.chrome.browser.download.home.filter.chips.ChipsCoordinator;
/**
* An empty version of {@code FilterCoordinator} that doesn't contain any tabs.
*/
public class FilterCoordinatorWithNoTabs extends FilterCoordinator {
private final ChipsCoordinator mChipsCoordinator;
private final FilterChipsProvider mChipsProvider;
public FilterCoordinatorWithNoTabs(Context context, OfflineItemFilterSource chipFilterSource) {
mChipsProvider = new FilterChipsProvider(type -> handleChipSelected(), chipFilterSource);
mChipsCoordinator = new ChipsCoordinator(context, mChipsProvider);
}
@Override
public View getView() {
return mChipsCoordinator.getView();
}
@Override
public void setSelectedFilter(int filter) {
mChipsProvider.setFilterSelected(filter);
}
private void handleChipSelected() {
notifyFilterChanged(mChipsProvider.getSelectedFilter());
}
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.download.home.filter;
import android.view.View;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.download.home.filter.FilterCoordinator.TabType;
import org.chromium.chrome.browser.modelutil.PropertyObservable;
/**
* The model responsible for maintaining the visual state of the tab content filter widget. It also
* holds callbacks meant to be notified when the tab selection changes.
*/
class FilterModel extends PropertyObservable<FilterModel.PropertyKey> {
static class PropertyKey {
static final PropertyKey CONTENT_VIEW = new PropertyKey();
static final PropertyKey SELECTED_TAB = new PropertyKey();
static final PropertyKey CHANGE_LISTENER = new PropertyKey();
private PropertyKey() {}
}
private View mContentView;
private @TabType int mSelectedTab;
private Callback</* @TabType */ Integer> mChangeListener;
/** Sets {@code contentView} as the {@link View} to be shown in the content area. */
public void setContentView(View contentView) {
if (mContentView == contentView) return;
mContentView = contentView;
notifyPropertyChanged(PropertyKey.CONTENT_VIEW);
}
/** Sets which tab should be selected. */
public void setSelectedTab(@TabType int selectedTab) {
// Note: This does not early-out if selectedTab is the same as mSelectedTab. This is
// because default values might prevent us from pushing valid state and causing the UI to
// refresh.
mSelectedTab = selectedTab;
notifyPropertyChanged(PropertyKey.SELECTED_TAB);
}
/** Sets the {@link Callback} to call when a tab is selected. */
public void setChangeListener(Callback</* @TabType */ Integer> changeListener) {
if (mChangeListener == changeListener) return;
mChangeListener = changeListener;
notifyPropertyChanged(PropertyKey.CHANGE_LISTENER);
}
/** @return The {@link View} to use in the content area of the tab selection. */
public View getContentView() {
return mContentView;
}
/** @return The selected tab type. */
public @TabType int getSelectedTab() {
return mSelectedTab;
}
/** @return The {@link Callback} to call when a tab is selected. */
public Callback</* @TabType */ Integer> getChangeListener() {
return mChangeListener;
}
}
\ No newline at end of file
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.download.home.filter;
import android.view.View;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.modelutil.PropertyKey;
import org.chromium.chrome.browser.modelutil.PropertyModel.BooleanPropertyKey;
import org.chromium.chrome.browser.modelutil.PropertyModel.IntPropertyKey;
import org.chromium.chrome.browser.modelutil.PropertyModel.ObjectPropertyKey;
/** 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 ObjectPropertyKey<View> CONTENT_VIEW = new ObjectPropertyKey<>();
/** Which {@code TabType} should be selected. */
public static final IntPropertyKey SELECTED_TAB = new IntPropertyKey();
/** The callback listener for {@code TabType} selection changes. */
public static final ObjectPropertyKey<Callback</* @TabType */ Integer>> CHANGE_LISTENER =
new ObjectPropertyKey<>();
/** Whether or not to show the tabs or just show the content. */
public static final BooleanPropertyKey SHOW_TABS = new BooleanPropertyKey();
public static final PropertyKey[] ALL_KEYS =
new PropertyKey[] {CONTENT_VIEW, SELECTED_TAB, CHANGE_LISTENER, SHOW_TABS};
}
\ No newline at end of file
......@@ -79,4 +79,9 @@ class FilterView {
public void setTabSelectedCallback(Callback</* @TabType */ Integer> callback) {
mTabSelectedCallback = callback;
}
/** Sets whether or not we show the tabs. */
public void setShowTabs(boolean show) {
mTabsView.setVisibility(show ? View.VISIBLE : View.GONE);
}
}
\ No newline at end of file
......@@ -4,22 +4,25 @@
package org.chromium.chrome.browser.download.home.filter;
import org.chromium.chrome.browser.download.home.filter.FilterModel.PropertyKey;
import org.chromium.chrome.browser.modelutil.PropertyKey;
import org.chromium.chrome.browser.modelutil.PropertyModel;
import org.chromium.chrome.browser.modelutil.PropertyModelChangeProcessor.ViewBinder;
/**
* A helper {@link ViewBinder} responsible for gluing {@link FilterModel} to
* A helper {@link ViewBinder} responsible for gluing {@link FilterProperties} to
* {@link FilterView}.
*/
class FilterViewBinder implements ViewBinder<FilterModel, FilterView, FilterModel.PropertyKey> {
class FilterViewBinder implements ViewBinder<PropertyModel, FilterView, PropertyKey> {
@Override
public void bind(FilterModel model, FilterView view, PropertyKey propertyKey) {
if (propertyKey == FilterModel.PropertyKey.CONTENT_VIEW) {
view.setContentView(model.getContentView());
} else if (propertyKey == FilterModel.PropertyKey.SELECTED_TAB) {
view.setTabSelected(model.getSelectedTab());
} else if (propertyKey == FilterModel.PropertyKey.CHANGE_LISTENER) {
view.setTabSelectedCallback(model.getChangeListener());
public void bind(PropertyModel model, FilterView view, PropertyKey propertyKey) {
if (propertyKey == FilterProperties.CONTENT_VIEW) {
view.setContentView(model.getValue(FilterProperties.CONTENT_VIEW));
} else if (propertyKey == FilterProperties.SELECTED_TAB) {
view.setTabSelected(model.getValue(FilterProperties.SELECTED_TAB));
} else if (propertyKey == FilterProperties.CHANGE_LISTENER) {
view.setTabSelectedCallback(model.getValue(FilterProperties.CHANGE_LISTENER));
} else if (propertyKey == FilterProperties.SHOW_TABS) {
view.setShowTabs(model.getValue(FilterProperties.SHOW_TABS));
}
}
}
\ No newline at end of file
......@@ -9,7 +9,6 @@ import android.view.View;
import org.chromium.base.Callback;
import org.chromium.chrome.browser.download.home.filter.FilterCoordinator;
import org.chromium.chrome.browser.download.home.filter.FilterCoordinatorWithNoTabs;
import org.chromium.chrome.browser.download.home.filter.Filters.FilterType;
import org.chromium.chrome.browser.download.home.list.ListItem.ViewListItem;
import org.chromium.chrome.browser.widget.selection.SelectionDelegate;
......@@ -69,9 +68,7 @@ public class DateOrderedListCoordinator {
offTheRecord, provider, deleteController, selectionDelegate, model);
// Hook up the FilterCoordinator with our mediator.
mFilterCoordinator = shouldShowPrefetchTab()
? new FilterCoordinator(context, mMediator.getFilterSource())
: new FilterCoordinatorWithNoTabs(context, mMediator.getFilterSource());
mFilterCoordinator = new FilterCoordinator(context, mMediator.getFilterSource());
mFilterCoordinator.addObserver(mMediator::onFilterTypeSelected);
mFilterCoordinator.addObserver(filterObserver);
......@@ -105,9 +102,4 @@ public class DateOrderedListCoordinator {
public void onDeletionRequested(List<ListItem> items) {
mMediator.onDeletionRequested(items);
}
private boolean shouldShowPrefetchTab() {
// TODO(shaktisahu): Check if prefetch UI is enabled.
return true;
}
}
......@@ -448,8 +448,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/download/home/filter/Filters.java",
"java/src/org/chromium/chrome/browser/download/home/filter/FilterChipsProvider.java",
"java/src/org/chromium/chrome/browser/download/home/filter/FilterCoordinator.java",
"java/src/org/chromium/chrome/browser/download/home/filter/FilterCoordinatorWithNoTabs.java",
"java/src/org/chromium/chrome/browser/download/home/filter/FilterModel.java",
"java/src/org/chromium/chrome/browser/download/home/filter/FilterProperties.java",
"java/src/org/chromium/chrome/browser/download/home/filter/FilterView.java",
"java/src/org/chromium/chrome/browser/download/home/filter/FilterViewBinder.java",
"java/src/org/chromium/chrome/browser/download/home/filter/OfflineItemFilter.java",
......
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