Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-03-14 14:10:42 +01:00
commit 0a9e44c61a
6 changed files with 76 additions and 21 deletions

View file

@ -2,7 +2,6 @@ package net.osmand.util;
import net.osmand.IProgress;
import net.osmand.PlatformUtil;
import net.osmand.binary.BinaryMapIndexReader;
import org.apache.commons.logging.Log;
@ -21,10 +20,12 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
/**
@ -177,6 +178,24 @@ public class Algorithms {
return "";
}
public static Set<String> decodeStringSet(String s) {
if (isEmpty(s)) {
return Collections.emptySet();
}
return new HashSet<>(Arrays.asList(s.split(CHAR_TOSPLIT + "")));
}
public static String encodeStringSet(Set<String> set) {
if (set != null) {
StringBuilder sb = new StringBuilder();
for (String s : set) {
sb.append(s).append(CHAR_TOSPLIT);
}
return sb.toString();
}
return "";
}
public static int findFirstNumberEndIndex(String value) {
int i = 0;
boolean valid = false;

View file

@ -15,7 +15,7 @@ import java.util.List;
public class GPXDatabase {
private static final String DB_NAME = "gpx_database";
private static final int DB_VERSION = 6;
private static final int DB_VERSION = 7;
private static final String GPX_TABLE_NAME = "gpxTable";
private static final String GPX_COL_NAME = "fileName";
private static final String GPX_COL_DIR = "fileDir";
@ -47,6 +47,8 @@ public class GPXDatabase {
private static final String GPX_COL_API_IMPORTED = "apiImported";
private static final String GPX_COL_WPT_CATEGORY_NAMES = "wptCategoryNames";
public static final int GPX_SPLIT_TYPE_NO_SPLIT = -1;
public static final int GPX_SPLIT_TYPE_DISTANCE = 1;
public static final int GPX_SPLIT_TYPE_TIME = 2;
@ -77,7 +79,8 @@ public class GPXDatabase {
GPX_COL_FILE_LAST_MODIFIED_TIME + " long, " +
GPX_COL_SPLIT_TYPE + " int, " +
GPX_COL_SPLIT_INTERVAL + " double, " +
GPX_COL_API_IMPORTED + " int);"; // 1 = true, 0 = false
GPX_COL_API_IMPORTED + " int, " + // 1 = true, 0 = false
GPX_COL_WPT_CATEGORY_NAMES + " TEXT);";
private static final String GPX_TABLE_SELECT = "SELECT " +
GPX_COL_NAME + ", " +
@ -102,7 +105,8 @@ public class GPXDatabase {
GPX_COL_FILE_LAST_MODIFIED_TIME + ", " +
GPX_COL_SPLIT_TYPE + ", " +
GPX_COL_SPLIT_INTERVAL + ", " +
GPX_COL_API_IMPORTED +
GPX_COL_API_IMPORTED + ", " +
GPX_COL_WPT_CATEGORY_NAMES +
" FROM " + GPX_TABLE_NAME;
private OsmandApplication context;
@ -244,6 +248,10 @@ public class GPXDatabase {
" SET " + GPX_COL_API_IMPORTED + " = ? " +
"WHERE " + GPX_COL_API_IMPORTED + " IS NULL", new Object[]{0});
}
if (oldVersion < 7) {
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_WPT_CATEGORY_NAMES + " TEXT");
}
}
private boolean updateLastModifiedTime(GpxDataItem item) {
@ -382,11 +390,12 @@ public class GPXDatabase {
}
if (a != null) {
db.execSQL(
"INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
"INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
new Object[]{ fileName, fileDir, a.totalDistance, a.totalTracks, a.startTime, a.endTime,
a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown,
a.avgElevation, a.minElevation, a.maxElevation, a.maxSpeed, a.avgSpeed, a.points, a.wptPoints,
color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0});
color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0,
Algorithms.encodeStringSet(item.analysis.wptCategoryNames)});
} else {
db.execSQL("INSERT INTO " + GPX_TABLE_NAME + "(" +
GPX_COL_NAME + ", " +
@ -424,13 +433,14 @@ public class GPXDatabase {
GPX_COL_AVG_SPEED + " = ?, " +
GPX_COL_POINTS + " = ?, " +
GPX_COL_WPT_POINTS + " = ?, " +
GPX_COL_FILE_LAST_MODIFIED_TIME + " = ? " +
GPX_COL_FILE_LAST_MODIFIED_TIME + " = ?, " +
GPX_COL_WPT_CATEGORY_NAMES + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[]{ a.totalDistance, a.totalTracks, a.startTime, a.endTime,
a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp,
a.diffElevationDown, a.avgElevation, a.minElevation, a.maxElevation,
a.maxSpeed, a.avgSpeed, a.points, a.wptPoints, item.file.lastModified(),
fileName, fileDir });
Algorithms.encodeStringSet(a.wptCategoryNames), fileName, fileDir });
} finally {
db.close();
}
@ -463,6 +473,7 @@ public class GPXDatabase {
int splitType = (int)query.getInt(20);
double splitInterval = query.getDouble(21);
boolean apiImported = query.getInt(22) == 1;
String wptCategoryNames = query.getString(23);
GPXTrackAnalysis a = new GPXTrackAnalysis();
a.totalDistance = totalDistance;
@ -482,6 +493,9 @@ public class GPXDatabase {
a.avgSpeed = avgSpeed;
a.points = points;
a.wptPoints = wptPoints;
if (wptCategoryNames != null) {
a.wptCategoryNames = Algorithms.decodeStringSet(wptCategoryNames);
}
File dir;
if (!Algorithms.isEmpty(fileDir)) {

View file

@ -42,10 +42,13 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.TimeZone;
@ -287,6 +290,8 @@ public class GPXUtilities {
public int points;
public int wptPoints = 0;
public Set<String> wptCategoryNames;
public double metricEnd;
public double secondaryMetricEnd;
public WptPt locationStart;
@ -787,6 +792,22 @@ public class GPXUtilities {
return Collections.unmodifiableList(points);
}
public Map<String, List<WptPt>> getPointsByCategories() {
Map<String, List<WptPt>> res = new HashMap<>();
for (WptPt pt : points) {
String category = pt.category == null ? "" : pt.category;
List<WptPt> list = res.get(category);
if (list != null) {
list.add(pt);
} else {
list = new ArrayList<>();
list.add(pt);
res.put(category, list);
}
}
return res;
}
public boolean isPointsEmpty() {
return points.isEmpty();
}
@ -868,6 +889,7 @@ public class GPXUtilities {
public GPXTrackAnalysis getAnalysis(long fileTimestamp) {
GPXTrackAnalysis g = new GPXTrackAnalysis();
g.wptPoints = points.size();
g.wptCategoryNames = getWaypointCategories(true);
List<SplitSegment> splitSegments = new ArrayList<GPXUtilities.SplitSegment>();
for (int i = 0; i < tracks.size(); i++) {
Track subtrack = tracks.get(i);
@ -1167,16 +1189,14 @@ public class GPXUtilities {
return count;
}
public List<String> getWaypointCategories() {
List<String> categories = new ArrayList<>();
public Set<String> getWaypointCategories(boolean withDefaultCategory) {
Set<String> categories = new HashSet<>();
for (WptPt pt : points) {
String category = pt.category;
if (!TextUtils.isEmpty(category)) {
if (!categories.contains(category)) {
String category = pt.category == null ? "" : pt.category;
if (withDefaultCategory || !TextUtils.isEmpty(category)) {
categories.add(category);
}
}
}
return categories;
}
}

View file

@ -20,11 +20,9 @@ import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionFactory;
import net.osmand.plus.quickaction.QuickActionRegistry;
import java.util.List;
import java.util.Set;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
@ -69,7 +67,7 @@ public class SelectCategoryDialogFragment extends DialogFragment {
final FavouritesDbHelper helper = ((OsmandApplication) getActivity().getApplication()).getFavorites();
if (gpxFile != null) {
List<String> categories = gpxFile.getWaypointCategories();
Set<String> categories = gpxFile.getWaypointCategories(false);
for (final String category : categories) {
addCategory(ll, category, 0);
}

View file

@ -124,7 +124,9 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
processGPXFolder(gpxFile, sub);
} else if (gpxFile.isFile() && gpxFile.getName().toLowerCase().endsWith(".gpx")) {
GpxDataItem item = processedDataFiles.get(gpxFile);
if (item == null || item.getFileLastModifiedTime() != gpxFile.lastModified()) {
if (item == null
|| item.getFileLastModifiedTime() != gpxFile.lastModified()
|| item.getAnalysis().wptCategoryNames == null) {
GPXFile f = GPXUtilities.loadGPXFile(app, gpxFile);
GPXTrackAnalysis analysis = f.getAnalysis(gpxFile.lastModified());
if (item == null) {

View file

@ -1582,7 +1582,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
processGPXFolder(gpxFile, sub);
} else if (gpxFile.isFile() && gpxFile.getName().toLowerCase().endsWith(".gpx")) {
GpxDataItem item = processedDataFiles.get(gpxFile);
if (item == null || item.getFileLastModifiedTime() != gpxFile.lastModified()) {
if (item == null
|| item.getFileLastModifiedTime() != gpxFile.lastModified()
|| item.getAnalysis().wptCategoryNames == null) {
GPXFile f = GPXUtilities.loadGPXFile(app, gpxFile);
GPXTrackAnalysis analysis = f.getAnalysis(gpxFile.lastModified());
if (item == null) {