Merge "Fix WalletContextualSuggestionsController so it works for multiple cards" into udc-qpr-dev
This commit is contained in:
@@ -157,9 +157,10 @@ public class QuickAccessWalletController {
|
|||||||
* Query the wallet cards from {@link QuickAccessWalletClient}.
|
* Query the wallet cards from {@link QuickAccessWalletClient}.
|
||||||
*
|
*
|
||||||
* @param cardsRetriever a callback to retrieve wallet cards.
|
* @param cardsRetriever a callback to retrieve wallet cards.
|
||||||
|
* @param maxCards the maximum number of cards requested from the QuickAccessWallet
|
||||||
*/
|
*/
|
||||||
public void queryWalletCards(
|
public void queryWalletCards(
|
||||||
QuickAccessWalletClient.OnWalletCardsRetrievedCallback cardsRetriever) {
|
QuickAccessWalletClient.OnWalletCardsRetrievedCallback cardsRetriever, int maxCards) {
|
||||||
if (mClock.elapsedRealtime() - mQawClientCreatedTimeMillis
|
if (mClock.elapsedRealtime() - mQawClientCreatedTimeMillis
|
||||||
> RECREATION_TIME_WINDOW) {
|
> RECREATION_TIME_WINDOW) {
|
||||||
Log.i(TAG, "Re-creating the QAW client to avoid stale.");
|
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);
|
mContext.getResources().getDimensionPixelSize(R.dimen.wallet_tile_card_view_height);
|
||||||
int iconSizePx = mContext.getResources().getDimensionPixelSize(R.dimen.wallet_icon_size);
|
int iconSizePx = mContext.getResources().getDimensionPixelSize(R.dimen.wallet_icon_size);
|
||||||
GetWalletCardsRequest request =
|
GetWalletCardsRequest request =
|
||||||
new GetWalletCardsRequest(cardWidth, cardHeight, iconSizePx, /* maxCards= */ 1);
|
new GetWalletCardsRequest(cardWidth, cardHeight, iconSizePx, maxCards);
|
||||||
mQuickAccessWalletClient.getWalletCards(mBgExecutor, request, cardsRetriever);
|
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.
|
* Re-create the {@link QuickAccessWalletClient} of the controller.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import kotlinx.coroutines.flow.SharingStarted
|
|||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.emptyFlow
|
|
||||||
import kotlinx.coroutines.flow.flatMapLatest
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.stateIn
|
import kotlinx.coroutines.flow.stateIn
|
||||||
@@ -88,7 +87,7 @@ constructor(
|
|||||||
QuickAccessWalletController.WalletChangeEvent.DEFAULT_PAYMENT_APP_CHANGE
|
QuickAccessWalletController.WalletChangeEvent.DEFAULT_PAYMENT_APP_CHANGE
|
||||||
)
|
)
|
||||||
walletController.updateWalletPreference()
|
walletController.updateWalletPreference()
|
||||||
walletController.queryWalletCards(callback)
|
walletController.queryWalletCards(callback, MAX_CARDS)
|
||||||
|
|
||||||
awaitClose {
|
awaitClose {
|
||||||
walletController.unregisterWalletChangeObservers(
|
walletController.unregisterWalletChangeObservers(
|
||||||
@@ -152,5 +151,6 @@ constructor(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "WalletSuggestions"
|
private const val TAG = "WalletSuggestions"
|
||||||
|
private const val MAX_CARDS = 50
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,6 +187,25 @@ public class QuickAccessWalletControllerTest extends SysuiTestCase {
|
|||||||
request.getCardHeightPx());
|
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
|
@Test
|
||||||
public void queryWalletCards_walletFeatureNotAvailable_noQuery() {
|
public void queryWalletCards_walletFeatureNotAvailable_noQuery() {
|
||||||
when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(false);
|
when(mQuickAccessWalletClient.isWalletFeatureAvailable()).thenReturn(false);
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ class WalletContextualSuggestionsControllerTest : SysuiTestCase() {
|
|||||||
cards: List<WalletCard> = emptyList(),
|
cards: List<WalletCard> = emptyList(),
|
||||||
shouldFail: Boolean = false
|
shouldFail: Boolean = false
|
||||||
) {
|
) {
|
||||||
whenever(walletController.queryWalletCards(any())).thenAnswer { invocation ->
|
whenever(walletController.queryWalletCards(any(), anyInt())).thenAnswer { invocation ->
|
||||||
with(
|
with(
|
||||||
invocation.arguments[0] as QuickAccessWalletClient.OnWalletCardsRetrievedCallback
|
invocation.arguments[0] as QuickAccessWalletClient.OnWalletCardsRetrievedCallback
|
||||||
) {
|
) {
|
||||||
|
|||||||
Reference in New Issue
Block a user