Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2927997f authored by Jakub Tyszkowski's avatar Jakub Tyszkowski
Browse files

LeAudioTestApp: Basic broadcast metadata handling

Uses broadcast metadata list rather than playback state map
for filling in the RecycleViewAdapter items for broadcast list.
This should properly handle Broadcast Scan Assistant use case,
while the previously used playback state was known only for
local broadcasts in the Broadcast Source use case.

Bug: 150670922
Tag: #feature
Test: build
Sponsor: jpawlowski@
Change-Id: Ibda1889e315204b0fd589da42369dace778d2093
parent 0174efa2
Loading
Loading
Loading
Loading
+18 −12
Original line number Original line Diff line number Diff line
@@ -55,10 +55,13 @@ public class BroadcastItemsAdapter


    @Override
    @Override
    public void onBindViewHolder(@NonNull BroadcastItemHolder holder, int position) {
    public void onBindViewHolder(@NonNull BroadcastItemHolder holder, int position) {
        Integer broadcastId = (Integer) mBroadcastPlaybackMap.keySet().toArray()[position];
        BluetoothLeBroadcastMetadata meta = mBroadcastMetadataList.get(position);
        Boolean isPlaying = mBroadcastPlaybackMap.get(broadcastId);
        Integer broadcastId = meta.getBroadcastId();
        Boolean isPlaybackStateKnown = mBroadcastPlaybackMap.containsKey(broadcastId);


        if (isPlaybackStateKnown) {
            // Set card color based on the playback state
            // Set card color based on the playback state
            Boolean isPlaying = mBroadcastPlaybackMap.getOrDefault(broadcastId, false);
            if (isPlaying) {
            if (isPlaying) {
                holder.background
                holder.background
                .setCardBackgroundColor(ColorStateList.valueOf(Color.parseColor("#92b141")));
                .setCardBackgroundColor(ColorStateList.valueOf(Color.parseColor("#92b141")));
@@ -67,14 +70,17 @@ public class BroadcastItemsAdapter
                holder.background.setCardBackgroundColor(ColorStateList.valueOf(Color.WHITE));
                holder.background.setCardBackgroundColor(ColorStateList.valueOf(Color.WHITE));
                holder.mTextViewBroadcastId.setText("ID: " + broadcastId + " ⏸");
                holder.mTextViewBroadcastId.setText("ID: " + broadcastId + " ⏸");
            }
            }
        } else {
            holder.background.setCardBackgroundColor(ColorStateList.valueOf(Color.WHITE));
            holder.mTextViewBroadcastId.setText("ID: " + broadcastId);
        }


        // TODO: Add additional informations to the card
        // TODO: Add additional informations to the card
        // BluetoothLeBroadcastMetadata current_item = mBroadcastMetadata.get(position);
    }
    }


    @Override
    @Override
    public int getItemCount() {
    public int getItemCount() {
        return mBroadcastPlaybackMap.size();
        return mBroadcastMetadataList.size();
    }
    }


    public void updateBroadcastsMetadata(List<BluetoothLeBroadcastMetadata> broadcasts) {
    public void updateBroadcastsMetadata(List<BluetoothLeBroadcastMetadata> broadcasts) {
@@ -137,7 +143,7 @@ public class BroadcastItemsAdapter


                int position = getAdapterPosition();
                int position = getAdapterPosition();
                if (position != RecyclerView.NO_POSITION) {
                if (position != RecyclerView.NO_POSITION) {
                    Integer broadcastId = (Integer) mBroadcastPlaybackMap.keySet().toArray()[position];
                    Integer broadcastId = mBroadcastMetadataList.get(position).getBroadcastId();
                    listener.onItemClick(broadcastId);
                    listener.onItemClick(broadcastId);
                }
                }
            });
            });