Remove extra padding and dismiss gesture listener

Also update border on zero-state button per mocks.

Bug: 152879981
Test: atest QuickAccessWalletRoboTests
Test: manual
Change-Id: Ie444ae1b8e9c81ffc81d2a329e9a698b0f46eeae
diff --git a/res/drawable/wallet_empty_state_bg.xml b/res/drawable/wallet_empty_state_bg.xml
index 58ea044..170253c 100644
--- a/res/drawable/wallet_empty_state_bg.xml
+++ b/res/drawable/wallet_empty_state_bg.xml
@@ -17,8 +17,8 @@
 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
     <item>
         <shape>
-            <stroke android:width="1dp" android:color="@*android:color/foreground_material_dark"/>
-            <corners android:radius="12dp"/>
+            <stroke android:width="1dp" android:color="#66FFFFFF"/>
+            <corners android:radius="20dp"/>
         </shape>
     </item>
     <item android:drawable="?android:selectableItemBackground"/>
diff --git a/res/layout/wallet_card_view.xml b/res/layout/wallet_card_view.xml
index 3b1f7c1..3e2ad4c 100644
--- a/res/layout/wallet_card_view.xml
+++ b/res/layout/wallet_card_view.xml
@@ -24,7 +24,7 @@
         android:id="@+id/card"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_margin="@dimen/card_margin"
+        android:layout_marginHorizontal="@dimen/card_margin"
         android:foreground="?android:attr/selectableItemBackground"
         app:cardBackgroundColor="@android:color/transparent"
         app:cardElevation="12dp">
diff --git a/res/layout/wallet_view.xml b/res/layout/wallet_view.xml
index ffc7e70..a35feed 100644
--- a/res/layout/wallet_view.xml
+++ b/res/layout/wallet_view.xml
@@ -15,11 +15,9 @@
   ~ limitations under the License.
   -->
 
-<FrameLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:layout_marginTop="24dp"
     android:clipChildren="false">
 
     <LinearLayout
@@ -41,9 +39,8 @@
                 android:layout_height="wrap_content"
                 android:layout_gravity="center"
                 android:importantForAccessibility="no"
-                android:paddingBottom="4dp"
                 android:drawablePadding="8dp"
-                android:textAlignment="center"/>
+                android:textAlignment="center" />
 
             <ImageView
                 android:id="@+id/menu_btn"
@@ -55,8 +52,7 @@
                 android:tint="@color/wallet_more_vert"
                 android:contentDescription="@strings/accessibility_menu"
                 android:background="?android:attr/selectableItemBackgroundBorderless"
-                android:theme="@style/Wallet.Theme"
-            />
+                android:theme="@style/Wallet.Theme" />
         </FrameLayout>
 
         <com.android.systemui.plugin.globalactions.wallet.WalletCardCarousel
@@ -64,25 +60,22 @@
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:clipChildren="false"
-            android:clipToPadding="false"/>
+            android:clipToPadding="false" />
     </LinearLayout>
 
-    <include layout="@layout/empty_state_view"/>
+    <include layout="@layout/empty_state_view" />
 
     <TextView
         android:id="@+id/error_view"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_marginTop="80dp"
-        android:layout_marginBottom="50dp"
-        android:layout_marginLeft="24dp"
-        android:layout_marginRight="24dp"
+        android:layout_marginHorizontal="40dp"
         android:textSize="14sp"
         android:textColor="#DADCE0"
-        android:padding="15dp"
         android:elevation="7dp"
         android:background="@drawable/rounded_corners"
         android:gravity="center"
-        android:visibility="gone"/>
+        android:visibility="gone" />
 
 </FrameLayout>
diff --git a/src/com/android/systemui/plugin/globalactions/wallet/WalletCardCarousel.java b/src/com/android/systemui/plugin/globalactions/wallet/WalletCardCarousel.java
index 1cdec2d..da7cfb5 100644
--- a/src/com/android/systemui/plugin/globalactions/wallet/WalletCardCarousel.java
+++ b/src/com/android/systemui/plugin/globalactions/wallet/WalletCardCarousel.java
@@ -24,10 +24,8 @@
 import android.os.Build.VERSION_CODES;
 import android.util.AttributeSet;
 import android.util.DisplayMetrics;
-import android.view.GestureDetector;
 import android.view.HapticFeedbackConstants;
 import android.view.LayoutInflater;
-import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityEvent;
@@ -68,7 +66,6 @@
     private final float mCornerRadiusPx;
     private final int mTotalCardWidth;
     private final float mCardEdgeToCenterDistance;
-    private final GestureDetector mOnTapGestureDetector;
 
     private OnSelectionListener mSelectionListener;
     private OnCardScrollListener mCardScrollListener;
@@ -92,11 +89,6 @@
          * The card was clicked.
          */
         void onCardClicked(@NonNull WalletCardViewInfo card);
-
-        /**
-         * The view was tapped outside of a card view.
-         */
-        void onDismissGesture();
     }
 
     interface OnCardScrollListener {
@@ -125,7 +117,6 @@
         mWalletCardAdapter = new WalletCardAdapter();
         mWalletCardAdapter.setHasStableIds(true);
         setAdapter(mWalletCardAdapter);
-        mOnTapGestureDetector = new GestureDetector(context, new OnTapGestureDetector());
         ViewCompat.setAccessibilityDelegate(this, new CardCarouselAccessibilityDelegate(this));
         updatePadding(mScreenWidth);
     }
@@ -154,7 +145,8 @@
     }
 
     /**
-     * The padding pushes the first and last cards in the list to the center when they are selected.
+     * The padding pushes the first and last cards in the list to the center when they are
+     * selected.
      */
     private void updatePadding(int viewWidth) {
         int paddingHorizontal = (viewWidth - mTotalCardWidth) / 2 - mCardMarginPx;
@@ -176,14 +168,6 @@
         }
     }
 
-    @Override
-    public boolean onTouchEvent(MotionEvent e) {
-        if (mOnTapGestureDetector.onTouchEvent(e)) {
-            mSelectionListener.onDismissGesture();
-        }
-        return super.onTouchEvent(e);
-    }
-
     void setSelectionListener(OnSelectionListener selectionListener) {
         mSelectionListener = selectionListener;
     }
@@ -445,18 +429,6 @@
         }
     }
 
-    private static class OnTapGestureDetector extends GestureDetector.SimpleOnGestureListener {
-        @Override
-        public boolean onSingleTapUp(MotionEvent e) {
-            return true;
-        }
-
-        @Override
-        public boolean onSingleTapConfirmed(MotionEvent e) {
-            return true;
-        }
-    }
-
     private class CardCarouselAccessibilityDelegate extends RecyclerViewAccessibilityDelegate {
 
         private CardCarouselAccessibilityDelegate(@NonNull RecyclerView recyclerView) {
diff --git a/src/com/android/systemui/plugin/globalactions/wallet/WalletPanelViewController.java b/src/com/android/systemui/plugin/globalactions/wallet/WalletPanelViewController.java
index 1fd75a8..6221ca6 100644
--- a/src/com/android/systemui/plugin/globalactions/wallet/WalletPanelViewController.java
+++ b/src/com/android/systemui/plugin/globalactions/wallet/WalletPanelViewController.java
@@ -71,6 +71,7 @@
     private boolean mIsDismissed;
     private boolean mHasRegisteredListener;
     private String mSelectedCardId;
+    private boolean mResponseReceived;
 
     public WalletPanelViewController(
             Context sysuiContext,
@@ -161,6 +162,14 @@
         GetWalletCardsRequest request =
                 new GetWalletCardsRequest(cardWidthPx, cardHeightPx, iconSizePx, MAX_CARDS);
         mWalletClient.getWalletCards(mExecutor, request, this);
+        mHandler.postDelayed(this::showErrorIfResponseUnavailable, 2000);
+    }
+
+    private void showErrorIfResponseUnavailable() {
+        if (mIsDismissed || mResponseReceived) {
+            return;
+        }
+        mWalletView.showErrorMessage(null);
     }
 
     /**
@@ -183,6 +192,7 @@
             if (mIsDismissed) {
                 return;
             }
+            mResponseReceived = true;
             if (data.isEmpty()) {
                 showEmptyStateView();
             } else {
@@ -202,6 +212,7 @@
             if (mIsDismissed) {
                 return;
             }
+            mResponseReceived = true;
             mWalletView.showErrorMessage(error.getMessage());
         });
     }
@@ -241,19 +252,6 @@
         selectCard();
     }
 
-    /**
-     * Implements {@link WalletCardCarousel.OnSelectionListener}. Called when the user taps on the
-     * view outside of a card target which should cause the wallet to be dismissed.
-     */
-    @Override
-    public void onDismissGesture() {
-        if (mIsDismissed) {
-            return;
-        }
-        mPluginCallbacks.dismissGlobalActionsMenu();
-        onDismissed();
-    }
-
     private void selectCard() {
         mHandler.removeCallbacks(mSelectionRunnable);
         String selectedCardId = mSelectedCardId;
diff --git a/tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/WalletPanelViewControllerTest.java b/tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/WalletPanelViewControllerTest.java
index 999faa8..826cb2c 100644
--- a/tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/WalletPanelViewControllerTest.java
+++ b/tests/robolectric/src/com/android/systemui/plugin/globalactions/wallet/WalletPanelViewControllerTest.java
@@ -26,6 +26,8 @@
 import static org.mockito.Mockito.when;
 import static org.robolectric.Shadows.shadowOf;
 
+import static java.util.concurrent.TimeUnit.SECONDS;
+
 import android.app.Application;
 import android.app.PendingIntent;
 import android.content.ComponentName;
@@ -62,6 +64,7 @@
 import org.mockito.Captor;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.annotation.Config;
 import org.robolectric.shadows.ShadowLog;
@@ -438,6 +441,28 @@
     }
 
     @Test
+    public void onWalletCardsRetrieved_isDelayed_showsError() {
+        WalletView walletView = (WalletView) mViewController.getPanelContent();
+        TextView errorView = walletView.getErrorView();
+        ViewGroup cardCarouselContainer = walletView.getCardCarouselContainer();
+        ViewGroup emptyStateView = walletView.getEmptyStateView();
+
+        mViewController.queryWalletCards();
+        Robolectric.getForegroundThreadScheduler().advanceBy(3, SECONDS);
+
+        assertThat(emptyStateView.getVisibility()).isEqualTo(View.GONE);
+        assertThat(cardCarouselContainer.getVisibility()).isEqualTo(View.GONE);
+        assertThat(errorView.getVisibility()).isEqualTo(View.VISIBLE);
+
+        GetWalletCardsResponse response = new GetWalletCardsResponse(Collections.emptyList(), 0);
+        mViewController.onWalletCardsRetrieved(response);
+
+        assertThat(emptyStateView.getVisibility()).isEqualTo(View.VISIBLE);
+        assertThat(cardCarouselContainer.getVisibility()).isEqualTo(View.GONE);
+        assertThat(errorView.getVisibility()).isEqualTo(View.GONE);
+    }
+
+    @Test
     public void onWalletServiceEvent_tapStarted_dismissesGlobalActionsMenu() {
         mViewController.queryWalletCards();
         verify(mWalletClient).addWalletServiceEventListener(mListenerCaptor.capture());
@@ -516,7 +541,7 @@
     }
 
     @Test
-    public void onSingleTapUp_dismissesWallet() {
+    public void onSingleTapUp_doesNotdismissWallet() {
         mViewController.queryWalletCards();
         verify(mWalletClient).getWalletCards(any(), mRequestCaptor.capture(),
                 mCallbackCaptor.capture());
@@ -535,9 +560,9 @@
         view.onTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0));
 
         verify(mPluginCallbacks, never()).startPendingIntentDismissingKeyguard(any());
-        verify(mPluginCallbacks).dismissGlobalActionsMenu();
-        verify(mWalletClient).notifyWalletDismissed();
-        verify(mWalletClient).removeWalletServiceEventListener(any());
+        verify(mPluginCallbacks, never()).dismissGlobalActionsMenu();
+        verify(mWalletClient, never()).notifyWalletDismissed();
+        verify(mWalletClient, never()).removeWalletServiceEventListener(any());
     }
 
     private WalletCard createWalletCard(String cardId) {