added updating location when you're close to it

This commit is contained in:
Sem van der Hoeven
2021-01-05 16:39:12 +01:00
parent 062739ac7b
commit 587380fd89
6 changed files with 66 additions and 1 deletions

View File

@@ -154,7 +154,12 @@ public class HomeFragment extends Fragment implements LocationListener{
try {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,this);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,0,0,this);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (currentLocation == null) {
currentLocation = location;
@@ -257,6 +262,16 @@ public class HomeFragment extends Fragment implements LocationListener{
double distance = currentLocation.distanceTo(location); // in meters
StaticData.INSTANCE.addDistance(distance);
currentLocation = location;
Thread t = new Thread(() -> {
for (com.a1.nextlocation.data.Location l : LocationListManager.INSTANCE.getLocationList()) {
if (com.a1.nextlocation.data.Location.getDistance(currentLocation.getLatitude(),currentLocation.getLongitude(),l.getLat(),l.getLong()) < 10) {
StaticData.INSTANCE.visitLocation(l);
}
}
});
t.start();
}
@Override

View File

@@ -16,6 +16,7 @@ import android.widget.Toast;
import com.a1.nextlocation.R;
import com.a1.nextlocation.data.Coupon;
import com.a1.nextlocation.data.StaticData;
import com.a1.nextlocation.recyclerview.CouponAdapter;
import com.a1.nextlocation.recyclerview.CouponListManager;
@@ -36,6 +37,13 @@ public class StatisticFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_statistic, container, false);
TextView distance = view.findViewById(R.id.statistics_km);
TextView locs = view.findViewById(R.id.statistics_locations_visited);
double dist = StaticData.INSTANCE.getDistanceTraveled()/1000;
distance.setText("" + String.format("%.1f",dist) + " km");
locs.setText("" + StaticData.INSTANCE.getLocationsVisited());
this.couponList = CouponListManager.INSTANCE.getCouponList();
CouponAdapter adapter = new CouponAdapter(this.getContext(), this.couponList);
TextView couponNumber = view.findViewById(R.id.couponAmount);