Commit aa5e19bb authored by Bernhard Bauer's avatar Bernhard Bauer Committed by Commit Bot

Rename PropertyModel.getValue() and setValue() to get() / set()

Change-Id: Icc55ebab929b8a0b7f9119b9ff2ecf23a5554260
Reviewed-on: https://chromium-review.googlesource.com/1199588
Commit-Queue: Bernhard Bauer <bauerb@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarFriedrich Horschig [CEST] <fhorschig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589114}
parent bed6b883
...@@ -102,12 +102,12 @@ public class EmptyCoordinator implements OfflineItemFilterObserver, FilterCoordi ...@@ -102,12 +102,12 @@ public class EmptyCoordinator implements OfflineItemFilterObserver, FilterCoordi
textId = R.string.download_manager_ui_empty; textId = R.string.download_manager_ui_empty;
} }
mModel.setValue(EmptyProperties.EMPTY_TEXT_RES_ID, textId); mModel.set(EmptyProperties.EMPTY_TEXT_RES_ID, textId);
mModel.setValue(EmptyProperties.EMPTY_ICON_RES_ID, iconId); mModel.set(EmptyProperties.EMPTY_ICON_RES_ID, iconId);
} else { } else {
state = State.GONE; state = State.GONE;
} }
mModel.setValue(EmptyProperties.STATE, state); mModel.set(EmptyProperties.STATE, state);
} }
} }
...@@ -16,11 +16,11 @@ class EmptyViewBinder implements ViewBinder<PropertyModel, EmptyView, PropertyKe ...@@ -16,11 +16,11 @@ class EmptyViewBinder implements ViewBinder<PropertyModel, EmptyView, PropertyKe
@Override @Override
public void bind(PropertyModel model, EmptyView view, PropertyKey propertyKey) { public void bind(PropertyModel model, EmptyView view, PropertyKey propertyKey) {
if (propertyKey == EmptyProperties.STATE) { if (propertyKey == EmptyProperties.STATE) {
view.setState(model.getValue(EmptyProperties.STATE)); view.setState(model.get(EmptyProperties.STATE));
} else if (propertyKey == EmptyProperties.EMPTY_TEXT_RES_ID) { } else if (propertyKey == EmptyProperties.EMPTY_TEXT_RES_ID) {
view.setEmptyText(model.getValue(EmptyProperties.EMPTY_TEXT_RES_ID)); view.setEmptyText(model.get(EmptyProperties.EMPTY_TEXT_RES_ID));
} else if (propertyKey == EmptyProperties.EMPTY_ICON_RES_ID) { } else if (propertyKey == EmptyProperties.EMPTY_ICON_RES_ID) {
view.setEmptyIcon(model.getValue(EmptyProperties.EMPTY_ICON_RES_ID)); view.setEmptyIcon(model.get(EmptyProperties.EMPTY_ICON_RES_ID));
} }
} }
} }
\ No newline at end of file
...@@ -52,10 +52,10 @@ public class FilterCoordinator { ...@@ -52,10 +52,10 @@ public class FilterCoordinator {
mView = new FilterView(context); mView = new FilterView(context);
PropertyModelChangeProcessor.create(mModel, mView, new FilterViewBinder()); PropertyModelChangeProcessor.create(mModel, mView, new FilterViewBinder());
mModel.setValue(FilterProperties.CHANGE_LISTENER, this::handleTabSelected); mModel.set(FilterProperties.CHANGE_LISTENER, this::handleTabSelected);
selectTab(TabType.FILES); selectTab(TabType.FILES);
mModel.setValue(FilterProperties.SHOW_TABS, prefetchStatusProvider.enabled()); mModel.set(FilterProperties.SHOW_TABS, prefetchStatusProvider.enabled());
} }
/** @return The {@link View} representing this widget. */ /** @return The {@link View} representing this widget. */
...@@ -87,12 +87,12 @@ public class FilterCoordinator { ...@@ -87,12 +87,12 @@ public class FilterCoordinator {
} }
private void selectTab(@TabType int selectedTab) { private void selectTab(@TabType int selectedTab) {
mModel.setValue(FilterProperties.SELECTED_TAB, selectedTab); mModel.set(FilterProperties.SELECTED_TAB, selectedTab);
if (selectedTab == TabType.FILES) { if (selectedTab == TabType.FILES) {
mModel.setValue(FilterProperties.CONTENT_VIEW, mChipsCoordinator.getView()); mModel.set(FilterProperties.CONTENT_VIEW, mChipsCoordinator.getView());
} else if (selectedTab == TabType.PREFETCH) { } else if (selectedTab == TabType.PREFETCH) {
mModel.setValue(FilterProperties.CONTENT_VIEW, null); mModel.set(FilterProperties.CONTENT_VIEW, null);
} }
} }
...@@ -115,6 +115,6 @@ public class FilterCoordinator { ...@@ -115,6 +115,6 @@ public class FilterCoordinator {
} }
private void handleChipSelected() { private void handleChipSelected() {
handleTabSelected(mModel.getValue(FilterProperties.SELECTED_TAB)); handleTabSelected(mModel.get(FilterProperties.SELECTED_TAB));
} }
} }
\ No newline at end of file
...@@ -16,13 +16,13 @@ class FilterViewBinder implements ViewBinder<PropertyModel, FilterView, Property ...@@ -16,13 +16,13 @@ class FilterViewBinder implements ViewBinder<PropertyModel, FilterView, Property
@Override @Override
public void bind(PropertyModel model, FilterView view, PropertyKey propertyKey) { public void bind(PropertyModel model, FilterView view, PropertyKey propertyKey) {
if (propertyKey == FilterProperties.CONTENT_VIEW) { if (propertyKey == FilterProperties.CONTENT_VIEW) {
view.setContentView(model.getValue(FilterProperties.CONTENT_VIEW)); view.setContentView(model.get(FilterProperties.CONTENT_VIEW));
} else if (propertyKey == FilterProperties.SELECTED_TAB) { } else if (propertyKey == FilterProperties.SELECTED_TAB) {
view.setTabSelected(model.getValue(FilterProperties.SELECTED_TAB)); view.setTabSelected(model.get(FilterProperties.SELECTED_TAB));
} else if (propertyKey == FilterProperties.CHANGE_LISTENER) { } else if (propertyKey == FilterProperties.CHANGE_LISTENER) {
view.setTabSelectedCallback(model.getValue(FilterProperties.CHANGE_LISTENER)); view.setTabSelectedCallback(model.get(FilterProperties.CHANGE_LISTENER));
} else if (propertyKey == FilterProperties.SHOW_TABS) { } else if (propertyKey == FilterProperties.SHOW_TABS) {
view.setShowTabs(model.getValue(FilterProperties.SHOW_TABS)); view.setShowTabs(model.get(FilterProperties.SHOW_TABS));
} }
} }
} }
\ No newline at end of file
...@@ -94,7 +94,7 @@ class DateOrderedListMediator { ...@@ -94,7 +94,7 @@ class DateOrderedListMediator {
mModel.update(i, item); mModel.update(i, item);
} }
mModel.dispatchLastEvent(); mModel.dispatchLastEvent();
mModel.getProperties().setValue( mModel.getProperties().set(
ListProperties.SELECTION_MODE_ACTIVE, mSelectionDelegate.isSelectionEnabled()); ListProperties.SELECTION_MODE_ACTIVE, mSelectionDelegate.isSelectionEnabled());
} }
} }
...@@ -143,16 +143,16 @@ class DateOrderedListMediator { ...@@ -143,16 +143,16 @@ class DateOrderedListMediator {
((ChromeApplication) ContextUtils.getApplicationContext()).getReferencePool()); ((ChromeApplication) ContextUtils.getApplicationContext()).getReferencePool());
mSelectionObserver = new MediatorSelectionObserver(selectionDelegate); mSelectionObserver = new MediatorSelectionObserver(selectionDelegate);
mModel.getProperties().setValue(ListProperties.ENABLE_ITEM_ANIMATIONS, true); mModel.getProperties().set(ListProperties.ENABLE_ITEM_ANIMATIONS, true);
mModel.getProperties().setValue(ListProperties.CALLBACK_OPEN, mProvider::openItem); mModel.getProperties().set(ListProperties.CALLBACK_OPEN, mProvider::openItem);
mModel.getProperties().setValue(ListProperties.CALLBACK_PAUSE, mProvider::pauseDownload); mModel.getProperties().set(ListProperties.CALLBACK_PAUSE, mProvider::pauseDownload);
mModel.getProperties().setValue( mModel.getProperties().set(
ListProperties.CALLBACK_RESUME, item -> mProvider.resumeDownload(item, true)); ListProperties.CALLBACK_RESUME, item -> mProvider.resumeDownload(item, true));
mModel.getProperties().setValue(ListProperties.CALLBACK_CANCEL, mProvider::cancelDownload); mModel.getProperties().set(ListProperties.CALLBACK_CANCEL, mProvider::cancelDownload);
mModel.getProperties().setValue(ListProperties.CALLBACK_SHARE, this ::onShareItem); mModel.getProperties().set(ListProperties.CALLBACK_SHARE, this ::onShareItem);
mModel.getProperties().setValue(ListProperties.CALLBACK_REMOVE, this ::onDeleteItem); mModel.getProperties().set(ListProperties.CALLBACK_REMOVE, this ::onDeleteItem);
mModel.getProperties().setValue(ListProperties.PROVIDER_VISUALS, this ::getVisuals); mModel.getProperties().set(ListProperties.PROVIDER_VISUALS, this ::getVisuals);
mModel.getProperties().setValue( mModel.getProperties().set(
ListProperties.CALLBACK_SELECTION, selectionDelegate::toggleSelectionForItem); ListProperties.CALLBACK_SELECTION, selectionDelegate::toggleSelectionForItem);
} }
...@@ -288,14 +288,14 @@ class DateOrderedListMediator { ...@@ -288,14 +288,14 @@ class DateOrderedListMediator {
/** Helper class to disable animations for certain list changes. */ /** Helper class to disable animations for certain list changes. */
private class AnimationDisableClosable implements Closeable { private class AnimationDisableClosable implements Closeable {
AnimationDisableClosable() { AnimationDisableClosable() {
mModel.getProperties().setValue(ListProperties.ENABLE_ITEM_ANIMATIONS, false); mModel.getProperties().set(ListProperties.ENABLE_ITEM_ANIMATIONS, false);
} }
// Closeable implementation. // Closeable implementation.
@Override @Override
public void close() { public void close() {
mHandler.post(() -> { mHandler.post(() -> {
mModel.getProperties().setValue(ListProperties.ENABLE_ITEM_ANIMATIONS, true); mModel.getProperties().set(ListProperties.ENABLE_ITEM_ANIMATIONS, true);
}); });
} }
} }
......
...@@ -16,7 +16,7 @@ class ListPropertyViewBinder implements ViewBinder<PropertyModel, RecyclerView, ...@@ -16,7 +16,7 @@ class ListPropertyViewBinder implements ViewBinder<PropertyModel, RecyclerView,
@Override @Override
public void bind(PropertyModel model, RecyclerView view, PropertyKey propertyKey) { public void bind(PropertyModel model, RecyclerView view, PropertyKey propertyKey) {
if (propertyKey == ListProperties.ENABLE_ITEM_ANIMATIONS) { if (propertyKey == ListProperties.ENABLE_ITEM_ANIMATIONS) {
if (model.getValue(ListProperties.ENABLE_ITEM_ANIMATIONS)) { if (model.get(ListProperties.ENABLE_ITEM_ANIMATIONS)) {
if (view.getItemAnimator() == null) { if (view.getItemAnimator() == null) {
view.setItemAnimator((ItemAnimator) view.getTag(R.id.item_animator)); view.setItemAnimator((ItemAnimator) view.getTag(R.id.item_animator));
view.setTag(R.id.item_animator, null); view.setTag(R.id.item_animator, null);
......
...@@ -53,8 +53,8 @@ public class InProgressViewHolder extends ListItemViewHolder { ...@@ -53,8 +53,8 @@ public class InProgressViewHolder extends ListItemViewHolder {
public void bind(PropertyModel properties, ListItem item) { public void bind(PropertyModel properties, ListItem item) {
ListItem.OfflineItemListItem offlineItem = (ListItem.OfflineItemListItem) item; ListItem.OfflineItemListItem offlineItem = (ListItem.OfflineItemListItem) item;
mTitle.setText(offlineItem.item.title); mTitle.setText(offlineItem.item.title);
mCancelButton.setOnClickListener(v mCancelButton.setOnClickListener(
-> properties.getValue(ListProperties.CALLBACK_CANCEL).onResult(offlineItem.item)); v -> properties.get(ListProperties.CALLBACK_CANCEL).onResult(offlineItem.item));
if (offlineItem.item.state == OfflineItemState.PAUSED) { if (offlineItem.item.state == OfflineItemState.PAUSED) {
mPauseResumeButton.setImageResource(R.drawable.ic_play_arrow_white_24dp); mPauseResumeButton.setImageResource(R.drawable.ic_play_arrow_white_24dp);
...@@ -70,9 +70,9 @@ public class InProgressViewHolder extends ListItemViewHolder { ...@@ -70,9 +70,9 @@ public class InProgressViewHolder extends ListItemViewHolder {
mCaption.setText(DownloadUtils.getProgressTextForNotification(offlineItem.item.progress)); mCaption.setText(DownloadUtils.getProgressTextForNotification(offlineItem.item.progress));
mPauseResumeButton.setOnClickListener(view -> { mPauseResumeButton.setOnClickListener(view -> {
if (offlineItem.item.state == OfflineItemState.PAUSED) { if (offlineItem.item.state == OfflineItemState.PAUSED) {
properties.getValue(ListProperties.CALLBACK_RESUME).onResult(offlineItem.item); properties.get(ListProperties.CALLBACK_RESUME).onResult(offlineItem.item);
} else { } else {
properties.getValue(ListProperties.CALLBACK_PAUSE).onResult(offlineItem.item); properties.get(ListProperties.CALLBACK_PAUSE).onResult(offlineItem.item);
} }
}); });
......
...@@ -37,11 +37,11 @@ class MoreButtonViewHolder extends ListItemViewHolder implements ListMenuButton. ...@@ -37,11 +37,11 @@ class MoreButtonViewHolder extends ListItemViewHolder implements ListMenuButton.
public void bind(PropertyModel properties, ListItem item) { public void bind(PropertyModel properties, ListItem item) {
ListItem.OfflineItemListItem offlineItem = (ListItem.OfflineItemListItem) item; ListItem.OfflineItemListItem offlineItem = (ListItem.OfflineItemListItem) item;
mShareCallback = mShareCallback =
() -> properties.getValue(ListProperties.CALLBACK_SHARE).onResult(offlineItem.item); () -> properties.get(ListProperties.CALLBACK_SHARE).onResult(offlineItem.item);
mDeleteCallback = () mDeleteCallback =
-> properties.getValue(ListProperties.CALLBACK_REMOVE).onResult(offlineItem.item); () -> properties.get(ListProperties.CALLBACK_REMOVE).onResult(offlineItem.item);
if (mMore != null) { if (mMore != null) {
mMore.setClickable(!properties.getValue(ListProperties.SELECTION_MODE_ACTIVE)); mMore.setClickable(!properties.get(ListProperties.SELECTION_MODE_ACTIVE));
} }
} }
......
...@@ -83,20 +83,20 @@ abstract class ThumbnailAwareViewHolder extends MoreButtonViewHolder implements ...@@ -83,20 +83,20 @@ abstract class ThumbnailAwareViewHolder extends MoreButtonViewHolder implements
if (mSelectionView != null) { if (mSelectionView != null) {
mSelectionView.setSelectionState(item.selected, mSelectionView.setSelectionState(item.selected,
properties.getValue(ListProperties.SELECTION_MODE_ACTIVE), properties.get(ListProperties.SELECTION_MODE_ACTIVE),
item.showSelectedAnimation); item.showSelectedAnimation);
} }
itemView.setOnLongClickListener(v -> { itemView.setOnLongClickListener(v -> {
properties.getValue(ListProperties.CALLBACK_SELECTION).onResult(item); properties.get(ListProperties.CALLBACK_SELECTION).onResult(item);
return true; return true;
}); });
itemView.setOnClickListener(v -> { itemView.setOnClickListener(v -> {
if (mSelectionView != null && mSelectionView.isInSelectionMode()) { if (mSelectionView != null && mSelectionView.isInSelectionMode()) {
properties.getValue(ListProperties.CALLBACK_SELECTION).onResult(item); properties.get(ListProperties.CALLBACK_SELECTION).onResult(item);
} else { } else {
properties.getValue(ListProperties.CALLBACK_OPEN).onResult(offlineItem); properties.get(ListProperties.CALLBACK_OPEN).onResult(offlineItem);
} }
}); });
...@@ -111,7 +111,7 @@ abstract class ThumbnailAwareViewHolder extends MoreButtonViewHolder implements ...@@ -111,7 +111,7 @@ abstract class ThumbnailAwareViewHolder extends MoreButtonViewHolder implements
// Start the new request. // Start the new request.
mId = offlineItem.id; mId = offlineItem.id;
mCancellable = properties.getValue(ListProperties.PROVIDER_VISUALS) mCancellable = properties.get(ListProperties.PROVIDER_VISUALS)
.getVisuals(offlineItem, mWidthPx, mHeightPx, this); .getVisuals(offlineItem, mWidthPx, mHeightPx, this);
// Make sure to update our state properly if we got a synchronous response. // Make sure to update our state properly if we got a synchronous response.
...@@ -123,7 +123,7 @@ abstract class ThumbnailAwareViewHolder extends MoreButtonViewHolder implements ...@@ -123,7 +123,7 @@ abstract class ThumbnailAwareViewHolder extends MoreButtonViewHolder implements
return mSelectionView.isSelected() != item.selected return mSelectionView.isSelected() != item.selected
|| mSelectionView.isInSelectionMode() || mSelectionView.isInSelectionMode()
!= properties.getValue(ListProperties.SELECTION_MODE_ACTIVE); != properties.get(ListProperties.SELECTION_MODE_ACTIVE);
} }
// VisualsCallback implementation. // VisualsCallback implementation.
......
...@@ -36,12 +36,12 @@ public class StorageCoordinator { ...@@ -36,12 +36,12 @@ public class StorageCoordinator {
} }
private void onStorageInfoUpdated(String storageInfoText) { private void onStorageInfoUpdated(String storageInfoText) {
mModel.setValue(StorageProperties.STORAGE_INFO_TEXT, storageInfoText); mModel.set(StorageProperties.STORAGE_INFO_TEXT, storageInfoText);
} }
private void bind(PropertyModel model, TextView view, PropertyKey propertyKey) { private void bind(PropertyModel model, TextView view, PropertyKey propertyKey) {
if (propertyKey == StorageProperties.STORAGE_INFO_TEXT) { if (propertyKey == StorageProperties.STORAGE_INFO_TEXT) {
view.setText(model.getValue(StorageProperties.STORAGE_INFO_TEXT)); view.setText(model.get(StorageProperties.STORAGE_INFO_TEXT));
} }
} }
......
...@@ -63,7 +63,7 @@ public class LazyConstructionPropertyMcp<M extends PropertyObservable<P>, V exte ...@@ -63,7 +63,7 @@ public class LazyConstructionPropertyMcp<M extends PropertyObservable<P>, V exte
ViewProvider<V> viewFactory, ViewProvider<V> viewFactory,
PropertyModelChangeProcessor.ViewBinder<M, V, PropertyKey> viewBinder) { PropertyModelChangeProcessor.ViewBinder<M, V, PropertyKey> viewBinder) {
return new LazyConstructionPropertyMcp<>(model, visibilityProperty, return new LazyConstructionPropertyMcp<>(model, visibilityProperty,
item -> item.getValue(visibilityProperty), viewFactory, viewBinder); item -> item.get(visibilityProperty), viewFactory, viewBinder);
} }
private void flushPendingUpdates() { private void flushPendingUpdates() {
......
...@@ -58,7 +58,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> { ...@@ -58,7 +58,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> {
/** /**
* Get the current value from the float based key. * Get the current value from the float based key.
*/ */
public float getValue(FloatPropertyKey key) { public float get(FloatPropertyKey key) {
validateKey(key); validateKey(key);
FloatContainer container = (FloatContainer) mData.get(key); FloatContainer container = (FloatContainer) mData.get(key);
return container == null ? 0f : container.value; return container == null ? 0f : container.value;
...@@ -67,7 +67,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> { ...@@ -67,7 +67,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> {
/** /**
* Set the value for the float based key. * Set the value for the float based key.
*/ */
public void setValue(FloatPropertyKey key, float value) { public void set(FloatPropertyKey key, float value) {
validateKey(key); validateKey(key);
FloatContainer container = (FloatContainer) mData.get(key); FloatContainer container = (FloatContainer) mData.get(key);
if (container == null) { if (container == null) {
...@@ -83,7 +83,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> { ...@@ -83,7 +83,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> {
/** /**
* Get the current value from the int based key. * Get the current value from the int based key.
*/ */
public int getValue(IntPropertyKey key) { public int get(IntPropertyKey key) {
validateKey(key); validateKey(key);
IntContainer container = (IntContainer) mData.get(key); IntContainer container = (IntContainer) mData.get(key);
return container == null ? 0 : container.value; return container == null ? 0 : container.value;
...@@ -92,7 +92,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> { ...@@ -92,7 +92,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> {
/** /**
* Set the value for the int based key. * Set the value for the int based key.
*/ */
public void setValue(IntPropertyKey key, int value) { public void set(IntPropertyKey key, int value) {
validateKey(key); validateKey(key);
IntContainer container = (IntContainer) mData.get(key); IntContainer container = (IntContainer) mData.get(key);
if (container == null) { if (container == null) {
...@@ -108,7 +108,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> { ...@@ -108,7 +108,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> {
/** /**
* Get the current value from the boolean based key. * Get the current value from the boolean based key.
*/ */
public boolean getValue(BooleanPropertyKey key) { public boolean get(BooleanPropertyKey key) {
validateKey(key); validateKey(key);
BooleanContainer container = (BooleanContainer) mData.get(key); BooleanContainer container = (BooleanContainer) mData.get(key);
return container == null ? false : container.value; return container == null ? false : container.value;
...@@ -117,7 +117,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> { ...@@ -117,7 +117,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> {
/** /**
* Set the value for the boolean based key. * Set the value for the boolean based key.
*/ */
public void setValue(BooleanPropertyKey key, boolean value) { public void set(BooleanPropertyKey key, boolean value) {
validateKey(key); validateKey(key);
BooleanContainer container = (BooleanContainer) mData.get(key); BooleanContainer container = (BooleanContainer) mData.get(key);
if (container == null) { if (container == null) {
...@@ -134,7 +134,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> { ...@@ -134,7 +134,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> {
* Get the current value from the object based key. * Get the current value from the object based key.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T getValue(ObjectPropertyKey<T> key) { public <T> T get(ObjectPropertyKey<T> key) {
validateKey(key); validateKey(key);
ObjectContainer<T> container = (ObjectContainer<T>) mData.get(key); ObjectContainer<T> container = (ObjectContainer<T>) mData.get(key);
return container == null ? null : container.value; return container == null ? null : container.value;
...@@ -144,7 +144,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> { ...@@ -144,7 +144,7 @@ public class PropertyModel extends PropertyObservable<PropertyKey> {
* Set the value for the Object based key. * Set the value for the Object based key.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> void setValue(ObjectPropertyKey<T> key, T value) { public <T> void set(ObjectPropertyKey<T> key, T value) {
validateKey(key); validateKey(key);
ObjectContainer<T> container = (ObjectContainer<T>) mData.get(key); ObjectContainer<T> container = (ObjectContainer<T>) mData.get(key);
if (container == null) { if (container == null) {
......
...@@ -44,9 +44,9 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate { ...@@ -44,9 +44,9 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate {
public UrlBarMediator(PropertyModel model) { public UrlBarMediator(PropertyModel model) {
mModel = model; mModel = model;
mModel.setValue(UrlBarProperties.FOCUS_CHANGE_CALLBACK, this::onUrlFocusChange); mModel.set(UrlBarProperties.FOCUS_CHANGE_CALLBACK, this::onUrlFocusChange);
mModel.setValue(UrlBarProperties.SHOW_CURSOR, false); mModel.set(UrlBarProperties.SHOW_CURSOR, false);
mModel.setValue(UrlBarProperties.TEXT_CONTEXT_MENU_DELEGATE, this); mModel.set(UrlBarProperties.TEXT_CONTEXT_MENU_DELEGATE, this);
setUseDarkTextColors(true); setUseDarkTextColors(true);
} }
...@@ -54,7 +54,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate { ...@@ -54,7 +54,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate {
* Set the primary delegate for the UrlBar view. * Set the primary delegate for the UrlBar view.
*/ */
public void setDelegate(UrlBarDelegate delegate) { public void setDelegate(UrlBarDelegate delegate) {
mModel.setValue(UrlBarProperties.DELEGATE, delegate); mModel.set(UrlBarProperties.DELEGATE, delegate);
} }
/** /**
...@@ -73,7 +73,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate { ...@@ -73,7 +73,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate {
// Do not scroll to the end of the host for URLs such as data:, javascript:, etc... // Do not scroll to the end of the host for URLs such as data:, javascript:, etc...
if (data.url != null && data.originEndIndex == data.url.length()) { if (data.url != null && data.originEndIndex == data.url.length()) {
Uri uri = Uri.parse(data.url.toString()); Uri uri = Uri.parse(data.url);
String scheme = uri.getScheme(); String scheme = uri.getScheme();
if (!TextUtils.isEmpty(scheme) if (!TextUtils.isEmpty(scheme)
&& UrlBarData.UNSUPPORTED_SCHEMES_TO_SPLIT.contains(scheme)) { && UrlBarData.UNSUPPORTED_SCHEMES_TO_SPLIT.contains(scheme)) {
...@@ -102,7 +102,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate { ...@@ -102,7 +102,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate {
UrlBarTextState state = UrlBarTextState state =
new UrlBarTextState(text, scrollType, mUrlBarData.originEndIndex, mSelectionState); new UrlBarTextState(text, scrollType, mUrlBarData.originEndIndex, mSelectionState);
mModel.setValue(UrlBarProperties.TEXT_STATE, state); mModel.set(UrlBarProperties.TEXT_STATE, state);
} }
@VisibleForTesting @VisibleForTesting
...@@ -162,7 +162,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate { ...@@ -162,7 +162,7 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate {
assert false : "Should not update autocomplete text when not focused"; assert false : "Should not update autocomplete text when not focused";
return; return;
} }
mModel.setValue(UrlBarProperties.AUTOCOMPLETE_TEXT, mModel.set(UrlBarProperties.AUTOCOMPLETE_TEXT,
new AutocompleteText(userText, autocompleteText)); new AutocompleteText(userText, autocompleteText));
} }
...@@ -178,14 +178,14 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate { ...@@ -178,14 +178,14 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate {
private void onUrlFocusChange(boolean focus) { private void onUrlFocusChange(boolean focus) {
mHasFocus = focus; mHasFocus = focus;
if (mModel.getValue(UrlBarProperties.ALLOW_FOCUS)) { if (mModel.get(UrlBarProperties.ALLOW_FOCUS)) {
mModel.setValue(UrlBarProperties.SHOW_CURSOR, mHasFocus); mModel.set(UrlBarProperties.SHOW_CURSOR, mHasFocus);
} }
UrlBarTextState preCallbackState = mModel.getValue(UrlBarProperties.TEXT_STATE); UrlBarTextState preCallbackState = mModel.get(UrlBarProperties.TEXT_STATE);
if (mOnFocusChangeCallback != null) mOnFocusChangeCallback.onResult(focus); if (mOnFocusChangeCallback != null) mOnFocusChangeCallback.onResult(focus);
boolean textChangedInFocusCallback = boolean textChangedInFocusCallback =
mModel.getValue(UrlBarProperties.TEXT_STATE) != preCallbackState; mModel.get(UrlBarProperties.TEXT_STATE) != preCallbackState;
if (mUrlBarData != null && !textChangedInFocusCallback) { if (mUrlBarData != null && !textChangedInFocusCallback) {
pushTextToModel(); pushTextToModel();
} }
...@@ -197,8 +197,9 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate { ...@@ -197,8 +197,9 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate {
* @return Whether this resulted in a change from the previous value. * @return Whether this resulted in a change from the previous value.
*/ */
public boolean setUseDarkTextColors(boolean useDarkColors) { public boolean setUseDarkTextColors(boolean useDarkColors) {
boolean previousValue = mModel.getValue(UrlBarProperties.USE_DARK_TEXT_COLORS); // TODO(bauerb): Make clients observe the property instead of checking the return value.
mModel.setValue(UrlBarProperties.USE_DARK_TEXT_COLORS, useDarkColors); boolean previousValue = mModel.get(UrlBarProperties.USE_DARK_TEXT_COLORS);
mModel.set(UrlBarProperties.USE_DARK_TEXT_COLORS, useDarkColors);
return previousValue != useDarkColors; return previousValue != useDarkColors;
} }
...@@ -206,9 +207,9 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate { ...@@ -206,9 +207,9 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate {
* Sets whether the view allows user focus. * Sets whether the view allows user focus.
*/ */
public void setAllowFocus(boolean allowFocus) { public void setAllowFocus(boolean allowFocus) {
mModel.setValue(UrlBarProperties.ALLOW_FOCUS, allowFocus); mModel.set(UrlBarProperties.ALLOW_FOCUS, allowFocus);
if (allowFocus) { if (allowFocus) {
mModel.setValue(UrlBarProperties.SHOW_CURSOR, mHasFocus); mModel.set(UrlBarProperties.SHOW_CURSOR, mHasFocus);
} }
} }
...@@ -216,21 +217,21 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate { ...@@ -216,21 +217,21 @@ class UrlBarMediator implements UrlBar.UrlBarTextContextMenuDelegate {
* Set the listener to be notified for URL direction changes. * Set the listener to be notified for URL direction changes.
*/ */
public void setUrlDirectionListener(UrlDirectionListener listener) { public void setUrlDirectionListener(UrlDirectionListener listener) {
mModel.setValue(UrlBarProperties.URL_DIRECTION_LISTENER, listener); mModel.set(UrlBarProperties.URL_DIRECTION_LISTENER, listener);
} }
/** /**
* Set the delegate that provides Window capabilities. * Set the delegate that provides Window capabilities.
*/ */
public void setWindowDelegate(WindowDelegate windowDelegate) { public void setWindowDelegate(WindowDelegate windowDelegate) {
mModel.setValue(UrlBarProperties.WINDOW_DELEGATE, windowDelegate); mModel.set(UrlBarProperties.WINDOW_DELEGATE, windowDelegate);
} }
/** /**
* Set the callback to handle contextual Action Modes. * Set the callback to handle contextual Action Modes.
*/ */
public void setActionModeCallback(ActionMode.Callback callback) { public void setActionModeCallback(ActionMode.Callback callback) {
mModel.setValue(UrlBarProperties.ACTION_MODE_CALLBACK, callback); mModel.set(UrlBarProperties.ACTION_MODE_CALLBACK, callback);
} }
@Override @Override
......
...@@ -30,30 +30,29 @@ class UrlBarViewBinder { ...@@ -30,30 +30,29 @@ class UrlBarViewBinder {
public static void bind(PropertyModel model, UrlBar view, PropertyKey propertyKey) { public static void bind(PropertyModel model, UrlBar view, PropertyKey propertyKey) {
if (UrlBarProperties.ACTION_MODE_CALLBACK.equals(propertyKey)) { if (UrlBarProperties.ACTION_MODE_CALLBACK.equals(propertyKey)) {
view.setCustomSelectionActionModeCallback( view.setCustomSelectionActionModeCallback(
model.getValue(UrlBarProperties.ACTION_MODE_CALLBACK)); model.get(UrlBarProperties.ACTION_MODE_CALLBACK));
} else if (UrlBarProperties.ALLOW_FOCUS.equals(propertyKey)) { } else if (UrlBarProperties.ALLOW_FOCUS.equals(propertyKey)) {
view.setAllowFocus(model.getValue(UrlBarProperties.ALLOW_FOCUS)); view.setAllowFocus(model.get(UrlBarProperties.ALLOW_FOCUS));
} else if (UrlBarProperties.AUTOCOMPLETE_TEXT.equals(propertyKey)) { } else if (UrlBarProperties.AUTOCOMPLETE_TEXT.equals(propertyKey)) {
AutocompleteText autocomplete = model.getValue(UrlBarProperties.AUTOCOMPLETE_TEXT); AutocompleteText autocomplete = model.get(UrlBarProperties.AUTOCOMPLETE_TEXT);
if (view.shouldAutocomplete()) { if (view.shouldAutocomplete()) {
view.setAutocompleteText(autocomplete.userText, autocomplete.autocompleteText); view.setAutocompleteText(autocomplete.userText, autocomplete.autocompleteText);
} }
} else if (UrlBarProperties.DELEGATE.equals(propertyKey)) { } else if (UrlBarProperties.DELEGATE.equals(propertyKey)) {
view.setDelegate(model.getValue(UrlBarProperties.DELEGATE)); view.setDelegate(model.get(UrlBarProperties.DELEGATE));
} else if (UrlBarProperties.FOCUS_CHANGE_CALLBACK.equals(propertyKey)) { } else if (UrlBarProperties.FOCUS_CHANGE_CALLBACK.equals(propertyKey)) {
final Callback<Boolean> focusChangeCallback = final Callback<Boolean> focusChangeCallback =
model.getValue(UrlBarProperties.FOCUS_CHANGE_CALLBACK); model.get(UrlBarProperties.FOCUS_CHANGE_CALLBACK);
view.setOnFocusChangeListener((v, focused) -> { view.setOnFocusChangeListener((v, focused) -> {
if (focused) view.setIgnoreTextChangesForAutocomplete(false); if (focused) view.setIgnoreTextChangesForAutocomplete(false);
focusChangeCallback.onResult(focused); focusChangeCallback.onResult(focused);
}); });
} else if (UrlBarProperties.SHOW_CURSOR.equals(propertyKey)) { } else if (UrlBarProperties.SHOW_CURSOR.equals(propertyKey)) {
view.setCursorVisible(model.getValue(UrlBarProperties.SHOW_CURSOR)); view.setCursorVisible(model.get(UrlBarProperties.SHOW_CURSOR));
} else if (UrlBarProperties.TEXT_CONTEXT_MENU_DELEGATE.equals(propertyKey)) { } else if (UrlBarProperties.TEXT_CONTEXT_MENU_DELEGATE.equals(propertyKey)) {
view.setTextContextMenuDelegate( view.setTextContextMenuDelegate(model.get(UrlBarProperties.TEXT_CONTEXT_MENU_DELEGATE));
model.getValue(UrlBarProperties.TEXT_CONTEXT_MENU_DELEGATE));
} else if (UrlBarProperties.TEXT_STATE.equals(propertyKey)) { } else if (UrlBarProperties.TEXT_STATE.equals(propertyKey)) {
UrlBarTextState state = model.getValue(UrlBarProperties.TEXT_STATE); UrlBarTextState state = model.get(UrlBarProperties.TEXT_STATE);
view.setIgnoreTextChangesForAutocomplete(true); view.setIgnoreTextChangesForAutocomplete(true);
view.setText(state.text); view.setText(state.text);
view.setScrollState(state.scrollType, state.scrollToIndex); view.setScrollState(state.scrollType, state.scrollToIndex);
...@@ -67,11 +66,11 @@ class UrlBarViewBinder { ...@@ -67,11 +66,11 @@ class UrlBarViewBinder {
} }
} }
} else if (UrlBarProperties.USE_DARK_TEXT_COLORS.equals(propertyKey)) { } else if (UrlBarProperties.USE_DARK_TEXT_COLORS.equals(propertyKey)) {
updateTextColors(view, model.getValue(UrlBarProperties.USE_DARK_TEXT_COLORS)); updateTextColors(view, model.get(UrlBarProperties.USE_DARK_TEXT_COLORS));
} else if (UrlBarProperties.URL_DIRECTION_LISTENER.equals(propertyKey)) { } else if (UrlBarProperties.URL_DIRECTION_LISTENER.equals(propertyKey)) {
view.setUrlDirectionListener(model.getValue(UrlBarProperties.URL_DIRECTION_LISTENER)); view.setUrlDirectionListener(model.get(UrlBarProperties.URL_DIRECTION_LISTENER));
} else if (UrlBarProperties.WINDOW_DELEGATE.equals(propertyKey)) { } else if (UrlBarProperties.WINDOW_DELEGATE.equals(propertyKey)) {
view.setWindowDelegate(model.getValue(UrlBarProperties.WINDOW_DELEGATE)); view.setWindowDelegate(model.get(UrlBarProperties.WINDOW_DELEGATE));
} }
} }
......
...@@ -11,9 +11,9 @@ public class PasswordGenerationDialogMediator { ...@@ -11,9 +11,9 @@ public class PasswordGenerationDialogMediator {
public static void initializeState(PasswordGenerationDialogModel model, String password, public static void initializeState(PasswordGenerationDialogModel model, String password,
String saveExplanationText, String saveExplanationText,
Callback<Boolean> onPasswordAcceptedOrRejected) { Callback<Boolean> onPasswordAcceptedOrRejected) {
model.setValue(PasswordGenerationDialogModel.GENERATED_PASSWORD, password); model.set(PasswordGenerationDialogModel.GENERATED_PASSWORD, password);
model.setValue(PasswordGenerationDialogModel.SAVE_EXPLANATION_TEXT, saveExplanationText); model.set(PasswordGenerationDialogModel.SAVE_EXPLANATION_TEXT, saveExplanationText);
model.setValue(PasswordGenerationDialogModel.PASSWORD_ACTION_CALLBACK, model.set(PasswordGenerationDialogModel.PASSWORD_ACTION_CALLBACK,
onPasswordAcceptedOrRejected); onPasswordAcceptedOrRejected);
} }
} }
...@@ -46,11 +46,11 @@ public class PasswordGenerationDialogViewBinder { ...@@ -46,11 +46,11 @@ public class PasswordGenerationDialogViewBinder {
public static void bind( public static void bind(
PasswordGenerationDialogModel model, PasswordGenerationDialogViewHolder viewHolder) { PasswordGenerationDialogModel model, PasswordGenerationDialogViewHolder viewHolder) {
viewHolder.setController(new PasswordGenerationDialogController( viewHolder.setController(new PasswordGenerationDialogController(
model.getValue(PasswordGenerationDialogModel.PASSWORD_ACTION_CALLBACK))); model.get(PasswordGenerationDialogModel.PASSWORD_ACTION_CALLBACK)));
viewHolder.setGeneratedPassword( viewHolder.setGeneratedPassword(
model.getValue(PasswordGenerationDialogModel.GENERATED_PASSWORD)); model.get(PasswordGenerationDialogModel.GENERATED_PASSWORD));
viewHolder.setSaveExplanationText( viewHolder.setSaveExplanationText(
model.getValue(PasswordGenerationDialogModel.SAVE_EXPLANATION_TEXT)); model.get(PasswordGenerationDialogModel.SAVE_EXPLANATION_TEXT));
viewHolder.initializeView(); viewHolder.initializeView();
} }
} }
...@@ -79,19 +79,17 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis ...@@ -79,19 +79,17 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis
mFirstSlotData = firstSlotData; mFirstSlotData = firstSlotData;
mSecondSlotData = secondSlotData; mSecondSlotData = secondSlotData;
mModel.setValue(BottomToolbarModel.PRIMARY_COLOR, primaryColor); mModel.set(BottomToolbarModel.PRIMARY_COLOR, primaryColor);
mModel.setValue( mModel.set(BottomToolbarModel.FIRST_BUTTON_DATA, mFirstSlotData.browsingModeButtonData);
BottomToolbarModel.FIRST_BUTTON_DATA, mFirstSlotData.browsingModeButtonData); mModel.set(BottomToolbarModel.SECOND_BUTTON_DATA, mSecondSlotData.browsingModeButtonData);
mModel.setValue(
BottomToolbarModel.SECOND_BUTTON_DATA, mSecondSlotData.browsingModeButtonData);
} }
/** /**
* @param swipeHandler The handler that controls the toolbar swipe behavior. * @param swipeHandler The handler that controls the toolbar swipe behavior.
*/ */
void setToolbarSwipeHandler(EdgeSwipeHandler swipeHandler) { void setToolbarSwipeHandler(EdgeSwipeHandler swipeHandler) {
mModel.setValue(BottomToolbarModel.TOOLBAR_SWIPE_HANDLER, swipeHandler); mModel.set(BottomToolbarModel.TOOLBAR_SWIPE_HANDLER, swipeHandler);
} }
/** /**
...@@ -101,8 +99,8 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis ...@@ -101,8 +99,8 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis
mFullscreenManager.removeListener(this); mFullscreenManager.removeListener(this);
if (mOverviewModeBehavior != null) mOverviewModeBehavior.removeOverviewModeObserver(this); if (mOverviewModeBehavior != null) mOverviewModeBehavior.removeOverviewModeObserver(this);
if (mWindowAndroid != null) mWindowAndroid.removeKeyboardVisibilityListener(this); if (mWindowAndroid != null) mWindowAndroid.removeKeyboardVisibilityListener(this);
if (mModel.getValue(BottomToolbarModel.LAYOUT_MANAGER) != null) { if (mModel.get(BottomToolbarModel.LAYOUT_MANAGER) != null) {
LayoutManager manager = mModel.getValue(BottomToolbarModel.LAYOUT_MANAGER); LayoutManager manager = mModel.get(BottomToolbarModel.LAYOUT_MANAGER);
manager.getOverlayPanelManager().removeObserver(this); manager.getOverlayPanelManager().removeObserver(this);
manager.removeSceneChangeObserver(this); manager.removeSceneChangeObserver(this);
} }
...@@ -113,9 +111,9 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis ...@@ -113,9 +111,9 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis
@Override @Override
public void onControlsOffsetChanged(float topOffset, float bottomOffset, boolean needsAnimate) { public void onControlsOffsetChanged(float topOffset, float bottomOffset, boolean needsAnimate) {
mModel.setValue(BottomToolbarModel.Y_OFFSET, (int) bottomOffset); mModel.set(BottomToolbarModel.Y_OFFSET, (int) bottomOffset);
if (bottomOffset > 0 || mFullscreenManager.getBottomControlsHeight() == 0) { if (bottomOffset > 0 || mFullscreenManager.getBottomControlsHeight() == 0) {
mModel.setValue(BottomToolbarModel.ANDROID_VIEW_VISIBLE, false); mModel.set(BottomToolbarModel.ANDROID_VIEW_VISIBLE, false);
} else { } else {
tryShowingAndroidView(); tryShowingAndroidView();
} }
...@@ -129,9 +127,8 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis ...@@ -129,9 +127,8 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis
@Override @Override
public void onOverviewModeStartedShowing(boolean showToolbar) { public void onOverviewModeStartedShowing(boolean showToolbar) {
mModel.setValue( mModel.set(BottomToolbarModel.FIRST_BUTTON_DATA, mFirstSlotData.tabSwitcherModeButtonData);
BottomToolbarModel.FIRST_BUTTON_DATA, mFirstSlotData.tabSwitcherModeButtonData); mModel.set(
mModel.setValue(
BottomToolbarModel.SECOND_BUTTON_DATA, mSecondSlotData.tabSwitcherModeButtonData); BottomToolbarModel.SECOND_BUTTON_DATA, mSecondSlotData.tabSwitcherModeButtonData);
} }
...@@ -140,10 +137,8 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis ...@@ -140,10 +137,8 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis
@Override @Override
public void onOverviewModeStartedHiding(boolean showToolbar, boolean delayAnimation) { public void onOverviewModeStartedHiding(boolean showToolbar, boolean delayAnimation) {
mModel.setValue( mModel.set(BottomToolbarModel.FIRST_BUTTON_DATA, mFirstSlotData.browsingModeButtonData);
BottomToolbarModel.FIRST_BUTTON_DATA, mFirstSlotData.browsingModeButtonData); mModel.set(BottomToolbarModel.SECOND_BUTTON_DATA, mSecondSlotData.browsingModeButtonData);
mModel.setValue(
BottomToolbarModel.SECOND_BUTTON_DATA, mSecondSlotData.browsingModeButtonData);
} }
@Override @Override
...@@ -151,7 +146,7 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis ...@@ -151,7 +146,7 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis
@Override @Override
public void onOverlayPanelShown() { public void onOverlayPanelShown() {
mModel.setValue(BottomToolbarModel.ANDROID_VIEW_VISIBLE, false); mModel.set(BottomToolbarModel.ANDROID_VIEW_VISIBLE, false);
} }
@Override @Override
...@@ -165,15 +160,15 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis ...@@ -165,15 +160,15 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis
// the bottom toolbar view to visible or invisible regardless of the previous state. // the bottom toolbar view to visible or invisible regardless of the previous state.
if (isShowing) { if (isShowing) {
mBottomToolbarHeightBeforeHide = mFullscreenManager.getBottomControlsHeight(); mBottomToolbarHeightBeforeHide = mFullscreenManager.getBottomControlsHeight();
mModel.setValue(BottomToolbarModel.ANDROID_VIEW_VISIBLE, false); mModel.set(BottomToolbarModel.ANDROID_VIEW_VISIBLE, false);
mModel.setValue(BottomToolbarModel.COMPOSITED_VIEW_VISIBLE, false); mModel.set(BottomToolbarModel.COMPOSITED_VIEW_VISIBLE, false);
mFullscreenManager.setBottomControlsHeight(0); mFullscreenManager.setBottomControlsHeight(0);
} else { } else {
mFullscreenManager.setBottomControlsHeight(mBottomToolbarHeightBeforeHide); mFullscreenManager.setBottomControlsHeight(mBottomToolbarHeightBeforeHide);
tryShowingAndroidView(); tryShowingAndroidView();
mModel.setValue( mModel.set(
BottomToolbarModel.Y_OFFSET, (int) mFullscreenManager.getBottomControlOffset()); BottomToolbarModel.Y_OFFSET, (int) mFullscreenManager.getBottomControlOffset());
mModel.setValue(BottomToolbarModel.COMPOSITED_VIEW_VISIBLE, true); mModel.set(BottomToolbarModel.COMPOSITED_VIEW_VISIBLE, true);
} }
} }
...@@ -184,12 +179,12 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis ...@@ -184,12 +179,12 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis
*/ */
private void tryShowingAndroidView() { private void tryShowingAndroidView() {
if (mFullscreenManager.getBottomControlOffset() > 0) return; if (mFullscreenManager.getBottomControlOffset() > 0) return;
if (mModel.getValue(BottomToolbarModel.Y_OFFSET) != 0) return; if (mModel.get(BottomToolbarModel.Y_OFFSET) != 0) return;
mModel.setValue(BottomToolbarModel.ANDROID_VIEW_VISIBLE, true); mModel.set(BottomToolbarModel.ANDROID_VIEW_VISIBLE, true);
} }
void setLayoutManager(LayoutManager layoutManager) { void setLayoutManager(LayoutManager layoutManager) {
mModel.setValue(BottomToolbarModel.LAYOUT_MANAGER, layoutManager); mModel.set(BottomToolbarModel.LAYOUT_MANAGER, layoutManager);
layoutManager.addSceneChangeObserver(this); layoutManager.addSceneChangeObserver(this);
layoutManager.getOverlayPanelManager().addObserver(this); layoutManager.getOverlayPanelManager().addObserver(this);
} }
...@@ -201,16 +196,16 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis ...@@ -201,16 +196,16 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis
public void onSceneChange(Layout layout) { public void onSceneChange(Layout layout) {
if (layout instanceof ToolbarSwipeLayout) { if (layout instanceof ToolbarSwipeLayout) {
mIsInSwipeLayout = true; mIsInSwipeLayout = true;
mModel.setValue(BottomToolbarModel.ANDROID_VIEW_VISIBLE, false); mModel.set(BottomToolbarModel.ANDROID_VIEW_VISIBLE, false);
} else if (mIsInSwipeLayout) { } else if (mIsInSwipeLayout) {
// Only change to visible if leaving the swipe layout. // Only change to visible if leaving the swipe layout.
mIsInSwipeLayout = false; mIsInSwipeLayout = false;
mModel.setValue(BottomToolbarModel.ANDROID_VIEW_VISIBLE, true); mModel.set(BottomToolbarModel.ANDROID_VIEW_VISIBLE, true);
} }
} }
void setResourceManager(ResourceManager resourceManager) { void setResourceManager(ResourceManager resourceManager) {
mModel.setValue(BottomToolbarModel.RESOURCE_MANAGER, resourceManager); mModel.set(BottomToolbarModel.RESOURCE_MANAGER, resourceManager);
} }
void setOverviewModeBehavior(OverviewModeBehavior overviewModeBehavior) { void setOverviewModeBehavior(OverviewModeBehavior overviewModeBehavior) {
...@@ -219,7 +214,7 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis ...@@ -219,7 +214,7 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis
} }
void setToolbarSwipeLayout(ToolbarSwipeLayout layout) { void setToolbarSwipeLayout(ToolbarSwipeLayout layout) {
mModel.setValue(BottomToolbarModel.TOOLBAR_SWIPE_LAYOUT, layout); mModel.set(BottomToolbarModel.TOOLBAR_SWIPE_LAYOUT, layout);
} }
void setWindowAndroid(WindowAndroid windowAndroid) { void setWindowAndroid(WindowAndroid windowAndroid) {
...@@ -235,14 +230,14 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis ...@@ -235,14 +230,14 @@ class BottomToolbarMediator implements FullscreenListener, KeyboardVisibilityLis
mSecondSlotData.tabSwitcherModeButtonData = secondSlotButtonData; mSecondSlotData.tabSwitcherModeButtonData = secondSlotButtonData;
if (mOverviewModeBehavior.overviewVisible()) { if (mOverviewModeBehavior.overviewVisible()) {
mModel.setValue( mModel.set(
BottomToolbarModel.FIRST_BUTTON_DATA, mFirstSlotData.tabSwitcherModeButtonData); BottomToolbarModel.FIRST_BUTTON_DATA, mFirstSlotData.tabSwitcherModeButtonData);
mModel.setValue(BottomToolbarModel.SECOND_BUTTON_DATA, mModel.set(BottomToolbarModel.SECOND_BUTTON_DATA,
mSecondSlotData.tabSwitcherModeButtonData); mSecondSlotData.tabSwitcherModeButtonData);
} }
} }
void setPrimaryColor(int color) { void setPrimaryColor(int color) {
mModel.setValue(BottomToolbarModel.PRIMARY_COLOR, color); mModel.set(BottomToolbarModel.PRIMARY_COLOR, color);
} }
} }
...@@ -60,48 +60,45 @@ public class BottomToolbarViewBinder ...@@ -60,48 +60,45 @@ public class BottomToolbarViewBinder
public final void bind(BottomToolbarModel model, ViewHolder view, PropertyKey propertyKey) { public final void bind(BottomToolbarModel model, ViewHolder view, PropertyKey propertyKey) {
if (BottomToolbarModel.Y_OFFSET == propertyKey) { if (BottomToolbarModel.Y_OFFSET == propertyKey) {
assert view.sceneLayer != null; assert view.sceneLayer != null;
view.sceneLayer.setYOffset(model.getValue(BottomToolbarModel.Y_OFFSET)); view.sceneLayer.setYOffset(model.get(BottomToolbarModel.Y_OFFSET));
} else if (BottomToolbarModel.ANDROID_VIEW_VISIBLE == propertyKey) { } else if (BottomToolbarModel.ANDROID_VIEW_VISIBLE == propertyKey) {
view.toolbarRoot.setVisibility(model.getValue(BottomToolbarModel.ANDROID_VIEW_VISIBLE) view.toolbarRoot.setVisibility(model.get(BottomToolbarModel.ANDROID_VIEW_VISIBLE)
? View.VISIBLE ? View.VISIBLE
: View.INVISIBLE); : View.INVISIBLE);
} else if (BottomToolbarModel.COMPOSITED_VIEW_VISIBLE == propertyKey) { } else if (BottomToolbarModel.COMPOSITED_VIEW_VISIBLE == propertyKey) {
view.sceneLayer.setIsVisible( view.sceneLayer.setIsVisible(model.get(BottomToolbarModel.COMPOSITED_VIEW_VISIBLE));
model.getValue(BottomToolbarModel.COMPOSITED_VIEW_VISIBLE)); model.get(BottomToolbarModel.LAYOUT_MANAGER).requestUpdate();
model.getValue(BottomToolbarModel.LAYOUT_MANAGER).requestUpdate();
} else if (BottomToolbarModel.LAYOUT_MANAGER == propertyKey) { } else if (BottomToolbarModel.LAYOUT_MANAGER == propertyKey) {
assert view.sceneLayer == null; assert view.sceneLayer == null;
view.sceneLayer = new ScrollingBottomViewSceneLayer( view.sceneLayer = new ScrollingBottomViewSceneLayer(
view.toolbarRoot, view.toolbarRoot.getTopShadowHeight()); view.toolbarRoot, view.toolbarRoot.getTopShadowHeight());
model.getValue(BottomToolbarModel.LAYOUT_MANAGER) model.get(BottomToolbarModel.LAYOUT_MANAGER).addSceneOverlayToBack(view.sceneLayer);
.addSceneOverlayToBack(view.sceneLayer);
} else if (BottomToolbarModel.TOOLBAR_SWIPE_LAYOUT == propertyKey) { } else if (BottomToolbarModel.TOOLBAR_SWIPE_LAYOUT == propertyKey) {
assert view.sceneLayer != null; assert view.sceneLayer != null;
model.getValue(BottomToolbarModel.TOOLBAR_SWIPE_LAYOUT) model.get(BottomToolbarModel.TOOLBAR_SWIPE_LAYOUT)
.setBottomToolbarSceneLayers(new ScrollingBottomViewSceneLayer(view.sceneLayer), .setBottomToolbarSceneLayers(new ScrollingBottomViewSceneLayer(view.sceneLayer),
new ScrollingBottomViewSceneLayer(view.sceneLayer)); new ScrollingBottomViewSceneLayer(view.sceneLayer));
} else if (BottomToolbarModel.RESOURCE_MANAGER == propertyKey) { } else if (BottomToolbarModel.RESOURCE_MANAGER == propertyKey) {
model.getValue(BottomToolbarModel.RESOURCE_MANAGER) model.get(BottomToolbarModel.RESOURCE_MANAGER)
.getDynamicResourceLoader() .getDynamicResourceLoader()
.registerResource( .registerResource(
view.toolbarRoot.getId(), view.toolbarRoot.getResourceAdapter()); view.toolbarRoot.getId(), view.toolbarRoot.getResourceAdapter());
} else if (BottomToolbarModel.TOOLBAR_SWIPE_HANDLER == propertyKey) { } else if (BottomToolbarModel.TOOLBAR_SWIPE_HANDLER == propertyKey) {
view.toolbarRoot.setSwipeDetector( view.toolbarRoot.setSwipeDetector(model.get(BottomToolbarModel.TOOLBAR_SWIPE_HANDLER));
model.getValue(BottomToolbarModel.TOOLBAR_SWIPE_HANDLER));
} else if (BottomToolbarModel.FIRST_BUTTON_DATA == propertyKey) { } else if (BottomToolbarModel.FIRST_BUTTON_DATA == propertyKey) {
updateButton(view.firstTintedImageButton, updateButton(view.firstTintedImageButton,
model.getValue(BottomToolbarModel.FIRST_BUTTON_DATA), useLightIcons(model)); model.get(BottomToolbarModel.FIRST_BUTTON_DATA), useLightIcons(model));
} else if (BottomToolbarModel.SECOND_BUTTON_DATA == propertyKey) { } else if (BottomToolbarModel.SECOND_BUTTON_DATA == propertyKey) {
updateButton(view.secondTintedImageButton, updateButton(view.secondTintedImageButton,
model.getValue(BottomToolbarModel.SECOND_BUTTON_DATA), useLightIcons(model)); model.get(BottomToolbarModel.SECOND_BUTTON_DATA), useLightIcons(model));
} else if (BottomToolbarModel.PRIMARY_COLOR == propertyKey) { } else if (BottomToolbarModel.PRIMARY_COLOR == propertyKey) {
final boolean useLightIcons = useLightIcons(model); final boolean useLightIcons = useLightIcons(model);
view.toolbarRoot.findViewById(R.id.bottom_sheet_toolbar) view.toolbarRoot.findViewById(R.id.bottom_sheet_toolbar)
.setBackgroundColor(model.getValue(BottomToolbarModel.PRIMARY_COLOR)); .setBackgroundColor(model.get(BottomToolbarModel.PRIMARY_COLOR));
updateButtonDrawable(view.firstTintedImageButton, updateButtonDrawable(view.firstTintedImageButton,
model.getValue(BottomToolbarModel.FIRST_BUTTON_DATA), useLightIcons); model.get(BottomToolbarModel.FIRST_BUTTON_DATA), useLightIcons);
updateButtonDrawable(view.secondTintedImageButton, updateButtonDrawable(view.secondTintedImageButton,
model.getValue(BottomToolbarModel.SECOND_BUTTON_DATA), useLightIcons); model.get(BottomToolbarModel.SECOND_BUTTON_DATA), useLightIcons);
} else { } else {
assert false : "Unhandled property detected in BottomToolbarViewBinder!"; assert false : "Unhandled property detected in BottomToolbarViewBinder!";
} }
...@@ -109,7 +106,7 @@ public class BottomToolbarViewBinder ...@@ -109,7 +106,7 @@ public class BottomToolbarViewBinder
private static boolean useLightIcons(BottomToolbarModel model) { private static boolean useLightIcons(BottomToolbarModel model) {
return ColorUtils.shouldUseLightForegroundOnBackground( return ColorUtils.shouldUseLightForegroundOnBackground(
model.getValue(BottomToolbarModel.PRIMARY_COLOR)); model.get(BottomToolbarModel.PRIMARY_COLOR));
} }
private static void updateButton( private static void updateButton(
......
...@@ -49,7 +49,7 @@ public class TabSwitcherButtonCoordinator { ...@@ -49,7 +49,7 @@ public class TabSwitcherButtonCoordinator {
mTabSwitcherButtonModel, view, new TabSwitcherButtonViewBinder()); mTabSwitcherButtonModel, view, new TabSwitcherButtonViewBinder());
CharSequence description = root.getResources().getString(R.string.open_tabs); CharSequence description = root.getResources().getString(R.string.open_tabs);
mTabSwitcherButtonModel.setValue(TabSwitcherButtonProperties.ON_LONG_CLICK_LISTENER, mTabSwitcherButtonModel.set(TabSwitcherButtonProperties.ON_LONG_CLICK_LISTENER,
v -> AccessibilityUtil.showAccessibilityToast(root.getContext(), v, description)); v -> AccessibilityUtil.showAccessibilityToast(root.getContext(), v, description));
} }
...@@ -58,8 +58,7 @@ public class TabSwitcherButtonCoordinator { ...@@ -58,8 +58,7 @@ public class TabSwitcherButtonCoordinator {
* button is clicked. * button is clicked.
*/ */
public void setTabSwitcherListener(OnClickListener onClickListener) { public void setTabSwitcherListener(OnClickListener onClickListener) {
mTabSwitcherButtonModel.setValue( mTabSwitcherButtonModel.set(TabSwitcherButtonProperties.ON_CLICK_LISTENER, onClickListener);
TabSwitcherButtonProperties.ON_CLICK_LISTENER, onClickListener);
} }
/** /**
...@@ -121,7 +120,7 @@ public class TabSwitcherButtonCoordinator { ...@@ -121,7 +120,7 @@ public class TabSwitcherButtonCoordinator {
* @param tint The {@link ColorStateList} used to tint the button. * @param tint The {@link ColorStateList} used to tint the button.
*/ */
public void setTint(ColorStateList tint) { public void setTint(ColorStateList tint) {
mTabSwitcherButtonModel.setValue(TabSwitcherButtonProperties.TINT, tint); mTabSwitcherButtonModel.set(TabSwitcherButtonProperties.TINT, tint);
} }
public void destroy() { public void destroy() {
...@@ -130,7 +129,7 @@ public class TabSwitcherButtonCoordinator { ...@@ -130,7 +129,7 @@ public class TabSwitcherButtonCoordinator {
} }
private void updateTabCount() { private void updateTabCount() {
mTabSwitcherButtonModel.setValue(TabSwitcherButtonProperties.NUMBER_OF_TABS, mTabSwitcherButtonModel.set(TabSwitcherButtonProperties.NUMBER_OF_TABS,
mTabModelSelector.getCurrentModel().getCount()); mTabModelSelector.getCurrentModel().getCount());
} }
} }
...@@ -26,14 +26,14 @@ public class TabSwitcherButtonViewBinder ...@@ -26,14 +26,14 @@ public class TabSwitcherButtonViewBinder
public final void bind( public final void bind(
PropertyModel model, TabSwitcherButtonView view, PropertyKey propertyKey) { PropertyModel model, TabSwitcherButtonView view, PropertyKey propertyKey) {
if (TabSwitcherButtonProperties.NUMBER_OF_TABS == propertyKey) { if (TabSwitcherButtonProperties.NUMBER_OF_TABS == propertyKey) {
view.updateTabCountVisuals(model.getValue(TabSwitcherButtonProperties.NUMBER_OF_TABS)); view.updateTabCountVisuals(model.get(TabSwitcherButtonProperties.NUMBER_OF_TABS));
} else if (TabSwitcherButtonProperties.ON_CLICK_LISTENER == propertyKey) { } else if (TabSwitcherButtonProperties.ON_CLICK_LISTENER == propertyKey) {
view.setOnClickListener(model.getValue(TabSwitcherButtonProperties.ON_CLICK_LISTENER)); view.setOnClickListener(model.get(TabSwitcherButtonProperties.ON_CLICK_LISTENER));
} else if (TabSwitcherButtonProperties.ON_LONG_CLICK_LISTENER == propertyKey) { } else if (TabSwitcherButtonProperties.ON_LONG_CLICK_LISTENER == propertyKey) {
view.setOnLongClickListener( view.setOnLongClickListener(
model.getValue(TabSwitcherButtonProperties.ON_LONG_CLICK_LISTENER)); model.get(TabSwitcherButtonProperties.ON_LONG_CLICK_LISTENER));
} else if (TabSwitcherButtonProperties.TINT == propertyKey) { } else if (TabSwitcherButtonProperties.TINT == propertyKey) {
view.setTint(model.getValue(TabSwitcherButtonProperties.TINT)); view.setTint(model.get(TabSwitcherButtonProperties.TINT));
} else { } else {
assert false : "Unhandled property detected in TabSwitcherViewBinder!"; assert false : "Unhandled property detected in TabSwitcherViewBinder!";
} }
......
...@@ -57,6 +57,7 @@ public class LazyConstructionPropertyMcpTest { ...@@ -57,6 +57,7 @@ public class LazyConstructionPropertyMcpTest {
public void setup() { public void setup() {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mModel = new PropertyModel(ALL_PROPERTIES); mModel = new PropertyModel(ALL_PROPERTIES);
mModel.set(VISIBILITY, false);
mViewProvider = new FakeViewProvider<>(); mViewProvider = new FakeViewProvider<>();
mModel.addObserver((source, propertyKey) -> { mModel.addObserver((source, propertyKey) -> {
// Forward model changes to the model observer if it exists. It's important for the test // Forward model changes to the model observer if it exists. It's important for the test
...@@ -70,7 +71,7 @@ public class LazyConstructionPropertyMcpTest { ...@@ -70,7 +71,7 @@ public class LazyConstructionPropertyMcpTest {
LazyConstructionPropertyMcp.create(mModel, VISIBILITY, mViewProvider, mViewBinder); LazyConstructionPropertyMcp.create(mModel, VISIBILITY, mViewProvider, mViewBinder);
assertFalse(mViewProvider.inflationHasStarted()); assertFalse(mViewProvider.inflationHasStarted());
mModel.setValue(VISIBILITY, true); mModel.set(VISIBILITY, true);
assertTrue(mViewProvider.inflationHasStarted()); assertTrue(mViewProvider.inflationHasStarted());
mViewProvider.finishInflation(mView); mViewProvider.finishInflation(mView);
...@@ -82,8 +83,8 @@ public class LazyConstructionPropertyMcpTest { ...@@ -82,8 +83,8 @@ public class LazyConstructionPropertyMcpTest {
@Test @Test
public void testUpdatesBeforeInflation() { public void testUpdatesBeforeInflation() {
LazyConstructionPropertyMcp.create(mModel, VISIBILITY, mViewProvider, mViewBinder); LazyConstructionPropertyMcp.create(mModel, VISIBILITY, mViewProvider, mViewBinder);
mModel.setValue(STRING_PROPERTY, "foo"); mModel.set(STRING_PROPERTY, "foo");
mModel.setValue(VISIBILITY, true); mModel.set(VISIBILITY, true);
assertTrue(mViewProvider.inflationHasStarted()); assertTrue(mViewProvider.inflationHasStarted());
mViewProvider.finishInflation(mView); mViewProvider.finishInflation(mView);
ShadowLooper.idleMainLooper(); ShadowLooper.idleMainLooper();
...@@ -95,17 +96,17 @@ public class LazyConstructionPropertyMcpTest { ...@@ -95,17 +96,17 @@ public class LazyConstructionPropertyMcpTest {
LazyConstructionPropertyMcp.create(mModel, VISIBILITY, mViewProvider, mViewBinder); LazyConstructionPropertyMcp.create(mModel, VISIBILITY, mViewProvider, mViewBinder);
// Show the view and pump the looper to do the initial bind. // Show the view and pump the looper to do the initial bind.
mModel.setValue(VISIBILITY, true); mModel.set(VISIBILITY, true);
assertTrue(mViewProvider.inflationHasStarted()); assertTrue(mViewProvider.inflationHasStarted());
mViewProvider.finishInflation(mView); mViewProvider.finishInflation(mView);
ShadowLooper.idleMainLooper(); ShadowLooper.idleMainLooper();
verifyBind(VISIBILITY); verifyBind(VISIBILITY);
Mockito.<ViewBinder>reset(mViewBinder); Mockito.<ViewBinder>reset(mViewBinder);
mModel.setValue(INT_PROPERTY, 42); mModel.set(INT_PROPERTY, 42);
verifyBind(INT_PROPERTY); verifyBind(INT_PROPERTY);
mModel.setValue(VISIBILITY, false); mModel.set(VISIBILITY, false);
verifyBind(VISIBILITY); verifyBind(VISIBILITY);
} }
...@@ -114,48 +115,49 @@ public class LazyConstructionPropertyMcpTest { ...@@ -114,48 +115,49 @@ public class LazyConstructionPropertyMcpTest {
LazyConstructionPropertyMcp.create(mModel, VISIBILITY, mViewProvider, mViewBinder); LazyConstructionPropertyMcp.create(mModel, VISIBILITY, mViewProvider, mViewBinder);
// Show the view and pump the looper to do the initial bind, then hide the view again. // Show the view and pump the looper to do the initial bind, then hide the view again.
mModel.setValue(VISIBILITY, true); mModel.set(VISIBILITY, true);
assertTrue(mViewProvider.inflationHasStarted()); assertTrue(mViewProvider.inflationHasStarted());
mViewProvider.finishInflation(mView); mViewProvider.finishInflation(mView);
ShadowLooper.idleMainLooper(); ShadowLooper.idleMainLooper();
verifyBind(VISIBILITY); verifyBind(VISIBILITY);
mModel.setValue(VISIBILITY, false); mModel.set(VISIBILITY, false);
verify(mViewBinder, times(2)).bind(eq(mModel), eq(mView), eq(VISIBILITY)); verify(mViewBinder, times(2)).bind(eq(mModel), eq(mView), eq(VISIBILITY));
Mockito.<ViewBinder>reset(mViewBinder); Mockito.<ViewBinder>reset(mViewBinder);
// While the view is hidden, the binder should not be invoked. // While the view is hidden, the binder should not be invoked.
mModel.setValue(STRING_PROPERTY, "foo"); mModel.set(STRING_PROPERTY, "foo");
mModel.setValue(STRING_PROPERTY, "bar"); mModel.set(STRING_PROPERTY, "bar");
verify(mViewBinder, never()) verify(mViewBinder, never())
.bind(any(PropertyModel.class), any(View.class), any(PropertyKey.class)); .bind(any(PropertyModel.class), any(View.class), any(PropertyKey.class));
// When the view is shown, all pending updates should be dispatched, coalescing updates to // When the view is shown, all pending updates should be dispatched, coalescing updates to
// the same property. // the same property.
mModel.setValue(VISIBILITY, true); mModel.set(VISIBILITY, true);
verifyBind(VISIBILITY, STRING_PROPERTY); verifyBind(VISIBILITY, STRING_PROPERTY);
} }
@Test @Test
public void testReentrantUpdates() { public void testReentrantUpdates() {
mModel.set(INT_PROPERTY, 0);
LazyConstructionPropertyMcp.create(mModel, VISIBILITY, mViewProvider, mViewBinder); LazyConstructionPropertyMcp.create(mModel, VISIBILITY, mViewProvider, mViewBinder);
// Increase INT_PROPERTY any time visibility changes. // Increase INT_PROPERTY any time visibility changes.
mModelObserver = (source, propertyKey) -> { mModelObserver = (source, propertyKey) -> {
if (propertyKey != VISIBILITY) return; if (propertyKey != VISIBILITY) return;
mModel.setValue(INT_PROPERTY, mModel.getValue(INT_PROPERTY) + 1); mModel.set(INT_PROPERTY, mModel.get(INT_PROPERTY) + 1);
}; };
mModel.setValue(VISIBILITY, true); mModel.set(VISIBILITY, true);
mViewProvider.finishInflation(mView); mViewProvider.finishInflation(mView);
ShadowLooper.idleMainLooper(); ShadowLooper.idleMainLooper();
verifyBind(VISIBILITY, INT_PROPERTY); verifyBind(VISIBILITY, INT_PROPERTY);
assertThat(mModel.getValue(INT_PROPERTY), is(1)); assertThat(mModel.get(INT_PROPERTY), is(1));
Mockito.<ViewBinder>reset(mViewBinder); Mockito.<ViewBinder>reset(mViewBinder);
mModel.setValue(VISIBILITY, false); mModel.set(VISIBILITY, false);
verifyBind(INT_PROPERTY, VISIBILITY); verifyBind(INT_PROPERTY, VISIBILITY);
assertThat(mModel.getValue(INT_PROPERTY), is(2)); assertThat(mModel.get(INT_PROPERTY), is(2));
} }
private void verifyBind(PropertyKey... properties) { private void verifyBind(PropertyKey... properties) {
......
...@@ -52,23 +52,12 @@ public class PropertyModelTest { ...@@ -52,23 +52,12 @@ public class PropertyModelTest {
public static ObjectPropertyKey<String> OBJECT_PROPERTY_B = new ObjectPropertyKey<>(); public static ObjectPropertyKey<String> OBJECT_PROPERTY_B = new ObjectPropertyKey<>();
public static ObjectPropertyKey<List<Integer>> OBJECT_PROPERTY_C = new ObjectPropertyKey<>(); public static ObjectPropertyKey<List<Integer>> OBJECT_PROPERTY_C = new ObjectPropertyKey<>();
@Test
public void defaultValues() {
PropertyModel model = new PropertyModel(
BOOLEAN_PROPERTY_A, FLOAT_PROPERTY_A, INT_PROPERTY_A, OBJECT_PROPERTY_A);
assertThat(model.getValue(BOOLEAN_PROPERTY_A), equalTo(false));
assertThat(model.getValue(FLOAT_PROPERTY_A), equalTo(0f));
assertThat(model.getValue(INT_PROPERTY_A), equalTo(0));
assertThat(model.getValue(OBJECT_PROPERTY_A), equalTo(null));
}
@Test @Test
public void getAllSetProperties() { public void getAllSetProperties() {
PropertyModel model = new PropertyModel( PropertyModel model = new PropertyModel(
BOOLEAN_PROPERTY_A, FLOAT_PROPERTY_A, INT_PROPERTY_A, OBJECT_PROPERTY_A); BOOLEAN_PROPERTY_A, FLOAT_PROPERTY_A, INT_PROPERTY_A, OBJECT_PROPERTY_A);
model.setValue(BOOLEAN_PROPERTY_A, true); model.set(BOOLEAN_PROPERTY_A, true);
model.setValue(INT_PROPERTY_A, 42); model.set(INT_PROPERTY_A, 42);
Collection<PropertyKey> setProperties = model.getAllSetProperties(); Collection<PropertyKey> setProperties = model.getAllSetProperties();
assertThat(setProperties, containsInAnyOrder(BOOLEAN_PROPERTY_A, INT_PROPERTY_A)); assertThat(setProperties, containsInAnyOrder(BOOLEAN_PROPERTY_A, INT_PROPERTY_A));
assertThat(setProperties.size(), equalTo(2)); assertThat(setProperties.size(), equalTo(2));
...@@ -90,9 +79,9 @@ public class PropertyModelTest { ...@@ -90,9 +79,9 @@ public class PropertyModelTest {
model.addObserver(observer); model.addObserver(observer);
Mockito.<PropertyObserver>reset(observer); Mockito.<PropertyObserver>reset(observer);
model.setValue(key, value); model.set(key, value);
verify(observer).onPropertyChanged(model, key); verify(observer).onPropertyChanged(model, key);
assertThat(model.getValue(key), equalTo(value)); assertThat(model.get(key), equalTo(value));
model.removeObserver(observer); model.removeObserver(observer);
} }
...@@ -119,9 +108,9 @@ public class PropertyModelTest { ...@@ -119,9 +108,9 @@ public class PropertyModelTest {
model.addObserver(observer); model.addObserver(observer);
Mockito.<PropertyObserver>reset(observer); Mockito.<PropertyObserver>reset(observer);
model.setValue(key, value); model.set(key, value);
verify(observer).onPropertyChanged(model, key); verify(observer).onPropertyChanged(model, key);
assertThat(model.getValue(key), equalTo(value)); assertThat(model.get(key), equalTo(value));
model.removeObserver(observer); model.removeObserver(observer);
} }
...@@ -144,9 +133,9 @@ public class PropertyModelTest { ...@@ -144,9 +133,9 @@ public class PropertyModelTest {
model.addObserver(observer); model.addObserver(observer);
Mockito.<PropertyObserver>reset(observer); Mockito.<PropertyObserver>reset(observer);
model.setValue(key, value); model.set(key, value);
verify(observer).onPropertyChanged(model, key); verify(observer).onPropertyChanged(model, key);
assertThat(model.getValue(key), equalTo(value)); assertThat(model.get(key), equalTo(value));
model.removeObserver(observer); model.removeObserver(observer);
} }
...@@ -180,9 +169,9 @@ public class PropertyModelTest { ...@@ -180,9 +169,9 @@ public class PropertyModelTest {
model.addObserver(observer); model.addObserver(observer);
Mockito.<PropertyObserver>reset(observer); Mockito.<PropertyObserver>reset(observer);
model.setValue(key, value); model.set(key, value);
verify(observer).onPropertyChanged(model, key); verify(observer).onPropertyChanged(model, key);
assertThat(model.getValue(key), equalTo(value)); assertThat(model.get(key), equalTo(value));
model.removeObserver(observer); model.removeObserver(observer);
} }
...@@ -191,22 +180,22 @@ public class PropertyModelTest { ...@@ -191,22 +180,22 @@ public class PropertyModelTest {
public void duplicateSetChangeSuppression() { public void duplicateSetChangeSuppression() {
PropertyModel model = new PropertyModel( PropertyModel model = new PropertyModel(
BOOLEAN_PROPERTY_A, FLOAT_PROPERTY_A, INT_PROPERTY_A, OBJECT_PROPERTY_A); BOOLEAN_PROPERTY_A, FLOAT_PROPERTY_A, INT_PROPERTY_A, OBJECT_PROPERTY_A);
model.setValue(BOOLEAN_PROPERTY_A, true); model.set(BOOLEAN_PROPERTY_A, true);
model.setValue(FLOAT_PROPERTY_A, 1f); model.set(FLOAT_PROPERTY_A, 1f);
model.setValue(INT_PROPERTY_A, -1); model.set(INT_PROPERTY_A, -1);
Object obj = new Object(); Object obj = new Object();
model.setValue(OBJECT_PROPERTY_A, obj); model.set(OBJECT_PROPERTY_A, obj);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
PropertyObserver<PropertyKey> observer = Mockito.mock(PropertyObserver.class); PropertyObserver<PropertyKey> observer = Mockito.mock(PropertyObserver.class);
model.addObserver(observer); model.addObserver(observer);
Mockito.<PropertyObserver>reset(observer); Mockito.<PropertyObserver>reset(observer);
model.setValue(BOOLEAN_PROPERTY_A, true); model.set(BOOLEAN_PROPERTY_A, true);
model.setValue(FLOAT_PROPERTY_A, 1f); model.set(FLOAT_PROPERTY_A, 1f);
model.setValue(INT_PROPERTY_A, -1); model.set(INT_PROPERTY_A, -1);
model.setValue(OBJECT_PROPERTY_A, obj); model.set(OBJECT_PROPERTY_A, obj);
Mockito.verifyZeroInteractions(observer); Mockito.verifyZeroInteractions(observer);
} }
...@@ -215,7 +204,7 @@ public class PropertyModelTest { ...@@ -215,7 +204,7 @@ public class PropertyModelTest {
public void ensureValidKey() { public void ensureValidKey() {
PropertyModel model = new PropertyModel(BOOLEAN_PROPERTY_A, BOOLEAN_PROPERTY_B); PropertyModel model = new PropertyModel(BOOLEAN_PROPERTY_A, BOOLEAN_PROPERTY_B);
thrown.expect(IllegalArgumentException.class); thrown.expect(IllegalArgumentException.class);
model.setValue(BOOLEAN_PROPERTY_C, true); model.set(BOOLEAN_PROPERTY_C, true);
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
......
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