From bf14d3d88a7e015913c5616b4c72d75cdc9c2abc Mon Sep 17 00:00:00 2001 From: FurWaz <fur.waz06@gmail.com> Date: Wed, 7 Dec 2022 20:40:48 +0100 Subject: [PATCH] Added smart room in-popup adding --- .../src/main/java/Popups/PathwayPopup.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/Sources/app/src/main/java/Popups/PathwayPopup.java b/Sources/app/src/main/java/Popups/PathwayPopup.java index 72a78ae..df9ec4a 100644 --- a/Sources/app/src/main/java/Popups/PathwayPopup.java +++ b/Sources/app/src/main/java/Popups/PathwayPopup.java @@ -207,16 +207,35 @@ public class PathwayPopup { if (onValidate != null) onValidate.call(this); } + protected void updateRoomLists(RoomInfo selection) { + this.updateRoomLists(); + int roomindex = building.getRooms().indexOf(selection) + 1; + if (getSelectedType() == PathType.DOOR) { + sp_dest_up.setSelection( roomindex ); + } else { + if (getUpDestination() == null) + sp_dest_up.setSelection( roomindex ); + if (getDownDestination() == null) + sp_dest_down.setSelection( roomindex ); + } + } + protected void updateRoomLists() { List<String> names = new ArrayList<>(); names.add("<"+context.getResources().getString(R.string.none)+">"); - for(RoomInfo r : building.getRooms()) names.add(r.getName()); + for (RoomInfo r : building.getRooms()) names.add(r.getName()); String[] sp_dest_items = new String[names.size()]; for (int i = 0; i < names.size(); i++) sp_dest_items[i] = names.get(i); - sp_dest_up.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, sp_dest_items)); - sp_dest_down.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, sp_dest_items)); + RoomInfo selection_up = getUpDestination(); + RoomInfo selection_down = getDownDestination(); + + sp_dest_up.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, sp_dest_items)); + sp_dest_down.setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_spinner_dropdown_item, sp_dest_items)); + + if (selection_up != null) sp_dest_up.setSelection( building.getRooms().indexOf(selection_up) + 1 ); + if (selection_down != null) sp_dest_down.setSelection( building.getRooms().indexOf(selection_down) + 1 ); } protected void showAddRoomPopup() { @@ -233,8 +252,9 @@ public class PathwayPopup { }, param -> { RoomPopup popup = ((RoomPopup) param); - building.addRoom(new RoomInfo(popup.getInput().getText().toString())); - updateRoomLists(); + RoomInfo new_room = new RoomInfo(popup.getInput().getText().toString()); + building.addRoom(new_room); + updateRoomLists(new_room); popup.dismiss(); return null; }, -- GitLab