Added distance from current location to opend location

This commit is contained in:
RemoMeijer
2021-01-12 12:18:21 +01:00
parent d4abd7a566
commit 0f17e8d1e5
5 changed files with 75 additions and 44 deletions

View File

@@ -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;

View File

@@ -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);