diff --git a/Sources/app/src/main/java/Popups/PathwayPopup.java b/Sources/app/src/main/java/Popups/PathwayPopup.java index 0df2827247a656f5f8fda8a4e8cba86fbf001cf6..72a78ae3306e17fc54b1f63bf4fa3e29733ee035 100644 --- a/Sources/app/src/main/java/Popups/PathwayPopup.java +++ b/Sources/app/src/main/java/Popups/PathwayPopup.java @@ -9,9 +9,13 @@ import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; +import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.EditText; +import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; +import android.widget.Toast; import androidx.appcompat.app.AlertDialog; @@ -23,8 +27,11 @@ import java.util.List; import Common.Callback; import Structures.BuildingInfo; +import Structures.PathDoor; +import Structures.PathStairs; import Structures.PathType; import Structures.RoomInfo; +import Structures.StairsDirection; public class PathwayPopup { public static final int MODE_NEW = 1; @@ -43,6 +50,10 @@ public class PathwayPopup { BuildingInfo building = null; Context context = null; + Callback onValidate; + int mode; + RoomInfo room; + boolean reversedPathChecked; public PathwayPopup(Context context, BuildingInfo building, RoomInfo room, Callback onCreate, Callback onCancel, Callback onValidate, int mode) { AlertDialog.Builder builder = new AlertDialog.Builder(context); @@ -53,6 +64,9 @@ public class PathwayPopup { this.building = building; this.context = context; + this.onValidate = onValidate; + this.mode = mode; + this.room = room; PATHWAY_DOOR = context.getResources().getString(R.string.door); PATHWAY_STAIRS = context.getResources().getString(R.string.stairs); @@ -62,6 +76,8 @@ public class PathwayPopup { p_name = popup.findViewById(R.id.input_pathway_name); validate_btn = popup.findViewById(R.id.btn_validate_room); cancel_btn = popup.findViewById(R.id.btn_cancel_room); + CheckBox check_reversed = popup.findViewById(R.id.check_reversed); + LinearLayout layout_reversed = popup.findViewById(R.id.layout_reversed); validate_btn.setEnabled(false); p_err.setText(""); @@ -96,6 +112,16 @@ public class PathwayPopup { } }); + if (mode == MODE_EDIT) { + layout_reversed.setVisibility(View.GONE); + } else { + layout_reversed.setVisibility(View.VISIBLE); + check_reversed.setOnCheckedChangeListener((compoundButton, b) -> { + reversedPathChecked = b; + }); + reversedPathChecked = check_reversed.isChecked(); + } + sp_type = dialog.findViewById(R.id.pathway_type); String[] sp_type_items = new String[]{PATHWAY_DOOR, PATHWAY_STAIRS}; sp_type.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_spinner_dropdown_item, sp_type_items)); @@ -127,7 +153,7 @@ public class PathwayPopup { }); cancel_btn.setOnClickListener(view -> onCancel.call(this)); - validate_btn.setOnClickListener(view -> onValidate.call(this)); + validate_btn.setOnClickListener(view -> this.validate()); }); dialog.setOnDismissListener(dialogInterface -> { @@ -162,6 +188,25 @@ public class PathwayPopup { dialog.show(); } + public void validate() { + if (this.mode == MODE_NEW && this.reversedPathChecked) { + if (this.getSelectedType() == PathType.DOOR) { + String name = context.getResources().getString(R.string.door) + " - " + this.room.getName(); + this.getUpDestination().addPath(new PathDoor(name, this.room)); + } else { + String name = context.getResources().getString(R.string.stair) + " - " + this.room.getName(); + if (getUpDestination() != null) { + this.getUpDestination().addPath(new PathStairs(name, null, this.room)); + } + if (getDownDestination() != null) { + this.getDownDestination().addPath(new PathStairs(name, this.room, null)); + } + } + } + + if (onValidate != null) onValidate.call(this); + } + protected void updateRoomLists() { List<String> names = new ArrayList<>(); names.add("<"+context.getResources().getString(R.string.none)+">"); diff --git a/Sources/app/src/main/java/com/furwaz/roomview/RoomActivity.java b/Sources/app/src/main/java/com/furwaz/roomview/RoomActivity.java index 9c6bdccf536f2ca4767b58151f7a94b904400a35..838c5fe4d2e540251d383223a97ade7ec01c67b8 100644 --- a/Sources/app/src/main/java/com/furwaz/roomview/RoomActivity.java +++ b/Sources/app/src/main/java/com/furwaz/roomview/RoomActivity.java @@ -322,12 +322,10 @@ public class RoomActivity extends AppCompatActivity { param -> { PathwayPopup popup = ((PathwayPopup) param); String name = popup.getInput().getText().toString(); - if (name != "") { - if (popup.getSelectedType() == PathType.DOOR) { - room.addPath(new PathDoor(name, popup.getUpDestination())); - } else { - room.addPath(new PathStairs(name, popup.getUpDestination(), popup.getDownDestination())); - } + if (popup.getSelectedType() == PathType.DOOR) { + room.addPath(new PathDoor(name, popup.getUpDestination())); + } else { + room.addPath(new PathStairs(name, popup.getUpDestination(), popup.getDownDestination())); } pathways_adapter.setData(room.getPaths()); popup.dismiss(); diff --git a/Sources/app/src/main/res/layout/add_pathway_popup.xml b/Sources/app/src/main/res/layout/add_pathway_popup.xml index fc33d43950e76041dfb685eae26981809a25bb2c..60dbf9e302fbd4ac4d4370af37ac8c337ea8717b 100644 --- a/Sources/app/src/main/res/layout/add_pathway_popup.xml +++ b/Sources/app/src/main/res/layout/add_pathway_popup.xml @@ -7,26 +7,26 @@ <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical" - android:background="@color/slate_50"> + android:background="@color/slate_50" + android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" + android:layout_marginBottom="20dp" android:background="@color/blue_500" - android:layout_marginBottom="20dp"> + android:orientation="horizontal"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginBottom="4dp" android:background="@color/slate_200" + android:padding="10dp" android:text="@string/new_pathway" android:textColor="@color/blue_500" android:textSize="20sp" - android:layout_marginBottom="4dp" - android:textStyle="bold" - android:padding="10dp"/> + android:textStyle="bold" /> </LinearLayout> <LinearLayout @@ -34,44 +34,48 @@ android:layout_height="wrap_content" android:orientation="vertical" android:padding="10dp"> + <EditText android:id="@+id/input_pathway_name" android:layout_width="match_parent" android:layout_height="wrap_content" - android:inputType="text" + android:backgroundTint="@color/blue_500" android:hint="@string/pathway_name" - android:textColorHint="@color/slate_300" + android:inputType="text" android:textColor="@color/slate_500" - android:backgroundTint="@color/blue_500" + android:textColorHint="@color/slate_300" android:textSize="20sp" - android:textStyle="bold"/> + android:textStyle="bold" /> + <TextView android:id="@+id/pathway_input_error_msg" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginStart="4dp" + android:layout_marginEnd="4dp" android:gravity="start" + android:text="" android:textColor="@color/red_500" android:textSize="12sp" - android:textStyle="normal" - android:text="" - android:layout_marginStart="4dp" - android:layout_marginEnd="4dp"/> + android:textStyle="normal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" + android:paddingTop="20dp" + android:paddingBottom="4dp" + android:text="@string/pathway_type" android:textColor="@color/slate_700" android:textSize="16dp" - android:textStyle="normal" - android:text="@string/pathway_type" - android:paddingTop="20dp" - android:paddingBottom="4dp"/> + android:textStyle="normal" /> + <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" android:background="@color/blue_500" + android:orientation="horizontal" android:paddingBottom="4dp"> + <Spinner android:id="@+id/pathway_type" android:layout_width="match_parent" @@ -80,26 +84,28 @@ android:text="@string/new_pathway" android:textColor="@color/slate_800" android:textSize="20sp" - android:textStyle="bold"/> + android:textStyle="bold" /> </LinearLayout> <TextView android:id="@+id/pathway_dest_up_txt" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:paddingTop="20dp" + android:paddingBottom="4dp" + android:text="@string/pathway_destination_up" android:textColor="@color/slate_700" android:textSize="16sp" - android:textStyle="normal" - android:text="@string/pathway_destination_up" - android:paddingTop="20dp" - android:paddingBottom="4dp"/> + android:textStyle="normal" /> + <LinearLayout android:id="@+id/dest_up_layout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" android:background="@color/blue_500" + android:orientation="horizontal" android:paddingBottom="4dp"> + <Spinner android:id="@+id/pathway_dest_up" android:layout_width="match_parent" @@ -108,28 +114,30 @@ android:text="@string/new_pathway" android:textColor="@color/slate_800" android:textSize="20sp" - android:textStyle="bold"/> + android:textStyle="bold" /> </LinearLayout> <TextView - android:visibility="gone" android:id="@+id/pathway_dest_down_txt" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:paddingTop="20dp" + android:paddingBottom="4dp" + android:text="@string/pathway_destination_down" android:textColor="@color/slate_700" android:textSize="16sp" android:textStyle="normal" - android:text="@string/pathway_destination_down" - android:paddingTop="20dp" - android:paddingBottom="4dp"/> + android:visibility="gone" /> + <LinearLayout - android:visibility="gone" android:id="@+id/dest_down_layout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" android:background="@color/blue_500" - android:paddingBottom="4dp"> + android:orientation="horizontal" + android:paddingBottom="4dp" + android:visibility="gone"> + <Spinner android:id="@+id/pathway_dest_down" android:layout_width="match_parent" @@ -138,53 +146,75 @@ android:text="@string/new_pathway" android:textColor="@color/slate_800" android:textSize="20sp" - android:textStyle="bold"/> + android:textStyle="bold" /> </LinearLayout> </LinearLayout> + <LinearLayout + android:id="@+id/layout_reversed" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> + + <CheckBox + android:id="@+id/check_reversed" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:checked="true" /> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textSize="16sp" + android:textStyle="bold" + android:textColor="@color/slate_700" + android:text="@string/create_otherside" /> + </LinearLayout> + <TextView android:id="@+id/new_room_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:gravity="start" + android:layout_marginStart="10dp" + android:layout_marginTop="20dp" + android:layout_marginEnd="10dp" android:background="@drawable/flat_btn" - android:textColor="@color/blue_500" - android:textSize="16sp" - android:textStyle="bold" - android:text="@string/new_room" - android:paddingEnd="8dp" + android:gravity="start" android:paddingStart="8dp" android:paddingTop="4dp" + android:paddingEnd="8dp" android:paddingBottom="4dp" - android:layout_marginTop="20dp" - android:layout_marginStart="10dp" - android:layout_marginEnd="10dp"/> + android:text="@string/new_room" + android:textColor="@color/blue_500" + android:textSize="16sp" + android:textStyle="bold" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" android:layout_marginTop="20dp" + android:orientation="horizontal" android:padding="8dp"> <Button android:id="@+id/btn_cancel_room" + style="@style/Widget.AppCompat.Button.Borderless" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textColor="@color/red_500" - style="@style/Widget.AppCompat.Button.Borderless" - android:text="@string/cancel"/> + android:text="@string/cancel" + android:textColor="@color/red_500" /> + <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" - android:gravity="right"> + android:gravity="right" + android:orientation="horizontal"> + <Button android:id="@+id/btn_validate_room" android:layout_width="wrap_content" android:layout_height="wrap_content" android:backgroundTint="@color/blue_500" - android:text="@string/create"/> + android:text="@string/create" /> </LinearLayout> </LinearLayout> </LinearLayout> diff --git a/Sources/app/src/main/res/values-fr/strings.xml b/Sources/app/src/main/res/values-fr/strings.xml index 8dde6a5327e6be6dbb05b4881981332d037cd75a..51838577a82813161dc8c4598c12119bcba6a314 100644 --- a/Sources/app/src/main/res/values-fr/strings.xml +++ b/Sources/app/src/main/res/values-fr/strings.xml @@ -98,4 +98,7 @@ <string name="go_to_value">Allez dans la pièce {{value}}</string> <string name="go_to_value_desc">Allez dans la pièce {{value1}} en utilisant le passage {{value2}}</string> <string name="camera_error">Erreur : La camera ne peux pas être utilisée\n(Vérifiez peut-être les permissions de l\'app)</string> + <string name="create_otherside">Créer le chemin inverse</string> + <string name="pathway">Chemin</string> + <string name="stair">Escalier</string> </resources> \ No newline at end of file diff --git a/Sources/app/src/main/res/values/strings.xml b/Sources/app/src/main/res/values/strings.xml index 31dbd8aad22275270e63f845059aefc5b4722025..2b2c7c800a21e5b1cd8495880ef780d681250a2a 100644 --- a/Sources/app/src/main/res/values/strings.xml +++ b/Sources/app/src/main/res/values/strings.xml @@ -98,4 +98,7 @@ <string name="go_to_value">Go to the room {{value}}</string> <string name="go_to_value_desc">Go to the room {{value1}} by using the path {{value2}}</string> <string name="camera_error">Error : The camera cannot be open !\n(Maybe check the app\'s permissions)</string> + <string name="create_otherside">Create reverse pathway</string> + <string name="pathway">Pathway</string> + <string name="stair">Stair</string> </resources> \ No newline at end of file