Merge "Update the handleUpdateState() of Wallet Tile." into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f7ac580ec2
@@ -1637,8 +1637,12 @@
|
|||||||
<string name="wallet_button_label_device_unlocked">Show all</string>
|
<string name="wallet_button_label_device_unlocked">Show all</string>
|
||||||
<!-- Label of the button underneath the card carousel when device is locked. [CHAR LIMIT=NONE] -->
|
<!-- Label of the button underneath the card carousel when device is locked. [CHAR LIMIT=NONE] -->
|
||||||
<string name="wallet_button_label_device_locked">Unlock to pay</string>
|
<string name="wallet_button_label_device_locked">Unlock to pay</string>
|
||||||
<!-- Secondary label of the quick access wallet tile. [CHAR LIMIT=32] -->
|
<!-- Secondary label of the quick access wallet tile if active. [CHAR LIMIT=32] -->
|
||||||
<string name="wallet_secondary_label">Ready</string>
|
<string name="wallet_secondary_label_active">Ready</string>
|
||||||
|
<!-- Secondary label of the quick access wallet tile if no card. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="wallet_secondary_label_no_card">Set up payment</string>
|
||||||
|
<!-- Secondary label of the quick access wallet tile if device locked. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="wallet_secondary_label_device_locked">Unlock to use</string>
|
||||||
<!-- Message shown when an unknown failure occurred when fetching cards. [CHAR LIMIT=NONE] -->
|
<!-- Message shown when an unknown failure occurred when fetching cards. [CHAR LIMIT=NONE] -->
|
||||||
<string name="wallet_error_generic">There was a problem getting your cards, please try again later</string>
|
<string name="wallet_error_generic">There was a problem getting your cards, please try again later</string>
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
|
|||||||
private final FeatureFlags mFeatureFlags;
|
private final FeatureFlags mFeatureFlags;
|
||||||
|
|
||||||
@VisibleForTesting Drawable mCardViewDrawable;
|
@VisibleForTesting Drawable mCardViewDrawable;
|
||||||
|
private boolean mHasCard;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public QuickAccessWalletTile(
|
public QuickAccessWalletTile(
|
||||||
@@ -128,15 +129,27 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
|
|||||||
state.icon = ResourceIcon.get(R.drawable.ic_qs_wallet);
|
state.icon = ResourceIcon.get(R.drawable.ic_qs_wallet);
|
||||||
boolean isDeviceLocked = !mKeyguardStateController.isUnlocked();
|
boolean isDeviceLocked = !mKeyguardStateController.isUnlocked();
|
||||||
if (mQuickAccessWalletClient.isWalletFeatureAvailable()) {
|
if (mQuickAccessWalletClient.isWalletFeatureAvailable()) {
|
||||||
state.state = isDeviceLocked ? Tile.STATE_INACTIVE : Tile.STATE_ACTIVE;
|
if (mHasCard) {
|
||||||
state.secondaryLabel = isDeviceLocked
|
if (isDeviceLocked) {
|
||||||
? null
|
state.state = Tile.STATE_INACTIVE;
|
||||||
: mContext.getString(R.string.wallet_secondary_label);
|
state.secondaryLabel =
|
||||||
|
mContext.getString(R.string.wallet_secondary_label_device_locked);
|
||||||
|
} else {
|
||||||
|
state.state = Tile.STATE_ACTIVE;
|
||||||
|
state.secondaryLabel =
|
||||||
|
mContext.getString(R.string.wallet_secondary_label_active);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
state.state = Tile.STATE_INACTIVE;
|
||||||
|
state.secondaryLabel = mContext.getString(R.string.wallet_secondary_label_no_card);
|
||||||
|
}
|
||||||
state.stateDescription = state.secondaryLabel;
|
state.stateDescription = state.secondaryLabel;
|
||||||
} else {
|
} else {
|
||||||
state.state = Tile.STATE_UNAVAILABLE;
|
state.state = Tile.STATE_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
state.sideViewDrawable = mCardViewDrawable;
|
if (!isDeviceLocked) {
|
||||||
|
state.sideViewDrawable = mCardViewDrawable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -184,10 +197,12 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
|
|||||||
if (cards.isEmpty()) {
|
if (cards.isEmpty()) {
|
||||||
Log.d(TAG, "No wallet cards exist.");
|
Log.d(TAG, "No wallet cards exist.");
|
||||||
mCardViewDrawable = null;
|
mCardViewDrawable = null;
|
||||||
|
mHasCard = false;
|
||||||
refreshState();
|
refreshState();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mCardViewDrawable = cards.get(0).getCardImage().loadDrawable(mContext);
|
mCardViewDrawable = cards.get(0).getCardImage().loadDrawable(mContext);
|
||||||
|
mHasCard = true;
|
||||||
refreshState();
|
refreshState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,6 +210,7 @@ public class QuickAccessWalletTile extends QSTileImpl<QSTile.State> {
|
|||||||
public void onWalletCardRetrievalError(@NonNull GetWalletCardsError error) {
|
public void onWalletCardRetrievalError(@NonNull GetWalletCardsError error) {
|
||||||
Log.w(TAG, "Error retrieve wallet cards");
|
Log.w(TAG, "Error retrieve wallet cards");
|
||||||
mCardViewDrawable = null;
|
mCardViewDrawable = null;
|
||||||
|
mHasCard = false;
|
||||||
refreshState();
|
refreshState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
|
|||||||
when(mHost.getContext()).thenReturn(mContext);
|
when(mHost.getContext()).thenReturn(mContext);
|
||||||
when(mHost.getUiEventLogger()).thenReturn(mUiEventLogger);
|
when(mHost.getUiEventLogger()).thenReturn(mUiEventLogger);
|
||||||
when(mFeatureFlags.isQuickAccessWalletEnabled()).thenReturn(true);
|
when(mFeatureFlags.isQuickAccessWalletEnabled()).thenReturn(true);
|
||||||
|
when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(true);
|
||||||
|
|
||||||
mTile = new QuickAccessWalletTile(
|
mTile = new QuickAccessWalletTile(
|
||||||
mHost,
|
mHost,
|
||||||
@@ -189,11 +190,11 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandleUpdateState_updateLabelAndIcon() {
|
public void testHandleUpdateState_updateLabelAndIcon() {
|
||||||
QSTile.Icon icon = QSTileImpl.ResourceIcon.get(R.drawable.ic_qs_wallet);
|
|
||||||
QSTile.State state = new QSTile.State();
|
QSTile.State state = new QSTile.State();
|
||||||
|
QSTile.Icon icon = QSTileImpl.ResourceIcon.get(R.drawable.ic_qs_wallet);
|
||||||
when(mQuickAccessWalletClient.getServiceLabel()).thenReturn("QuickAccessWallet");
|
when(mQuickAccessWalletClient.getServiceLabel()).thenReturn("QuickAccessWallet");
|
||||||
|
|
||||||
mTile.handleUpdateState(state, new Object());
|
mTile.handleUpdateState(state, null);
|
||||||
|
|
||||||
assertEquals("QuickAccessWallet", state.label.toString());
|
assertEquals("QuickAccessWallet", state.label.toString());
|
||||||
assertTrue(state.label.toString().contentEquals(state.contentDescription));
|
assertTrue(state.label.toString().contentEquals(state.contentDescription));
|
||||||
@@ -201,41 +202,63 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandleUpdateState_deviceLocked_tileInactive() {
|
public void testHandleUpdateState_hasCard_deviceLocked_tileInactive() {
|
||||||
QSTile.State state = new QSTile.State();
|
|
||||||
when(mKeyguardStateController.isUnlocked()).thenReturn(false);
|
when(mKeyguardStateController.isUnlocked()).thenReturn(false);
|
||||||
when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(true);
|
QSTile.State state = new QSTile.State();
|
||||||
|
setUpWalletCard(/* hasCard= */ true);
|
||||||
|
|
||||||
mTile.handleUpdateState(state, new Object());
|
mTile.handleUpdateState(state, null);
|
||||||
|
|
||||||
assertEquals(Tile.STATE_INACTIVE, state.state);
|
assertEquals(Tile.STATE_INACTIVE, state.state);
|
||||||
assertNull(state.stateDescription);
|
assertEquals(
|
||||||
|
mContext.getString(R.string.wallet_secondary_label_device_locked),
|
||||||
|
state.secondaryLabel);
|
||||||
|
assertNotNull(state.stateDescription);
|
||||||
|
assertNull(state.sideViewDrawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandleUpdateState_deviceLocked_tileActive() {
|
public void testHandleUpdateState_hasCard_deviceUnlocked_tileActive() {
|
||||||
QSTile.State state = new QSTile.State();
|
|
||||||
when(mKeyguardStateController.isUnlocked()).thenReturn(true);
|
when(mKeyguardStateController.isUnlocked()).thenReturn(true);
|
||||||
when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(true);
|
QSTile.State state = new QSTile.State();
|
||||||
|
setUpWalletCard(/* hasCard= */ true);
|
||||||
|
|
||||||
mTile.handleUpdateState(state, new Object());
|
mTile.handleUpdateState(state, null);
|
||||||
|
|
||||||
assertEquals(Tile.STATE_ACTIVE, state.state);
|
assertEquals(Tile.STATE_ACTIVE, state.state);
|
||||||
assertTrue(state.secondaryLabel.toString().contentEquals(state.stateDescription));
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
getContext().getString(R.string.wallet_secondary_label),
|
mContext.getString(R.string.wallet_secondary_label_active),
|
||||||
state.secondaryLabel.toString());
|
state.secondaryLabel);
|
||||||
|
assertNotNull(state.stateDescription);
|
||||||
|
assertNotNull(state.sideViewDrawable);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHandleUpdateState_noCard_tileInactive() {
|
||||||
|
QSTile.State state = new QSTile.State();
|
||||||
|
setUpWalletCard(/* hasCard= */ false);
|
||||||
|
|
||||||
|
mTile.handleUpdateState(state, null);
|
||||||
|
|
||||||
|
assertEquals(Tile.STATE_INACTIVE, state.state);
|
||||||
|
assertEquals(
|
||||||
|
mContext.getString(R.string.wallet_secondary_label_no_card),
|
||||||
|
state.secondaryLabel);
|
||||||
|
assertNotNull(state.stateDescription);
|
||||||
|
assertNull(state.sideViewDrawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandleUpdateState_qawFeatureUnavailable_tileUnavailable() {
|
public void testHandleUpdateState_qawFeatureUnavailable_tileUnavailable() {
|
||||||
QSTile.State state = new QSTile.State();
|
|
||||||
when(mKeyguardStateController.isUnlocked()).thenReturn(true);
|
|
||||||
when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(false);
|
when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(false);
|
||||||
|
QSTile.State state = new QSTile.State();
|
||||||
|
|
||||||
mTile.handleUpdateState(state, new Object());
|
mTile.handleUpdateState(state, null);
|
||||||
|
|
||||||
assertEquals(Tile.STATE_UNAVAILABLE, state.state);
|
assertEquals(Tile.STATE_UNAVAILABLE, state.state);
|
||||||
|
assertNull(state.stateDescription);
|
||||||
|
assertNull(state.sideViewDrawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -258,23 +281,16 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandleSetListening_queryCards_hasCards_updateSideViewDrawable() {
|
public void testQueryCards_hasCards_updateSideViewDrawable() {
|
||||||
GetWalletCardsResponse response =
|
when(mKeyguardStateController.isUnlocked()).thenReturn(true);
|
||||||
new GetWalletCardsResponse(
|
setUpWalletCard(/* hasCard= */ true);
|
||||||
Collections.singletonList(createWalletCard(mContext)), 0);
|
|
||||||
|
|
||||||
mTile.handleSetListening(true);
|
|
||||||
|
|
||||||
verify(mQuickAccessWalletClient).getWalletCards(any(), any(), mCallbackCaptor.capture());
|
|
||||||
|
|
||||||
mCallbackCaptor.getValue().onWalletCardsRetrieved(response);
|
|
||||||
mTestableLooper.processAllMessages();
|
|
||||||
|
|
||||||
assertNotNull(mTile.getState().sideViewDrawable);
|
assertNotNull(mTile.getState().sideViewDrawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testState_queryCards_hasCards_then_noCards() {
|
public void testState_queryCards_hasCards_then_noCards() {
|
||||||
|
when(mKeyguardStateController.isUnlocked()).thenReturn(true);
|
||||||
GetWalletCardsResponse responseWithCards =
|
GetWalletCardsResponse responseWithCards =
|
||||||
new GetWalletCardsResponse(
|
new GetWalletCardsResponse(
|
||||||
Collections.singletonList(createWalletCard(mContext)), 0);
|
Collections.singletonList(createWalletCard(mContext)), 0);
|
||||||
@@ -304,22 +320,14 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandleSetListening_queryCards_noCards_notUpdateSideViewDrawable() {
|
public void testQueryCards_noCards_notUpdateSideViewDrawable() {
|
||||||
QSTile.State state = new QSTile.State();
|
setUpWalletCard(/* hasCard= */ false);
|
||||||
GetWalletCardsResponse response = new GetWalletCardsResponse(Collections.EMPTY_LIST, 0);
|
|
||||||
|
|
||||||
mTile.handleSetListening(true);
|
|
||||||
|
|
||||||
verify(mQuickAccessWalletClient).getWalletCards(any(), any(), mCallbackCaptor.capture());
|
|
||||||
|
|
||||||
mCallbackCaptor.getValue().onWalletCardsRetrieved(response);
|
|
||||||
mTestableLooper.processAllMessages();
|
|
||||||
|
|
||||||
assertNull(mTile.getState().sideViewDrawable);
|
assertNull(mTile.getState().sideViewDrawable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandleSetListening_queryCards_error_notUpdateSideViewDrawable() {
|
public void testQueryCards_error_notUpdateSideViewDrawable() {
|
||||||
String errorMessage = "getWalletCardsError";
|
String errorMessage = "getWalletCardsError";
|
||||||
GetWalletCardsError error = new GetWalletCardsError(CARD_IMAGE, errorMessage);
|
GetWalletCardsError error = new GetWalletCardsError(CARD_IMAGE, errorMessage);
|
||||||
|
|
||||||
@@ -340,6 +348,21 @@ public class QuickAccessWalletTileTest extends SysuiTestCase {
|
|||||||
verifyZeroInteractions(mQuickAccessWalletClient);
|
verifyZeroInteractions(mQuickAccessWalletClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setUpWalletCard(boolean hasCard) {
|
||||||
|
GetWalletCardsResponse response =
|
||||||
|
new GetWalletCardsResponse(
|
||||||
|
hasCard
|
||||||
|
? Collections.singletonList(createWalletCard(mContext))
|
||||||
|
: Collections.EMPTY_LIST, 0);
|
||||||
|
|
||||||
|
mTile.handleSetListening(true);
|
||||||
|
|
||||||
|
verify(mQuickAccessWalletClient).getWalletCards(any(), any(), mCallbackCaptor.capture());
|
||||||
|
|
||||||
|
mCallbackCaptor.getValue().onWalletCardsRetrieved(response);
|
||||||
|
mTestableLooper.processAllMessages();
|
||||||
|
}
|
||||||
|
|
||||||
private WalletCard createWalletCard(Context context) {
|
private WalletCard createWalletCard(Context context) {
|
||||||
PendingIntent pendingIntent =
|
PendingIntent pendingIntent =
|
||||||
PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);
|
PendingIntent.getActivity(context, 0, mWalletIntent, PendingIntent.FLAG_IMMUTABLE);
|
||||||
|
|||||||
Reference in New Issue
Block a user