Skip to content

Commit

Permalink
Merge branch 'master' into GroupLocalizedContextMenuRows
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-kutz committed Sep 24, 2024
2 parents ab28938 + 8115e5f commit 5203044
Show file tree
Hide file tree
Showing 40 changed files with 966 additions and 382 deletions.
454 changes: 227 additions & 227 deletions OsmAnd-java/src/main/java/net/osmand/binary/OsmandOdb.java

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions OsmAnd-java/src/main/java/net/osmand/gpx/GPXFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;
import java.util.Set;

@Deprecated
public class GPXFile extends GPXUtilities.GPXExtensions {

public String author;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Objects;
import java.util.Set;

@Deprecated
public class GPXTrackAnalysis {

public static final Log LOG = PlatformUtil.getLog(GPXTrackAnalysis.class);
Expand Down
1 change: 1 addition & 0 deletions OsmAnd-java/src/main/java/net/osmand/gpx/GPXUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.Stack;
import java.util.TimeZone;

@Deprecated
public class GPXUtilities {

public static final Log log = PlatformUtil.getLog(GPXUtilities.class);
Expand Down
1 change: 1 addition & 0 deletions OsmAnd-java/src/main/java/net/osmand/gpx/GpxParameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Arrays;
import java.util.List;

@Deprecated
public enum GpxParameter {

FILE_NAME("fileName", "TEXT", String.class, null, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.List;

@Deprecated
public class RouteColorize {

public static double MAX_CORRECT_ELEVATION_DISTANCE = 100.0;// in meters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import co.touchlab.stately.collections.ConcurrentMutableList
import co.touchlab.stately.collections.ConcurrentMutableMap
import co.touchlab.stately.concurrency.Synchronizable
import co.touchlab.stately.concurrency.synchronize
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.runBlocking
import net.osmand.shared.api.SQLiteAPI.SQLiteConnection
import net.osmand.shared.data.StringIntPair
import net.osmand.shared.extensions.currentTimeMillis
import net.osmand.shared.gpx.GpxReader.GpxDbReaderCallback
import net.osmand.shared.io.KFile
import net.osmand.shared.util.LoggerFactory
import kotlin.random.Random


object GpxDbHelper : GpxDbReaderCallback {
val log = LoggerFactory.getLogger("GpxDbHelper")
Expand Down Expand Up @@ -51,19 +56,34 @@ object GpxDbHelper : GpxDbReaderCallback {
private suspend fun loadGpxItems() {
val start = currentTimeMillis()
val items = getItems()
val fileExistenceMap = items.associate { it.file to it.file.exists() }
val startEx = currentTimeMillis()
val fileExistenceMap = getFileExistenceMap(items)
log.info("Time to getFileExistenceMap ${currentTimeMillis() - startEx} ms, ${items.size} items")

val itemsToCache = mutableMapOf<KFile, GpxDataItem>()
val itemsToRemove = mutableSetOf<KFile>()
items.forEach { item ->
val file = item.file
if (fileExistenceMap[file] == true) {
dataItems[file] = item
itemsToCache[file] = item
} else {
remove(file)
itemsToRemove.add(file)
}
}
putToCacheBulk(itemsToCache);
removeFromCacheBulk(itemsToRemove);
log.info("Time to loadGpxItems ${currentTimeMillis() - start} ms, ${items.size} items")
}

private suspend fun getFileExistenceMap(
items: List<GpxDataItem>,
batchSize: Int = 100
): Map<KFile, Boolean> = coroutineScope {
items.chunked(batchSize).map { batch ->
async(Dispatchers.IO) { batch.associate { it.file to it.file.exists() } }
}.awaitAll().fold(mutableMapOf()) { acc, map -> acc.apply { putAll(map) } }
}

private fun loadGpxDirItems() {
val start = currentTimeMillis()
val items = getDirItems()
Expand Down Expand Up @@ -96,6 +116,14 @@ object GpxDbHelper : GpxDbReaderCallback {
}
}

private fun putToCacheBulk(itemsToCache: Map<KFile, GpxDataItem>) {
dataItems.putAll(itemsToCache)
}

private fun removeFromCacheBulk(filesToRemove: Set<KFile>) {
dataItems.keys.removeAll(filesToRemove)
}

fun rename(currentFile: KFile, newFile: KFile): Boolean {
val success = database.rename(currentFile, newFile)
if (success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ class GpxTrackAnalysis {
set(value) = setGpxParameter(GpxParameter.TOTAL_DISTANCE, value.toDouble())

fun isTimeSpecified(): Boolean {
return startTime != Long.MAX_VALUE && startTime != 0L
val startTime = startTime
val endTime = endTime
return startTime != Long.MAX_VALUE && startTime != 0L && endTime != Long.MIN_VALUE && endTime != 0L
}

fun isTimeMoving(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ object GpxUtilities {
val gpxColor = GpxColor.getColorFromName(colorString)
if (gpxColor != null) {
return gpxColor.color
} else {
try {
return colorString.toInt()
} catch (_: NumberFormatException) {
}
}
}
}
Expand Down Expand Up @@ -729,10 +734,10 @@ object GpxUtilities {
progress?.progress(1)
}

fun assignExtensionWriter(wptPt: WptPt, pluginsExtensions: Map<String, String>) {
fun assignExtensionWriter(wptPt: WptPt, extensions: Map<String, String>) {
val regularExtensions = HashMap<String, String>()
val gpxtpxExtensions = HashMap<String, String>()
for ((key, value) in pluginsExtensions) {
for ((key, value) in extensions) {
if (key.startsWith(GPXTPX_PREFIX)) {
gpxtpxExtensions[key] = value
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import net.osmand.shared.KAsyncTask
import net.osmand.shared.extensions.currentTimeMillis
import net.osmand.shared.extensions.format
import net.osmand.shared.gpx.GpxDbHelper.GpxDataItemCallback
import net.osmand.shared.gpx.GpxDbHelper.GpxDataItemCallbackEx
import net.osmand.shared.gpx.data.TrackFolder
import net.osmand.shared.io.KFile
import net.osmand.shared.util.LoggerFactory
import net.osmand.shared.util.PlatformUtil

class TrackFolderLoaderTask(
private val folder: TrackFolder,
Expand Down Expand Up @@ -64,10 +61,6 @@ class TrackFolderLoaderTask(
Companion.cachedRootFolder = TrackFolder(folder)
}

if (progress.isNotEmpty()) {
publishProgress(*progress.toTypedArray())
}

listener.tracksLoaded(folder)
log.info("Finished loading tracks. Took ${currentTimeMillis() - start}ms")

Expand All @@ -77,6 +70,7 @@ class TrackFolderLoaderTask(
override fun onPostExecute(result: TrackFolder) {
val cachedRootFolder = cachedRootFolder
if (result === cachedRootFolder) folder.update(cachedRootFolder)
resetCachedData(folder)
listener.loadTracksFinished(folder)
SmartFolderHelper.notifyUpdateListeners()
}
Expand Down Expand Up @@ -121,7 +115,7 @@ class TrackFolderLoaderTask(
launch {
log.info("Loading track subfolder = $subfolder")
scanFolder(subfolder, progress, trackItems)
folder.addSubFolder(subfolder)
taskSync.synchronize { folder.addSubFolder(subfolder) }
}
} else if (GpxHelper.isGpxFile(file)) {
val item = TrackItem(file)
Expand All @@ -145,7 +139,7 @@ class TrackFolderLoaderTask(
}
}
}
folder.addTrackItems(batchTrackItems)
taskSync.synchronize { folder.addTrackItems(batchTrackItems) }
}
}
if (isCancelled()) return@coroutineScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class TrackFolder(dirFile: KFile, parentFolder: TrackFolder?) :
TracksGroup, ComparableTracksGroup {
private var dirFile: KFile
private val parentFolder: TrackFolder?
private var trackItems = listOf<TrackItem>()
private var subFolders = listOf<TrackFolder>()
private var trackItems = mutableListOf<TrackItem>()
private var subFolders = mutableListOf<TrackFolder>()
private var flattenedTrackItems: List<TrackItem>? = null
private var flattenedSubFolders: List<TrackFolder>? = null
private var folderAnalysis: TrackFolderAnalysis? = null
Expand All @@ -29,8 +29,8 @@ class TrackFolder(dirFile: KFile, parentFolder: TrackFolder?) :
}

fun update(folder: TrackFolder) {
trackItems = folder.trackItems.toList()
subFolders = folder.subFolders.toList()
trackItems = ArrayList(folder.trackItems)
subFolders = ArrayList(folder.subFolders)
flattenedTrackItems = folder.flattenedTrackItems?.toList()
flattenedSubFolders = folder.flattenedSubFolders?.toList()
folderAnalysis = folder.folderAnalysis
Expand Down Expand Up @@ -76,19 +76,19 @@ class TrackFolder(dirFile: KFile, parentFolder: TrackFolder?) :
}

fun addSubFolder(subFolder: TrackFolder) {
this.subFolders = KCollectionUtils.addToList(this.subFolders, subFolder)
this.subFolders.add(subFolder)
}

fun setTrackItems(trackItems: MutableList<TrackItem>) {
this.trackItems = ArrayList(trackItems)
}

fun addTrackItem(trackItem: TrackItem) {
this.trackItems = KCollectionUtils.addToList(this.trackItems, trackItem)
this.trackItems.add(trackItem)
}

fun addTrackItems(trackItems: List<TrackItem>) {
this.trackItems = KCollectionUtils.addAllToList(this.trackItems, trackItems)
this.trackItems.addAll(trackItems)
}

val isEmpty: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class TrackFolderAnalysis(folder: TracksGroup) {
items.addAll(folder.getTrackItems())
}
var totalDistanceSum = 0.0
for (trackItem in items.sortedBy { it.name }) {
var timeSpanSum = 0.0
for (trackItem in items) {
val dataItem = trackItem.dataItem
val analysis = dataItem?.getAnalysis()
if (analysis != null) {
Expand All @@ -43,11 +44,12 @@ class TrackFolderAnalysis(folder: TracksGroup) {
fileSize += file.length()
}
if (analysis.isTimeSpecified()) {
timeSpan = (timeSpan + analysis.getDurationInMs() / 1000.0).toInt()
timeSpanSum += analysis.getDurationInMs() / 1000.0
}
}
}
totalDistance = totalDistanceSum.toFloat()
timeSpan = timeSpanSum.toInt()
tracksCount = items.size

log.info(">>>> ${folder.getName()} = (tracks: $tracksCount, totalDistance: ${"%.2f".format(totalDistance)}, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ actual class NativeFile actual constructor(actual val file: KFile) {

private val filePath = file.path()

actual fun absolutePath(): String {
TODO("Not yet implemented")
}
actual fun absolutePath(): String = filePath

actual fun isDirectory(): Boolean {
return memScoped {
Expand Down
14 changes: 14 additions & 0 deletions OsmAnd/res/drawable/ic_action_car_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M5.9146,18.0001H8.5121C8.1805,17.0617 8,16.0519 8,15C8,13.1499 8.5583,11.4301 9.5155,10H6.0276L6.6943,6H17.3057L17.3066,6.0051C18.0244,6.0292 18.721,6.1372 19.3866,6.3199L19.2785,5.6712C19.1178,4.7068 18.2834,4 17.3057,4H6.6943C5.7166,4 4.8822,4.7068 4.7215,5.6712L4,10L3,10.0001C2.4477,10.0001 2,10.4478 2,11.0001C2,11.5523 2.4477,12.0001 3,12.0001L3,18.0001H3.0854C3.0301,18.1564 3,18.3247 3,18.5001C3,19.3285 3.6716,20.0001 4.5,20.0001C5.3284,20.0001 6,19.3285 6,18.5001C6,18.3247 5.9699,18.1564 5.9146,18.0001ZM5,13.5001C5,12.6716 5.6716,12.0001 6.5,12.0001C7.3284,12.0001 8,12.6716 8,13.5001C8,14.3285 7.3284,15.0001 6.5,15.0001C5.6716,15.0001 5,14.3285 5,13.5001Z"
android:fillColor="#ffffff"
android:fillType="evenOdd"/>
<path
android:pathData="M24,15C24,18.866 20.866,22 17,22C13.134,22 10,18.866 10,15C10,11.134 13.134,8 17,8C20.866,8 24,11.134 24,15ZM18,13V11H16V13H18ZM18,19V15H16V19H18Z"
android:fillColor="#ffffff"
android:fillType="evenOdd"/>
</vector>
4 changes: 2 additions & 2 deletions OsmAnd/res/layout/map_hud_quick_actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/quick_actions_container"
<net.osmand.plus.views.controls.MapButtonsLayout
android:id="@+id/map_buttons_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
Expand Down
56 changes: 55 additions & 1 deletion OsmAnd/res/values-b+sr+Latn/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3041,7 +3041,7 @@
<string name="complex_routing_descr">Dvofazno usmeravanje za auto navigaciju.</string>
<string name="use_fast_recalculation_desc">Preračunava samo početni deo puta, korisno za duga putovanja.</string>
<string name="use_native_pt">Razvoj lokalnog javnog prevoza</string>
<string name="use_native_pt_desc">Prebaci se na Java (bezbedno) izrečunavanje rute javnog prevoza</string>
<string name="use_native_pt_desc">Prebaci se na Java (bezbedno) izračunavanje rute javnog prevoza</string>
<string name="perform_oauth_authorization_description">Prijavi se pomoću OAuth -a radi korišćenja mogućnosti uređivanja OpenStritMapa</string>
<string name="perform_oauth_authorization">Prijavi se preko OAuth-a</string>
<string name="clear_osm_token">Obriši OpenStreetMap OAuth token</string>
Expand Down Expand Up @@ -5908,4 +5908,58 @@
<string name="no_photos_available_descr">Još uvek nije dodata nijedna korisnička fotografija na ovu lokaciju</string>
<string name="no_photos_available">Nema dostupnih fotografija</string>
<string name="wikimedia">Vikimedia</string>
<string name="unit_volt">V</string>
<string name="obd_fuel_type_not_provided">Nije navedena vrsta goriva</string>
<string name="obd_fuel_type_gasoline">Benzin</string>
<string name="obd_fuel_type_methanol">Metanol</string>
<string name="obd_fuel_type_ethanol">Etanol</string>
<string name="obd_fuel_type_diesel">Dizel</string>
<string name="obd_fuel_type_lpg">TNG</string>
<string name="obd_fuel_type_cng">KPG</string>
<string name="obd_fuel_type_propane">Propan</string>
<string name="obd_fuel_type_electric">Električno</string>
<string name="obd_fuel_type_bifuel_gasoline">Dvogorivno radno Benzin</string>
<string name="obd_fuel_type_bifuel_methanol">Dvogorivno radno Metanol</string>
<string name="obd_fuel_type_bifuel_ethanol">Dvogorivno radno Etanol</string>
<string name="obd_fuel_type_bifuel_lpg">Dvogorivno radno TNG</string>
<string name="obd_fuel_type_bifuel_cng">Dvogorivno radno KPG</string>
<string name="obd_fuel_type_bifuel_propane">Dvogorivno radno Propan</string>
<string name="obd_fuel_type_bifuel_electricity">Dvogorivno radno Električno</string>
<string name="obd_fuel_type_hybrid_gasoline">Hibridno Benzinsko</string>
<string name="obd_fuel_type_bifuel_electric_combustion">Dvogorivno radno Električna i sa US mašina</string>
<string name="obd_fuel_type_hybrid_ethanol">Hibridno Etanol</string>
<string name="obd_fuel_type_hybrid_diesel">Hibridno Dizel</string>
<string name="obd_fuel_type_hybrid_electric_combustion">Hibridno Električna i sa US mašina</string>
<string name="obd_fuel_type_hybrid_regenerative">Hibridno Regenerativno</string>
<string name="obd_fuel_type_bifuel_hydrogen">Dvogorivno radno Vodonik</string>
<string name="obd_fuel_type_hybrid_hydrogen">Hibridno Vodonik</string>
<string name="obd_fuel_type_hydrogen">Vodonik</string>
<string name="obd_fuel_type_unknown">Nepoznati tip goriva</string>
<string name="shared_string_obd">OBD</string>
<string name="obd_fuel_type_hybrid_electric">Hibridno Električno</string>
<string name="obd_widget_group">Metrika vozila</string>
<string name="percent_unit">%</string>
<string name="obd_rpm">RPM</string>
<string name="rpm_unit">rpm</string>
<string name="obd_speed_desc">Prikazuje brzinu vozila preko OBD senzora</string>
<string name="obd_rpm_desc">Prikazuje tahometarski RPM preko OBD senzora</string>
<string name="obd_air_intake_temp_desc">Prikazuje temperaturu usisnog vazduha vozila preko OBD senzora</string>
<string name="obd_ambient_air_temp_desc">Prikazuje temperaturu ambijentalnog vazduha preko OBD senzora</string>
<string name="obd_battery_voltage_desc">Prikazuje napon baterije preko OBD senzora</string>
<string name="obd_fuel_level_desc">Prikazuje nivo goriva u vozilu preko OBD senzora</string>
<string name="obd_fuel_type_desc">Prikazuje vrstu goriva vozila preko OBD senzora</string>
<string name="obd_air_intake_temp">Temperatura ulaznog vazduha</string>
<string name="obd_ambient_air_temp">Temperatura ambijentalnog vazduha</string>
<string name="obd_battery_voltage">Napon baterije</string>
<string name="obd_engine_coolant_temp">Temperatura rashladne tečnosti motora</string>
<string name="obd_fuel_level">Nivo goriva</string>
<string name="obd_fuel_consumption_rate">Stopa potrošnje goriva</string>
<string name="obd_fuel_consumption_rate_desc">Prikazuje stopu potrošnje goriva vozila na osnovu OBD lokacije</string>
<string name="obd_fuel_left_distance">Preostalo gorivo (rastojanje)</string>
<string name="obd_fuel_type">Tip goriva</string>
<string name="obd_plugin_name">Metrika vozila</string>
<string name="obd_support">OBD podrška</string>
<string name="obd_plugin_description">Pristupa informacijama o vašem vozilu preko OBD protokola</string>
<string name="obd_engine_coolant_temp_desc">Prikazuje temperaturu rashladne tečnosti motora preko OBD senzora</string>
<string name="obd_fuel_left_distance_desc">Pokazuje razdaljinu koju vozilo može da pređe sa preostalim gorivom preko OBD senzora</string>
</resources>
Loading

0 comments on commit 5203044

Please sign in to comment.