Skip to content

Commit

Permalink
Making UI a bit nicer on Android TV Casting App (project-chip#116)
Browse files Browse the repository at this point in the history
This change fixes a bug in the layout of the commissioning page and also
makes the list items look more like buttons
  • Loading branch information
cliffamzn committed Mar 3, 2023
1 parent 527f0f2 commit ad2aa95
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.chip.casting.DiscoveredNodeData;
Expand Down Expand Up @@ -76,18 +75,10 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
View.OnClickListener manualCommissioningButtonOnClickListener =
v -> callback.handleCommissioningButtonClicked(null);
manualCommissioningButton.setOnClickListener(manualCommissioningButtonOnClickListener);
ArrayAdapter<DiscoveredNodeData> arrayAdapter =
new VideoPlayerCommissionerAdapter(getActivity(), commissionerVideoPlayerList);

ArrayAdapter<DiscoveredNodeData> arrayAdapter = new VideoPlayerCommissionerAdapter(getActivity(), commissionerVideoPlayerList);
final ListView list = getActivity().findViewById(R.id.commissionerList);
list.setAdapter(arrayAdapter);
list.setOnItemClickListener(
(parent, view1, position, id) -> {
DiscoveredNodeData discoveredNodeData =
(DiscoveredNodeData) parent.getItemAtPosition(position);
Log.d(TAG, "OnItemClickListener.onClick called for " + discoveredNodeData);
Callback callback1 = (Callback) getActivity();
callback1.handleCommissioningButtonClicked(discoveredNodeData);
});

this.successCallback =
new SuccessCallback<DiscoveredNodeData>() {
Expand Down Expand Up @@ -156,24 +147,37 @@ public interface Callback {
}

class VideoPlayerCommissionerAdapter extends ArrayAdapter<DiscoveredNodeData> {
private final List<DiscoveredNodeData> playerList;
private LayoutInflater inflater;

public VideoPlayerCommissionerAdapter(
Context applicationContext, List<DiscoveredNodeData> playerList) {
super(applicationContext, 0, playerList);
this.playerList = playerList;
inflater = (LayoutInflater.from(applicationContext));
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflater.inflate(R.layout.commissionable_player_list_item, null);
String buttonText = getCommissionerButtonText(playerList.get(i));
TextView playerDescription = view.findViewById(R.id.commissionable_player_description);
playerDescription.setText(buttonText);
return view;
}
private final List<DiscoveredNodeData> playerList;
private final Context context;
private LayoutInflater inflater;
private static final String TAG = VideoPlayerCommissionerAdapter.class.getSimpleName();

public VideoPlayerCommissionerAdapter(Context context, List<DiscoveredNodeData> playerList) {
super(context, 0, playerList);
this.context = context;
this.playerList = playerList;
inflater = (LayoutInflater.from(context));
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view = inflater.inflate(R.layout.commissionable_player_list_item, null);
String buttonText = getCommissionerButtonText(playerList.get(i));
Button playerDescription = view.findViewById(R.id.commissionable_player_description);
playerDescription.setText(buttonText);
View.OnClickListener clickListener = v -> {
DiscoveredNodeData discoveredNodeData = playerList.get(i);
Log.d(
TAG,
"OnItemClickListener.onClick called for "
+ discoveredNodeData);
CommissionerDiscoveryFragment.Callback callback1 =
(CommissionerDiscoveryFragment.Callback) context;
callback1.handleCommissioningButtonClicked(discoveredNodeData);
};
playerDescription.setOnClickListener(clickListener);
return view;
}

private String getCommissionerButtonText(DiscoveredNodeData commissioner) {
String main = commissioner.getDeviceName() != null ? commissioner.getDeviceName() : "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class ConnectionFragment extends Fragment {
private final TvCastingApp tvCastingApp;
private final DiscoveredNodeData selectedCommissioner;

private boolean verifyOrEstablishConnectionSuccess;
private boolean openCommissioningWindowSuccess;
private boolean sendUdcSuccess;

Expand Down Expand Up @@ -83,9 +82,8 @@ public void handle(ContentApp contentApp) {
if (selectedCommissioner != null && selectedCommissioner.isPreCommissioned()) {
VideoPlayer videoPlayer = selectedCommissioner.toConnectableVideoPlayer();
Log.d(TAG, "Calling verifyOrEstablishConnectionSuccess with VideoPlayer: " + videoPlayer);
this.verifyOrEstablishConnectionSuccess =
tvCastingApp.verifyOrEstablishConnection(
videoPlayer, onConnectionSuccess, onConnectionFailure, onNewOrUpdatedEndpoints);
tvCastingApp.verifyOrEstablishConnection(
videoPlayer, onConnectionSuccess, onConnectionFailure, onNewOrUpdatedEndpoints);
} else {
Log.d(TAG, "Running commissioning");
this.openCommissioningWindowSuccess =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
<Button
android:id="@+id/commissionable_player_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="blah"
android:textAlignment="center"
android:textColor="@android:color/black"
android:textSize="20dp" />
android:padding="10dp" />

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<LinearLayout
android:id="@+id/castingCommissioners"
android:layout_width="409dp"
android:layout_height="729dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp"
Expand All @@ -34,8 +34,9 @@

<ListView
android:id = "@+id/commissionerList"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"/>
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:fadeScrollbars = "false" />
</LinearLayout>


Expand Down

0 comments on commit ad2aa95

Please sign in to comment.