Saves distance, visitedNames list and displays saved info in statistics.
This commit is contained in:
@@ -3,6 +3,7 @@ package com.a1.nextlocation.fragments;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.location.Location;
|
||||
@@ -336,8 +337,9 @@ public class HomeFragment extends Fragment implements LocationListener {
|
||||
if (currentLocation != null) {
|
||||
double distance = currentLocation.distanceTo(location); // in meters
|
||||
// can't walk 100 meters in a few seconds
|
||||
if (distance < 100)
|
||||
if (distance < 100) {
|
||||
Data.INSTANCE.addDistance(distance);
|
||||
}
|
||||
}
|
||||
currentLocation = location;
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ public class StatisticFragment extends Fragment {
|
||||
|
||||
private void initializeDistanceTextView(View view){
|
||||
distance = view.findViewById(R.id.statistics_km);
|
||||
double dist = Data.INSTANCE.getDistanceTraveled()/1000;
|
||||
double dist = Double.parseDouble(getContext().getSharedPreferences("Data", Context.MODE_PRIVATE).getString("distanceTraveled", "0")) /1000;
|
||||
if (getContext().getSharedPreferences("Settings", Context.MODE_PRIVATE).getBoolean("imperialSwitch", false))
|
||||
distance.setText("" + String.format("%.1f",dist * 0.621371) + " mi");
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user