diff --git a/src/mahomaps/api/YmapsApi.java b/src/mahomaps/api/YmapsApi.java index f7b282c..dd2c54e 100644 --- a/src/mahomaps/api/YmapsApi.java +++ b/src/mahomaps/api/YmapsApi.java @@ -53,17 +53,17 @@ private final String GetRouteUrl(Geopoint a, Geopoint b, int type) { public final JSONArray Search(String text, Geopoint around, double zone) throws JSONException, IOException, Http403Exception { - JSONArray j = (JSON.getObject(GetUtf(GetSearchUrl(text, around, zone)))).getArray("features"); - return j; + JSONObject j = JSON.getObject(GetUtf(GetSearchUrl(text, around, zone))); + if (!j.has("features")) throw new Http403Exception(); + return j.getArray("features"); } - public final JSONObject Route(Geopoint a, Geopoint b, int type) + public final JSONArray Routes(Geopoint a, Geopoint b, int type) throws JSONException, IOException, Http403Exception { JSONArray j = (JSON.getObject(GetUtf(GetRouteUrl(a, b, type)))).getArray("features"); if (j.size() == 0) throw new ConnectionNotFoundException(); - JSONObject j1 = j.getObject(0).getArray("features").getObject(0); - return j1; + return j.getObject(0).getArray("features"); } public static final int ROUTE_BYFOOT = 1; diff --git a/src/mahomaps/overlays/RouteOverlay.java b/src/mahomaps/overlays/RouteOverlay.java index dfef72b..31c1d0a 100644 --- a/src/mahomaps/overlays/RouteOverlay.java +++ b/src/mahomaps/overlays/RouteOverlay.java @@ -35,6 +35,7 @@ public class RouteOverlay extends MapOverlay implements Runnable, IButtonHandler private Geopoint b; private final int method; Route route; + private int tries; private boolean anchorsShown = false; @@ -62,12 +63,20 @@ public boolean OnPointTap(Geopoint p) { public void run() { try { - route = new Route(MahoMapsApp.api.Route(a, b, method)); + if (tries != 0) { + MahoMapsApp.api.RefreshToken(); + } + // TODO route variant selection + route = new Route(MahoMapsApp.api.Routes(a, b, method).getObject(0)); LoadRoute(); } catch (IOException e) { content = new FillFlowContainer(new UIElement[] { new SimpleText(MahoMapsApp.text[111]), new Button(MahoMapsApp.text[37], 2, this), new Button(MahoMapsApp.text[38], 0, this) }); } catch (Http403Exception e) { + if (tries++ == 0) { + run(); + return; + } content = new FillFlowContainer( new UIElement[] { new SimpleText(MahoMapsApp.text[135]), new SimpleText(MahoMapsApp.text[136]), new Button(MahoMapsApp.text[37], 2, this), new Button(MahoMapsApp.text[38], 0, this) }); diff --git a/src/mahomaps/screens/SearchLoader.java b/src/mahomaps/screens/SearchLoader.java index 02ce6ae..d2822cb 100644 --- a/src/mahomaps/screens/SearchLoader.java +++ b/src/mahomaps/screens/SearchLoader.java @@ -20,6 +20,7 @@ public class SearchLoader extends Form implements Runnable, CommandListener { private Thread th; public final String query; public final Geopoint point; + private int tries; public SearchLoader(String query, Geopoint point) { super(query); @@ -33,6 +34,9 @@ public SearchLoader(String query, Geopoint point) { public void run() { append(new Gauge(MahoMapsApp.text[14], false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING)); try { + if (tries != 0) { + MahoMapsApp.api.RefreshToken(); + } JSONArray arr = MahoMapsApp.api.Search(query, point, 0.1d); MahoMapsApp.BringSubScreen(new SearchScreen(query, point, arr)); } catch (IOException e) { @@ -42,6 +46,10 @@ public void run() { e.printStackTrace(); } catch (Http403Exception e) { deleteAll(); + if (tries++ == 0) { + run(); + return; + } append(new StringItem(MahoMapsApp.text[135], MahoMapsApp.text[136])); } catch (Exception e) { deleteAll();