Skip to content

Commit

Permalink
Merge pull request #133 from longjunyu2/run-button
Browse files Browse the repository at this point in the history
Add run button to container
  • Loading branch information
lvonasek authored Sep 27, 2024
2 parents be2bbe1 + 56300e6 commit eea3156
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
20 changes: 14 additions & 6 deletions app/src/main/java/com/winlator/ContainersFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private class ContainersAdapter extends RecyclerView.Adapter<ContainersAdapter.V

private class ViewHolder extends RecyclerView.ViewHolder {
private final ImageButton menuButton;
private final ImageButton runButton;
private final ImageView imageView;
private final TextView title;

Expand All @@ -107,6 +108,7 @@ private ViewHolder(View view) {
this.imageView = view.findViewById(R.id.ImageView);
this.title = view.findViewById(R.id.TVTitle);
this.menuButton = view.findViewById(R.id.BTMenu);
this.runButton = view.findViewById(R.id.BTRun);
}
}

Expand All @@ -122,6 +124,7 @@ public final ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
holder.menuButton.setOnClickListener(null);
holder.runButton.setOnClickListener(null);
super.onViewRecycled(holder);
}

Expand All @@ -131,13 +134,23 @@ public void onBindViewHolder(final ViewHolder holder, int position) {
holder.imageView.setImageResource(R.drawable.icon_container);
holder.title.setText(item.getName());
holder.menuButton.setOnClickListener((view) -> showListItemMenu(view, item));
holder.runButton.setOnClickListener((view) -> runContainer(item));
}

@Override
public final int getItemCount() {
return data.size();
}

private void runContainer(Container container) {
if (!XrActivity.isSupported()) {
Intent intent = new Intent(getContext(), XServerDisplayActivity.class);
intent.putExtra("container_id", container.id);
requireActivity().startActivity(intent);
}
else XrActivity.openIntent(getActivity(), container.id, null);
}

private void showListItemMenu(View anchorView, Container container) {
final Context context = getContext();
PopupMenu listItemMenu = new PopupMenu(context, anchorView);
Expand All @@ -147,12 +160,7 @@ private void showListItemMenu(View anchorView, Container container) {
listItemMenu.setOnMenuItemClickListener((menuItem) -> {
switch (menuItem.getItemId()) {
case R.id.container_run:
if (!XrActivity.isSupported()) {
Intent intent = new Intent(context, XServerDisplayActivity.class);
intent.putExtra("container_id", container.id);
requireActivity().startActivity(intent);
}
else XrActivity.openIntent(getActivity(), container.id, null);
runContainer(container);
break;
case R.id.container_edit:
FragmentManager fragmentManager = getParentFragmentManager();
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/container_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
android:ellipsize="end"
android:maxLines="1" />

<ImageButton
style="@style/ListMenuButton"
android:id="@+id/BTRun"
android:layout_marginHorizontal="10dp"
android:src="@drawable/icon_popup_menu_run" />

<ImageButton
style="@style/ListMenuButton"
android:id="@+id/BTMenu"
Expand Down

0 comments on commit eea3156

Please sign in to comment.