From 5ded7768eaf917cac42ee2583f885db495e75770 Mon Sep 17 00:00:00 2001
From: FurWaz <fur.waz06@gmail.com>
Date: Tue, 13 Dec 2022 11:44:17 +0100
Subject: [PATCH] Added lots of comments again

---
 .../app/src/main/java/Common/BuildingManager.java  |  9 +++++++++
 Sources/app/src/main/java/Common/Callback.java     |  1 +
 Sources/app/src/main/java/Common/Coord.java        | 14 ++++++++++++--
 .../app/src/main/java/Common/DirectionStep.java    |  6 ++++++
 Sources/app/src/main/java/Common/Directions.java   | 10 +++++++++-
 Sources/app/src/main/java/Common/ImageManager.java |  1 +
 Sources/app/src/main/java/Common/InfoBinding.java  |  5 +++++
 Sources/app/src/main/java/Common/Position.java     |  5 +++++
 8 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/Sources/app/src/main/java/Common/BuildingManager.java b/Sources/app/src/main/java/Common/BuildingManager.java
index 2ba5d96..e8f7c6e 100644
--- a/Sources/app/src/main/java/Common/BuildingManager.java
+++ b/Sources/app/src/main/java/Common/BuildingManager.java
@@ -28,10 +28,12 @@ public class BuildingManager {
         save_dir = context.getFilesDir();
     }
 
+    // set the context of the building manager
     public static Context getContext() {
         return context;
     }
 
+    // remove a building from the list (+ saves the list)
     public static void removeBuilding(BuildingInfo b) {
         if (BuildingManager.buildings == null)
             loadBuildings();
@@ -39,6 +41,7 @@ public class BuildingManager {
         new File(save_dir, b.getName()).delete();
     }
 
+    // adds a building from the list (+ saves the list)
     public static void addBuilding(BuildingInfo b) {
         if (BuildingManager.buildings == null)
             loadBuildings();
@@ -46,18 +49,21 @@ public class BuildingManager {
         BuildingManager.saveBuilding(b);
     }
 
+    // returns the list of buildings (loads it if not loaded)
     public static List<BuildingInfo> getBuildings() {
         if (BuildingManager.buildings == null)
             loadBuildings();
         return BuildingManager.buildings;
     }
 
+    // returns the building at the given index (loads the list if not loaded)
     public static BuildingInfo getBuilding(int index) {
         if (BuildingManager.buildings == null)
             loadBuildings();
         return BuildingManager.buildings.get(index);
     }
 
+    // returns the building with the given name (loads the list if not loaded)
     public static BuildingInfo getBuilding(String name) {
         if (BuildingManager.buildings == null)
             loadBuildings();
@@ -67,6 +73,7 @@ public class BuildingManager {
         return null;
     }
 
+    // saves the given building to the file system
     public static void saveBuilding(BuildingInfo building) {
         new File(save_dir, building.getName()).delete();
 
@@ -87,11 +94,13 @@ public class BuildingManager {
         BuildingManager.buildings.add(building);
     }
 
+    // saves all the buildings to the file system
     public static void saveBuildings() {
         for(BuildingInfo building: BuildingManager.buildings)
             saveBuilding(building);
     }
 
+    // loads all the buildings from the file system
     public static void loadBuildings() {
         BuildingManager.buildings = new ArrayList<>();
         if (save_dir == null) return;
diff --git a/Sources/app/src/main/java/Common/Callback.java b/Sources/app/src/main/java/Common/Callback.java
index ad3e6f0..797bd4c 100644
--- a/Sources/app/src/main/java/Common/Callback.java
+++ b/Sources/app/src/main/java/Common/Callback.java
@@ -1,5 +1,6 @@
 package Common;
 
 public interface Callback {
+    // callback function
     public Object call(Object param);
 }
diff --git a/Sources/app/src/main/java/Common/Coord.java b/Sources/app/src/main/java/Common/Coord.java
index 1479617..a897dd7 100644
--- a/Sources/app/src/main/java/Common/Coord.java
+++ b/Sources/app/src/main/java/Common/Coord.java
@@ -4,15 +4,24 @@ import android.view.View;
 
 public class Coord {
     private float x, y;
+
+    // constructor
     public Coord() { }
+
+    // constructor with x and y coords
     public Coord(float x, float y) { this.x = x; this.y = y; }
-    public float getY() { return y; }
+
+    // returns the x coord
     public float getX() { return x; }
+    // returns the y coord
+    public float getY() { return y; }
+
+    // returns the distance between this coord and the given coord
     public float distance(Coord c) {
         return (float) Math.sqrt( Math.pow(c.getX() - this.getX(), 2) + Math.pow(c.getY() - this.getY(), 2) );
     }
 
-
+    // returns the relative coordinates (in percent) of this coord (relative to the given view)
     public Coord getRelativeCoord(View v) {
         float width = v.getWidth();
         float height = v.getHeight();
@@ -22,6 +31,7 @@ public class Coord {
         );
     }
 
+    // returns the absolute coordinates (in px) of this coord (relative to the given view)
     public Coord getAbsoluteCoord(View v) {
         float width = v.getWidth();
         float height = v.getHeight();
diff --git a/Sources/app/src/main/java/Common/DirectionStep.java b/Sources/app/src/main/java/Common/DirectionStep.java
index c472c1a..621f5c2 100644
--- a/Sources/app/src/main/java/Common/DirectionStep.java
+++ b/Sources/app/src/main/java/Common/DirectionStep.java
@@ -12,6 +12,7 @@ public class DirectionStep {
     String title = "";
     String description = "";
 
+    // generates the direction's title and description for user display
     private void generateStrings() {
         this.title = context.getString(R.string.go_to_value).replace("{{value}}", path.getDestination().getName());
         this.description = context.getString(R.string.go_to_value_desc)
@@ -19,26 +20,31 @@ public class DirectionStep {
                 .replace("{{value2}}", path.getName());
     }
 
+    // Constructor
     public DirectionStep(PathInfo path) {
         this.context = BuildingManager.getContext();
         this.path = path;
         this.generateStrings();
     }
 
+    // Set the path of the direction
     public void setPath(PathInfo path) {
         this.path = path;
         this.generateStrings();
     }
 
+    // Get the path of the direction
     public PathInfo getPath() {
         return path;
     }
 
+    // Get the title of the direction
     public String getTitle() {
         if (this.title.equals("")) this.generateStrings();
         return title;
     }
 
+    // Get the description of the direction
     public String getDescription() {
         if (this.description.equals("")) this.generateStrings();
         return description;
diff --git a/Sources/app/src/main/java/Common/Directions.java b/Sources/app/src/main/java/Common/Directions.java
index 5664277..287c34a 100644
--- a/Sources/app/src/main/java/Common/Directions.java
+++ b/Sources/app/src/main/java/Common/Directions.java
@@ -12,6 +12,7 @@ import Structures.RoomInfo;
 import Structures.StairsDirection;
 
 public class Directions {
+    // Returns a list of directions to follow to the destination if found (list of size 0 if no path found)
     private static List<DirectionStep> testRoute(List<RoomInfo> blacklist, PathInfo path, RoomInfo pdest, RoomInfo dest) {
         if (pdest == null || dest == null || path == null) return new ArrayList<>();
 
@@ -33,19 +34,23 @@ public class Directions {
         return res;
     }
 
+    // adds the list of steps to the list of paths if it is not empty
     private static void tryToAdd(List<DirectionStep> steps, List<List<DirectionStep>> paths) {
         if (steps.size() > 0) paths.add(steps);
     }
 
+    // Returns the list of directions to go from the given room to the given destination (list of size 0 if no path found)
     public static List<DirectionStep> findRoute(RoomInfo from, RoomInfo to) {
         return findRoute(new ArrayList<>(), from, to);
     }
 
+    // Returns the list of directions to go from the given room to the given destination, with blacklisted rooms if already used for path (list of size 0 if no path found)
     public static List<DirectionStep> findRoute(List<RoomInfo> blacklist, RoomInfo from, RoomInfo to) {
         if (from == null || to == null) return new ArrayList<>();
-        blacklist.add(from);
+        blacklist.add(from); // add the current room to the blacklist
 
         List<List<DirectionStep>> paths = new ArrayList<>();
+        // for each path of the current room, try to find (recursively) a path to the destination
         for (PathInfo path: from.getPaths()) {
             List<RoomInfo> blacklist_copy = new ArrayList<>(blacklist);
             if (path.getType() == PathType.STAIRS) {
@@ -78,6 +83,7 @@ public class Directions {
         List<DirectionStep> res = new ArrayList<>();
         if (paths.size() == 0) return res;
 
+        // find the shortest path
         int length = paths.get(0).size() + 1;
         for (List<DirectionStep> path: paths) {
             int size = path.size();
@@ -86,6 +92,8 @@ public class Directions {
                 res = path;
             }
         }
+        
+        // return the shortest path
         return res;
     }
 }
diff --git a/Sources/app/src/main/java/Common/ImageManager.java b/Sources/app/src/main/java/Common/ImageManager.java
index ee139f4..7c8aa1f 100644
--- a/Sources/app/src/main/java/Common/ImageManager.java
+++ b/Sources/app/src/main/java/Common/ImageManager.java
@@ -18,6 +18,7 @@ import Structures.RoomInfo;
 import Structures.ZoneInfo;
 
 public class ImageManager {
+    // Retreived the bitmap from the given url (executes onResolve with the bitmap on success, onReject with the error message on failure)
     public static void bitmapFromURL(Callback onResolve, Callback onReject, String url) {
         ExecutorService service = Executors.newSingleThreadExecutor();
         service.execute(() -> {
diff --git a/Sources/app/src/main/java/Common/InfoBinding.java b/Sources/app/src/main/java/Common/InfoBinding.java
index 17affb9..f08e040 100644
--- a/Sources/app/src/main/java/Common/InfoBinding.java
+++ b/Sources/app/src/main/java/Common/InfoBinding.java
@@ -1,18 +1,23 @@
 package Common;
 
 public class InfoBinding {
+    // callback function to execute to get the data
     private Callback callback;
+    // if of the element to bind the data to
     private int element;
 
+    // constructor
     public InfoBinding(Callback cb, int el) {
         this.element = el;
         this.callback = cb;
     }
 
+    // returns the callback function
     public Callback getCallback() {
         return callback;
     }
 
+    // returns the id of the element to bind the data to
     public int getElement() {
         return element;
     }
diff --git a/Sources/app/src/main/java/Common/Position.java b/Sources/app/src/main/java/Common/Position.java
index 5eb0e61..6376752 100644
--- a/Sources/app/src/main/java/Common/Position.java
+++ b/Sources/app/src/main/java/Common/Position.java
@@ -8,25 +8,30 @@ public class Position implements Serializable {
     public double latitude;
     public double longitude;
 
+    // constructor with latitude and longitude
     public Position(double latitude, double longitude) {
         this.latitude = latitude;
         this.longitude = longitude;
     }
 
+    // constructor with a location object
     public Position(Location location) {
         this.latitude = location.getLatitude();
         this.longitude = location.getLongitude();
     }
 
+    // constructor with no parameters
     public Position() {
         this.latitude = 0;
         this.longitude = 0;
     }
 
+    // returns latitude
     public double getLatitude() {
         return latitude;
     }
 
+    // returns longitude
     public double getLongitude() {
         return longitude;
     }
-- 
GitLab