rename staticdata to data
This commit is contained in:
@@ -1,88 +1,55 @@
|
|||||||
package com.a1.nextlocation.data;
|
package com.a1.nextlocation.data;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Data {
|
/**
|
||||||
|
* singleton to keep track of different global data
|
||||||
|
*/
|
||||||
|
public enum Data {
|
||||||
|
INSTANCE;
|
||||||
|
private double distanceTraveled = 0;
|
||||||
|
private int locationsVisited = 0;
|
||||||
|
private long totalTime = 0;
|
||||||
|
private double zoom = 0;
|
||||||
|
|
||||||
private float distanceTraveled;
|
public double getZoom() {
|
||||||
|
return zoom;
|
||||||
private int locationsVisited;
|
|
||||||
|
|
||||||
private int totalTime;
|
|
||||||
|
|
||||||
private List<Coupon> couponList;
|
|
||||||
|
|
||||||
private Location nextLocation;
|
|
||||||
|
|
||||||
private Location lastLocation;
|
|
||||||
|
|
||||||
private Route currentRoute;
|
|
||||||
|
|
||||||
|
|
||||||
public Data() {
|
|
||||||
this.distanceTraveled = 0;
|
|
||||||
this.locationsVisited = 0;
|
|
||||||
this.totalTime = 0;
|
|
||||||
couponList = new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public float getDistanceTraveled() {
|
public void setZoom(double zoom) {
|
||||||
|
this.zoom = zoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<String> visitedNames = new ArrayList<>();
|
||||||
|
|
||||||
|
public void addDistance(double d) {
|
||||||
|
distanceTraveled += d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTotalTime() {
|
||||||
|
return totalTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addTimeWalked(long time) {
|
||||||
|
totalTime += time;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public double getDistanceTraveled() {
|
||||||
return distanceTraveled;
|
return distanceTraveled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDistanceTraveled(float distanceTraveled) {
|
public void visitLocation(Location location) {
|
||||||
this.distanceTraveled = distanceTraveled;
|
if (!visitedNames.contains(location.getName())) {
|
||||||
|
locationsVisited++;
|
||||||
|
visitedNames.add(location.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLocationsVisited() {
|
public int getLocationsVisited() {
|
||||||
return locationsVisited;
|
return locationsVisited;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocationsVisited(int locationsVisited) {
|
|
||||||
this.locationsVisited = locationsVisited;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTotalTime() {
|
|
||||||
return totalTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTotalTime(int totalTime) {
|
|
||||||
this.totalTime = totalTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Coupon> getCouponList() {
|
|
||||||
return couponList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCouponList(List<Coupon> couponList) {
|
|
||||||
this.couponList = couponList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getNextLocation() {
|
|
||||||
return nextLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNextLocation(Location nextLocation) {
|
|
||||||
this.nextLocation = nextLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLastLocation() {
|
|
||||||
return lastLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastLocation(Location lastLocation) {
|
|
||||||
this.lastLocation = lastLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Route getCurrentRoute() {
|
|
||||||
return currentRoute;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCurrentRoute(Route currentRoute) {
|
|
||||||
this.currentRoute = currentRoute;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,13 +45,13 @@ public enum RouteHandler {
|
|||||||
isFollowingRoute = false;
|
isFollowingRoute = false;
|
||||||
currentRoute = null;
|
currentRoute = null;
|
||||||
currentRouteLine = null;
|
currentRouteLine = null;
|
||||||
StaticData.INSTANCE.addTimeWalked(System.currentTimeMillis()-startedTime);
|
Data.INSTANCE.addTimeWalked(System.currentTimeMillis()-startedTime);
|
||||||
startedTime = 0;
|
startedTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void followRoute(Route route) {
|
public void followRoute(Route route) {
|
||||||
if (isFollowingRoute) {
|
if (isFollowingRoute) {
|
||||||
StaticData.INSTANCE.addTimeWalked(System.currentTimeMillis()-startedTime);
|
Data.INSTANCE.addTimeWalked(System.currentTimeMillis()-startedTime);
|
||||||
}
|
}
|
||||||
this.currentRoute = route;
|
this.currentRoute = route;
|
||||||
setFollowingRoute(true);
|
setFollowingRoute(true);
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
package com.a1.nextlocation.data;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* singleton to keep track of different global data
|
|
||||||
*/
|
|
||||||
public enum StaticData {
|
|
||||||
INSTANCE;
|
|
||||||
private double distanceTraveled = 0;
|
|
||||||
private int locationsVisited = 0;
|
|
||||||
private long timeWalked = 0;
|
|
||||||
private double zoom = 0;
|
|
||||||
|
|
||||||
public double getZoom() {
|
|
||||||
return zoom;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setZoom(double zoom) {
|
|
||||||
this.zoom = zoom;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArrayList<String> visitedNames = new ArrayList<>();
|
|
||||||
|
|
||||||
public void addDistance(double d) {
|
|
||||||
distanceTraveled += d;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getTimeWalked() {
|
|
||||||
return timeWalked;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addTimeWalked(long time) {
|
|
||||||
timeWalked += time;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public double getDistanceTraveled() {
|
|
||||||
return distanceTraveled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void visitLocation(Location location) {
|
|
||||||
if (!visitedNames.contains(location.getName())) {
|
|
||||||
locationsVisited++;
|
|
||||||
visitedNames.add(location.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLocationsVisited() {
|
|
||||||
return locationsVisited;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -27,7 +27,7 @@ import androidx.fragment.app.FragmentActivity;
|
|||||||
|
|
||||||
import com.a1.nextlocation.R;
|
import com.a1.nextlocation.R;
|
||||||
import com.a1.nextlocation.data.RouteHandler;
|
import com.a1.nextlocation.data.RouteHandler;
|
||||||
import com.a1.nextlocation.data.StaticData;
|
import com.a1.nextlocation.data.Data;
|
||||||
import com.a1.nextlocation.json.DirectionsResult;
|
import com.a1.nextlocation.json.DirectionsResult;
|
||||||
import com.a1.nextlocation.network.ApiHandler;
|
import com.a1.nextlocation.network.ApiHandler;
|
||||||
import com.a1.nextlocation.network.DirectionsListener;
|
import com.a1.nextlocation.network.DirectionsListener;
|
||||||
@@ -181,10 +181,10 @@ public class HomeFragment extends Fragment implements LocationListener {
|
|||||||
|
|
||||||
// add the zoom controller
|
// add the zoom controller
|
||||||
IMapController mapController = mapView.getController();
|
IMapController mapController = mapView.getController();
|
||||||
if (StaticData.INSTANCE.getZoom() == 0) {
|
if (Data.INSTANCE.getZoom() == 0) {
|
||||||
StaticData.INSTANCE.setZoom(15.0);
|
Data.INSTANCE.setZoom(15.0);
|
||||||
}
|
}
|
||||||
mapController.setZoom(StaticData.INSTANCE.getZoom());
|
mapController.setZoom(Data.INSTANCE.getZoom());
|
||||||
|
|
||||||
// add location manager and set the start point
|
// add location manager and set the start point
|
||||||
LocationManager locationManager = (LocationManager) requireActivity().getSystemService(Context.LOCATION_SERVICE);
|
LocationManager locationManager = (LocationManager) requireActivity().getSystemService(Context.LOCATION_SERVICE);
|
||||||
@@ -341,7 +341,7 @@ public class HomeFragment extends Fragment implements LocationListener {
|
|||||||
double distance = currentLocation.distanceTo(location); // in meters
|
double distance = currentLocation.distanceTo(location); // in meters
|
||||||
// can't walk 100 meters in a few seconds
|
// can't walk 100 meters in a few seconds
|
||||||
if (distance < 100)
|
if (distance < 100)
|
||||||
StaticData.INSTANCE.addDistance(distance);
|
Data.INSTANCE.addDistance(distance);
|
||||||
}
|
}
|
||||||
currentLocation = location;
|
currentLocation = location;
|
||||||
|
|
||||||
@@ -357,12 +357,12 @@ public class HomeFragment extends Fragment implements LocationListener {
|
|||||||
for (com.a1.nextlocation.data.Location l : LocationListManager.INSTANCE.getLocationList()) {
|
for (com.a1.nextlocation.data.Location l : LocationListManager.INSTANCE.getLocationList()) {
|
||||||
// mark the location visited if we are less than 20 meters away
|
// mark the location visited if we are less than 20 meters away
|
||||||
if (com.a1.nextlocation.data.Location.getDistance(currentLocation.getLatitude(), currentLocation.getLongitude(), l.getLat(), l.getLong()) < 20) {
|
if (com.a1.nextlocation.data.Location.getDistance(currentLocation.getLatitude(), currentLocation.getLongitude(), l.getLat(), l.getLong()) < 20) {
|
||||||
StaticData.INSTANCE.visitLocation(l);
|
Data.INSTANCE.visitLocation(l);
|
||||||
if (l.equals(last)) stopRoute();
|
if (l.equals(last)) stopRoute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StaticData.INSTANCE.setZoom(mapView.getZoomLevelDouble());
|
Data.INSTANCE.setZoom(mapView.getZoomLevelDouble());
|
||||||
});
|
});
|
||||||
|
|
||||||
t.start();
|
t.start();
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import com.a1.nextlocation.R;
|
import com.a1.nextlocation.R;
|
||||||
import com.a1.nextlocation.data.Coupon;
|
import com.a1.nextlocation.data.Coupon;
|
||||||
import com.a1.nextlocation.data.StaticData;
|
import com.a1.nextlocation.data.Data;
|
||||||
import com.a1.nextlocation.recyclerview.CouponAdapter;
|
import com.a1.nextlocation.recyclerview.CouponAdapter;
|
||||||
import com.a1.nextlocation.recyclerview.CouponListManager;
|
import com.a1.nextlocation.recyclerview.CouponListManager;
|
||||||
|
|
||||||
@@ -39,11 +39,11 @@ public class StatisticFragment extends Fragment {
|
|||||||
TextView distance = view.findViewById(R.id.statistics_km);
|
TextView distance = view.findViewById(R.id.statistics_km);
|
||||||
TextView locs = view.findViewById(R.id.statistics_locations_visited);
|
TextView locs = view.findViewById(R.id.statistics_locations_visited);
|
||||||
TextView timeText = view.findViewById(R.id.statistics_time_value);
|
TextView timeText = view.findViewById(R.id.statistics_time_value);
|
||||||
double dist = StaticData.INSTANCE.getDistanceTraveled()/1000;
|
double dist = Data.INSTANCE.getDistanceTraveled()/1000;
|
||||||
distance.setText("" + String.format("%.1f",dist) + " km");
|
distance.setText("" + String.format("%.1f",dist) + " km");
|
||||||
locs.setText("" + StaticData.INSTANCE.getLocationsVisited());
|
locs.setText("" + Data.INSTANCE.getLocationsVisited());
|
||||||
|
|
||||||
long seconds = StaticData.INSTANCE.getTimeWalked() / 1000;
|
long seconds = Data.INSTANCE.getTotalTime() / 1000;
|
||||||
long p1 = seconds % 60;
|
long p1 = seconds % 60;
|
||||||
long p2 = seconds / 60;
|
long p2 = seconds / 60;
|
||||||
long p3 = p2 % 60;
|
long p3 = p2 % 60;
|
||||||
|
|||||||
49
app/src/test/java/com/a1/nextlocation/DataTest.java
Normal file
49
app/src/test/java/com/a1/nextlocation/DataTest.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package com.a1.nextlocation;
|
||||||
|
|
||||||
|
import com.a1.nextlocation.data.Location;
|
||||||
|
import com.a1.nextlocation.data.Data;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
import static org.junit.Assert.assertNotSame;
|
||||||
|
|
||||||
|
public class DataTest {
|
||||||
|
private Data Data;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init(){
|
||||||
|
Data = Data.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDistance(){
|
||||||
|
Data.addDistance(2356.234);
|
||||||
|
double expected = 2356.234;
|
||||||
|
assertEquals(expected, Data.getDistanceTraveled(), 0.01);
|
||||||
|
Data.addDistance(234342.1);
|
||||||
|
assertNotEquals(expected, Data.getDistanceTraveled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTimeWalked(){
|
||||||
|
Data.addTimeWalked(3456);
|
||||||
|
long expected = 3456;
|
||||||
|
assertEquals(expected, Data.getTimeWalked());
|
||||||
|
Data.addTimeWalked(3445);
|
||||||
|
assertNotEquals(expected, Data.getTimeWalked());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVisitedLocation(){
|
||||||
|
Location testLocation = new Location("test", "test", "test", "test");
|
||||||
|
Data.visitLocation(testLocation);
|
||||||
|
int expected = 1;
|
||||||
|
assertEquals(expected, Data.getLocationsVisited());
|
||||||
|
Data.visitLocation(new Location("TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE"));
|
||||||
|
assertNotEquals(expected, Data.getLocationsVisited());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package com.a1.nextlocation;
|
|
||||||
|
|
||||||
import com.a1.nextlocation.data.Location;
|
|
||||||
import com.a1.nextlocation.data.StaticData;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotEquals;
|
|
||||||
import static org.junit.Assert.assertNotSame;
|
|
||||||
|
|
||||||
public class StaticDataTest {
|
|
||||||
private StaticData staticData;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void init(){
|
|
||||||
staticData = StaticData.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDistance(){
|
|
||||||
staticData.addDistance(2356.234);
|
|
||||||
double expected = 2356.234;
|
|
||||||
assertEquals(expected, staticData.getDistanceTraveled(), 0.01);
|
|
||||||
staticData.addDistance(234342.1);
|
|
||||||
assertNotEquals(expected, staticData.getDistanceTraveled());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testTimeWalked(){
|
|
||||||
staticData.addTimeWalked(3456);
|
|
||||||
long expected = 3456;
|
|
||||||
assertEquals(expected, staticData.getTimeWalked());
|
|
||||||
staticData.addTimeWalked(3445);
|
|
||||||
assertNotEquals(expected, staticData.getTimeWalked());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testVisitedLocation(){
|
|
||||||
Location testLocation = new Location("test", "test", "test", "test");
|
|
||||||
staticData.visitLocation(testLocation);
|
|
||||||
int expected = 1;
|
|
||||||
assertEquals(expected, staticData.getLocationsVisited());
|
|
||||||
staticData.visitLocation(new Location("TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE", "TESTFORFALSE"));
|
|
||||||
assertNotEquals(expected, staticData.getLocationsVisited());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user