Remove divider above device switcher in panel
Remove the divider above the media device switcher Slice per the request. Do a little refactor in Panel View, to use DividerItemDecoration instead of adding divider views in layout file as the recycler view items divider. Since dividers should be shown in most cases, we are setting DividerCondition to DIVIDER_CONDITION_BOTH and default true to allow divider. For the slice we don't need divider (media device switch in this case) we are setting the the target direction of isDividerAllowed (above in this case) to false. Since we have DIVIDER_CONDITION_BOTH, if one of the item view set the divider not allow, the divider won't be shown. Test: Visual/Manual inspection Fixes: 126205139 Change-Id: Ic857705c90819ef9375f877a44bb32987b5d4438
This commit is contained in:
@@ -31,8 +31,6 @@
|
||||
android:textColor="?android:attr/colorPrimary"
|
||||
android:textSize="20sp"/>
|
||||
|
||||
<include layout="@layout/horizontal_divider"/>
|
||||
|
||||
<include layout="@layout/panel_slice_list"/>
|
||||
|
||||
<LinearLayout
|
||||
|
@@ -26,6 +26,4 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="20dp"/>
|
||||
|
||||
<include layout="@layout/horizontal_divider"/>
|
||||
</LinearLayout>
|
@@ -37,6 +37,7 @@ import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.panel.PanelLoggingContract.PanelClosedKeys;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.google.android.setupdesign.DividerItemDecoration;
|
||||
|
||||
public class PanelFragment extends Fragment {
|
||||
|
||||
@@ -93,6 +94,10 @@ public class PanelFragment extends Fragment {
|
||||
mPanelSlices.setLayoutManager(new LinearLayoutManager((activity)));
|
||||
mPanelSlices.setAdapter(mAdapter);
|
||||
|
||||
DividerItemDecoration itemDecoration = new DividerItemDecoration(getActivity());
|
||||
itemDecoration.setDividerCondition(DividerItemDecoration.DIVIDER_CONDITION_BOTH);
|
||||
mPanelSlices.addItemDecoration(itemDecoration);
|
||||
|
||||
mTitleView.setText(mPanel.getTitle());
|
||||
|
||||
mSeeMoreButton.setOnClickListener(getSeeMoreListener());
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.panel;
|
||||
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
@@ -33,6 +35,7 @@ import androidx.slice.widget.SliceView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.google.android.setupdesign.DividerItemDecoration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -80,10 +83,13 @@ public class PanelSlicesAdapter
|
||||
/**
|
||||
* ViewHolder for binding Slices to SliceViews.
|
||||
*/
|
||||
public static class SliceRowViewHolder extends RecyclerView.ViewHolder {
|
||||
public static class SliceRowViewHolder extends RecyclerView.ViewHolder
|
||||
implements DividerItemDecoration.DividedViewHolder {
|
||||
|
||||
private final PanelContent mPanelContent;
|
||||
|
||||
private boolean mDividerAllowedAbove = true;
|
||||
|
||||
@VisibleForTesting
|
||||
LiveData<Slice> sliceLiveData;
|
||||
|
||||
@@ -103,6 +109,11 @@ public class PanelSlicesAdapter
|
||||
sliceLiveData = SliceLiveData.fromUri(context, sliceUri);
|
||||
sliceLiveData.observe(fragment.getViewLifecycleOwner(), sliceView);
|
||||
|
||||
// Do not show the divider above media devices switcher slice per request
|
||||
if (sliceUri.equals(MEDIA_OUTPUT_INDICATOR_SLICE_URI)) {
|
||||
mDividerAllowedAbove = false;
|
||||
}
|
||||
|
||||
// Log Panel interaction
|
||||
sliceView.setOnSliceActionListener(
|
||||
((eventInfo, sliceItem) -> {
|
||||
@@ -116,5 +127,15 @@ public class PanelSlicesAdapter
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDividerAllowedAbove() {
|
||||
return mDividerAllowedAbove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDividerAllowedBelow() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,13 +16,18 @@
|
||||
|
||||
package com.android.settings.panel;
|
||||
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
@@ -39,6 +44,9 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.android.controller.ActivityController;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PanelSlicesAdapterTest {
|
||||
|
||||
@@ -48,8 +56,6 @@ public class PanelSlicesAdapterTest {
|
||||
private FakeFeatureFactory mFakeFeatureFactory;
|
||||
private PanelFeatureProvider mPanelFeatureProvider;
|
||||
|
||||
private PanelSlicesAdapter mAdapter;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
@@ -70,28 +76,83 @@ public class PanelSlicesAdapterTest {
|
||||
.get()
|
||||
.getSupportFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
|
||||
mAdapter = new PanelSlicesAdapter(mPanelFragment, mFakePanelContent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateViewHolder_returnsSliceRowViewHolder() {
|
||||
final PanelSlicesAdapter adapter =
|
||||
new PanelSlicesAdapter(mPanelFragment, mFakePanelContent);
|
||||
final ViewGroup view = new FrameLayout(mContext);
|
||||
final PanelSlicesAdapter.SliceRowViewHolder viewHolder =
|
||||
mAdapter.onCreateViewHolder(view, 0);
|
||||
adapter.onCreateViewHolder(view, 0);
|
||||
|
||||
assertThat(viewHolder.sliceView).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onBindViewHolder_bindsSlice() {
|
||||
final PanelSlicesAdapter adapter =
|
||||
new PanelSlicesAdapter(mPanelFragment, mFakePanelContent);
|
||||
final int position = 0;
|
||||
final ViewGroup view = new FrameLayout(mContext);
|
||||
final PanelSlicesAdapter.SliceRowViewHolder viewHolder =
|
||||
mAdapter.onCreateViewHolder(view, 0 /* view type*/);
|
||||
adapter.onCreateViewHolder(view, 0 /* view type*/);
|
||||
|
||||
mAdapter.onBindViewHolder(viewHolder, position);
|
||||
adapter.onBindViewHolder(viewHolder, position);
|
||||
|
||||
assertThat(viewHolder.sliceLiveData).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonMediaOutputIndicatorSlice_shouldAllowDividerAboveAndBelow() {
|
||||
final PanelSlicesAdapter adapter =
|
||||
new PanelSlicesAdapter(mPanelFragment, mFakePanelContent);
|
||||
final int position = 0;
|
||||
final ViewGroup view = new FrameLayout(mContext);
|
||||
final PanelSlicesAdapter.SliceRowViewHolder viewHolder =
|
||||
adapter.onCreateViewHolder(view, 0 /* view type*/);
|
||||
|
||||
adapter.onBindViewHolder(viewHolder, position);
|
||||
|
||||
assertThat(viewHolder.isDividerAllowedAbove()).isTrue();
|
||||
assertThat(viewHolder.isDividerAllowedBelow()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mediaOutputIndicatorSlice_shouldNotAllowDividerAbove() {
|
||||
PanelContent mediaOutputIndicatorSlicePanelContent = new PanelContent() {
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return "title";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Uri> getSlices() {
|
||||
return Arrays.asList(
|
||||
MEDIA_OUTPUT_INDICATOR_SLICE_URI
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intent getSeeMoreIntent() {
|
||||
return new Intent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.TESTING;
|
||||
}
|
||||
};
|
||||
|
||||
final PanelSlicesAdapter adapter =
|
||||
new PanelSlicesAdapter(mPanelFragment, mediaOutputIndicatorSlicePanelContent);
|
||||
final int position = 0;
|
||||
final ViewGroup view = new FrameLayout(mContext);
|
||||
final PanelSlicesAdapter.SliceRowViewHolder viewHolder =
|
||||
adapter.onCreateViewHolder(view, 0 /* view type*/);
|
||||
|
||||
adapter.onBindViewHolder(viewHolder, position);
|
||||
|
||||
assertThat(viewHolder.isDividerAllowedAbove()).isFalse();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user