[Sound Panel] Fix bugs for sound panel slice

1. notify item change when slice live data has update
2. keep showing Output Switcher slice when media state is in "Pause"
   state

Bug: 247043239
Bug: 238715094
Bug: 204165377
Test: verified on device
Change-Id: Ic56a70f2f2835231519e2fccf0d2e649d41b106e
This commit is contained in:
shaoweishen
2022-08-18 03:52:05 +00:00
committed by Shaowei Shen
parent 062b18c736
commit 66098febbc
4 changed files with 71 additions and 15 deletions

View File

@@ -64,7 +64,9 @@ public class MediaOutputUtils {
+ ", play back type : " + pi.getPlaybackType() + ", play back state : "
+ playbackState.getState());
}
if (playbackState.getState() != PlaybackState.STATE_PLAYING) {
if (playbackState.getState() == PlaybackState.STATE_STOPPED
|| playbackState.getState() == PlaybackState.STATE_NONE
|| playbackState.getState() == PlaybackState.STATE_ERROR) {
// do nothing
continue;
}

View File

@@ -60,6 +60,7 @@ import com.android.settingslib.utils.ThreadUtils;
import com.google.android.setupdesign.DividerItemDecoration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
@@ -339,8 +340,13 @@ public class PanelFragment extends Fragment {
mSliceLiveData.put(uri, sliceLiveData);
sliceLiveData.observe(getViewLifecycleOwner(), slice -> {
// If the Slice has already loaded, do nothing.
// If the Slice has already loaded, refresh list with slice data.
if (mPanelSlicesLoaderCountdownLatch.isSliceLoaded(uri)) {
if (mAdapter != null) {
int itemIndex = (new ArrayList<>(mSliceLiveData.keySet())).indexOf(uri);
mAdapter.notifyItemChanged(itemIndex);
}
return;
}

View File

@@ -84,7 +84,7 @@ public class PanelSlicesAdapter
@Override
public void onBindViewHolder(@NonNull SliceRowViewHolder sliceRowViewHolder, int position) {
sliceRowViewHolder.onBind(mSliceLiveData.get(position), position);
sliceRowViewHolder.onBind(mSliceLiveData.get(position).getValue());
}
/**
@@ -132,15 +132,14 @@ public class PanelSlicesAdapter
/**
* Called when the view is displayed.
*/
public void onBind(LiveData<Slice> sliceLiveData, int position) {
sliceLiveData.observe(mPanelFragment.getViewLifecycleOwner(), sliceView);
// Do not show the divider above media devices switcher slice per request
final Slice slice = sliceLiveData.getValue();
public void onBind(Slice slice) {
// Hides slice which reports with error hint or not contain any slice sub-item.
if (slice == null || !isValidSlice(slice)) {
sliceView.setVisibility(View.GONE);
return;
} else {
sliceView.setSlice(slice);
sliceView.setVisibility(View.VISIBLE);
}
// Add divider for the end icon
@@ -154,7 +153,7 @@ public class PanelSlicesAdapter
.action(0 /* attribution */,
SettingsEnums.ACTION_PANEL_INTERACTION,
mMetricsCategory,
sliceLiveData.getValue().getUri().getLastPathSegment()
slice.getUri().getLastPathSegment()
/* log key */,
eventInfo.actionType /* value */);
})