Merge "Add null check before setting the visibility of swipe background" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1079d2833a
@@ -112,8 +112,10 @@ public class SliceContextualCardRenderer implements ContextualCardRenderer, Life
|
|||||||
|
|
||||||
final View swipeBackground = holder.itemView.findViewById(R.id.dismissal_swipe_background);
|
final View swipeBackground = holder.itemView.findViewById(R.id.dismissal_swipe_background);
|
||||||
sliceLiveData.removeObservers(mLifecycleOwner);
|
sliceLiveData.removeObservers(mLifecycleOwner);
|
||||||
// set the background to Gone in case the holder is reused.
|
// set the background to GONE in case the holder is reused.
|
||||||
swipeBackground.setVisibility(View.GONE);
|
if (swipeBackground != null) {
|
||||||
|
swipeBackground.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
sliceLiveData.observe(mLifecycleOwner, slice -> {
|
sliceLiveData.observe(mLifecycleOwner, slice -> {
|
||||||
if (slice == null) {
|
if (slice == null) {
|
||||||
Log.w(TAG, "Slice is null");
|
Log.w(TAG, "Slice is null");
|
||||||
@@ -140,8 +142,9 @@ public class SliceContextualCardRenderer implements ContextualCardRenderer, Life
|
|||||||
default:
|
default:
|
||||||
mFullCardHelper.bindView(holder, card, slice);
|
mFullCardHelper.bindView(holder, card, slice);
|
||||||
}
|
}
|
||||||
|
if (swipeBackground != null) {
|
||||||
swipeBackground.setVisibility(View.VISIBLE);
|
swipeBackground.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
switch (holder.getItemViewType()) {
|
switch (holder.getItemViewType()) {
|
||||||
|
@@ -16,11 +16,13 @@
|
|||||||
|
|
||||||
package com.android.settings.homepage.contextualcards.slices;
|
package com.android.settings.homepage.contextualcards.slices;
|
||||||
|
|
||||||
|
import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_DEFERRED_SETUP;
|
||||||
import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_FULL_WIDTH;
|
import static com.android.settings.homepage.contextualcards.slices.SliceContextualCardRenderer.VIEW_TYPE_FULL_WIDTH;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -160,6 +162,15 @@ public class SliceContextualCardRendererTest {
|
|||||||
assertThat(swipeBg.getVisibility()).isEqualTo(View.GONE);
|
assertThat(swipeBg.getVisibility()).isEqualTo(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bindView_deferredSetupCard_shouldNotCrash() {
|
||||||
|
final RecyclerView.ViewHolder viewHolder = getDeferredSetupViewHolder();
|
||||||
|
final ContextualCard card = buildContextualCard(TEST_SLICE_URI);
|
||||||
|
mRenderer.mSliceLiveDataMap.put(TEST_SLICE_URI, mSliceLiveData);
|
||||||
|
|
||||||
|
mRenderer.bindView(viewHolder, card);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void viewClick_keepCard_shouldShowSlice() {
|
public void viewClick_keepCard_shouldShowSlice() {
|
||||||
final RecyclerView.ViewHolder viewHolder = getSliceViewHolder();
|
final RecyclerView.ViewHolder viewHolder = getSliceViewHolder();
|
||||||
@@ -246,6 +257,18 @@ public class SliceContextualCardRendererTest {
|
|||||||
return mRenderer.createViewHolder(view, VIEW_TYPE_FULL_WIDTH);
|
return mRenderer.createViewHolder(view, VIEW_TYPE_FULL_WIDTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RecyclerView.ViewHolder getDeferredSetupViewHolder() {
|
||||||
|
final RecyclerView recyclerView = new RecyclerView(mActivity);
|
||||||
|
recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
|
||||||
|
final View view = LayoutInflater.from(mActivity)
|
||||||
|
.inflate(VIEW_TYPE_DEFERRED_SETUP, recyclerView, false);
|
||||||
|
final RecyclerView.ViewHolder viewHolder = spy(
|
||||||
|
new SliceDeferredSetupCardRendererHelper.DeferredSetupCardViewHolder(view));
|
||||||
|
doReturn(VIEW_TYPE_DEFERRED_SETUP).when(viewHolder).getItemViewType();
|
||||||
|
|
||||||
|
return viewHolder;
|
||||||
|
}
|
||||||
|
|
||||||
private ContextualCard buildContextualCard(Uri sliceUri) {
|
private ContextualCard buildContextualCard(Uri sliceUri) {
|
||||||
return new ContextualCard.Builder()
|
return new ContextualCard.Builder()
|
||||||
.setName("test_name")
|
.setName("test_name")
|
||||||
|
Reference in New Issue
Block a user