Added distance from current location to opend location
This commit is contained in:
@@ -11,6 +11,7 @@ public enum Data {
|
||||
private int locationsVisited = 0;
|
||||
private long totalTime = 0;
|
||||
private double zoom = 0;
|
||||
private android.location.Location location;
|
||||
|
||||
public double getZoom() {
|
||||
return zoom;
|
||||
@@ -51,4 +52,11 @@ public enum Data {
|
||||
}
|
||||
|
||||
|
||||
public android.location.Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(android.location.Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,6 +338,7 @@ public class HomeFragment extends Fragment implements LocationListener {
|
||||
// can't walk 100 meters in a few seconds
|
||||
if (distance < 100)
|
||||
Data.INSTANCE.addDistance(distance);
|
||||
Data.INSTANCE.setLocation(location);
|
||||
}
|
||||
currentLocation = location;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.a1.nextlocation.fragments;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -13,6 +15,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.a1.nextlocation.R;
|
||||
import com.a1.nextlocation.data.Data;
|
||||
import com.a1.nextlocation.data.Location;
|
||||
import com.a1.nextlocation.recyclerview.LocationListManager;
|
||||
|
||||
@@ -37,6 +40,7 @@ public class LocationDetailFragment extends Fragment {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
@@ -45,8 +49,26 @@ public class LocationDetailFragment extends Fragment {
|
||||
this.titelText = view.findViewById(R.id.detail_location_name);
|
||||
this.titelText.setText(location.getName());
|
||||
|
||||
double currentDistanceToLocation = 0.0;
|
||||
if(Data.INSTANCE.getLocation() != null){
|
||||
currentDistanceToLocation = Location.getDistance(Data.INSTANCE.getLocation().getLatitude(), Data.INSTANCE.getLocation().getLongitude(), this.location.getLat(), this.location.getLong());
|
||||
}
|
||||
|
||||
String detailText = "";
|
||||
if(getContext().getSharedPreferences("Settings", Context.MODE_PRIVATE).getBoolean("imperialSwitch", false)){
|
||||
if(currentDistanceToLocation > 1609)
|
||||
detailText = location.getDescription() + String.format("%.3f",currentDistanceToLocation * 0.000621371192) + "mi";
|
||||
else
|
||||
detailText = location.getDescription() + String.format("%.2f",currentDistanceToLocation * 1.0936133) + "yd";
|
||||
} else {
|
||||
if(currentDistanceToLocation > 1000)
|
||||
detailText = location.getDescription() + String.format("%.3f",currentDistanceToLocation / 1000) + "km";
|
||||
else
|
||||
detailText = location.getDescription() + currentDistanceToLocation + "m";
|
||||
}
|
||||
|
||||
this.detailText = view.findViewById(R.id.detail_location_text);
|
||||
this.detailText.setText(location.getDescription());
|
||||
this.detailText.setText(detailText);
|
||||
|
||||
//Initialises the back button
|
||||
this.backButton = view.findViewById(R.id.detail_location_back_button);
|
||||
|
||||
Reference in New Issue
Block a user