Skip to content

Commit

Permalink
Merge branch 'master' into move_to_14_sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-osm committed Jul 16, 2024
2 parents 0cce5b6 + a363f63 commit a02e5dc
Show file tree
Hide file tree
Showing 56 changed files with 479 additions and 295 deletions.
6 changes: 6 additions & 0 deletions OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,15 @@ public void initFromInputStream(InputStream is) {
for (String lng : MapRenderingTypes.langs) {
parsePoiAdditional(parser, lastCategory, lastFilter, lastType, lng, baseType,
lastPoiAdditionalCategory, textPoiAdditionals);
if (baseType.isTopIndex()) {
topIndexPoiAdditional.put(TOP_INDEX_ADDITIONAL_PREFIX + baseType.getKeyName() + ":" + lng, baseType);
}
}
parsePoiAdditional(parser, lastCategory, lastFilter, lastType, "en", baseType,
lastPoiAdditionalCategory, textPoiAdditionals);
if (baseType.isTopIndex()) {
topIndexPoiAdditional.put(TOP_INDEX_ADDITIONAL_PREFIX + baseType.getKeyName() + ":en", baseType);
}
}
if (lastPoiAdditionalCategory != null) {
List<PoiType> categoryAdditionals = categoryPoiAdditionalMap.get(lastPoiAdditionalCategory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ public GpxRouteApproximation searchGpxRouteInternal(RoutePlannerFrontEnd router,
this.router = router;
GpxRouteApproximation result;
if (router.isUseGeometryBasedApproximation()) {
result = searchGpxSegments(this, gpxPoints, resultMatcher);
result = searchGpxSegments(this, gpxPoints);
} else {
result = searchGpxRouteByRouting(this, gpxPoints, resultMatcher);
result = searchGpxRouteByRouting(this, gpxPoints);
}
result.reconstructFinalPointsFromFullRoute();
if (useExternalTimestamps) {
result.applyExternalTimestamps(gpxPoints);
}
if (resultMatcher != null) {
resultMatcher.publish(this.ctx.calculationProgress.isCancelled ? null : this);
}
return result;
}

Expand Down Expand Up @@ -171,7 +174,7 @@ private void reconstructFinalPointsFromFullRoute() {
}
}

private GpxRouteApproximation searchGpxSegments(GpxRouteApproximation gctx, List<RoutePlannerFrontEnd.GpxPoint> gpxPoints, ResultMatcher<GpxRouteApproximation> resultMatcher) throws IOException, InterruptedException {
private GpxRouteApproximation searchGpxSegments(GpxRouteApproximation gctx, List<RoutePlannerFrontEnd.GpxPoint> gpxPoints) throws IOException, InterruptedException {
NativeLibrary nativeLib = gctx.ctx.nativeLib;
if (nativeLib != null && router.isUseNativeApproximation()) {
gctx = nativeLib.runNativeSearchGpxRoute(gctx, gpxPoints, true);
Expand All @@ -188,13 +191,10 @@ private GpxRouteApproximation searchGpxSegments(GpxRouteApproximation gctx, List
log.info(gctx);
}
}
if (resultMatcher != null) {
resultMatcher.publish(gctx.ctx.calculationProgress.isCancelled ? null : gctx);
}
return gctx;
}

private GpxRouteApproximation searchGpxRouteByRouting(GpxRouteApproximation gctx, List<RoutePlannerFrontEnd.GpxPoint> gpxPoints, ResultMatcher<GpxRouteApproximation> resultMatcher) throws IOException, InterruptedException {
private GpxRouteApproximation searchGpxRouteByRouting(GpxRouteApproximation gctx, List<RoutePlannerFrontEnd.GpxPoint> gpxPoints) throws IOException, InterruptedException {
long timeToCalculate = System.nanoTime();
NativeLibrary nativeLib = gctx.ctx.nativeLib;
if (nativeLib != null && router.isUseNativeApproximation()) {
Expand Down Expand Up @@ -288,9 +288,6 @@ private GpxRouteApproximation searchGpxRouteByRouting(GpxRouteApproximation gctx
log.info(gctx);
}
}
if (resultMatcher != null) {
resultMatcher.publish(gctx.ctx.calculationProgress.isCancelled ? null : gctx);
}
return gctx;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,13 @@ protected void ignorePrecedingStraightsOnSameIntersection(boolean leftside, List
distanceToNextTurn += currentSegment.getDistance();
if (currentSegment.getTurnType() != null &&
currentSegment.getTurnType().getValue() == TurnType.C &&
distanceToNextTurn <= 100) {
result.get(i).getTurnType().setSkipToSpeak(true);
distanceToNextTurn <= 200) {
currentSegment.getTurnType().setSkipToSpeak(true);
} else {
nextSegment = currentSegment;
distanceToNextTurn = 999999;
if (currentSegment.getTurnType() != null) {
distanceToNextTurn = 999999;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,8 @@ public void searchTopIndexPoiAdditional(SearchPhrase phrase, SearchResultMatcher
private TopIndexMatch matchTopIndex(BinaryMapIndexReader r, SearchPhrase phrase) throws IOException {
String search = phrase.getText(true);
List<PoiSubType> poiSubTypes = r.getTopIndexSubTypes();
String lang = phrase.getSettings().getLang();
List<TopIndexMatch> matches = new ArrayList<>();
for (PoiSubType subType : poiSubTypes) {
NameStringMatcher nm = new NameStringMatcher(search, CHECK_ONLY_STARTS_WITH);
String topIndexValue = null;
Expand All @@ -1105,9 +1107,20 @@ private TopIndexMatch matchTopIndex(BinaryMapIndexReader r, SearchPhrase phrase)
}
if (topIndexValue != null) {
TopIndexMatch topIndexMatch = new TopIndexMatch(subType, topIndexValue, translate);
return topIndexMatch;
if (!Algorithms.isEmpty(lang) && subType.name.contains(":" + lang)) {
return topIndexMatch;
}
matches.add(topIndexMatch);
}
}
for (TopIndexMatch m : matches) {
if (!m.subType.name.contains(":")) {
return m;
}
}
if (matches.size() > 0) {
return matches.get(0);
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.binary.BinaryMapPoiReaderAdapter.PoiSubType;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;

public class TopIndexFilter implements BinaryMapIndexReader.SearchPoiAdditionalFilter {
Expand Down Expand Up @@ -32,6 +33,10 @@ public String getTag() {
@Override
public String getName() {
// type of object: brand, operator
AbstractPoiType pt = types.getAnyPoiAdditionalTypeByKey(tag);
if (pt != null) {
return pt.getTranslation();
}
return types.getPoiTranslation(tag);
}

Expand Down
5 changes: 5 additions & 0 deletions OsmAnd-telegram/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
<package android:name="net.osmand" />
<package android:name="net.osmand.plus" />
<package android:name="net.osmand.dev" />
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" />
</intent>
</queries>

<application
Expand Down
8 changes: 4 additions & 4 deletions OsmAnd-telegram/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,21 @@ android {

task downloadTdLibzip {
doLast {
ant.get(src: 'https://core.telegram.org/tdlib/tdlib.zip', dest: 'tdlib.zip', skipexisting: 'true')
ant.get(src: 'https://osmand.net/uploads/libs/tdlib.zip', dest: 'tdlib.zip', skipexisting: 'true')
ant.unzip(src: 'tdlib.zip', dest: 'tdlib/')
}
}

task copyNativeLibs(type: Copy) {
dependsOn downloadTdLibzip
from "tdlib/libtd/src/main/libs"
from "tdlib/tdlib/libs"
into "libs"
}

task copyJavaSources(type: Copy) {
dependsOn downloadTdLibzip
from "tdlib/libtd/src/main/java/org/drinkless/td"
into "src/org/drinkless/td"
from "tdlib/tdlib/java"
into "src"
}

task downloadPrebuiltTelegram {
Expand Down
2 changes: 1 addition & 1 deletion OsmAnd-telegram/src/net/osmand/telegram/TelegramService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import net.osmand.telegram.helpers.location.LocationCallback
import net.osmand.telegram.helpers.location.LocationServiceHelper
import net.osmand.telegram.notifications.TelegramNotification.NotificationType
import net.osmand.telegram.utils.AndroidUtils
import org.drinkless.td.libcore.telegram.TdApi
import org.drinkless.tdlib.TdApi

private const val UPDATE_WIDGET_INTERVAL_MS = 1000L // 1 sec
private const val UPDATE_LIVE_MESSAGES_INTERVAL_MS = 10000L // 10 sec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import net.osmand.telegram.helpers.TelegramHelper
import net.osmand.telegram.utils.*
import net.osmand.telegram.utils.OsmandFormatter.MetricsConstants
import net.osmand.telegram.utils.OsmandFormatter.SpeedConstants
import org.drinkless.td.libcore.telegram.TdApi
import org.drinkless.tdlib.TdApi
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import net.osmand.data.LatLon
import net.osmand.telegram.TelegramApplication
import net.osmand.telegram.utils.OsmandLocationUtils
import net.osmand.util.MapUtils
import org.drinkless.td.libcore.telegram.TdApi
import org.drinkless.tdlib.TdApi
import java.util.concurrent.ConcurrentLinkedQueue

class LocationMessages(val app: TelegramApplication) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import net.osmand.telegram.utils.AndroidNetworkUtils
import net.osmand.telegram.utils.BASE_URL
import net.osmand.telegram.utils.OsmandLocationUtils
import net.osmand.util.MapUtils
import org.drinkless.td.libcore.telegram.TdApi
import org.drinkless.tdlib.TdApi
import org.json.JSONException
import org.json.JSONObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import net.osmand.telegram.utils.OsmandFormatter
import net.osmand.telegram.utils.OsmandLocationUtils
import net.osmand.telegram.utils.OsmandLocationUtils.MessageOsmAndBotLocation
import net.osmand.telegram.utils.OsmandLocationUtils.MessageUserLocation
import org.drinkless.td.libcore.telegram.TdApi
import net.osmand.util.Algorithms
import org.drinkless.tdlib.TdApi
import org.drinkless.tdlib.TdApi.User
import java.io.File
import java.util.*
import java.util.concurrent.ConcurrentHashMap
Expand Down Expand Up @@ -313,15 +315,9 @@ class ShowLocationHelper(private val app: TelegramApplication) {
val content = message.content
val senderId = OsmandLocationUtils.getSenderMessageId(message)
if ((content is TdApi.MessageLocation || (content is MessageUserLocation && content.isValid()))) {
val user = telegramHelper.getUser(senderId)
val user:User? = telegramHelper.getUser(senderId)
if (user != null) {
name = "${user.firstName} ${user.lastName}".trim()
if (name.isEmpty()) {
name = user.username
}
if (name.isEmpty()) {
name = user.phoneNumber
}
name = user.getName();
}
if (name.isEmpty()) {
name = senderId.toString()
Expand Down
66 changes: 39 additions & 27 deletions OsmAnd-telegram/src/net/osmand/telegram/helpers/TelegramHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,26 @@ import net.osmand.telegram.SHARE_TYPE_MAP_AND_TEXT
import net.osmand.telegram.SHARE_TYPE_TEXT
import net.osmand.telegram.TelegramSettings
import net.osmand.telegram.TelegramSettings.ShareChatInfo
import net.osmand.telegram.helpers.TelegramHelper.TelegramAuthParamType.*
import net.osmand.telegram.helpers.TelegramHelper.TelegramAuthParamType.CODE
import net.osmand.telegram.helpers.TelegramHelper.TelegramAuthParamType.PASSWORD
import net.osmand.telegram.helpers.TelegramHelper.TelegramAuthParamType.PHONE_NUMBER
import net.osmand.telegram.utils.GRAYSCALE_PHOTOS_DIR
import net.osmand.telegram.utils.GRAYSCALE_PHOTOS_EXT
import net.osmand.telegram.utils.OsmandLocationUtils
import net.osmand.telegram.utils.OsmandLocationUtils.DEVICE_PREFIX
import net.osmand.telegram.utils.OsmandLocationUtils.USER_TEXT_LOCATION_TITLE
import org.drinkless.td.libcore.telegram.Client
import org.drinkless.td.libcore.telegram.Client.ResultHandler
import org.drinkless.td.libcore.telegram.TdApi
import org.drinkless.td.libcore.telegram.TdApi.AuthorizationState
import net.osmand.util.Algorithms
import org.drinkless.tdlib.Client
import org.drinkless.tdlib.Client.ResultHandler
import org.drinkless.tdlib.TdApi
import org.drinkless.tdlib.TdApi.AuthorizationState
import org.drinkless.tdlib.TdApi.User
import java.io.File
import java.util.*
import java.util.TreeSet
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit
import kotlin.collections.HashSet


class TelegramHelper private constructor() {
Expand Down Expand Up @@ -282,7 +285,7 @@ class TelegramHelper private constructor() {
PHONE_NUMBER -> client!!.send(
TdApi.SetAuthenticationPhoneNumber(
value,
TdApi.PhoneNumberAuthenticationSettings(false, false, false, false, null)
TdApi.PhoneNumberAuthenticationSettings()
), AuthorizationRequestHandler()
)
CODE -> client!!.send(TdApi.CheckAuthenticationCode(value), AuthorizationRequestHandler())
Expand Down Expand Up @@ -317,7 +320,7 @@ class TelegramHelper private constructor() {
try {
log.debug("Loading native tdlib...")
System.loadLibrary("tdjni")
Client.setLogVerbosityLevel(1)
Client.setLogMessageHandler(1) { level, message -> log.debug("$level: $message") }
libraryLoaded = true
} catch (e: Throwable) {
log.error("Failed to load tdlib", e)
Expand Down Expand Up @@ -373,7 +376,7 @@ class TelegramHelper private constructor() {
else -> 0
}

fun isOsmAndBot(userId: Long) = users[userId]?.username == OSMAND_BOT_USERNAME
fun isOsmAndBot(userId: Long) = users[userId]?.getName() == OSMAND_BOT_USERNAME

fun isBot(userId: Long) = users[userId]?.type is TdApi.UserTypeBot

Expand Down Expand Up @@ -527,8 +530,8 @@ class TelegramHelper private constructor() {
}
resultArticles.forEach {
shareInfo.lastTextMessageHandled = false
val sendOptions = TdApi.MessageSendOptions(true, true, null)
client?.send(TdApi.SendInlineQueryResultMessage(shareInfo.chatId, 0, 0, sendOptions,
val sendOptions = TdApi.MessageSendOptions(true, true, true, true, null, 0, 0, false)
client?.send(TdApi.SendInlineQueryResultMessage(shareInfo.chatId, 0, null, sendOptions,
inlineQueryResults.inlineQueryId, it.id, false)) { obj ->
handleTextLocationMessageUpdate(obj, shareInfo, true)
}
Expand Down Expand Up @@ -840,7 +843,7 @@ class TelegramHelper private constructor() {
client?.send(
TdApi.EditMessageLiveLocation(
shareInfo.chatId, shareInfo.currentMapMessageId,
null, null, 0, 0
null, null, 0, 0, 0
)
)
{ obj ->
Expand All @@ -863,8 +866,8 @@ class TelegramHelper private constructor() {
shareInfo.pendingTdLibText++
shareInfo.lastSendTextMessageTime = (System.currentTimeMillis() / 1000).toInt()
log.error("sendNewTextLocation ${shareInfo.pendingTdLibText}")
val sendOptions = TdApi.MessageSendOptions(false, true, null)
client?.send(TdApi.SendMessage(shareInfo.chatId, 0, 0, sendOptions, null, content)) { obj ->
val sendOptions = TdApi.MessageSendOptions(true, true, true, true, null, 0, 0, false)
client?.send(TdApi.SendMessage(shareInfo.chatId, 0, null, sendOptions, null, content)) { obj ->
handleTextLocationMessageUpdate(obj, shareInfo, false)
}
}
Expand Down Expand Up @@ -896,8 +899,8 @@ class TelegramHelper private constructor() {
shareInfo.pendingTdLibMap++
shareInfo.lastSendMapMessageTime = (System.currentTimeMillis() / 1000).toInt()
log.error("sendNewMapLocation ${shareInfo.pendingTdLibMap}")
val sendOptions = TdApi.MessageSendOptions(false, true, null)
client?.send(TdApi.SendMessage(shareInfo.chatId, 0, 0, sendOptions, null, content)) { obj ->
val sendOptions = TdApi.MessageSendOptions(false, true, true, true, null, 0, 0, false)
client?.send(TdApi.SendMessage(shareInfo.chatId, 0, null, sendOptions, null, content)) { obj ->
handleMapLocationMessageUpdate(obj, shareInfo, false)
}
}
Expand All @@ -911,7 +914,7 @@ class TelegramHelper private constructor() {
shareInfo.lastSendMapMessageTime = (System.currentTimeMillis() / 1000).toInt()
log.info("editMapLocation ${shareInfo.currentMapMessageId} pendingTdLibMap: ${shareInfo.pendingTdLibMap}")
client?.send(TdApi.EditMessageLiveLocation(shareInfo.chatId, shareInfo.currentMapMessageId,
null, location, locationMessage.bearing.toInt(), 0)) { obj ->
null, location, locationMessage.bearing.toInt(), 0, 0)) { obj ->
handleMapLocationMessageUpdate(obj, shareInfo, false)
}
}
Expand Down Expand Up @@ -1110,7 +1113,7 @@ class TelegramHelper private constructor() {
if (!info) {
log.info("Init tdlib parameters")

val parameters = TdApi.TdlibParameters()
val parameters = TdApi.SetTdlibParameters()
parameters.databaseDirectory = File(appDir, "tdlib").absolutePath
parameters.useMessageDatabase = true
parameters.useSecretChats = true
Expand All @@ -1120,14 +1123,7 @@ class TelegramHelper private constructor() {
parameters.deviceModel = "Android"
parameters.systemVersion = "OsmAnd Telegram"
parameters.applicationVersion = "1.0"
parameters.enableStorageOptimizer = true

client!!.send(TdApi.SetTdlibParameters(parameters), AuthorizationRequestHandler())
}
}
TdApi.AuthorizationStateWaitEncryptionKey.CONSTRUCTOR -> {
if (!info) {
client!!.send(TdApi.CheckDatabaseEncryptionKey(), AuthorizationRequestHandler())
client!!.send(parameters, AuthorizationRequestHandler())
}
}
TdApi.AuthorizationStateWaitPhoneNumber.CONSTRUCTOR -> {
Expand Down Expand Up @@ -1560,4 +1556,20 @@ class TelegramHelper private constructor() {
}// result is already received through UpdateAuthorizationState, nothing to do
}
}
}

fun User.getName(): String {
var name = "${this.firstName} ${this.lastName}".trim()
if (name.isEmpty()) {
this.usernames?.let {
val userNames = it.activeUsernames
if(!Algorithms.isEmpty(userNames)) {
name = userNames[0]
}
}
}
if (name.isEmpty()) {
name = this.phoneNumber
}
return name
}
Loading

0 comments on commit a02e5dc

Please sign in to comment.