Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pop up #62

Merged
merged 3 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/java/nl/ags/picum/UI/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected void onCreate(Bundle savedInstanceState) {
AppDatabaseManager manager = AppDatabaseManager.getInstance(getApplicationContext());
this.routes.clear();


List<Route> tempList = manager.getRoutes();

this.routes.addAll(tempList);
Expand Down
103 changes: 74 additions & 29 deletions app/src/main/java/nl/ags/picum/UI/MapActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package nl.ags.picum.UI;



import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
Expand Down Expand Up @@ -41,6 +43,7 @@

import nl.ags.picum.R;
import nl.ags.picum.UI.fragments.CompleteRouteFragment;
import nl.ags.picum.UI.fragments.SightDetailsPopupFragment;
import nl.ags.picum.UI.Util.InstructionConverter;
import nl.ags.picum.UI.fragments.SightsListFragment;
import nl.ags.picum.UI.viewmodels.MapViewModel;
Expand Down Expand Up @@ -77,22 +80,19 @@ protected void onCreate(Bundle savedInstanceState) {

this.mapViewModel.getMapManager().setSightViewModel(sightViewModel);

sightViewModel.getCurrentSight().observe(this, this::onSightChanged);
sightViewModel.getSights().observe(this, this::onSightsChanged);
this.sightViewModel.getCurrentSight().observe(this, this::onSightChanged);
this.sightViewModel.getSights().observe(this, this::onSightsChanged);

this.sightViewModel.getCurrentSight().observe(this, (sight) -> {
FragmentManager fragmentManager = getSupportFragmentManager();
SightDetailsPopupFragment dialog = new SightDetailsPopupFragment(sight, this);
dialog.show(fragmentManager, "JOE");

calcProgress();

// Observe CalculatedRoute points
this.mapViewModel.getCalculatedRoute().observe(this, (pointsMap) -> {
// TODO: 17-12-2021 setPointsInMap method not called, visited points line are other method
//setPointsInMap(points);
drawRouteList(pointsMap);
mMapController.setCenter(getCenterOfRoute(pointsMap));
Log.d("ENTERLOCATION", sight.getSightName());
});

// observer the raw-route
this.mapViewModel.getOSMRoute().observe(this, this::setPointsInMap);

this.mMap = findViewById(R.id.MainMap);
Configuration.getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));
Configuration.getInstance().setUserAgentValue(BuildConfig.APPLICATION_ID);
Expand All @@ -110,13 +110,41 @@ protected void onCreate(Bundle savedInstanceState) {
Log.d("pizzaparty", "onCreate: " + mapViewModel.getCurrentRoute());
}

private void calcProgress() {
new Thread(() -> {
double amountOfVisitedSights = 0;
List<Waypoint> waypoints = AppDatabaseManager.getInstance(getApplicationContext()).getWaypointsWithSight(mapViewModel.getCurrentRoute());

for (Waypoint w : waypoints) {

if (w.isVisited())
amountOfVisitedSights++;
}

double divide = amountOfVisitedSights / waypoints.size();
int progress = (int) (divide * 100);

runOnUiThread(new Runnable() {
@Override
public void run() {
checkProgress(progress);
}
});
}).start();
}

private void checkProgress(int progress) {
if (progress == 100) {
drawWalkedRoute();

new Thread(() -> {
if (this.mapViewModel == null) return;
mapViewModel.getMapManager().stopRoute(mapViewModel.getCurrentRoute());
}).start();

} else {
drawYetToWalkRoute();
}

}

private void drawYetToWalkRoute() {
Expand All @@ -130,27 +158,42 @@ private void drawYetToWalkRoute() {
});

// observer the raw-route
this.mapViewModel.getOSMRoute().observe(this, (nodes) ->{
this.mapViewModel.getOSMRoute().observe(this, (nodes) -> {
setPointsInMap(nodes);
});
}

private void drawWalkedRoute() {
List<CurrentLocation> visitedLocations = AppDatabaseManager.getInstance(getApplicationContext()).getCurrentLocationsFromRoute(this.mapViewModel.getCurrentRoute());
List<GeoPoint> visitedPoints = new ArrayList<>();
new Thread(() -> {
List<CurrentLocation> visitedLocations = AppDatabaseManager.getInstance(getApplicationContext()).getCurrentLocationsFromRoute(this.mapViewModel.getCurrentRoute());
List<GeoPoint> visitedPoints = new ArrayList<>();

for (CurrentLocation c :visitedLocations) {
visitedPoints.add(new GeoPoint(c.getLatitude(), c.getLongitude()));
}
for (CurrentLocation c : visitedLocations) {
visitedPoints.add(new GeoPoint(c.getLatitude(), c.getLongitude()));
}

Polyline visitedLine = new Polyline();
visitedLine.getOutlinePaint().setColor(getColor(R.color.visited_line_color));
visitedLine.getOutlinePaint().setStrokeCap(Paint.Cap.ROUND);
mMap.getOverlayManager().add(visitedLine);

Polyline visitedLine = new Polyline();
visitedLine.getOutlinePaint().setColor(getColor(R.color.visited_line_color));
visitedLine.getOutlinePaint().setStrokeCap(Paint.Cap.ROUND);
mMap.getOverlayManager().add(visitedLine);
visitedLine.setPoints(visitedPoints);

FragmentManager fragmentManager = getSupportFragmentManager();
CompleteRouteFragment dialog = CompleteRouteFragment.newInstance();
dialog.show(fragmentManager, "JOE");
runOnUiThread(new Runnable() {
@Override
public void run() {
mMapController.setCenter(visitedPoints.get(0));
}
});

findViewById(R.id.floatingStopButton).setVisibility(View.INVISIBLE);
findViewById(R.id.floatingFollowButton).setVisibility(View.INVISIBLE);
findViewById(R.id.floatingActionButton).setVisibility(View.INVISIBLE);

FragmentManager fragmentManager = getSupportFragmentManager();
CompleteRouteFragment dialog = CompleteRouteFragment.newInstance();
dialog.show(fragmentManager, "JOE");
}).start();
}

private Polyline visitedLine;
Expand All @@ -169,7 +212,7 @@ private void drawRouteList(HashMap<Boolean, List<Point>> pointsMap) {
nextPoints.add(visitedPoints.get(visitedPoints.size()-1));

// Checking if the lines have been made
if(visitedLine == null || notVisitedLine == null) {
if (visitedLine == null || notVisitedLine == null) {
this.visitedLine = new Polyline();
this.visitedLine.getOutlinePaint().setColor(getColor(R.color.visited_line_color));
this.visitedLine.getOutlinePaint().setStrokeCap(Paint.Cap.ROUND);
Expand Down Expand Up @@ -300,19 +343,20 @@ public int getDirectionIcon(int instruction) {
}
}

public GeoPoint getCenterOfRoute(HashMap<Boolean, List<Point>> pointsMap){
public GeoPoint getCenterOfRoute(HashMap<Boolean, List<Point>> pointsMap) {
float longPoints = 0.0f;
float latPoints = 0.0f;
List<Point> points = Stream.concat(pointsMap.get(false).stream(), pointsMap.get(true).stream())
.collect(Collectors.toList());

for (Point point: points) {
for (Point point : points) {
longPoints += point.getLongitude();
latPoints += point.getLatitude();
}
return new GeoPoint((latPoints / points.size()), (longPoints / points.size()));
}


private HashMap<Sight, Marker> sightMarkers;

public void setMarkersInMap(Map<Sight, Waypoint> sights) {
Expand Down Expand Up @@ -382,7 +426,7 @@ public void onFABClicked (View view){
new SightsListFragment(this.sightViewModel.getSights().getValue(), this).show(getSupportFragmentManager(), "list");
}

public void onFFBClicked (View view){
public void onFFBClicked(View view) {
mLocationOverlay.enableFollowLocation();
}

Expand Down Expand Up @@ -410,5 +454,6 @@ public void onFSBClicked(View view) {
if (this.mapViewModel == null) return;
new Thread(() ->{ mapViewModel.getMapManager().stopRoute(mapViewModel.getCurrentRoute());}).start();
finish();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/res/layout/fragment_complete_route.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
tools:context=".UI.fragments.CompleteRouteFragment">

<TextView
android:id="@+id/FragmentCongratsMessage"
android:layout_width="wrap_content"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="U heeft de route voltooid. \n U heeft de bovenstaande route gelopen"
android:text="@string/walked_route"
android:layout_marginVertical="30dp"
android:layout_marginHorizontal="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -20,7 +23,9 @@
android:id="@+id/CloseFragmentButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="30dp"
android:layout_margin="10dp"
android:text="@string/close_window"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/FragmentCongratsMessage" />
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@
<string name="east">east</string>
<string name="step">step</string>
<string name="HistorischeBeschrijving">One-kilometre route where you will see the most interesting and important monuments of Breda</string>
<string name="walked_route">You have completed the route. The route shown above was the route you\'ve actually walked</string>
<string name="close_window">Close window</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@
<string name="east">oost</string>
<string name="step">stap</string>
<string name="HistorischeBeschrijving">Route van een kilometer waarbij u de meest bezienswaardige en belangrijkste monumenten van Breda ziet.</string>
<string name="walked_route">U heeft de route voltooid. U heeft de bovenstaande route gelopen</string>
<string name="close_window">Sluit venster</string>
</resources>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<string name="east">east</string>
<string name="step">step</string>
<string name="HistorischeBeschrijving">One-kilometre route where you will see the most interesting and important monuments of Breda</string>
<string name="hello_blank_fragment" translatable="false">Hello blank fragment</string>
<string name="walked_route">You have completed the route. The route shown above was the route you\'ve actually walked</string>
<string name="close_window">Close window</string>

</resources>