yeet
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
package com.a1.nextlocation.data;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
@@ -11,6 +18,26 @@ public enum Data {
|
||||
private int locationsVisited = 0;
|
||||
private long totalTime = 0;
|
||||
private double zoom = 0;
|
||||
private SharedPreferences.Editor editor;
|
||||
private Context context;
|
||||
private LocationProximityListener locationProximityListener;
|
||||
|
||||
public void setContext(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void setEditor(SharedPreferences.Editor editor) {
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
|
||||
public LocationProximityListener getLocationProximityListener() {
|
||||
return locationProximityListener;
|
||||
}
|
||||
|
||||
public void setLocationProximityListener(LocationProximityListener locationProximityListener) {
|
||||
this.locationProximityListener = locationProximityListener;
|
||||
}
|
||||
private android.location.Location location;
|
||||
|
||||
public double getZoom() {
|
||||
@@ -21,10 +48,13 @@ public enum Data {
|
||||
this.zoom = zoom;
|
||||
}
|
||||
|
||||
private final ArrayList<String> visitedNames = new ArrayList<>();
|
||||
private ArrayList<String> visitedNames = new ArrayList<>();
|
||||
|
||||
public void addDistance(double d) {
|
||||
distanceTraveled += d;
|
||||
|
||||
editor.putString("distanceTraveled", String.valueOf(distanceTraveled));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public long getTotalTime() {
|
||||
@@ -35,7 +65,6 @@ public enum Data {
|
||||
totalTime += time;
|
||||
}
|
||||
|
||||
|
||||
public double getDistanceTraveled() {
|
||||
return distanceTraveled;
|
||||
}
|
||||
@@ -44,6 +73,9 @@ public enum Data {
|
||||
if (!visitedNames.contains(location.getName())) {
|
||||
locationsVisited++;
|
||||
visitedNames.add(location.getName());
|
||||
saveVisitedNamesList();
|
||||
editor.putInt("locationsVisited", locationsVisited);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +83,31 @@ public enum Data {
|
||||
return locationsVisited;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface LocationProximityListener {
|
||||
void onLocationVisited(Location location);
|
||||
}
|
||||
|
||||
public void saveVisitedNamesList(){
|
||||
Gson gson = new Gson();
|
||||
String json = gson.toJson(visitedNames);
|
||||
editor.putString("visitedNames", json);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public ArrayList<String> loadAndGetVisitedNamesList(){
|
||||
String json = context.getSharedPreferences("Data", Context.MODE_PRIVATE).getString("visitedNames", "[]");
|
||||
Type type = new TypeToken<ArrayList<String>>() {}.getType();
|
||||
visitedNames = new Gson().fromJson(json, type);
|
||||
return visitedNames;
|
||||
}
|
||||
|
||||
public void load(){
|
||||
SharedPreferences prefs = context.getSharedPreferences("Data", Context.MODE_PRIVATE);
|
||||
this.editor = prefs.edit();
|
||||
Data.INSTANCE.addDistance(Double.parseDouble(prefs.getString("distanceTraveled", "0")));
|
||||
this.locationsVisited = loadAndGetVisitedNamesList().size();
|
||||
}
|
||||
|
||||
public android.location.Location getLocation() {
|
||||
return location;
|
||||
|
||||
@@ -25,6 +25,8 @@ public class Location implements Parcelable {
|
||||
private String imageUrl;
|
||||
private String iconUrl;
|
||||
|
||||
private boolean visited;
|
||||
|
||||
public Location(@NotNull String name, String coordinates, String description, @Nullable String imageUrl) {
|
||||
this.name = name;
|
||||
this.coordinates = coordinates;
|
||||
@@ -171,4 +173,12 @@ public class Location implements Parcelable {
|
||||
parcel.writeString(description);
|
||||
parcel.writeString(imageUrl);
|
||||
}
|
||||
|
||||
public boolean isVisited() {
|
||||
return visited;
|
||||
}
|
||||
|
||||
public void setVisited(boolean visited) {
|
||||
this.visited = visited;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,15 @@ public enum RouteHandler {
|
||||
private int stepCount = 0;
|
||||
private RouteFinishedListener routeFinishedListener;
|
||||
private long startedTime;
|
||||
private double currentRouteDuration;
|
||||
|
||||
public void setCurrentRouteDuration(double currentRouteDuration) {
|
||||
this.currentRouteDuration = currentRouteDuration;
|
||||
}
|
||||
|
||||
public double getCurrentRouteDuration() {
|
||||
return currentRouteDuration;
|
||||
}
|
||||
|
||||
private Polyline currentRouteLine;
|
||||
|
||||
@@ -20,6 +29,7 @@ public enum RouteHandler {
|
||||
this.currentRouteLine = currentRouteLine;
|
||||
}
|
||||
|
||||
|
||||
public Polyline getCurrentRouteLine() {
|
||||
return currentRouteLine;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user