Add check for already selected gpx color
This commit is contained in:
parent
960a231201
commit
a13367c0cc
6 changed files with 60 additions and 18 deletions
|
@ -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) {
|
||||
|
@ -80,10 +87,10 @@ public class AGpxFile implements Parcelable {
|
|||
} else {
|
||||
details = null;
|
||||
}
|
||||
color = in.readString();
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<BufferMessage>()
|
||||
|
||||
private var lastLocationPoints = mutableListOf<LocationMessage>()
|
||||
private var lastLocationPoints = ConcurrentLinkedQueue<LocationMessage>()
|
||||
|
||||
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) :
|
||||
|
|
|
@ -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<AGpxFile>?, gpxFile: GPXUtilities.GPXFile): Boolean {
|
||||
private fun checkAlreadyImportedGpx(importedGpxFiles: List<AGpxFile>?, 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) {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
@ -83,10 +87,10 @@ public class AGpxFile implements Parcelable {
|
|||
} else {
|
||||
details = null;
|
||||
}
|
||||
color = in.readString();
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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<RenderingRule> 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) {
|
||||
|
|
Loading…
Reference in a new issue