Commit 7892f11e authored by Sky Malice's avatar Sky Malice Committed by Commit Bot

Update MVC documentation to be more opinionated about view acquisition.

Bug: 1135799
Change-Id: I15d6bb6b866ce40c573eb251c53390229e26c541
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2499167Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Sky Malice <skym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825376}
parent 50ffd5be
......@@ -24,21 +24,19 @@ The class responsible for setting up the component. This should be the only publ
```java
public class SimpleProgressCoordinator {
private SimpleProgressMediator mMediator;
private final SimpleProgressMediator mMediator;
private final View mView;
public SimpleProgressCoordinator (Tab tabProgressBarIsFor) {
public SimpleProgressCoordinator (Tab tabProgressBarIsFor, Context context) {
PropertyModel model = new PropertyModel.Builder(SimpleProgressProperties.ALL_KEYS)
.with(SimpleProgressProperties.PROGRESS_FRACTION, 0f)
.with(SimpleProgressProperties.FOREGROUND_COLOR, Color.RED)
.build();
// This view can come from multiple places, in this case we find it in the existing
// view hierarchy.
View view = tabProgressBarIsFor.getActivity().findViewById(
R.id.my_simple_progress_bar);
mView = LayoutInflater.from(context).inflate(R.layout.my_simple_progress_bar);
PropertyModelChangeProcessor.create(model, view, SimpleProgressViewBinder::bind);
PropertyModelChangeProcessor.create(model, mView, SimpleProgressViewBinder::bind);
mMediator = new SimpleProgressMediator(model, tabProgressBarIsFor);
}
......@@ -46,8 +44,13 @@ public class SimpleProgressCoordinator {
public void destroy() {
mMediator.destroy();
}
public View getView() {
return mView;
}
}
```
Note that there are several ways to acquire the view. If this MVC component owns its own layout file, then it should inflate the view, as shown above. #getView() allows the parent component's coordinator to add this component's view to the hierarchy. However, if the desired view for this MVC component is part of some other parent component's layout file, then the parent component should be responsible for calling findViewById() and passing the right view into this coordinator. See [this email thread](http://g/clank-frontend/u8x2PBa5EfI) for related discussion.
#### SimpleProgressMediator
The class that handles all of the signals coming from the outside world. External classes should never interact with this class directly.
......@@ -55,9 +58,8 @@ The class that handles all of the signals coming from the outside world. Externa
```java
class SimpleProgressMediator extends EmptyTabObserver {
private PropertyModel mModel;
private Tab mObservedTab;
private final PropertyModel mModel;
private final Tab mObservedTab;
public SimpleProgressMediator(PropertyModel model, Tab tabProgressBarIsFor) {
mModel = model;
......@@ -118,4 +120,3 @@ class SimpleProgressProperties {
public static final PropertyKey[] ALL_KEYS = {PROGRESS_FRACTION, FOREGROUND_COLOR};
}
```
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