diff --git a/OsmAnd-telegram/src/net/osmand/aidl/gpx/AGpxFile.java b/OsmAnd-telegram/src/net/osmand/aidl/gpx/AGpxFile.java index 9572057fdc..fb357c79b1 100644 --- a/OsmAnd-telegram/src/net/osmand/aidl/gpx/AGpxFile.java +++ b/OsmAnd-telegram/src/net/osmand/aidl/gpx/AGpxFile.java @@ -11,13 +11,15 @@ public class AGpxFile implements Parcelable { private long modifiedTime; private long fileSize; private boolean active; + private String color; private AGpxFileDetails details; - public AGpxFile(@NonNull String fileName, long modifiedTime, long fileSize, boolean active, @Nullable AGpxFileDetails details) { + public AGpxFile(@NonNull String fileName, long modifiedTime, long fileSize, boolean active, String color, @Nullable AGpxFileDetails details) { this.fileName = fileName; this.modifiedTime = modifiedTime; this.fileSize = fileSize; this.active = active; + this.color = color; this.details = details; } @@ -52,6 +54,10 @@ public class AGpxFile implements Parcelable { return active; } + public String getColor() { + return color; + } + public AGpxFileDetails getDetails() { return details; } @@ -66,6 +72,7 @@ public class AGpxFile implements Parcelable { if (details != null) { out.writeParcelable(details, flags); } + out.writeString(color); } private void readFromParcel(Parcel in) { @@ -74,16 +81,16 @@ public class AGpxFile implements Parcelable { fileSize = in.readLong(); active = in.readByte() != 0; - boolean hasDetails= in.readByte() != 0; + boolean hasDetails = in.readByte() != 0; if (hasDetails) { details = in.readParcelable(AGpxFileDetails.class.getClassLoader()); } else { details = null; } + color = in.readString(); } public int describeContents() { return 0; } -} - +} \ No newline at end of file diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/LocationMessages.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/LocationMessages.kt index 43f307bc0e..59eb0e5961 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/LocationMessages.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/LocationMessages.kt @@ -11,6 +11,7 @@ import net.osmand.telegram.TelegramApplication import net.osmand.telegram.utils.OsmandLocationUtils import net.osmand.util.MapUtils import org.drinkless.td.libcore.telegram.TdApi +import java.util.concurrent.ConcurrentLinkedQueue class LocationMessages(val app: TelegramApplication) { @@ -18,7 +19,7 @@ class LocationMessages(val app: TelegramApplication) { private var bufferedMessages = emptyList() - private var lastLocationPoints = mutableListOf() + private var lastLocationPoints = ConcurrentLinkedQueue() private val dbHelper: SQLiteHelper @@ -144,7 +145,7 @@ class LocationMessages(val app: TelegramApplication) { } private fun readLastMessages() { - this.lastLocationPoints = dbHelper.getLastMessages() + this.lastLocationPoints.addAll(dbHelper.getLastMessages()) } private class SQLiteHelper(context: Context) : diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt index d5da914902..501133778f 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt @@ -272,7 +272,7 @@ class ShowLocationHelper(private val app: TelegramApplication) { val importedGpxFiles = osmandAidlHelper.importedGpxFiles gpxFiles.forEach { - if (!isGpxAlreadyImported(importedGpxFiles, it)) { + if (!checkAlreadyImportedGpx(importedGpxFiles, it)) { val listener = object : OsmandLocationUtils.SaveGpxListener { override fun onSavingGpxFinish(path: String) { @@ -294,12 +294,16 @@ class ShowLocationHelper(private val app: TelegramApplication) { } } - private fun isGpxAlreadyImported(importedGpxFiles: List?, gpxFile: GPXUtilities.GPXFile): Boolean { + private fun checkAlreadyImportedGpx(importedGpxFiles: List?, gpxFile: GPXUtilities.GPXFile): Boolean { if (importedGpxFiles != null && importedGpxFiles.isNotEmpty()) { val name = "${gpxFile.metadata.name}.gpx" val aGpxFile = importedGpxFiles.firstOrNull { it.fileName == name } if (aGpxFile != null) { + val color = aGpxFile.color + if (!color.isNullOrEmpty()) { + gpxFile.extensionsToWrite["color"] = color + } val startTimeImported = aGpxFile.details?.startTime val endTimeImported = aGpxFile.details?.endTime if (startTimeImported != null && endTimeImported != null) { diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index c67f63d588..a50813d692 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -1477,12 +1477,17 @@ public class OsmandAidlApi { boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null; long modifiedTime = dataItem.getFileLastModifiedTime(); long fileSize = file.length(); + int color = dataItem.getColor(); + String colorName = ""; + if (color != 0) { + colorName = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color); + } AGpxFileDetails details = null; GPXTrackAnalysis analysis = dataItem.getAnalysis(); if (analysis != null) { details = createGpxFileDetails(analysis); } - files.add(new AGpxFile(fileName, modifiedTime, fileSize, active, details)); + files.add(new AGpxFile(fileName, modifiedTime, fileSize, active, colorName, details)); } //} } diff --git a/OsmAnd/src/net/osmand/aidl/gpx/AGpxFile.java b/OsmAnd/src/net/osmand/aidl/gpx/AGpxFile.java index 7183f3024c..fb357c79b1 100644 --- a/OsmAnd/src/net/osmand/aidl/gpx/AGpxFile.java +++ b/OsmAnd/src/net/osmand/aidl/gpx/AGpxFile.java @@ -4,9 +4,6 @@ import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.text.TextUtils; - -import java.io.File; public class AGpxFile implements Parcelable { @@ -14,13 +11,15 @@ public class AGpxFile implements Parcelable { private long modifiedTime; private long fileSize; private boolean active; + private String color; private AGpxFileDetails details; - public AGpxFile(@NonNull String fileName, long modifiedTime, long fileSize, boolean active, @Nullable AGpxFileDetails details) { + public AGpxFile(@NonNull String fileName, long modifiedTime, long fileSize, boolean active, String color, @Nullable AGpxFileDetails details) { this.fileName = fileName; this.modifiedTime = modifiedTime; this.fileSize = fileSize; this.active = active; + this.color = color; this.details = details; } @@ -55,6 +54,10 @@ public class AGpxFile implements Parcelable { return active; } + public String getColor() { + return color; + } + public AGpxFileDetails getDetails() { return details; } @@ -69,6 +72,7 @@ public class AGpxFile implements Parcelable { if (details != null) { out.writeParcelable(details, flags); } + out.writeString(color); } private void readFromParcel(Parcel in) { @@ -77,16 +81,16 @@ public class AGpxFile implements Parcelable { fileSize = in.readLong(); active = in.readByte() != 0; - boolean hasDetails= in.readByte() != 0; + boolean hasDetails = in.readByte() != 0; if (hasDetails) { details = in.readParcelable(AGpxFileDetails.class.getClassLoader()); } else { details = null; } + color = in.readString(); } public int describeContents() { return 0; } -} - +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index 2180b33fc3..a283715c7a 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -23,7 +23,6 @@ import android.widget.ListView; import android.widget.Spinner; import android.widget.TextView; -import java.io.File; import net.osmand.AndroidUtils; import net.osmand.GPXUtilities; import net.osmand.PlatformUtil; @@ -58,6 +57,7 @@ import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -1415,7 +1415,7 @@ public class ConfigureMapMenu { public static int parseTrackColor(RenderingRulesStorage renderer, String colorName) { int defaultColor = -1; RenderingRule gpxRule = null; - if(renderer!=null) { + if (renderer != null) { gpxRule = renderer.getRenderingAttributeRule("gpx"); } if (gpxRule != null && gpxRule.getIfElseChildren().size() > 0) { @@ -1433,6 +1433,27 @@ public class ConfigureMapMenu { return defaultColor; } + public static String parseTrackColorName(RenderingRulesStorage renderer, int color) { + int defaultColor = -1; + RenderingRule gpxRule = null; + if (renderer != null) { + gpxRule = renderer.getRenderingAttributeRule("gpx"); + } + if (gpxRule != null && gpxRule.getIfElseChildren().size() > 0) { + List rules = renderer.getRenderingAttributeRule("gpx").getIfElseChildren().get(0).getIfElseChildren(); + for (RenderingRule r : rules) { + String cName = r.getStringPropertyValue(CURRENT_TRACK_COLOR_ATTR); + if (!Algorithms.isEmpty(cName) && color == r.getIntPropertyValue(COLOR_ATTR)) { + return cName; + } + if (cName == null && defaultColor == -1) { + defaultColor = r.getIntPropertyValue(COLOR_ATTR); + } + } + } + return Algorithms.colorToString(color); + } + @NonNull @Override public View getView(int position, View convertView, @NonNull ViewGroup parent) {