Commit 99ecd216 authored by Michele Mancina's avatar Michele Mancina Committed by Commit Bot

Add possibility to immediately trigger the ActivityTabObserver and to propagate the hint parameter.

Bug: b/159308598
Change-Id: I99118fd33bdfef27bfbbf9551266d9a3b8f072c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2362913Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Commit-Queue: Michele Mancina <micantox@google.com>
Cr-Commit-Position: refs/heads/master@{#801717}
parent 154433da
......@@ -73,16 +73,33 @@ public class ActivityTabProvider implements Supplier<Tab> {
private Tab mTab;
/**
* Create a new {@link TabObserver} that only observes the activity tab.
* Create a new {@link TabObserver} that only observes the activity tab. It doesn't trigger
* for the initial tab being attached to after creation.
* @param tabProvider An {@link ActivityTabProvider} to get the activity tab.
*/
public ActivityTabTabObserver(ActivityTabProvider tabProvider) {
this(tabProvider, false);
}
/**
* Create a new {@link TabObserver} that only observes the activity tab. This constructor
* allows the option of triggering for the initial tab being attached to after creation.
* @param tabProvider An {@link ActivityTabProvider} to get the activity tab.
* @param shouldTrigger Whether the observer should be triggered for the initial tab after
* creation.
*/
public ActivityTabTabObserver(ActivityTabProvider tabProvider, boolean shouldTrigger) {
mTabProvider = tabProvider;
mActivityTabObserver = (tab, hint) -> {
updateObservedTab(tab);
onObservingDifferentTab(tab, hint);
onObservingDifferentTab(tab);
};
mTabProvider.addObserver(mActivityTabObserver);
if (shouldTrigger) {
mTabProvider.addObserverAndTrigger(mActivityTabObserver);
} else {
mTabProvider.addObserver(mActivityTabObserver);
}
updateObservedTab(mTabProvider.get());
}
......@@ -97,12 +114,23 @@ public class ActivityTabProvider implements Supplier<Tab> {
}
/**
* A notification that the observer has switched to observing a different tab. This will not
* be called for the initial tab being attached to after creation.
* A notification that the observer has switched to observing a different tab.
* @param tab The tab that the observer is now observing. This can be null.
* @deprecated Use {@link #onObservingDifferentTab(Tab, boolean)} instead.
*/
@Deprecated
protected void onObservingDifferentTab(Tab tab) {}
/**
* A notification that the observer has switched to observing a different tab. This can be
* called a first time with the {@code hint} parameter set to true, indicating that a new
* tab is going to be selected.
* @param tab The tab that the observer is now observing. This can be null.
* @param hint Whether the change event is a hint that a tab change is likely. If true, the
* provided tab may still be frozen and is not yet selected.
*/
protected void onObservingDifferentTab(Tab tab, boolean hint) {}
/**
* Clean up any state held by this observer.
*/
......
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