Commit b4076165 authored by Alice Wang's avatar Alice Wang Committed by Commit Bot

[Signin][Android] Destroy account picker bottomsheet in observer

This CL destroys the account picker bottomsheet by registering a
BottomSheetObserver object in BottomSheetController.

Bug: 1063362
Change-Id: Ibfcc6e27fc8c5438589d49f4e753b76321d5604c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2241653
Commit-Queue: Alice Wang <aliceywang@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#779304}
parent 69382fce
......@@ -9,6 +9,8 @@ import android.content.Context;
import androidx.annotation.MainThread;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetObserver;
import org.chromium.chrome.browser.widget.bottomsheet.EmptyBottomSheetObserver;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
......@@ -17,6 +19,16 @@ import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
*/
public class AccountPickerBottomSheetCoordinator {
private final AccountPickerCoordinator mAccountPickerCoordinator;
private final BottomSheetController mBottomSheetController;
private final BottomSheetObserver mBottomSheetObserver = new EmptyBottomSheetObserver() {
@Override
public void onSheetStateChanged(int newState) {
super.onSheetStateChanged(newState);
if (newState == BottomSheetController.SheetState.HIDDEN) {
AccountPickerBottomSheetCoordinator.this.destroy();
}
}
};
/**
* Constructs the AccountPickerBottomSheetCoordinator and shows the
......@@ -29,16 +41,19 @@ public class AccountPickerBottomSheetCoordinator {
AccountPickerBottomSheetView view = new AccountPickerBottomSheetView(context);
mAccountPickerCoordinator = new AccountPickerCoordinator(
view.getAccountPickerItemView(), accountPickerListener, null);
mBottomSheetController = bottomSheetController;
PropertyModel model = AccountPickerBottomSheetProperties.createModel();
PropertyModelChangeProcessor.create(model, view, AccountPickerBottomSheetViewBinder::bind);
bottomSheetController.requestShowContent(view, true);
mBottomSheetController.addObserver(mBottomSheetObserver);
mBottomSheetController.requestShowContent(view, true);
}
/**
* Releases the resources used by AccountPickerBottomSheetCoordinator.
*/
@MainThread
public void destroy() {
private void destroy() {
mAccountPickerCoordinator.destroy();
mBottomSheetController.removeObserver(mBottomSheetObserver);
}
}
......@@ -15,7 +15,6 @@ import static org.mockito.MockitoAnnotations.initMocks;
import androidx.test.filters.MediumTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
......@@ -86,13 +85,6 @@ public class AccountPickerBottomSheetTest {
mAccountPickerListenerMock);
}
@After
public void tearDown() {
if (mAccountPickerBottomSheetCoordinator != null) {
TestThreadUtils.runOnUiThreadBlocking(mAccountPickerBottomSheetCoordinator::destroy);
}
}
@Test
@MediumTest
public void testTitle() {
......
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