Skip to content
Snippets Groups Projects
Commit fbfa491b authored by FurWaz's avatar FurWaz
Browse files

Added automatic reverse path adding

parent 5f88d69e
No related branches found
No related tags found
No related merge requests found
......@@ -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)+">");
......
......
......@@ -322,13 +322,11 @@ 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()));
}
}
pathways_adapter.setData(room.getPaths());
popup.dismiss();
return null;
......
......
......@@ -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" />
<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"
......@@ -87,19 +91,21 @@
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"
......@@ -112,24 +118,26 @@
</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"
......@@ -142,43 +150,65 @@
</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:id="@+id/new_room_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"
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: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:layout_marginStart="10dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="10dp"
android:background="@drawable/flat_btn"
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"
......
......
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment