Merge pull request #10779 from osmandapp/master

update test branch
This commit is contained in:
Hardy 2021-02-06 10:28:36 +01:00 committed by GitHub
commit b22953eee1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 156 additions and 125 deletions

View file

@ -1,12 +0,0 @@
---
name: "📚 Outdated FAQ"
about: Report an issue in FAQ
---
🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑
Please do not file FAQ issues on the GitHub issues tracker.
Instead use the [Google group](https://groups.google.com/forum/#!forum/osmand) to fix wrong or outdated FAQ.
🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑

4
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View file

@ -0,0 +1,4 @@
contact_links:
- name: Outdated FAQ
- url: https://groups.google.com/forum/#!forum/osmand
- about: Fix wrong or outdated FAQ on the forum instead

View file

@ -38,6 +38,11 @@ public class ProfileSettingsParams extends AidlParams {
this.silent = silent; this.silent = silent;
} }
public ProfileSettingsParams(Uri profileSettingsUri, List<AExportSettingsType> settingsTypeList,
boolean replace, String latestChanges, int version) {
this(profileSettingsUri, settingsTypeList, replace, false, latestChanges, version);
}
public ProfileSettingsParams(Parcel in) { public ProfileSettingsParams(Parcel in) {
readFromParcel(in); readFromParcel(in);
} }

View file

@ -4332,5 +4332,12 @@
<string name="poi_wildlife_crossing_bat_bridge">Bat bridge</string> <string name="poi_wildlife_crossing_bat_bridge">Bat bridge</string>
<string name="poi_wildlife_crossing_bat_tunnel">Bat tunnel</string> <string name="poi_wildlife_crossing_bat_tunnel">Bat tunnel</string>
<string name="poi_piste_ski_jump">Ski jump</string>
<string name="poi_piste_name">Piste name</string>
<string name="poi_gladed_yes">Gladed: yes</string>
<string name="poi_patrolled_yes">Patrolled: yes</string>
<string name="poi_patrolled_no">Patrolled: no</string>
<string name="poi_piste_status_open">Piste status: open</string>
<string name="poi_piste_status_closed">Piste status: closed</string>
</resources> </resources>

View file

@ -1,6 +1,7 @@
package net.osmand.plus.api; package net.osmand.plus.api;
import androidx.annotation.Nullable;
public interface SQLiteAPI { public interface SQLiteAPI {
@ -55,8 +56,6 @@ public interface SQLiteAPI {
void close(); void close();
} }
public interface SQLiteStatement { public interface SQLiteStatement {
@ -81,7 +80,9 @@ public interface SQLiteAPI {
} }
public SQLiteConnection getOrCreateDatabase(String name, boolean readOnly); @Nullable
SQLiteConnection getOrCreateDatabase(String name, boolean readOnly);
public SQLiteConnection openByAbsolutePath(String path, boolean readOnly); @Nullable
SQLiteConnection openByAbsolutePath(String path, boolean readOnly);
} }

View file

@ -1,15 +1,17 @@
package net.osmand.plus.api; package net.osmand.plus.api;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import org.apache.commons.logging.Log;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import androidx.annotation.Nullable;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import org.apache.commons.logging.Log;
public class SQLiteAPIImpl implements SQLiteAPI { public class SQLiteAPIImpl implements SQLiteAPI {
private OsmandApplication app; private OsmandApplication app;
@ -20,6 +22,7 @@ public class SQLiteAPIImpl implements SQLiteAPI {
} }
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
@Nullable
@Override @Override
public SQLiteConnection getOrCreateDatabase(String name, boolean readOnly) { public SQLiteConnection getOrCreateDatabase(String name, boolean readOnly) {
android.database.sqlite.SQLiteDatabase db = null; android.database.sqlite.SQLiteDatabase db = null;
@ -35,7 +38,6 @@ public class SQLiteAPIImpl implements SQLiteAPI {
return new SQLiteDatabaseWrapper(db); return new SQLiteDatabaseWrapper(db);
} }
public class SQLiteDatabaseWrapper implements SQLiteConnection { public class SQLiteDatabaseWrapper implements SQLiteConnection {
android.database.sqlite.SQLiteDatabase ds; android.database.sqlite.SQLiteDatabase ds;
@ -206,7 +208,7 @@ public class SQLiteAPIImpl implements SQLiteAPI {
} }
@Nullable
@Override @Override
public SQLiteConnection openByAbsolutePath(String path, boolean readOnly) { public SQLiteConnection openByAbsolutePath(String path, boolean readOnly) {
// fix http://stackoverflow.com/questions/26937152/workaround-for-nexus-9-sqlite-file-write-operations-on-external-dirs // fix http://stackoverflow.com/questions/26937152/workaround-for-nexus-9-sqlite-file-write-operations-on-external-dirs

View file

@ -1,6 +1,7 @@
package net.osmand.plus.importfiles; package net.osmand.plus.importfiles;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
@ -9,13 +10,13 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.provider.Settings; import android.provider.Settings;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
@ -418,7 +419,7 @@ public class ImportHelper {
final boolean useImportDir, boolean forceImportFavourites, boolean showInDetailsActivity) { final boolean useImportDir, boolean forceImportFavourites, boolean showInDetailsActivity) {
if (result != null) { if (result != null) {
if (result.error != null) { if (result.error != null) {
Toast.makeText(activity, result.error.getMessage(), Toast.LENGTH_LONG).show(); app.showToastMessage(result.error.getMessage());
if (gpxImportCompleteListener != null) { if (gpxImportCompleteListener != null) {
gpxImportCompleteListener.onImportComplete(false); gpxImportCompleteListener.onImportComplete(false);
} }
@ -439,6 +440,7 @@ public class ImportHelper {
} }
} }
} else { } else {
if (AndroidUtils.isActivityNotDestroyed(activity)) {
new AlertDialog.Builder(activity) new AlertDialog.Builder(activity)
.setTitle(R.string.shared_string_import2osmand) .setTitle(R.string.shared_string_import2osmand)
.setMessage(R.string.import_gpx_failed_descr) .setMessage(R.string.import_gpx_failed_descr)
@ -465,8 +467,9 @@ public class ImportHelper {
}) })
.show(); .show();
} }
}
if (forceImportFavourites) { if (forceImportFavourites) {
final Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity()); Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.putExtra(TAB_ID, GPX_TAB); newIntent.putExtra(TAB_ID, GPX_TAB);
activity.startActivity(newIntent); activity.startActivity(newIntent);
@ -577,7 +580,7 @@ public class ImportHelper {
showPlanRouteFragment(); showPlanRouteFragment();
} }
} else { } else {
Toast.makeText(activity, warning, Toast.LENGTH_LONG).show(); app.showToastMessage(warning);
} }
} }
@ -619,7 +622,8 @@ public class ImportHelper {
final boolean forceImportFavourites, final boolean forceImportGpx) { final boolean forceImportFavourites, final boolean forceImportGpx) {
if (gpxFile == null || gpxFile.isPointsEmpty()) { if (gpxFile == null || gpxFile.isPointsEmpty()) {
if (forceImportFavourites) { if (forceImportFavourites) {
final DialogInterface.OnClickListener importAsTrackListener = new DialogInterface.OnClickListener() { if (AndroidUtils.isActivityNotDestroyed(activity)) {
OnClickListener importAsTrackListener = new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
switch (which) { switch (which) {
@ -632,13 +636,13 @@ public class ImportHelper {
} }
} }
}; };
new AlertDialog.Builder(activity) new AlertDialog.Builder(activity)
.setTitle(R.string.import_track) .setTitle(R.string.import_track)
.setMessage(activity.getString(R.string.import_track_desc, fileName)) .setMessage(activity.getString(R.string.import_track_desc, fileName))
.setPositiveButton(R.string.shared_string_import, importAsTrackListener) .setPositiveButton(R.string.shared_string_import, importAsTrackListener)
.setNegativeButton(R.string.shared_string_cancel, importAsTrackListener) .setNegativeButton(R.string.shared_string_cancel, importAsTrackListener)
.show(); .show();
}
} else { } else {
handleResult(gpxFile, fileName, fileSize, save, useImportDir, false); handleResult(gpxFile, fileName, fileSize, save, useImportDir, false);
} }

View file

@ -7,6 +7,7 @@ import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
@ -37,7 +38,7 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
private static final Log LOG = PlatformUtil.getLog(UploadPhotosAsyncTask.class); private static final Log LOG = PlatformUtil.getLog(UploadPhotosAsyncTask.class);
private static final int MAX_IMAGE_LENGTH = 2048; private static final int IMAGE_MAX_SIZE = 4096;
private final OsmandApplication app; private final OsmandApplication app;
private final WeakReference<MapActivity> activityRef; private final WeakReference<MapActivity> activityRef;
@ -133,7 +134,12 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
private boolean uploadImageToPlace(InputStream image, int width, int height) { private boolean uploadImageToPlace(InputStream image, int width, int height) {
boolean success = false; boolean success = false;
InputStream serverData = new ByteArrayInputStream(compressImageToJpeg(image, width, height)); byte[] jpegImageBytes = compressImageToJpeg(image, width, height);
if (jpegImageBytes == null || jpegImageBytes.length == 0) {
app.showToastMessage(R.string.cannot_upload_image);
return false;
}
InputStream serverData = new ByteArrayInputStream(jpegImageBytes);
String baseUrl = OPRConstants.getBaseUrl(app); String baseUrl = OPRConstants.getBaseUrl(app);
// all these should be constant // all these should be constant
String url = baseUrl + "api/ipfs/image"; String url = baseUrl + "api/ipfs/image";
@ -201,13 +207,14 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
return new int[] { opts.outWidth, opts.outHeight }; return new int[] { opts.outWidth, opts.outHeight };
} }
@Nullable
private byte[] compressImageToJpeg(InputStream image, int width, int height) { private byte[] compressImageToJpeg(InputStream image, int width, int height) {
BufferedInputStream bufferedInputStream = new BufferedInputStream(image); BufferedInputStream bufferedInputStream = new BufferedInputStream(image);
int w = width; int w = width;
int h = height; int h = height;
boolean scale = false; boolean scale = false;
int divider = 1; int divider = 1;
while (w > MAX_IMAGE_LENGTH || h > MAX_IMAGE_LENGTH) { while (w > IMAGE_MAX_SIZE || h > IMAGE_MAX_SIZE) {
w /= 2; w /= 2;
h /= 2; h /= 2;
divider *= 2; divider *= 2;
@ -221,9 +228,13 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
} else { } else {
bmp = BitmapFactory.decodeStream(bufferedInputStream); bmp = BitmapFactory.decodeStream(bufferedInputStream);
} }
if (bmp != null) {
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 90, os); bmp.compress(Bitmap.CompressFormat.JPEG, 90, os);
return os.toByteArray(); return os.toByteArray();
} else {
return null;
}
} }
public interface UploadPhotosProgressListener { public interface UploadPhotosProgressListener {

View file

@ -19,8 +19,8 @@ import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -30,10 +30,10 @@ import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
import net.osmand.plus.measurementtool.MeasurementToolFragment.OnUpdateInfoListener; import net.osmand.plus.measurementtool.MeasurementToolFragment.OnUpdateInfoListener;
import net.osmand.plus.measurementtool.graph.BaseGraphAdapter;
import net.osmand.plus.measurementtool.graph.CommonGraphAdapter; import net.osmand.plus.measurementtool.graph.CommonGraphAdapter;
import net.osmand.plus.measurementtool.graph.CustomGraphAdapter; import net.osmand.plus.measurementtool.graph.CustomGraphAdapter;
import net.osmand.plus.measurementtool.graph.CustomGraphAdapter.LegendViewType; import net.osmand.plus.measurementtool.graph.CustomGraphAdapter.LegendViewType;
import net.osmand.plus.measurementtool.graph.BaseGraphAdapter;
import net.osmand.plus.measurementtool.graph.GraphAdapterHelper; import net.osmand.plus.measurementtool.graph.GraphAdapterHelper;
import net.osmand.plus.measurementtool.graph.GraphAdapterHelper.RefreshMapCallback; import net.osmand.plus.measurementtool.graph.GraphAdapterHelper.RefreshMapCallback;
import net.osmand.plus.routepreparationmenu.RouteDetailsFragment; import net.osmand.plus.routepreparationmenu.RouteDetailsFragment;
@ -422,7 +422,7 @@ public class GraphsCard extends BaseCard implements OnUpdateInfoListener {
GpxUiHelper.setupGPXChart(commonGraphAdapter.getChart(), 4, 24f, 16f, !nightMode, true); GpxUiHelper.setupGPXChart(commonGraphAdapter.getChart(), 4, 24f, 16f, !nightMode, true);
List<ILineDataSet> dataSets = GpxUiHelper.getDataSets(commonGraphAdapter.getChart(), List<ILineDataSet> dataSets = GpxUiHelper.getDataSets(commonGraphAdapter.getChart(),
app, analysis, firstType, secondType, false); app, analysis, firstType, secondType, false);
return !Algorithms.isEmpty(dataSets) ? new LineData(dataSets) : null; return new LineData(dataSets);
} }
} }
@ -447,12 +447,11 @@ public class GraphsCard extends BaseCard implements OnUpdateInfoListener {
@Override @Override
public BarData getChartData() { public BarData getChartData() {
GpxUiHelper.setupHorizontalGPXChart(app, customGraphAdapter.getChart(), 5, 9, 24, true, nightMode); GpxUiHelper.setupHorizontalGPXChart(app, customGraphAdapter.getChart(), 5, 9, 24, true, nightMode);
BarData data = null;
if (!Algorithms.isEmpty(statistics.elements)) { if (!Algorithms.isEmpty(statistics.elements)) {
data = GpxUiHelper.buildStatisticChart(app, customGraphAdapter.getChart(), return GpxUiHelper.buildStatisticChart(app, customGraphAdapter.getChart(),
statistics, analysis, true, nightMode); statistics, analysis, true, nightMode);
} }
return data; return new BarData();
} }
} }
} }

View file

@ -192,9 +192,9 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
} }
private BaseBottomSheetItem createCopyToMarkersItem(final GPXFile gpxFile) { private BaseBottomSheetItem createCopyToMarkersItem(final GPXFile gpxFile) {
final MapMarkersGroup markersGroup = getOrCreateMarkersGroup(gpxFile); MapMarkersGroup markersGroup = mapMarkersHelper.getMarkersGroup(gpxFile);
final Set<String> categories = markersGroup.getWptCategories(); final boolean synced = markersGroup != null && (Algorithms.isEmpty(markersGroup.getWptCategories())
final boolean synced = categories != null && categories.contains(group.getName()); || markersGroup.getWptCategories().contains(group.getName()));
return new SimpleBottomSheetItem.Builder() return new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_copy)) .setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_copy))
@ -203,18 +203,25 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
updateGroupWptCategory(gpxFile, markersGroup, categories, synced); updateGroupWptCategory(gpxFile, synced);
dismiss(); dismiss();
} }
}) })
.create(); .create();
} }
private void updateGroupWptCategory(GPXFile gpxFile, MapMarkersGroup markersGroup, Set<String> categories, boolean synced) { private void updateGroupWptCategory(GPXFile gpxFile, boolean synced) {
SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(gpxFile.path); SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(gpxFile.path);
if (selectedGpxFile == null) { if (selectedGpxFile == null) {
selectedGpxHelper.selectGpxFile(gpxFile, true, false, false, false, false); selectedGpxHelper.selectGpxFile(gpxFile, true, false, false, false, false);
} }
boolean groupCreated = false;
MapMarkersGroup markersGroup = mapMarkersHelper.getMarkersGroup(gpxFile);
if (markersGroup == null) {
groupCreated = true;
markersGroup = mapMarkersHelper.addOrEnableGroup(gpxFile);
}
Set<String> categories = markersGroup.getWptCategories();
Set<String> selectedCategories = new HashSet<>(); Set<String> selectedCategories = new HashSet<>();
if (categories != null) { if (categories != null) {
selectedCategories.addAll(categories); selectedCategories.addAll(categories);
@ -224,16 +231,14 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
} else { } else {
selectedCategories.add(group.getName()); selectedCategories.add(group.getName());
} }
if (Algorithms.isEmpty(selectedCategories)) {
mapMarkersHelper.removeMarkersGroup(markersGroup);
} else {
mapMarkersHelper.updateGroupWptCategories(markersGroup, selectedCategories); mapMarkersHelper.updateGroupWptCategories(markersGroup, selectedCategories);
if (!groupCreated) {
mapMarkersHelper.runSynchronization(markersGroup); mapMarkersHelper.runSynchronization(markersGroup);
} }
private MapMarkersGroup getOrCreateMarkersGroup(GPXFile gpxFile) {
MapMarkersGroup markersGroup = mapMarkersHelper.getMarkersGroup(gpxFile);
if (markersGroup == null) {
markersGroup = mapMarkersHelper.addOrEnableGroup(gpxFile);
} }
return markersGroup;
} }
private BaseBottomSheetItem createCopyToFavoritesItem() { private BaseBottomSheetItem createCopyToFavoritesItem() {

View file

@ -663,11 +663,12 @@ public class PoiFiltersHelper {
private SQLiteConnection openConnection(boolean readonly) { private SQLiteConnection openConnection(boolean readonly) {
conn = context.getSQLiteAPI().getOrCreateDatabase(DATABASE_NAME, readonly); conn = context.getSQLiteAPI().getOrCreateDatabase(DATABASE_NAME, readonly);
if (conn.getVersion() < DATABASE_VERSION) { if (conn != null && conn.getVersion() < DATABASE_VERSION) {
if (readonly) { if (readonly) {
conn.close(); conn.close();
conn = context.getSQLiteAPI().getOrCreateDatabase(DATABASE_NAME, false); conn = context.getSQLiteAPI().getOrCreateDatabase(DATABASE_NAME, false);
} }
if (conn != null) {
int version = conn.getVersion(); int version = conn.getVersion();
conn.setVersion(DATABASE_VERSION); conn.setVersion(DATABASE_VERSION);
if (version == 0) { if (version == 0) {
@ -676,6 +677,7 @@ public class PoiFiltersHelper {
onUpgrade(conn, version, DATABASE_VERSION); onUpgrade(conn, version, DATABASE_VERSION);
} }
} }
}
return conn; return conn;
} }

View file

@ -17,26 +17,28 @@ import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.base.PointImageDrawable;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.layers.ContextMenuLayer.ApplyMovedObjectCallback; import net.osmand.plus.views.layers.ContextMenuLayer.ApplyMovedObjectCallback;
import net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.layers.ContextMenuLayer.IMoveObjectProvider;
import net.osmand.plus.views.layers.MapTextLayer.MapTextProvider; import net.osmand.plus.views.layers.MapTextLayer.MapTextProvider;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, public class FavouritesLayer extends OsmandMapLayer implements IContextMenuProvider, IMoveObjectProvider,
ContextMenuLayer.IMoveObjectProvider, MapTextProvider<FavouritePoint> { MapTextProvider<FavouritePoint> {
protected int startZoom = 6; protected int startZoom = 6;
protected OsmandMapTileView view; protected OsmandMapTileView view;
private FavouritesDbHelper favorites; private FavouritesDbHelper favouritesDbHelper;
private MapMarkersHelper mapMarkersHelper; private MapMarkersHelper mapMarkersHelper;
protected List<FavouritePoint> cache = new ArrayList<>(); protected List<FavouritePoint> cache = new ArrayList<>();
private MapTextLayer textLayer; private MapTextLayer textLayer;
@ -54,7 +56,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
public void initLayer(OsmandMapTileView view) { public void initLayer(OsmandMapTileView view) {
this.view = view; this.view = view;
settings = view.getApplication().getSettings(); settings = view.getApplication().getSettings();
favorites = view.getApplication().getFavorites(); favouritesDbHelper = view.getApplication().getFavorites();
mapMarkersHelper = view.getApplication().getMapMarkersHelper(); mapMarkersHelper = view.getApplication().getMapMarkersHelper();
textLayer = view.getLayerByClass(MapTextLayer.class); textLayer = view.getLayerByClass(MapTextLayer.class);
defaultColor = ContextCompat.getColor(view.getContext(), R.color.color_favorite); defaultColor = ContextCompat.getColor(view.getContext(), R.color.color_favorite);
@ -92,7 +94,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
@Override @Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
cache.clear(); cache.clear();
if (this.settings.SHOW_FAVORITES.get() && favorites.isFavoritesLoaded()) { if (this.settings.SHOW_FAVORITES.get() && favouritesDbHelper.isFavoritesLoaded()) {
if (tileBox.getZoom() >= startZoom) { if (tileBox.getZoom() >= startZoom) {
float textScale = this.settings.TEXT_SCALE.get(); float textScale = this.settings.TEXT_SCALE.get();
float iconSize = getIconSize(view.getApplication()); float iconSize = getIconSize(view.getApplication());
@ -102,7 +104,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
final QuadRect latLonBounds = tileBox.getLatLonBounds(); final QuadRect latLonBounds = tileBox.getLatLonBounds();
List<LatLon> fullObjectsLatLon = new ArrayList<>(); List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>(); List<LatLon> smallObjectsLatLon = new ArrayList<>();
for (FavoriteGroup group : favorites.getFavoriteGroups()) { for (FavoriteGroup group : favouritesDbHelper.getFavoriteGroups()) {
List<Pair<FavouritePoint, MapMarker>> fullObjects = new ArrayList<>(); List<Pair<FavouritePoint, MapMarker>> fullObjects = new ArrayList<>();
boolean synced = mapMarkersHelper.getMarkersGroup(group) != null; boolean synced = mapMarkersHelper.getMarkersGroup(group) != null;
for (FavouritePoint favoritePoint : group.getPoints()) { for (FavouritePoint favoritePoint : group.getPoints()) {
@ -127,7 +129,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
if (marker != null && marker.history) { if (marker != null && marker.history) {
color = grayColor; color = grayColor;
} else { } else {
color = favorites.getColorWithCategory(favoritePoint,defaultColor); color = favouritesDbHelper.getColorWithCategory(favoritePoint,defaultColor);
} }
PointImageDrawable pointImageDrawable = PointImageDrawable.getFromFavorite( PointImageDrawable pointImageDrawable = PointImageDrawable.getFromFavorite(
view.getContext(), color,true, favoritePoint); view.getContext(), color,true, favoritePoint);
@ -162,11 +164,11 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
boolean history = false; boolean history = false;
if (marker != null) { if (marker != null) {
pointImageDrawable = PointImageDrawable.getOrCreateSyncedIcon(view.getContext(), pointImageDrawable = PointImageDrawable.getOrCreateSyncedIcon(view.getContext(),
favorites.getColorWithCategory(favoritePoint,defaultColor), favoritePoint); favouritesDbHelper.getColorWithCategory(favoritePoint,defaultColor), favoritePoint);
history = marker.history; history = marker.history;
} else { } else {
pointImageDrawable = PointImageDrawable.getFromFavorite(view.getContext(), pointImageDrawable = PointImageDrawable.getFromFavorite(view.getContext(),
favorites.getColorWithCategory(favoritePoint, defaultColor),true, favoritePoint); favouritesDbHelper.getColorWithCategory(favoritePoint, defaultColor),true, favoritePoint);
} }
pointImageDrawable.drawPoint(canvas, x, y, textScale, history); pointImageDrawable.drawPoint(canvas, x, y, textScale, history);
} }
@ -180,7 +182,8 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
int r = getScaledTouchRadius(view.getApplication(), getDefaultRadiusPoi(tb)); int r = getScaledTouchRadius(view.getApplication(), getDefaultRadiusPoi(tb));
int ex = (int) point.x; int ex = (int) point.x;
int ey = (int) point.y; int ey = (int) point.y;
for (FavouritePoint n : favorites.getFavouritePoints()) { List<FavouritePoint> favouritePoints = new ArrayList<>(favouritesDbHelper.getFavouritePoints());
for (FavouritePoint n : favouritePoints) {
getFavFromPoint(tb, res, r, ex, ey, n); getFavFromPoint(tb, res, r, ex, ey, n);
} }
} }
@ -275,8 +278,8 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
@Nullable ApplyMovedObjectCallback callback) { @Nullable ApplyMovedObjectCallback callback) {
boolean result = false; boolean result = false;
if (o instanceof FavouritePoint) { if (o instanceof FavouritePoint) {
favorites.editFavourite((FavouritePoint) o, position.getLatitude(), position.getLongitude()); favouritesDbHelper.editFavourite((FavouritePoint) o, position.getLatitude(), position.getLongitude());
favorites.lookupAddress((FavouritePoint) o); favouritesDbHelper.lookupAddress((FavouritePoint) o);
result = true; result = true;
} }
if (callback != null) { if (callback != null) {