Skip to content

Commit

Permalink
Merge pull request #52 from mahomaps/tiles-lang
Browse files Browse the repository at this point in the history
Tiles & search lang
  • Loading branch information
Feodor0090 authored May 28, 2023
2 parents 744363b + 5197e49 commit 607c612
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
11 changes: 10 additions & 1 deletion src/mahomaps/MahoMapsApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@ public void run() {
// just in case
}
Settings.Read(); // catch(Throwable) inside
tiles = new TilesProvider("ru_RU"); // nothing to fail
try {
tiles = new TilesProvider(Settings.GetLangString()); // wrong lang in settings
} catch (RuntimeException e) {
Form f = new Form("Ошибка", new Item[] { new StringItem("Настройки повреждены", "Переустановите приложение.") });
f.addCommand(exit);
f.setCommandListener(this);
BringSubScreen(f);
thread = null;
return;
}
if (!TryInitFSCache(true)) { // catch(Throwable) inside
thread = null;
return;
Expand Down
16 changes: 16 additions & 0 deletions src/mahomaps/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private Settings() {
public static boolean proxyTiles = false;
public static boolean proxyApi = false;
public static int uiSize = 0;
public static int lang = 0;

public static String proxyServer = "http://nnp.nnchan.ru:80/mahoproxy.php?u=";

Expand Down Expand Up @@ -52,6 +53,7 @@ public static boolean Read() {
proxyTiles = j.optBoolean("proxy_tiles");
proxyApi = j.optBoolean("proxy_api");
uiSize = j.optInt("ui_size", 0);
lang = j.optInt("lang", 0);
return true;
} catch (Throwable e) {
e.printStackTrace();
Expand Down Expand Up @@ -82,6 +84,7 @@ public static String Serialize() {
j.put("proxy_tiles", proxyTiles);
j.put("proxy_api", proxyApi);
j.put("ui_size", uiSize);
j.put("lang", lang);
return j.toString();
}

Expand All @@ -99,4 +102,17 @@ public static void Save() {
e.printStackTrace();
}
}

public static String GetLangString() {
switch (lang) {
case 0:
return new String(new char[] {'r','u','_','R','U'});
case 1:
return new String(new char[] {'e','n','_','U','S'});
case 2:
return new String(new char[] {'t','r','_','T','R'});
default:
throw new IndexOutOfBoundsException("Unknown language code!");
}
}
}
12 changes: 8 additions & 4 deletions src/mahomaps/api/YmapsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.json.me.JSONException;
import org.json.me.JSONObject;

import mahomaps.Settings;
import mahomaps.map.Geopoint;

public final class YmapsApi extends YmapsApiBase {
Expand All @@ -27,8 +28,8 @@ public final synchronized void RefreshToken() throws Exception {

private final String GetSearchUrl(String text, Geopoint around, double zone) {
String[] cs = around.GetRounded();
return "https://api-maps.yandex.ru/services/search/v2/?format=json&lang=ru_RU&token=" + token
+ "&rspn=0&results=40&origin=jsapi2SearchControl"
return "https://api-maps.yandex.ru/services/search/v2/?format=json&lang=" + Settings.GetLangString() + "&token="
+ token + "&rspn=0&results=40&origin=jsapi2SearchControl"
+ "&snippets=businessrating%2F1.x%2Cmasstransit%2F1.x&ask_direct=1&experimental_maxadv=200&apikey="
+ key + "&text=" + EncodeUrl(text) + "&ll=" + cs[1] + "%2C" + cs[0] + "&spn=" + zone + "%2C" + zone;
}
Expand All @@ -47,8 +48,11 @@ private final String GetRouteUrl(Geopoint a, Geopoint b, int type) {
default:
throw new IllegalArgumentException();
}
return "https://api-maps.yandex.ru/services/route/2.0/?lang=ru_RU&token=" + token + "&rll=" + a.lon + "%2C"
+ a.lat + "~" + b.lon + "%2C" + b.lat + "&rtm=dtr&results=1&apikey=" + key + typeS;
String baseUrl = "https://api-maps.yandex.ru/services/route/2.0/?lang=";
String lang = new String(new char[] { baseUrl.charAt(29), baseUrl.charAt(38), '_',
Character.toUpperCase(baseUrl.charAt(29)), 'U' });
return baseUrl + lang + "&token=" + token + "&rll=" + a.lon + "%2C" + a.lat + "~" + b.lon + "%2C" + b.lat
+ "&rtm=dtr&results=1&apikey=" + key + typeS;
}

public final JSONArray Search(String text, Geopoint around, double zone)
Expand Down
8 changes: 4 additions & 4 deletions src/mahomaps/map/TilesProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private Image tryLoadFromFS(TileId id) {
* @param id Тайл для поиска.
* @return Изображение, если тайл сохранён, иначе null.
*/
private static Image tryLoadFromRMS(TileId id) {
private Image tryLoadFromRMS(TileId id) {
byte[] b = null;
try {
RecordStore r = RecordStore.openRecordStore(getRmsName(id), true);
Expand Down Expand Up @@ -563,11 +563,11 @@ private String getUrl(TileId tileId) {
}

private String getFileName(TileId id) {
return localPath + "tile_" + id.x + "_" + id.y + "_" + id.zoom;
return localPath + "tile_" + lang + "_" + id.x + "_" + id.y + "_" + id.zoom;
}

private static String getRmsName(TileId id) {
return "tile_" + id.x + "_" + id.y + "_" + id.zoom;
private String getRmsName(TileId id) {
return "tile_" + lang + "_" + id.x + "_" + id.y + "_" + id.zoom;
}

}
5 changes: 5 additions & 0 deletions src/mahomaps/screens/SettingsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class SettingsScreen extends Form implements CommandListener {
new String[] { "Отключено", "nnchan.ru", }, null);
private ChoiceGroup uiSize = new ChoiceGroup("Размер кнопок управления (нужен перезапуск)", Choice.POPUP,
new String[] { "Автоматически", "50x50", "30x30" }, null);
private ChoiceGroup lang = new ChoiceGroup("Язык тайлов и поиска (нужен перезапуск)", Choice.POPUP,
new String[] { "Русский", "Английский", "Турецкий" }, null);

public SettingsScreen() {
super("Настройки");
Expand Down Expand Up @@ -68,6 +70,7 @@ public SettingsScreen() {
// апи отслеживается отдельно, однако предполагается что оно включено вместе с
// тайлами.
uiSize.setSelectedIndex(Settings.uiSize, true);
lang.setSelectedIndex(Settings.lang, true);

append(focusZoom);
append(geoLook);
Expand All @@ -77,6 +80,7 @@ public SettingsScreen() {
append(download);
append(proxyTiles);
append(uiSize);
append(lang);
}

private void Apply() {
Expand All @@ -89,6 +93,7 @@ private void Apply() {
Settings.proxyTiles = proxyTiles.getSelectedIndex() == 1;
Settings.proxyApi = proxyTiles.getSelectedIndex() == 1;
Settings.uiSize = uiSize.getSelectedIndex();
Settings.lang = lang.getSelectedIndex();
if (Settings.allowDownload) {
MahoMapsApp.tiles.ForceMissingDownload();
}
Expand Down

0 comments on commit 607c612

Please sign in to comment.