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 modifiedTime;
|
||||||
private long fileSize;
|
private long fileSize;
|
||||||
private boolean active;
|
private boolean active;
|
||||||
|
private String color;
|
||||||
private AGpxFileDetails details;
|
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.fileName = fileName;
|
||||||
this.modifiedTime = modifiedTime;
|
this.modifiedTime = modifiedTime;
|
||||||
this.fileSize = fileSize;
|
this.fileSize = fileSize;
|
||||||
this.active = active;
|
this.active = active;
|
||||||
|
this.color = color;
|
||||||
this.details = details;
|
this.details = details;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +54,10 @@ public class AGpxFile implements Parcelable {
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
public AGpxFileDetails getDetails() {
|
public AGpxFileDetails getDetails() {
|
||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
|
@ -66,6 +72,7 @@ public class AGpxFile implements Parcelable {
|
||||||
if (details != null) {
|
if (details != null) {
|
||||||
out.writeParcelable(details, flags);
|
out.writeParcelable(details, flags);
|
||||||
}
|
}
|
||||||
|
out.writeString(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readFromParcel(Parcel in) {
|
private void readFromParcel(Parcel in) {
|
||||||
|
@ -74,16 +81,16 @@ public class AGpxFile implements Parcelable {
|
||||||
fileSize = in.readLong();
|
fileSize = in.readLong();
|
||||||
active = in.readByte() != 0;
|
active = in.readByte() != 0;
|
||||||
|
|
||||||
boolean hasDetails= in.readByte() != 0;
|
boolean hasDetails = in.readByte() != 0;
|
||||||
if (hasDetails) {
|
if (hasDetails) {
|
||||||
details = in.readParcelable(AGpxFileDetails.class.getClassLoader());
|
details = in.readParcelable(AGpxFileDetails.class.getClassLoader());
|
||||||
} else {
|
} else {
|
||||||
details = null;
|
details = null;
|
||||||
}
|
}
|
||||||
|
color = in.readString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import net.osmand.telegram.TelegramApplication
|
||||||
import net.osmand.telegram.utils.OsmandLocationUtils
|
import net.osmand.telegram.utils.OsmandLocationUtils
|
||||||
import net.osmand.util.MapUtils
|
import net.osmand.util.MapUtils
|
||||||
import org.drinkless.td.libcore.telegram.TdApi
|
import org.drinkless.td.libcore.telegram.TdApi
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue
|
||||||
|
|
||||||
class LocationMessages(val app: TelegramApplication) {
|
class LocationMessages(val app: TelegramApplication) {
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ class LocationMessages(val app: TelegramApplication) {
|
||||||
|
|
||||||
private var bufferedMessages = emptyList<BufferMessage>()
|
private var bufferedMessages = emptyList<BufferMessage>()
|
||||||
|
|
||||||
private var lastLocationPoints = mutableListOf<LocationMessage>()
|
private var lastLocationPoints = ConcurrentLinkedQueue<LocationMessage>()
|
||||||
|
|
||||||
private val dbHelper: SQLiteHelper
|
private val dbHelper: SQLiteHelper
|
||||||
|
|
||||||
|
@ -144,7 +145,7 @@ class LocationMessages(val app: TelegramApplication) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readLastMessages() {
|
private fun readLastMessages() {
|
||||||
this.lastLocationPoints = dbHelper.getLastMessages()
|
this.lastLocationPoints.addAll(dbHelper.getLastMessages())
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SQLiteHelper(context: Context) :
|
private class SQLiteHelper(context: Context) :
|
||||||
|
|
|
@ -272,7 +272,7 @@ class ShowLocationHelper(private val app: TelegramApplication) {
|
||||||
|
|
||||||
val importedGpxFiles = osmandAidlHelper.importedGpxFiles
|
val importedGpxFiles = osmandAidlHelper.importedGpxFiles
|
||||||
gpxFiles.forEach {
|
gpxFiles.forEach {
|
||||||
if (!isGpxAlreadyImported(importedGpxFiles, it)) {
|
if (!checkAlreadyImportedGpx(importedGpxFiles, it)) {
|
||||||
val listener = object : OsmandLocationUtils.SaveGpxListener {
|
val listener = object : OsmandLocationUtils.SaveGpxListener {
|
||||||
|
|
||||||
override fun onSavingGpxFinish(path: String) {
|
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()) {
|
if (importedGpxFiles != null && importedGpxFiles.isNotEmpty()) {
|
||||||
val name = "${gpxFile.metadata.name}.gpx"
|
val name = "${gpxFile.metadata.name}.gpx"
|
||||||
val aGpxFile = importedGpxFiles.firstOrNull { it.fileName == name }
|
val aGpxFile = importedGpxFiles.firstOrNull { it.fileName == name }
|
||||||
|
|
||||||
if (aGpxFile != null) {
|
if (aGpxFile != null) {
|
||||||
|
val color = aGpxFile.color
|
||||||
|
if (!color.isNullOrEmpty()) {
|
||||||
|
gpxFile.extensionsToWrite["color"] = color
|
||||||
|
}
|
||||||
val startTimeImported = aGpxFile.details?.startTime
|
val startTimeImported = aGpxFile.details?.startTime
|
||||||
val endTimeImported = aGpxFile.details?.endTime
|
val endTimeImported = aGpxFile.details?.endTime
|
||||||
if (startTimeImported != null && endTimeImported != null) {
|
if (startTimeImported != null && endTimeImported != null) {
|
||||||
|
|
|
@ -1477,12 +1477,17 @@ public class OsmandAidlApi {
|
||||||
boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null;
|
boolean active = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath()) != null;
|
||||||
long modifiedTime = dataItem.getFileLastModifiedTime();
|
long modifiedTime = dataItem.getFileLastModifiedTime();
|
||||||
long fileSize = file.length();
|
long fileSize = file.length();
|
||||||
|
int color = dataItem.getColor();
|
||||||
|
String colorName = "";
|
||||||
|
if (color != 0) {
|
||||||
|
colorName = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
|
||||||
|
}
|
||||||
AGpxFileDetails details = null;
|
AGpxFileDetails details = null;
|
||||||
GPXTrackAnalysis analysis = dataItem.getAnalysis();
|
GPXTrackAnalysis analysis = dataItem.getAnalysis();
|
||||||
if (analysis != null) {
|
if (analysis != null) {
|
||||||
details = createGpxFileDetails(analysis);
|
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.os.Parcelable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class AGpxFile implements Parcelable {
|
public class AGpxFile implements Parcelable {
|
||||||
|
|
||||||
|
@ -14,13 +11,15 @@ public class AGpxFile implements Parcelable {
|
||||||
private long modifiedTime;
|
private long modifiedTime;
|
||||||
private long fileSize;
|
private long fileSize;
|
||||||
private boolean active;
|
private boolean active;
|
||||||
|
private String color;
|
||||||
private AGpxFileDetails details;
|
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.fileName = fileName;
|
||||||
this.modifiedTime = modifiedTime;
|
this.modifiedTime = modifiedTime;
|
||||||
this.fileSize = fileSize;
|
this.fileSize = fileSize;
|
||||||
this.active = active;
|
this.active = active;
|
||||||
|
this.color = color;
|
||||||
this.details = details;
|
this.details = details;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +54,10 @@ public class AGpxFile implements Parcelable {
|
||||||
return active;
|
return active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
public AGpxFileDetails getDetails() {
|
public AGpxFileDetails getDetails() {
|
||||||
return details;
|
return details;
|
||||||
}
|
}
|
||||||
|
@ -69,6 +72,7 @@ public class AGpxFile implements Parcelable {
|
||||||
if (details != null) {
|
if (details != null) {
|
||||||
out.writeParcelable(details, flags);
|
out.writeParcelable(details, flags);
|
||||||
}
|
}
|
||||||
|
out.writeString(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readFromParcel(Parcel in) {
|
private void readFromParcel(Parcel in) {
|
||||||
|
@ -77,16 +81,16 @@ public class AGpxFile implements Parcelable {
|
||||||
fileSize = in.readLong();
|
fileSize = in.readLong();
|
||||||
active = in.readByte() != 0;
|
active = in.readByte() != 0;
|
||||||
|
|
||||||
boolean hasDetails= in.readByte() != 0;
|
boolean hasDetails = in.readByte() != 0;
|
||||||
if (hasDetails) {
|
if (hasDetails) {
|
||||||
details = in.readParcelable(AGpxFileDetails.class.getClassLoader());
|
details = in.readParcelable(AGpxFileDetails.class.getClassLoader());
|
||||||
} else {
|
} else {
|
||||||
details = null;
|
details = null;
|
||||||
}
|
}
|
||||||
|
color = in.readString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import android.widget.ListView;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
@ -58,6 +57,7 @@ import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -1415,7 +1415,7 @@ public class ConfigureMapMenu {
|
||||||
public static int parseTrackColor(RenderingRulesStorage renderer, String colorName) {
|
public static int parseTrackColor(RenderingRulesStorage renderer, String colorName) {
|
||||||
int defaultColor = -1;
|
int defaultColor = -1;
|
||||||
RenderingRule gpxRule = null;
|
RenderingRule gpxRule = null;
|
||||||
if(renderer!=null) {
|
if (renderer != null) {
|
||||||
gpxRule = renderer.getRenderingAttributeRule("gpx");
|
gpxRule = renderer.getRenderingAttributeRule("gpx");
|
||||||
}
|
}
|
||||||
if (gpxRule != null && gpxRule.getIfElseChildren().size() > 0) {
|
if (gpxRule != null && gpxRule.getIfElseChildren().size() > 0) {
|
||||||
|
@ -1433,6 +1433,27 @@ public class ConfigureMapMenu {
|
||||||
return defaultColor;
|
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
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
|
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
|
||||||
|
|
Loading…
Reference in a new issue