diff --git a/app/src/main/java/nl/ags/picum/UI/MainActivity.java b/app/src/main/java/nl/ags/picum/UI/MainActivity.java index 0d844b8..10214ce 100644 --- a/app/src/main/java/nl/ags/picum/UI/MainActivity.java +++ b/app/src/main/java/nl/ags/picum/UI/MainActivity.java @@ -75,6 +75,7 @@ protected void onCreate(Bundle savedInstanceState) { AppDatabaseManager manager = AppDatabaseManager.getInstance(getApplicationContext()); this.routes.clear(); + List tempList = manager.getRoutes(); this.routes.addAll(tempList); diff --git a/app/src/main/java/nl/ags/picum/UI/MapActivity.java b/app/src/main/java/nl/ags/picum/UI/MapActivity.java index 4e6bb95..348fdc3 100644 --- a/app/src/main/java/nl/ags/picum/UI/MapActivity.java +++ b/app/src/main/java/nl/ags/picum/UI/MapActivity.java @@ -1,6 +1,8 @@ package nl.ags.picum.UI; + +import android.app.Activity; import android.graphics.Bitmap; import android.graphics.Paint; import android.graphics.drawable.BitmapDrawable; @@ -41,6 +43,7 @@ import nl.ags.picum.R; import nl.ags.picum.UI.fragments.CompleteRouteFragment; +import nl.ags.picum.UI.fragments.SightDetailsPopupFragment; import nl.ags.picum.UI.Util.InstructionConverter; import nl.ags.picum.UI.fragments.SightsListFragment; import nl.ags.picum.UI.viewmodels.MapViewModel; @@ -77,22 +80,19 @@ protected void onCreate(Bundle savedInstanceState) { this.mapViewModel.getMapManager().setSightViewModel(sightViewModel); - sightViewModel.getCurrentSight().observe(this, this::onSightChanged); - sightViewModel.getSights().observe(this, this::onSightsChanged); + this.sightViewModel.getCurrentSight().observe(this, this::onSightChanged); + this.sightViewModel.getSights().observe(this, this::onSightsChanged); + this.sightViewModel.getCurrentSight().observe(this, (sight) -> { + FragmentManager fragmentManager = getSupportFragmentManager(); + SightDetailsPopupFragment dialog = new SightDetailsPopupFragment(sight, this); + dialog.show(fragmentManager, "JOE"); + calcProgress(); - // Observe CalculatedRoute points - this.mapViewModel.getCalculatedRoute().observe(this, (pointsMap) -> { - // TODO: 17-12-2021 setPointsInMap method not called, visited points line are other method - //setPointsInMap(points); - drawRouteList(pointsMap); - mMapController.setCenter(getCenterOfRoute(pointsMap)); + Log.d("ENTERLOCATION", sight.getSightName()); }); - // observer the raw-route - this.mapViewModel.getOSMRoute().observe(this, this::setPointsInMap); - this.mMap = findViewById(R.id.MainMap); Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(getApplicationContext())); Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID); @@ -110,13 +110,41 @@ protected void onCreate(Bundle savedInstanceState) { Log.d("pizzaparty", "onCreate: " + mapViewModel.getCurrentRoute()); } + private void calcProgress() { + new Thread(() -> { + double amountOfVisitedSights = 0; + List waypoints = AppDatabaseManager.getInstance(getApplicationContext()).getWaypointsWithSight(mapViewModel.getCurrentRoute()); + + for (Waypoint w : waypoints) { + + if (w.isVisited()) + amountOfVisitedSights++; + } + + double divide = amountOfVisitedSights / waypoints.size(); + int progress = (int) (divide * 100); + + runOnUiThread(new Runnable() { + @Override + public void run() { + checkProgress(progress); + } + }); + }).start(); + } + private void checkProgress(int progress) { if (progress == 100) { drawWalkedRoute(); + + new Thread(() -> { + if (this.mapViewModel == null) return; + mapViewModel.getMapManager().stopRoute(mapViewModel.getCurrentRoute()); + }).start(); + } else { drawYetToWalkRoute(); } - } private void drawYetToWalkRoute() { @@ -130,27 +158,42 @@ private void drawYetToWalkRoute() { }); // observer the raw-route - this.mapViewModel.getOSMRoute().observe(this, (nodes) ->{ + this.mapViewModel.getOSMRoute().observe(this, (nodes) -> { setPointsInMap(nodes); }); } private void drawWalkedRoute() { - List visitedLocations = AppDatabaseManager.getInstance(getApplicationContext()).getCurrentLocationsFromRoute(this.mapViewModel.getCurrentRoute()); - List visitedPoints = new ArrayList<>(); + new Thread(() -> { + List visitedLocations = AppDatabaseManager.getInstance(getApplicationContext()).getCurrentLocationsFromRoute(this.mapViewModel.getCurrentRoute()); + List visitedPoints = new ArrayList<>(); - for (CurrentLocation c :visitedLocations) { - visitedPoints.add(new GeoPoint(c.getLatitude(), c.getLongitude())); - } + for (CurrentLocation c : visitedLocations) { + visitedPoints.add(new GeoPoint(c.getLatitude(), c.getLongitude())); + } + + Polyline visitedLine = new Polyline(); + visitedLine.getOutlinePaint().setColor(getColor(R.color.visited_line_color)); + visitedLine.getOutlinePaint().setStrokeCap(Paint.Cap.ROUND); + mMap.getOverlayManager().add(visitedLine); - Polyline visitedLine = new Polyline(); - visitedLine.getOutlinePaint().setColor(getColor(R.color.visited_line_color)); - visitedLine.getOutlinePaint().setStrokeCap(Paint.Cap.ROUND); - mMap.getOverlayManager().add(visitedLine); + visitedLine.setPoints(visitedPoints); - FragmentManager fragmentManager = getSupportFragmentManager(); - CompleteRouteFragment dialog = CompleteRouteFragment.newInstance(); - dialog.show(fragmentManager, "JOE"); + runOnUiThread(new Runnable() { + @Override + public void run() { + mMapController.setCenter(visitedPoints.get(0)); + } + }); + + findViewById(R.id.floatingStopButton).setVisibility(View.INVISIBLE); + findViewById(R.id.floatingFollowButton).setVisibility(View.INVISIBLE); + findViewById(R.id.floatingActionButton).setVisibility(View.INVISIBLE); + + FragmentManager fragmentManager = getSupportFragmentManager(); + CompleteRouteFragment dialog = CompleteRouteFragment.newInstance(); + dialog.show(fragmentManager, "JOE"); + }).start(); } private Polyline visitedLine; @@ -169,7 +212,7 @@ private void drawRouteList(HashMap> pointsMap) { nextPoints.add(visitedPoints.get(visitedPoints.size()-1)); // Checking if the lines have been made - if(visitedLine == null || notVisitedLine == null) { + if (visitedLine == null || notVisitedLine == null) { this.visitedLine = new Polyline(); this.visitedLine.getOutlinePaint().setColor(getColor(R.color.visited_line_color)); this.visitedLine.getOutlinePaint().setStrokeCap(Paint.Cap.ROUND); @@ -300,19 +343,20 @@ public int getDirectionIcon(int instruction) { } } - public GeoPoint getCenterOfRoute(HashMap> pointsMap){ + public GeoPoint getCenterOfRoute(HashMap> pointsMap) { float longPoints = 0.0f; float latPoints = 0.0f; List points = Stream.concat(pointsMap.get(false).stream(), pointsMap.get(true).stream()) .collect(Collectors.toList()); - for (Point point: points) { + for (Point point : points) { longPoints += point.getLongitude(); latPoints += point.getLatitude(); } return new GeoPoint((latPoints / points.size()), (longPoints / points.size())); } + private HashMap sightMarkers; public void setMarkersInMap(Map sights) { @@ -382,7 +426,7 @@ public void onFABClicked (View view){ new SightsListFragment(this.sightViewModel.getSights().getValue(), this).show(getSupportFragmentManager(), "list"); } - public void onFFBClicked (View view){ + public void onFFBClicked(View view) { mLocationOverlay.enableFollowLocation(); } @@ -410,5 +454,6 @@ public void onFSBClicked(View view) { if (this.mapViewModel == null) return; new Thread(() ->{ mapViewModel.getMapManager().stopRoute(mapViewModel.getCurrentRoute());}).start(); finish(); + } } \ No newline at end of file diff --git a/app/src/main/java/nl/ags/picum/UI/fragments/RouteDetailsFragment.java b/app/src/main/java/nl/ags/picum/UI/fragments/RouteDetailsFragment.java index 86d4530..c6a1b14 100644 --- a/app/src/main/java/nl/ags/picum/UI/fragments/RouteDetailsFragment.java +++ b/app/src/main/java/nl/ags/picum/UI/fragments/RouteDetailsFragment.java @@ -10,6 +10,7 @@ import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; diff --git a/app/src/main/res/layout/fragment_complete_route.xml b/app/src/main/res/layout/fragment_complete_route.xml index 3b407dc..d162649 100644 --- a/app/src/main/res/layout/fragment_complete_route.xml +++ b/app/src/main/res/layout/fragment_complete_route.xml @@ -4,14 +4,17 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginHorizontal="30dp" tools:context=".UI.fragments.CompleteRouteFragment"> @@ -20,7 +23,9 @@ android:id="@+id/CloseFragmentButton" android:layout_width="0dp" android:layout_height="wrap_content" - android:layout_marginHorizontal="30dp" + android:layout_margin="10dp" + android:text="@string/close_window" + app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/FragmentCongratsMessage" /> diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index cae4233..b408f73 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -62,4 +62,6 @@ east step One-kilometre route where you will see the most interesting and important monuments of Breda + You have completed the route. The route shown above was the route you\'ve actually walked + Close window \ No newline at end of file diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index 16755b5..ab06279 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -62,4 +62,6 @@ oost stap Route van een kilometer waarbij u de meest bezienswaardige en belangrijkste monumenten van Breda ziet. + U heeft de route voltooid. U heeft de bovenstaande route gelopen + Sluit venster \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 09f58b9..5bd0f35 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -61,6 +61,7 @@ east step One-kilometre route where you will see the most interesting and important monuments of Breda - Hello blank fragment + You have completed the route. The route shown above was the route you\'ve actually walked + Close window \ No newline at end of file