From cb1f203cc121cee423794d18f4cb59e4fa4fa40b Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Mon, 18 Jan 2021 01:09:45 +0200 Subject: [PATCH] Implement Online routing backend (fixes after code review) --- OsmAnd/res/values-ar/strings.xml | 1 - OsmAnd/res/values-cs/strings.xml | 1 - OsmAnd/res/values-de/strings.xml | 1 - OsmAnd/res/values-eo/strings.xml | 1 - OsmAnd/res/values-es-rAR/strings.xml | 1 - OsmAnd/res/values-eu/strings.xml | 1 - OsmAnd/res/values-fa/strings.xml | 1 - OsmAnd/res/values-fr/strings.xml | 1 - OsmAnd/res/values-gl/strings.xml | 1 - OsmAnd/res/values-hu/strings.xml | 1 - OsmAnd/res/values-is/strings.xml | 1 - OsmAnd/res/values-iw/strings.xml | 1 - OsmAnd/res/values-ka/strings.xml | 1 - OsmAnd/res/values-lt/strings.xml | 1 - OsmAnd/res/values-nl/strings.xml | 1 - OsmAnd/res/values-pl/strings.xml | 1 - OsmAnd/res/values-pt-rBR/strings.xml | 1 - OsmAnd/res/values-sc/strings.xml | 1 - OsmAnd/res/values-sk/strings.xml | 1 - OsmAnd/res/values-tr/strings.xml | 1 - OsmAnd/res/values-uk/strings.xml | 1 - OsmAnd/res/values-zh-rTW/strings.xml | 1 - OsmAnd/res/values/strings.xml | 16 +++++++++++++++- .../plus/onlinerouting/OnlineRoutingHelper.java | 2 +- .../onlinerouting/engine/GraphhopperEngine.java | 6 ++++-- .../engine/OnlineRoutingEngine.java | 14 ++++++-------- .../plus/onlinerouting/engine/OrsEngine.java | 2 ++ .../plus/onlinerouting/engine/OsrmEngine.java | 2 ++ .../plus/onlinerouting/ui/OnlineRoutingCard.java | 2 +- .../profiles/OnlineRoutingEngineDataObject.java | 8 ++++---- .../backup/OnlineRoutingSettingsItem.java | 2 +- 31 files changed, 36 insertions(+), 40 deletions(-) diff --git a/OsmAnd/res/values-ar/strings.xml b/OsmAnd/res/values-ar/strings.xml index bd3397afc2..4a9fde833f 100644 --- a/OsmAnd/res/values-ar/strings.xml +++ b/OsmAnd/res/values-ar/strings.xml @@ -4023,7 +4023,6 @@ قدم دراجة هوائية سيارة - خطأ، أعد التحقق من المعايير نسخ العنوان محرك التوجيه عبر الإنترنت محركات التوجيه عبر الإنترنت diff --git a/OsmAnd/res/values-cs/strings.xml b/OsmAnd/res/values-cs/strings.xml index 38af3fcceb..6d6b906b06 100644 --- a/OsmAnd/res/values-cs/strings.xml +++ b/OsmAnd/res/values-cs/strings.xml @@ -3960,7 +3960,6 @@ Chůze Kolo Auto - Chyba, zkontrolujte parametry Kopírovat adresu Online navigační služba Online navigační služby diff --git a/OsmAnd/res/values-de/strings.xml b/OsmAnd/res/values-de/strings.xml index e66df6bcd7..b216a47c7c 100644 --- a/OsmAnd/res/values-de/strings.xml +++ b/OsmAnd/res/values-de/strings.xml @@ -3962,7 +3962,6 @@ Zu Fuß Fahrrad Auto - Fehler, Parameter erneut prüfen Subtyp Leer lassen, wenn kein API-Schlüssel vorhanden Adresse kopieren diff --git a/OsmAnd/res/values-eo/strings.xml b/OsmAnd/res/values-eo/strings.xml index 391e96ba42..9671d14e5f 100644 --- a/OsmAnd/res/values-eo/strings.xml +++ b/OsmAnd/res/values-eo/strings.xml @@ -3960,7 +3960,6 @@ Piediranto Biciklo Aŭtomobilo - Eraro, rekontrolu parametrojn Kopii adreson Enreta navigilo Enretaj navigiloj diff --git a/OsmAnd/res/values-es-rAR/strings.xml b/OsmAnd/res/values-es-rAR/strings.xml index fd54cd500f..83700ce7cd 100644 --- a/OsmAnd/res/values-es-rAR/strings.xml +++ b/OsmAnd/res/values-es-rAR/strings.xml @@ -3963,7 +3963,6 @@ Peatón Bicicleta Automóvil - Error, vuelve a comprobar los parámetros Copiar dirección Motor de navegación en línea Motores de navegación en línea diff --git a/OsmAnd/res/values-eu/strings.xml b/OsmAnd/res/values-eu/strings.xml index ee2a825985..dced5cf049 100644 --- a/OsmAnd/res/values-eu/strings.xml +++ b/OsmAnd/res/values-eu/strings.xml @@ -3933,6 +3933,5 @@ Area honi dagokio: %1$s x %2$s Oinez Bizikleta Kotxea - Errorea, egiaztatu parametroak berriro Kopiatu helbidea \ No newline at end of file diff --git a/OsmAnd/res/values-fa/strings.xml b/OsmAnd/res/values-fa/strings.xml index 3cb0760eac..226a00cc5c 100644 --- a/OsmAnd/res/values-fa/strings.xml +++ b/OsmAnd/res/values-fa/strings.xml @@ -3953,5 +3953,4 @@ پا دوچرخه خودرو - خطا، پارامترها را بازبینی کنید \ No newline at end of file diff --git a/OsmAnd/res/values-fr/strings.xml b/OsmAnd/res/values-fr/strings.xml index 0b7dc82b1c..e5f41539c2 100644 --- a/OsmAnd/res/values-fr/strings.xml +++ b/OsmAnd/res/values-fr/strings.xml @@ -3947,7 +3947,6 @@ A pieds Vélo Automobile - Erreur, vérifiez les paramètres Ajouter un moteur de routage en ligne Modifier le moteur de routage en ligne L\'URL avec tous les paramètres sera de la forme : diff --git a/OsmAnd/res/values-gl/strings.xml b/OsmAnd/res/values-gl/strings.xml index 2e0c0053d3..5570577760 100644 --- a/OsmAnd/res/values-gl/strings.xml +++ b/OsmAnd/res/values-gl/strings.xml @@ -3968,7 +3968,6 @@ Lon %2$s Bicicleta Coche - Erro, verifica novamente os parámetros Copiar enderezo Horarios dos avisos por voz Motor de navegación en liña diff --git a/OsmAnd/res/values-hu/strings.xml b/OsmAnd/res/values-hu/strings.xml index d893dcf47e..64d40e287c 100644 --- a/OsmAnd/res/values-hu/strings.xml +++ b/OsmAnd/res/values-hu/strings.xml @@ -3954,7 +3954,6 @@ Hagyja üresen, ha nem Az összes paraméterrel rendelkező URL így néz ki: Útvonaltervezés kipróbálása - Hiba, ellenőrizze újra a paramétereket Cím másolása Online útvonaltervező Online útvonaltervezők diff --git a/OsmAnd/res/values-is/strings.xml b/OsmAnd/res/values-is/strings.xml index 3449458457..0b94e361f7 100644 --- a/OsmAnd/res/values-is/strings.xml +++ b/OsmAnd/res/values-is/strings.xml @@ -3965,6 +3965,5 @@ Gangandi Hjólandi Bíll - Villa, yfirfarðu breytur Afrita heimilisfang \ No newline at end of file diff --git a/OsmAnd/res/values-iw/strings.xml b/OsmAnd/res/values-iw/strings.xml index 44f2c8c034..7ca3bcdb8d 100644 --- a/OsmAnd/res/values-iw/strings.xml +++ b/OsmAnd/res/values-iw/strings.xml @@ -3963,7 +3963,6 @@ ברגל אופנוע מכונית - שגיאה, נא לבדוק את המשתנים מחדש העתקת כתובת מנוע ניווט מקוון מנועי ניווט מקוונים diff --git a/OsmAnd/res/values-ka/strings.xml b/OsmAnd/res/values-ka/strings.xml index 770916e3b3..330d43d2c4 100644 --- a/OsmAnd/res/values-ka/strings.xml +++ b/OsmAnd/res/values-ka/strings.xml @@ -2449,7 +2449,6 @@ OsmAndის გამოწერა დაპაუზებულია OsmAndის გამოწერა შეჩერებულია URL ყველა პარამეტრით აი ასეთი იქნება: - შეცდომა, გადაამოწმეთ პარამეტრები Mapillary-ის გამოსახულება Mapillary-ის ღილაკი ფერთა გამა diff --git a/OsmAnd/res/values-lt/strings.xml b/OsmAnd/res/values-lt/strings.xml index 65c711462f..09ee2a83fd 100644 --- a/OsmAnd/res/values-lt/strings.xml +++ b/OsmAnd/res/values-lt/strings.xml @@ -2770,7 +2770,6 @@ Tai yra puikus būdas paremti OsmAnd ir OSM, jei jie jums patinka. Patikrinti maršruto apskaičiavimą Dviratis Automobilis - Įvyko klaida, patikrinkite paametrus Kopijuoti adresą Folderiai Pasirinkite folderį diff --git a/OsmAnd/res/values-nl/strings.xml b/OsmAnd/res/values-nl/strings.xml index 04da6132ce..4420cd6987 100644 --- a/OsmAnd/res/values-nl/strings.xml +++ b/OsmAnd/res/values-nl/strings.xml @@ -3916,7 +3916,6 @@ Te voet Fiets Auto - Fout, controleer parameters opnieuw Kopieer adres Online routeplanningssysteem Online routeplanningssystemen diff --git a/OsmAnd/res/values-pl/strings.xml b/OsmAnd/res/values-pl/strings.xml index cf4852f488..840fa52189 100644 --- a/OsmAnd/res/values-pl/strings.xml +++ b/OsmAnd/res/values-pl/strings.xml @@ -3956,7 +3956,6 @@ Obliczanie trasy testowej Rower Samochód - Błąd, ponownie sprawdź parametry Skopiuj adres Jazda Stopa diff --git a/OsmAnd/res/values-pt-rBR/strings.xml b/OsmAnd/res/values-pt-rBR/strings.xml index da70b09ce8..52d578c035 100644 --- a/OsmAnd/res/values-pt-rBR/strings.xml +++ b/OsmAnd/res/values-pt-rBR/strings.xml @@ -3955,7 +3955,6 @@ Bicicleta Carro - Erro, verifique novamente os parâmetros Copiar endereço Motor de encaminhamento online Mecanismos de roteamento online diff --git a/OsmAnd/res/values-sc/strings.xml b/OsmAnd/res/values-sc/strings.xml index f5ff13cd8b..aa05e82d25 100644 --- a/OsmAnd/res/values-sc/strings.xml +++ b/OsmAnd/res/values-sc/strings.xml @@ -3957,7 +3957,6 @@ A pee Bitzicleta Màchina - Errore, torra a verificare sos paràmetros Còpia s\'indiritzu Motore de càrculu in lìnia Motores de càrculu in lìnia diff --git a/OsmAnd/res/values-sk/strings.xml b/OsmAnd/res/values-sk/strings.xml index 6d8fb45d93..81a9d73353 100644 --- a/OsmAnd/res/values-sk/strings.xml +++ b/OsmAnd/res/values-sk/strings.xml @@ -3955,7 +3955,6 @@ Chôdza Bicykel Auto - Chyba, skontrolujte parametre Kopírovať adresu Online navigačná služba Online navigačné služby diff --git a/OsmAnd/res/values-tr/strings.xml b/OsmAnd/res/values-tr/strings.xml index ee5e25124a..344183c102 100644 --- a/OsmAnd/res/values-tr/strings.xml +++ b/OsmAnd/res/values-tr/strings.xml @@ -3961,7 +3961,6 @@ Yürüme Bisiklet Araba - Hata, parametreleri tekrar gözden geçirin Adresi kopyala Çevrim içi yönlendirme motoru Çevrim içi yönlendirme motorları diff --git a/OsmAnd/res/values-uk/strings.xml b/OsmAnd/res/values-uk/strings.xml index 2738eda283..6910c9a902 100644 --- a/OsmAnd/res/values-uk/strings.xml +++ b/OsmAnd/res/values-uk/strings.xml @@ -3959,7 +3959,6 @@ Пішки Велосипед Автомобіль - Помилка, повторно перевірте параметри Копіювати адресу Мережний рушій маршрутизації Мережні рушії маршрутизації diff --git a/OsmAnd/res/values-zh-rTW/strings.xml b/OsmAnd/res/values-zh-rTW/strings.xml index 738ede85e2..0f19668c01 100644 --- a/OsmAnd/res/values-zh-rTW/strings.xml +++ b/OsmAnd/res/values-zh-rTW/strings.xml @@ -3953,7 +3953,6 @@ 步行 自行車 汽車 - 錯誤,重新檢查參數 複製地址 線上路線計算引擎 線上路線計算引擎 diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index bbb71f001a..c755dd11dc 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,6 +12,21 @@ --> + The name is already exists + Server error: %1$s + MTB + Racing bike + Scooter + Truck + Small truck + HGV + Regular cycling + Road cycling + Mountain cycling + Electric cycling + Walking + Hiking + Wheelchair Announcement time Announcement time of different voice prompts depends on prompt type, current navigation speed and default navigation speed. Time and distance intervals @@ -35,7 +50,6 @@ Online routing engines Online routing engine Copy address - Error, recheck parameters Car Bike Foot diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingHelper.java b/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingHelper.java index bf4f41a096..b28d98d55f 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/OnlineRoutingHelper.java @@ -156,7 +156,7 @@ public class OnlineRoutingHelper { try { JSONObject json = new JSONObject(jsonString); readFromJson(json, engines); - } catch (JSONException e) { + } catch (JSONException | IllegalArgumentException e) { LOG.debug("Error when reading engines from JSON ", e); } } diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/engine/GraphhopperEngine.java b/OsmAnd/src/net/osmand/plus/onlinerouting/engine/GraphhopperEngine.java index c7a31fb10c..d676e1e154 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/engine/GraphhopperEngine.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/engine/GraphhopperEngine.java @@ -15,6 +15,8 @@ import org.json.JSONObject; import java.util.List; import java.util.Map; +import static net.osmand.util.Algorithms.isEmpty; + public class GraphhopperEngine extends OnlineRoutingEngine { public GraphhopperEngine(@Nullable Map params) { @@ -62,11 +64,11 @@ public class GraphhopperEngine extends OnlineRoutingEngine { .append('&'); } String vehicle = get(EngineParameter.VEHICLE_KEY); - if (vehicle != null) { + if (isEmpty(vehicle)) { sb.append("vehicle=").append(vehicle); } String apiKey = get(EngineParameter.API_KEY); - if (apiKey != null) { + if (isEmpty(apiKey)) { sb.append('&').append("key=").append(apiKey); } } diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/engine/OnlineRoutingEngine.java b/OsmAnd/src/net/osmand/plus/onlinerouting/engine/OnlineRoutingEngine.java index 9072c7ada0..276837c347 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/engine/OnlineRoutingEngine.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/engine/OnlineRoutingEngine.java @@ -23,6 +23,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static net.osmand.util.Algorithms.isEmpty; + public abstract class OnlineRoutingEngine implements Cloneable { public final static String ONLINE_ROUTING_ENGINE_PREFIX = "online_routing_engine_"; @@ -33,7 +35,7 @@ public abstract class OnlineRoutingEngine implements Cloneable { private final Set allowedParameters = new HashSet<>(); public OnlineRoutingEngine(@Nullable Map params) { - if (!Algorithms.isEmpty(params)) { + if (!isEmpty(params)) { this.params.putAll(params); } collectAllowedVehiclesInternal(); @@ -62,13 +64,13 @@ public abstract class OnlineRoutingEngine implements Cloneable { private String getStandardName(@NonNull Context ctx) { String base = getBaseName(ctx); String index = get(EngineParameter.NAME_INDEX); - return !Algorithms.isEmpty(index) ? base + " " + index : base; + return !isEmpty(index) ? base + " " + index : base; } @NonNull public String getBaseName(@NonNull Context ctx) { String vehicleTitle = getSelectedVehicleName(ctx); - if (Algorithms.isEmpty(vehicleTitle)) { + if (isEmpty(vehicleTitle)) { return getType().getTitle(); } else { String pattern = ctx.getString(R.string.ltr_or_rtl_combine_via_dash); @@ -79,7 +81,7 @@ public abstract class OnlineRoutingEngine implements Cloneable { @NonNull public String getBaseUrl() { String customUrl = get(EngineParameter.CUSTOM_URL); - if (Algorithms.isEmpty(customUrl)) { + if (isEmpty(customUrl)) { return getStandardUrl(); } return customUrl; @@ -186,10 +188,6 @@ public abstract class OnlineRoutingEngine implements Cloneable { return OnlineRoutingFactory.createEngine(getType(), getParams()); } - protected boolean isEmpty(@Nullable String s) { - return Algorithms.isEmpty(s); - } - @NonNull public static String generateKey() { return ONLINE_ROUTING_ENGINE_PREFIX + System.currentTimeMillis(); diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/engine/OrsEngine.java b/OsmAnd/src/net/osmand/plus/onlinerouting/engine/OrsEngine.java index 507ecd3af0..594e7e1b36 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/engine/OrsEngine.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/engine/OrsEngine.java @@ -16,6 +16,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import static net.osmand.util.Algorithms.isEmpty; + public class OrsEngine extends OnlineRoutingEngine { public OrsEngine(@Nullable Map params) { diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/engine/OsrmEngine.java b/OsmAnd/src/net/osmand/plus/onlinerouting/engine/OsrmEngine.java index d88ae42ff7..1ef9c1a622 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/engine/OsrmEngine.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/engine/OsrmEngine.java @@ -15,6 +15,8 @@ import org.json.JSONObject; import java.util.List; import java.util.Map; +import static net.osmand.util.Algorithms.isEmpty; + public class OsrmEngine extends OnlineRoutingEngine { public OsrmEngine(@Nullable Map params) { diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java index 7a1f4c6b4b..fa6e2b6b74 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java @@ -156,7 +156,7 @@ public class OnlineRoutingCard extends BaseCard { public void hideFieldBoxError() { hideElements(tvErrorText); if (fieldBoxHelperTextShowed) { - showElements(tvErrorText); + showElements(tvHelperText); } } diff --git a/OsmAnd/src/net/osmand/plus/profiles/OnlineRoutingEngineDataObject.java b/OsmAnd/src/net/osmand/plus/profiles/OnlineRoutingEngineDataObject.java index 86b79ed910..fd0f593462 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/OnlineRoutingEngineDataObject.java +++ b/OsmAnd/src/net/osmand/plus/profiles/OnlineRoutingEngineDataObject.java @@ -17,10 +17,10 @@ public class OnlineRoutingEngineDataObject extends ProfileDataObject { } @Override - public int compareTo(@NonNull ProfileDataObject another) { - if (another instanceof OnlineRoutingEngineDataObject) { - OnlineRoutingEngineDataObject anotherEngine = (OnlineRoutingEngineDataObject) another; - return Integer.compare(this.order, anotherEngine.order); + public int compareTo(@NonNull ProfileDataObject profileDataObject) { + if (profileDataObject instanceof OnlineRoutingEngineDataObject) { + OnlineRoutingEngineDataObject another = (OnlineRoutingEngineDataObject) profileDataObject; + return (this.order < another.order) ? -1 : ((this.order == another.order) ? 0 : 1); } return 0; } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OnlineRoutingSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OnlineRoutingSettingsItem.java index fc71e8d183..cf08142393 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OnlineRoutingSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OnlineRoutingSettingsItem.java @@ -106,7 +106,7 @@ public class OnlineRoutingSettingsItem extends CollectionSettingsItem