Skip to content

Commit

Permalink
Merge branch 'master' into context_gallery_review_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRe1nk0 committed Oct 1, 2024
2 parents 4929809 + d650f36 commit 844bce2
Show file tree
Hide file tree
Showing 194 changed files with 2,359 additions and 886 deletions.
3 changes: 3 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/NativeLibrary.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ public boolean needRequestPrivateAccessRouting(RoutingContext ctx, int[] x31Coor
}
protected static native boolean nativeNeedRequestPrivateAccessRouting(RoutingContext ctx, int[] x31Coordinates, int[] y31Coordinates);

protected static native ByteBuffer getGeotiffTile(
String tilePath, String outColorFilename, String midColorFilename, int type, int size, int zoom, int x, int y);

/**/
// Empty native impl
/*
Expand Down
30 changes: 21 additions & 9 deletions OsmAnd-java/src/main/java/net/osmand/data/Amenity.java
Original file line number Diff line number Diff line change
Expand Up @@ -697,23 +697,35 @@ public String getCityFromTagGroups(String lang) {
}
String result = null;
for (Map.Entry<Integer, List<TagValuePair>> entry : tagGroups.entrySet()) {
String translated = "";
String nonTranslated = "";
City.CityType type = null;
for (TagValuePair tagValue : entry.getValue()) {
if (tagValue.tag.endsWith("city:" + lang)) {
if (result == null) {
result = tagValue.value;
} else {
result += ", " + tagValue.value;
}
break;
if (tagValue.tag.endsWith("name:" + lang)) {
translated = tagValue.value;
}
if (tagValue.tag.endsWith("city")) {
result = tagValue.value;
if (tagValue.tag.endsWith("name")) {
nonTranslated = tagValue.value;
}
if (tagValue.tag.equals("place")) {
type = City.CityType.valueFromString(tagValue.value.toUpperCase());
}
}
String name = translated.isEmpty() ? nonTranslated : translated;
if (!name.isEmpty() && isCityTypeAccept(type)) {
result = result == null ? name : result + ", " + name;
}
}
return result;
}

private boolean isCityTypeAccept(City.CityType type) {
if (type == null) {
return false;
}
return type.storedAsSeparateAdminEntity();
}

public List<LatLon> getPolygon() {
List<LatLon> res = new ArrayList<>();
if (x == null) {
Expand Down
12 changes: 3 additions & 9 deletions OsmAnd-java/src/main/java/net/osmand/data/DataTileManager.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package net.osmand.data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import gnu.trove.map.hash.TLongObjectHashMap;

import net.osmand.util.MapUtils;

import java.util.*;

/**
* @param <T> - object to store in that manager
*/
Expand Down Expand Up @@ -121,7 +115,7 @@ public List<T> getObjects(int leftX31, int topY31, int rightX31, int bottomY31,
*/
public List<T> getClosestObjects(double latitude, double longitude, double radius) {
if (isEmpty()) {
return Collections.emptyList();
return new ArrayList<>();
}
double tileDist = radius / MapUtils.getTileDistanceWidth(latitude, zoom);
int tileDistInt = (int) Math.ceil(tileDist);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package net.osmand.shared.io

import okio.BufferedSink
import okio.IOException
import okio.Sink
import okio.buffer
import java.io.StringWriter

class SinkStringWriter(sink: Sink) : StringWriter() {

private val bufferedSink: BufferedSink = sink.buffer()
private val bufferedSink = sink.buffer()

@Throws(IOException::class)
override fun write(c: Int) {
bufferedSink.writeUtf8CodePoint(c)
bufferedSink.writeUtf8(c.toChar().toString())
}

override fun write(str: String?) {
if (str != null) {
bufferedSink.writeUtf8(str)
}
}

@Throws(IOException::class)
Expand All @@ -29,4 +34,8 @@ class SinkStringWriter(sink: Sink) : StringWriter() {
override fun flush() {
bufferedSink.flush()
}

override fun toString(): String {
return bufferedSink.toString()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.osmand.shared.data

import net.osmand.shared.util.Localization

data class BTDeviceInfo(val name: String, val address: String) {
companion object {
val UNKNOWN_DEVICE = BTDeviceInfo(Localization.getString("unknown_bt_device"), "")
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package net.osmand.shared.extensions

import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime

fun currentTimeMillis(): Long = Clock.System.now().toEpochMilliseconds()
fun currentTimeMillis(): Long = Clock.System.now().toEpochMilliseconds()
fun millisToLocalDateTime(milliseconds: Long): LocalDateTime =
Instant.fromEpochMilliseconds(milliseconds).toLocalDateTime(TimeZone.currentSystemDefault())
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ package net.osmand.shared.gpx

import net.osmand.shared.io.KFile
import net.osmand.shared.routing.ColoringType
import net.osmand.shared.util.PlatformUtil

class GpxDataItem(
file: KFile
) : DataItem(file) {

private var analysis: GpxTrackAnalysis? = null

companion object {
fun isRegularTrack(file: KFile) = file.path().startsWith(PlatformUtil.getOsmAndContext().getGpxDir().path())
}

fun isRegularTrack() = Companion.isRegularTrack(file)

fun getAnalysis(): GpxTrackAnalysis? {
return analysis
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ class GpxDatabase {
private fun readItemFile(query: SQLiteCursor): KFile {
var fileDir: String = query.getString(query.getColumnIndex(FILE_DIR.columnName))
val fileName = query.getString(query.getColumnIndex(FILE_NAME.columnName))
log.info(">>>> ++++ readItemFile fileDir=$fileDir fileName=$fileName")

val appDir = PlatformUtil.getOsmAndContext().getAppDir()
val gpxDir = PlatformUtil.getOsmAndContext().getGpxDir()
Expand All @@ -207,6 +208,7 @@ class GpxDatabase {
fileDir = fileDir.replace(gpxDir.toString(), "")
fileDir = fileDir.replace(appDir.toString(), "")
val dir = if (fileDir.isEmpty()) gpxDir else KFile(gpxDir, fileDir)
log.info(">>>> ==== readItemFile fileDir=$fileDir dir=$dir gpxDir=$gpxDir")
return KFile(dir, fileName)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ object GpxDbHelper : GpxReaderAdapter {
private const val READER_TASKS_LIMIT = 4
private var readers = mutableListOf<GpxReader>()
private var readerSync = Synchronizable()
var readTrackItemCount: Long = 0

private var initialized: Boolean = false

Expand Down Expand Up @@ -249,8 +248,7 @@ object GpxDbHelper : GpxReaderAdapter {
return null
}
val item = dataItems[file]
if (GpxDbUtils.isAnalyseNeeded(item)) {
readTrackItemCount++
if (GpxDbUtils.isAnalyseNeeded(item) && GpxDataItem.isRegularTrack(file)) {
readGpxItem(file, item, callback)
}
return item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class GpxReader(private val adapter: GpxReaderAdapter)
if (gpxFile.error == null) {
val analyser = PlatformUtil.getOsmAndContext().getTrackPointsAnalyser()
updatedItem.setAnalysis(gpxFile.getAnalysis(file.lastModified(), null, null, analyser))
if (!updatedItem.isRegularTrack()) {
return updatedItem
}
val creationTime: Long = updatedItem.requireParameter(GpxParameter.FILE_CREATION_TIME)
if (creationTime <= 0) {
updatedItem.setParameter(GpxParameter.FILE_CREATION_TIME, GpxUtilities.getCreationTime(gpxFile))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ object GpxUtilities {

fun writeGpxFile(file: KFile, gpxFile: GpxFile): KException? {
return try {
file.getParentFile()?.createDirectories()
if (KAlgorithms.isEmpty(gpxFile.path)) {
gpxFile.path = if (file.isAbsolute()) file.path() else file.absolutePath()
}
writeGpx(file, null, gpxFile, null)
} catch (e: KException) {
log.error("Failed to write gpx '$file.path()'", e)
Expand Down Expand Up @@ -743,6 +747,7 @@ object GpxUtilities {
} else {
regularExtensions[key] = value
}
wptPt.getDeferredExtensionsToWrite()[key] = value
}
if (regularExtensions.isNotEmpty()) {
wptPt.setExtensionsWriter("extensions", createExtensionsWriter(regularExtensions, true))
Expand Down Expand Up @@ -970,7 +975,7 @@ object GpxUtilities {
gpxFile.modifiedTime = file.lastModified()
gpxFile.pointsModifiedTime = gpxFile.modifiedTime
if (gpxFile.error != null) {
log.info("Error reading gpx ${gpxFile.path}")
log.info("Error reading gpx ${gpxFile.path}: ${gpxFile.error!!.message}")
}
gpxFile
} catch (e: IOException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.osmand.shared.gpx

import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import net.osmand.shared.KAsyncTask
import net.osmand.shared.api.KStateChangedListener
Expand Down Expand Up @@ -30,6 +30,12 @@ object SmartFolderHelper {
}
}

val json = Json {
isLenient = true
ignoreUnknownKeys = true
classDiscriminator = "className"
}

init {
osmAndSettings.registerPreference(TRACK_FILTERS_SETTINGS_PREF, "")
osmAndSettings.addPreferenceListener(TRACK_FILTERS_SETTINGS_PREF, settingsChangedListener)
Expand Down Expand Up @@ -101,7 +107,7 @@ object SmartFolderHelper {
val newFolder = SmartFolder(name)
newFolder.creationTime = currentTimeMillis()
newFolder.filters = enabledFilters
KCollectionUtils.addToList(smartFolderCollection, newFolder)
smartFolderCollection = KCollectionUtils.addToList(smartFolderCollection, newFolder)
updateSmartFolderItems(newFolder)
writeSettings()
notifyFolderCreatedListeners(newFolder)
Expand Down Expand Up @@ -151,7 +157,7 @@ object SmartFolderHelper {

private fun writeSettings() {
isWritingSettings = true
val json = Json.encodeToString(ListSerializer(SmartFolder.serializer()), smartFolderCollection)
val json = json.encodeToString(smartFolderCollection)
osmAndSettings.setStringPreference(TRACK_FILTERS_SETTINGS_PREF, json)
isWritingSettings = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import net.osmand.shared.gpx.TrackItem
import net.osmand.shared.gpx.filters.BaseTrackFilter
import net.osmand.shared.gpx.filters.TrackFilterSerializer
import net.osmand.shared.gpx.filters.TrackFolderAnalysis
import net.osmand.shared.util.KCollectionUtils

Expand All @@ -13,21 +14,18 @@ class SmartFolder(@Serializable var folderName: String) : TracksGroup, Comparabl
@Transient
private var trackItems: List<TrackItem>? = null

constructor() : this("") {
}
constructor() : this("")

@Serializable
var creationTime = 0L

@Serializable
var filters: MutableList<BaseTrackFilter>? = null
@Serializable(with = TrackFilterSerializer::class)
var filters: List<BaseTrackFilter>? = null

@Transient
private var folderAnalysis: TrackFolderAnalysis? = null

override fun getName(): String {
return folderName
}
override fun getName() = folderName

override fun getTrackItems(): List<TrackItem> {
var trackItems = this.trackItems
Expand All @@ -54,13 +52,9 @@ class SmartFolder(@Serializable var folderName: String) : TracksGroup, Comparabl
return analysis
}

override fun getDirName(): String {
return folderName
}
override fun getDirName() = folderName

override fun lastModified(): Long {
return creationTime
}
override fun lastModified() = creationTime

fun resetItems() {
trackItems = ArrayList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package net.osmand.shared.gpx.filters

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import net.osmand.shared.gpx.TrackItem

@Serializable
abstract class BaseTrackFilter(
sealed class BaseTrackFilter(
@Serializable
@SerialName("filterType") val trackFilterType: TrackFilterType,
var filterChangedListener: FilterChangedListener?) {
@Transient var filterChangedListener: FilterChangedListener? = null) {

abstract fun isEnabled(): Boolean

Expand Down
Loading

0 comments on commit 844bce2

Please sign in to comment.