From bd623a3f1d5dcef6bac99575ab9ecaadc6552160 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Wed, 6 Jan 2021 13:54:30 +0100 Subject: [PATCH] stuff --- .../a1/nextlocation/fragments/HomeFragment.java | 14 +++++++++----- .../fragments/RouteDetailFragment.java | 2 +- .../com/a1/nextlocation/json/DirectionsResult.java | 4 ++++ app/src/main/res/layout/coupon_item.xml | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/a1/nextlocation/fragments/HomeFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/HomeFragment.java index 1b8f2e6..bd4155f 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/HomeFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/HomeFragment.java @@ -90,7 +90,7 @@ public class HomeFragment extends Fragment implements LocationListener { stopButton.setOnClickListener(v -> { RouteHandler.INSTANCE.finishRoute(); stopButton.setVisibility(View.GONE); - Toast.makeText(requireContext(),getResources().getString(R.string.route_stop_toast),Toast.LENGTH_SHORT).show(); + Toast.makeText(requireContext(), getResources().getString(R.string.route_stop_toast), Toast.LENGTH_SHORT).show(); mapView.getOverlays().remove(roadOverlay); mapView.getOverlays().remove(allLocationsOverlay); addLocations(); @@ -109,6 +109,7 @@ public class HomeFragment extends Fragment implements LocationListener { /** * callback method that gets called when there are new directions available in the form of a {@link DirectionsResult} object. + * * @param directionsResult the directions received from the api */ private void onDirectionsAvailable(DirectionsResult directionsResult) { @@ -285,9 +286,9 @@ public class HomeFragment extends Fragment implements LocationListener { } /** + * @param permissions tbe permissions we want to ask * @author Ricky * request the permissions needed for location and network, made by Ricky - * @param permissions tbe permissions we want to ask */ private void requestPermissionsIfNecessary(String... permissions) { ArrayList permissionsToRequest = new ArrayList<>(); @@ -309,14 +310,17 @@ public class HomeFragment extends Fragment implements LocationListener { /** * location callback that gets called each time the location is updated. It is used for updating the distance walked and checking if there are locations you have visited + * * @param location the new location */ @Override public void onLocationChanged(@NonNull Location location) { // calculate the distance walked - double distance = currentLocation.distanceTo(location); // in meters - StaticData.INSTANCE.addDistance(distance); - currentLocation = location; + if (currentLocation != null && currentLocation.getLatitude() != 0 && currentLocation.getLongitude() != 0) { + double distance = currentLocation.distanceTo(location); // in meters + StaticData.INSTANCE.addDistance(distance); + currentLocation = location; + } //new thread because we don't want the main thread to hang, this method gets called a lot Thread t = new Thread(() -> { diff --git a/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java b/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java index 1f0259c..917a54d 100644 --- a/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java +++ b/app/src/main/java/com/a1/nextlocation/fragments/RouteDetailFragment.java @@ -36,7 +36,7 @@ public class RouteDetailFragment extends Fragment { this.route = getArguments().getParcelable("route"); } - this.routeDetailText = view.findViewById(R.id.routeDetailText); + this.routeDetailText = view.findViewById(R.id.reoute_detail_tekst); this.routeDetailText.setText(this.route.getName()); Button startButton = view.findViewById(R.id.start_route_button); startButton.setOnClickListener(this::startRoute); diff --git a/app/src/main/java/com/a1/nextlocation/json/DirectionsResult.java b/app/src/main/java/com/a1/nextlocation/json/DirectionsResult.java index 7f52783..42ebe2f 100644 --- a/app/src/main/java/com/a1/nextlocation/json/DirectionsResult.java +++ b/app/src/main/java/com/a1/nextlocation/json/DirectionsResult.java @@ -132,6 +132,10 @@ public class DirectionsResult { } + /** + * parses the given json string into this object. This method is used for when you want to + * @param json + */ public void parseRoute(String json) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); diff --git a/app/src/main/res/layout/coupon_item.xml b/app/src/main/res/layout/coupon_item.xml index 783f34a..cb16242 100644 --- a/app/src/main/res/layout/coupon_item.xml +++ b/app/src/main/res/layout/coupon_item.xml @@ -24,7 +24,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="20dp" - android:text="@string/naam" + android:text="@string/app_name" android:textColor="@color/black" android:textSize="20sp" app:layout_constraintBottom_toBottomOf="parent"