Commit 8fe43867 authored by Ioana Pandele's avatar Ioana Pandele Committed by Commit Bot

[PwdCheckAndroid] Don't show the restart button for certain errors

This requires changing the end margin to ensure that the text is spaced
16dp from the end when there is no button icon.

Screenshot on the bug.

Bug: 1134164
Change-Id: I2c24a3a2be80ed555761fcee5dc6e25e46fca286
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2443251Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Commit-Queue: Ioana Pandele <ioanap@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813171}
parent 159a0955
......@@ -4,6 +4,7 @@
found in the LICENSE file. -->
<resources>
<dimen name="check_status_text_margin">16dp</dimen>
<dimen name="check_status_description_margin_top">2dp</dimen>
<dimen name="check_status_icon_margin_horizontal">16dp</dimen>
<dimen name="check_status_icon_size">24dp</dimen>
......
......@@ -257,14 +257,18 @@ class PasswordCheckViewBinder {
private static void updateActionButton(
View view, @PasswordCheckUIStatus int status, Runnable startCheck) {
ImageButton restartButton = view.findViewById(R.id.check_status_restart_button);
if (status != PasswordCheckUIStatus.RUNNING) {
restartButton.setVisibility(View.VISIBLE);
restartButton.setClickable(true);
restartButton.setOnClickListener(unusedView -> startCheck.run());
} else {
restartButton.setVisibility(View.GONE);
restartButton.setClickable(false);
}
LinearLayout textWrapper = view.findViewById(R.id.check_status_text_layout);
boolean shouldBeVisible = shouldShowActionButton(status);
LinearLayout.LayoutParams layoutParams =
(LinearLayout.LayoutParams) textWrapper.getLayoutParams();
layoutParams.setMarginEnd(shouldBeVisible ? 0
: view.getResources().getDimensionPixelSize(
R.dimen.check_status_text_margin));
restartButton.setVisibility(shouldBeVisible ? View.VISIBLE : View.GONE);
restartButton.setOnClickListener(shouldBeVisible ? unusedView -> startCheck.run() : null);
restartButton.setClickable(shouldBeVisible);
}
private static void updateStatusIcon(
......@@ -278,6 +282,23 @@ class PasswordCheckViewBinder {
.setVisibility(getProgressBarVisibility(status));
}
private static boolean shouldShowActionButton(@PasswordCheckUIStatus int status) {
switch (status) {
case PasswordCheckUIStatus.IDLE:
case PasswordCheckUIStatus.ERROR_OFFLINE:
case PasswordCheckUIStatus.ERROR_UNKNOWN:
return true;
case PasswordCheckUIStatus.RUNNING:
case PasswordCheckUIStatus.ERROR_NO_PASSWORDS:
case PasswordCheckUIStatus.ERROR_SIGNED_OUT:
case PasswordCheckUIStatus.ERROR_QUOTA_LIMIT:
case PasswordCheckUIStatus.ERROR_QUOTA_LIMIT_ACCOUNT_CHECK:
return false;
}
assert false : "Unhandled check status " + status + "on action button update";
return false;
}
private static int getIconResource(
@PasswordCheckUIStatus int status, Integer compromisedCredentialsCount) {
switch (status) {
......
......@@ -274,6 +274,24 @@ public class PasswordCheckViewTest {
assertFalse(getActionButton().isClickable());
}
@Test
@MediumTest
public void testStatusDisplaysRestartForOffline() {
runOnUiThreadBlocking(() -> { mModel.get(ITEMS).add(buildHeader(ERROR_OFFLINE)); });
waitForListViewToHaveLength(1);
assertThat(getActionButton().getVisibility(), is(View.VISIBLE));
assertTrue(getActionButton().isClickable());
}
@Test
@MediumTest
public void testStatusDoesNotDisplayRestartForNoPasswords() {
runOnUiThreadBlocking(() -> { mModel.get(ITEMS).add(buildHeader(ERROR_NO_PASSWORDS)); });
waitForListViewToHaveLength(1);
assertThat(getActionButton().getVisibility(), is(View.GONE));
assertFalse(getActionButton().isClickable());
}
@Test
@MediumTest
public void testStatusRunningText() {
......
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