Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import de.stephanlindauer.criticalmaps.events.NewLocationEvent;
import de.stephanlindauer.criticalmaps.events.NewServerResponseEvent;
import de.stephanlindauer.criticalmaps.handler.GetLocationHandler;
// import de.stephanlindauer.criticalmaps.handler.ShowGpxHandler;
import de.stephanlindauer.criticalmaps.handler.ShowGpxHandler;
import de.stephanlindauer.criticalmaps.managers.LocationUpdateManager;
import de.stephanlindauer.criticalmaps.model.OtherUsersLocationModel;
import de.stephanlindauer.criticalmaps.model.OwnLocationModel;
Expand Down Expand Up @@ -90,10 +90,8 @@ public class MapFragment extends Fragment {
@Inject
LocationUpdateManager locationUpdateManager;

/*
@Inject
ShowGpxHandler showGpxHandler;
*/

@Inject
SharedPreferences sharedPreferences;
Expand Down Expand Up @@ -216,6 +214,8 @@ public void getOutline(View view, Outline outline) {
mapStyle = style;
MapViewUtils.setupSourcesAndLayers(getActivity(), mapStyle);

showGpxHandler.showGpx(mapStyle);

// trigger fake location update in case fix was acquired already during map init
handleNewLocation(NEW_LOCATION_EVENT);
});
Expand All @@ -234,8 +234,6 @@ public void getOutline(View view, Outline outline) {
isInitialLocationSet = savedState.getBoolean(KEY_INITIAL_LOCATION_SET, false);
}

// showGpxHandler.showGpx(mapView);

if (!LocationUpdateManager.checkPermission()) {
zoomToLocation(defaultGeoPoint, NO_GPS_PERMISSION_ZOOM_LEVEL);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package de.stephanlindauer.criticalmaps.fragments;

// import android.annotation.SuppressLint;
// import android.app.Activity;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
// import android.database.Cursor;
// import android.net.Uri;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
// import android.provider.OpenableColumns;
import android.provider.OpenableColumns;
import android.text.format.Formatter;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -22,15 +22,15 @@
import de.stephanlindauer.criticalmaps.App;
import de.stephanlindauer.criticalmaps.R;
import de.stephanlindauer.criticalmaps.databinding.FragmentSettingsBinding;
// import de.stephanlindauer.criticalmaps.handler.ChooseGpxFileHandler;
import de.stephanlindauer.criticalmaps.handler.ChooseGpxFileHandler;
import de.stephanlindauer.criticalmaps.prefs.SharedPrefsKeys;
import de.stephanlindauer.criticalmaps.model.StorageLocation;
// import de.stephanlindauer.criticalmaps.vo.RequestCodes;
import de.stephanlindauer.criticalmaps.vo.RequestCodes;
import info.metadude.android.typedpreferences.BooleanPreference;
// import info.metadude.android.typedpreferences.StringPreference;
import info.metadude.android.typedpreferences.StringPreference;
import timber.log.Timber;

// import static de.stephanlindauer.criticalmaps.utils.GpxUtils.persistPermissionOnFile;
import static de.stephanlindauer.criticalmaps.utils.GpxUtils.persistPermissionOnFile;

import org.maplibre.android.offline.OfflineManager;

Expand Down Expand Up @@ -70,37 +70,33 @@ public void onViewStateRestored(@Nullable Bundle savedInstanceState) {

updateClearCachePref();
updateStorageGraph();
// updateGpxFileName();
updateGpxFileName();

binding.settingsShowOnLockscreenCheckbox.setChecked(
new BooleanPreference(sharedPreferences, SharedPrefsKeys.SHOW_ON_LOCKSCREEN).get());

binding.settingsKeepScreenOnCheckbox.setChecked(
new BooleanPreference(sharedPreferences, SharedPrefsKeys.KEEP_SCREEN_ON).get());

/*
binding.settingsShowGpxCheckbox.setChecked(
new BooleanPreference(sharedPreferences, SharedPrefsKeys.SHOW_GPX).get());
*/

binding.settingsClearCacheButton.setOnClickListener(v -> handleClearCacheClicked());

binding.settingsShowOnLockscreenCheckbox.setOnCheckedChangeListener(
(buttonView, isChecked) -> handleShowOnLockscreenChecked(isChecked));
binding.settingsKeepScreenOnCheckbox.setOnCheckedChangeListener(
(buttonView, isChecked) -> handleKeepScreenOnChecked(isChecked));
/*

binding.settingsShowGpxCheckbox.setOnCheckedChangeListener(
(buttonView, isChecked) -> handleShowTrack(isChecked));
binding.settingsChooseGpxContainer.setOnClickListener(v -> handleChooseTrackClicked());
*/
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

/*
if (requestCode == RequestCodes.CHOOSE_GPX_RESULT_CODE && resultCode == Activity.RESULT_OK) {
Uri fileUri = data.getData();
if (fileUri == null) {
Expand All @@ -112,7 +108,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
persistPermissionOnFile(data, app.getContentResolver());
updateGpxFileName();
}
*/
}

private void updateStorageGraph() {
Expand Down Expand Up @@ -141,7 +136,6 @@ private void updateClearCachePref() {
Formatter.formatShortFileSize(getActivity(), currentSize)));
}

/*
@SuppressLint("Range")
private void updateGpxFileName() {
String gpxFile = new StringPreference(
Expand All @@ -157,7 +151,6 @@ private void updateGpxFileName() {

binding.settingsChooseGpxSummaryText.setText(filename);
}
*/

void handleClearCacheClicked() {
OfflineManager.getInstance(getActivity()).clearAmbientCache(new OfflineManager.FileSourceCallback() {
Expand Down Expand Up @@ -185,7 +178,6 @@ void handleKeepScreenOnChecked(boolean isChecked) {
sharedPreferences, SharedPrefsKeys.KEEP_SCREEN_ON).set(isChecked);
}

/*
void handleShowTrack(boolean isChecked) {
new BooleanPreference(
sharedPreferences, SharedPrefsKeys.SHOW_GPX).set(isChecked);
Expand All @@ -194,7 +186,6 @@ void handleShowTrack(boolean isChecked) {
void handleChooseTrackClicked() {
new ChooseGpxFileHandler(this).openChooser();
}
*/

@Override
public void onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
/*
package de.stephanlindauer.criticalmaps.handler;

import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.widget.Toast;

import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Marker;
import org.osmdroid.views.overlay.Polyline;
import com.google.gson.JsonObject;

import org.maplibre.android.geometry.LatLng;
import org.maplibre.android.maps.Style;
import org.maplibre.android.style.sources.GeoJsonSource;

import org.maplibre.geojson.Feature;
import org.maplibre.geojson.FeatureCollection;
import org.maplibre.geojson.LineString;
import org.maplibre.geojson.Point;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import javax.inject.Inject;
import javax.xml.parsers.ParserConfigurationException;

import de.stephanlindauer.criticalmaps.App;
import de.stephanlindauer.criticalmaps.R;
import de.stephanlindauer.criticalmaps.model.gpx.GpxModel;
import de.stephanlindauer.criticalmaps.model.gpx.GpxPoi;
import de.stephanlindauer.criticalmaps.model.gpx.GpxTrack;
import de.stephanlindauer.criticalmaps.prefs.SharedPrefsKeys;
import de.stephanlindauer.criticalmaps.utils.GpxReader;
Expand All @@ -43,7 +48,7 @@ public ShowGpxHandler(SharedPreferences sharedPreferences, GpxModel gpxModel, Ap
this.gpxReader = gpxReader;
}

public void showGpx(MapView mapView) {
public void showGpx(Style mapStyle) {
boolean showTrack = new BooleanPreference(sharedPreferences, SharedPrefsKeys.SHOW_GPX).get();
if (!showTrack) {
return;
Expand All @@ -54,7 +59,7 @@ public void showGpx(MapView mapView) {
readFile(gpxUri);
}

showModelOnMap(mapView);
showModelOnMap(mapStyle);
}

private void readFile(String gpxUri) {
Expand All @@ -66,29 +71,44 @@ private void readFile(String gpxUri) {
}
}

private void showModelOnMap(MapView mapView) {
private void showModelOnMap(Style mapStyle) {
addTracksToMap(mapStyle);
addPoisToMap(mapStyle);
}

private void addTracksToMap(Style mapStyle) {
ArrayList<Feature> features = new ArrayList<>();

for (GpxTrack track : gpxModel.getTracks()) {
addTrackToMap(mapView, track);
}
ArrayList<Point> points = new ArrayList<>();

for (LatLng location : track.getWaypoints()) {
points.add(Point.fromLngLat(location.getLongitude(), location.getLatitude()));
}

for (GpxPoi poi : gpxModel.getPoiList()) {
addPoiToMap(mapView, poi);
JsonObject properties = new JsonObject();
properties.addProperty("label", track.getName());
features.add(Feature.fromGeometry(LineString.fromLngLats(points), properties));
}
}

private void addTrackToMap(MapView mapView, GpxTrack track) {
Polyline trackLine = new Polyline(mapView);
trackLine.setPoints(track.getWaypoints());
trackLine.setTitle(track.getName());
trackLine.getOutlinePaint().setColor(Color.RED);
mapView.getOverlayManager().add(trackLine);
GeoJsonSource gpxTrackSource =
(GeoJsonSource) mapStyle.getSource("gpxTrackSource");
gpxTrackSource.setGeoJson(FeatureCollection.fromFeatures(features));
}

private void addPoiToMap(MapView mapView, GpxPoi poi) {
Marker marker = new Marker(mapView);
marker.setPosition(poi.getPosition());
marker.setTitle(poi.getName());
mapView.getOverlayManager().add(marker);
private void addPoisToMap(Style mapStyle) {
ArrayList<Feature> features = new ArrayList<>();

gpxModel.getPoiList().forEach((gpxPoi) -> {
LatLng location = gpxPoi.getPosition();
JsonObject properties = new JsonObject();
properties.addProperty("label", gpxPoi.getName());
features.add(Feature.fromGeometry(
Point.fromLngLat(location.getLongitude(), location.getLatitude()), properties));
});

GeoJsonSource gpxPoiSource =
(GeoJsonSource) mapStyle.getSource("gpxPoiSource");
gpxPoiSource.setGeoJson(FeatureCollection.fromFeatures(features));
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*
package de.stephanlindauer.criticalmaps.model.gpx;

import java.util.ArrayList;
Expand Down Expand Up @@ -48,4 +47,3 @@ public void clear() {
uri = null;
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/*
package de.stephanlindauer.criticalmaps.model.gpx;

import org.osmdroid.util.GeoPoint;
import org.maplibre.android.geometry.LatLng;

public class GpxPoi {

private final String name;
private final GeoPoint position;
private final LatLng position;

public GpxPoi(String name, GeoPoint position) {
public GpxPoi(String name, LatLng position) {
this.name = name;
this.position = position;
}
Expand All @@ -17,8 +16,7 @@ public String getName() {
return name;
}

public GeoPoint getPosition() {
public LatLng getPosition() {
return position;
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/*
package de.stephanlindauer.criticalmaps.model.gpx;

import org.osmdroid.util.GeoPoint;
import org.maplibre.android.geometry.LatLng;

import java.util.List;

public class GpxTrack {

private final String name;
private final List<GeoPoint> waypoints;
private final List<LatLng> waypoints;

public GpxTrack(String name, List<GeoPoint> waypoints) {
public GpxTrack(String name, List<LatLng> waypoints) {
this.name = name;
this.waypoints = waypoints;
}
Expand All @@ -19,8 +18,7 @@ public String getName() {
return name;
}

public List<GeoPoint> getWaypoints() {
public List<LatLng> getWaypoints() {
return waypoints;
}
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ public interface SharedPrefsKeys {
BuildConfig.APPLICATION_ID + ".SHOW_ON_LOCKSCREEN";
String KEEP_SCREEN_ON =
BuildConfig.APPLICATION_ID + ".KEEP_SCREEN_ON";
/*
String SHOW_GPX =
BuildConfig.APPLICATION_ID + ".SHOW_GPX";
String GPX_FILE =
BuildConfig.APPLICATION_ID + ".GPX_FILE";
*/
}
Loading