Merge "Fix WalletContextualSuggestionsController so it works for multiple cards" into udc-qpr-dev

This commit is contained in:
John Johnson
2023-08-02 19:29:23 +00:00
committed by Android (Google) Code Review
4 changed files with 36 additions and 5 deletions

View File

@@ -157,9 +157,10 @@ public class QuickAccessWalletController {
* Query the wallet cards from {@link QuickAccessWalletClient}.
*
* @param cardsRetriever a callback to retrieve wallet cards.
* @param maxCards the maximum number of cards requested from the QuickAccessWallet
*/
public void queryWalletCards(
QuickAccessWalletClient.OnWalletCardsRetrievedCallback cardsRetriever) {
QuickAccessWalletClient.OnWalletCardsRetrievedCallback cardsRetriever, int maxCards) {
if (mClock.elapsedRealtime() - mQawClientCreatedTimeMillis
> RECREATION_TIME_WINDOW) {
Log.i(TAG, "Re-creating the QAW client to avoid stale.");
@@ -175,10 +176,21 @@ public class QuickAccessWalletController {
mContext.getResources().getDimensionPixelSize(R.dimen.wallet_tile_card_view_height);
int iconSizePx = mContext.getResources().getDimensionPixelSize(R.dimen.wallet_icon_size);
GetWalletCardsRequest request =
new GetWalletCardsRequest(cardWidth, cardHeight, iconSizePx, /* maxCards= */ 1);
new GetWalletCardsRequest(cardWidth, cardHeight, iconSizePx, maxCards);
mQuickAccessWalletClient.getWalletCards(mBgExecutor, request, cardsRetriever);
}
/**
* Query the wallet cards from {@link QuickAccessWalletClient}.
*
* @param cardsRetriever a callback to retrieve wallet cards.
*/
public void queryWalletCards(
QuickAccessWalletClient.OnWalletCardsRetrievedCallback cardsRetriever) {
queryWalletCards(cardsRetriever, /* maxCards= */ 1);
}
/**
* Re-create the {@link QuickAccessWalletClient} of the controller.
*/

View File

@@ -39,7 +39,6 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
@@ -88,7 +87,7 @@ constructor(
QuickAccessWalletController.WalletChangeEvent.DEFAULT_PAYMENT_APP_CHANGE
)
walletController.updateWalletPreference()
walletController.queryWalletCards(callback)
walletController.queryWalletCards(callback, MAX_CARDS)
awaitClose {
walletController.unregisterWalletChangeObservers(
@@ -152,5 +151,6 @@ constructor(
companion object {
private const val TAG = "WalletSuggestions"
private const val MAX_CARDS = 50
}
}

View File

@@ -187,6 +187,25 @@ public class QuickAccessWalletControllerTest extends SysuiTestCase {
request.getCardHeightPx());
}
@Test
public void queryWalletCards_walletEnabled_queryMultipleCards() {
mController.queryWalletCards(mCardsRetriever, 5);
verify(mQuickAccessWalletClient)
.getWalletCards(
eq(MoreExecutors.directExecutor()), mRequestCaptor.capture(),
eq(mCardsRetriever));
GetWalletCardsRequest request = mRequestCaptor.getValue();
assertEquals(5, mRequestCaptor.getValue().getMaxCards());
assertEquals(
mContext.getResources().getDimensionPixelSize(R.dimen.wallet_tile_card_view_width),
request.getCardWidthPx());
assertEquals(
mContext.getResources().getDimensionPixelSize(R.dimen.wallet_tile_card_view_height),
request.getCardHeightPx());
}
@Test
public void queryWalletCards_walletFeatureNotAvailable_noQuery() {
when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(false);

View File

@@ -215,7 +215,7 @@ class WalletContextualSuggestionsControllerTest : SysuiTestCase() {
cards: List<WalletCard> = emptyList(),
shouldFail: Boolean = false
) {
whenever(walletController.queryWalletCards(any())).thenAnswer { invocation ->
whenever(walletController.queryWalletCards(any(), anyInt())).thenAnswer { invocation ->
with(
invocation.arguments[0] as QuickAccessWalletClient.OnWalletCardsRetrievedCallback
) {