This commit is contained in:
GaidamakUA 2015-10-06 09:43:17 +03:00
commit 0476996ccf
16 changed files with 477 additions and 212 deletions

View file

@ -136,4 +136,10 @@
- Praha: «Prag Metro Logo» (wikinight2) - Eigenes Werk (own work), created with inkscape, based on PDF http://www.zdanice.cz/clanky/letak_Haje_.pdf. Licensed under Public Domain via Commons from site - https://commons.wikimedia.org/wiki/File:Prag_Metro_Logo.svg#/media/File:Prag_Metro_Logo.svg - Praha: «Prag Metro Logo» (wikinight2) - Eigenes Werk (own work), created with inkscape, based on PDF http://www.zdanice.cz/clanky/letak_Haje_.pdf. Licensed under Public Domain via Commons from site - https://commons.wikimedia.org/wiki/File:Prag_Metro_Logo.svg#/media/File:Prag_Metro_Logo.svg
- Tehran: "Tehran Metro Logo" by Tehran Urban and Suburban Railway Organization - http://metro.tehran.ir/. Licensed under Public Domain via Wikipedia - https://en.wikipedia.org/wiki/File:Tehran_Metro_Logo.svg#/media/File:Tehran_Metro_Logo.svg - Tehran: "Tehran Metro Logo" by Tehran Urban and Suburban Railway Organization - http://metro.tehran.ir/. Licensed under Public Domain via Wikipedia - https://en.wikipedia.org/wiki/File:Tehran_Metro_Logo.svg#/media/File:Tehran_Metro_Logo.svg
- Athens: "Logo of the Athens Metro Operating Company (AMEL)" by Marianian - Own work, based on personal observations of publicity and signage.. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Logo_of_the_Athens_Metro_Operating_Company_(AMEL).svg#/media/File:Logo_of_the_Athens_Metro_Operating_Company_(AMEL).svg - Athens: "Logo of the Athens Metro Operating Company (AMEL)" by Marianian - Own work, based on personal observations of publicity and signage.. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Logo_of_the_Athens_Metro_Operating_Company_(AMEL).svg#/media/File:Logo_of_the_Athens_Metro_Operating_Company_(AMEL).svg
- Nagoya: "Nagoya Municipal Subway Logo" by ASDFGHJ - 名古屋市交通局. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Nagoya_Municipal_Subway_Logo.svg#/media/File:Nagoya_Municipal_Subway_Logo.svg - Nagoya: "Nagoya Municipal Subway Logo" by ASDFGHJ - 名古屋市交通局. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Nagoya_Municipal_Subway_Logo.svg#/media/File:Nagoya_Municipal_Subway_Logo.svg
- Catania: "Logo metropolitana di Catania" by Friedrichstrasse - Own work. Licensed under CC BY-SA 3.0 via Commons - https://commons.wikimedia.org/wiki/File:Logo_metropolitana_di_Catania.svg#/media/File:Logo_metropolitana_di_Catania.svg
- Manila: "Lrtalogo" by Cda stitch - Own work. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Lrtalogo.svg#/media/File:Lrtalogo.svg
- Rio de Janeiro: "Metrorioicon" by Metrô Rio - http://www.metrorio.com.br/. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Metrorioicon.png#/media/File:Metrorioicon.png
- Montreal: "Montreal Metro" by STM - http://www.stm.info/en-bref/pictometro.htm. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:Montreal_Metro.svg#/media/File:Montreal_Metro.svg
- Toronto: "TTC" by Source. Licensed under Fair use via Wikipedia - https://en.wikipedia.org/wiki/File:TTC.svg#/media/File:TTC.svg
- Bangkok: "MRT (Bangkok) logo" by Bangkok_Metro_logo.png: Paul_012.Original uploader was Paul 012 at en.wikipediaderivative work: Nevetsjc (talk)Revision traced from http://si0.twimg.com/profile_images/975897559/logo.jpg - Bangkok_Metro_logo.png. Licensed under Public Domain via Commons - https://commons.wikimedia.org/wiki/File:MRT_(Bangkok)_logo.svg#/media/File:MRT_(Bangkok)_logo.svg

View file

@ -66,9 +66,9 @@ public class BinaryInspector {
// test cases show info // test cases show info
if(args.length == 1 && "test".equals(args[0])) { if(args.length == 1 && "test".equals(args[0])) {
in.inspector(new String[]{ in.inspector(new String[]{
"-vpoi", // "-vpoi",
// "-vmap", "-vmapobjects", // "-vmapcoordinates", // "-vmap", "-vmapobjects", // "-vmapcoordinates",
// "-vrouting", "-vrouting",
// "-vaddress", "-vcities",//"-vstreetgroups", // "-vaddress", "-vcities",//"-vstreetgroups",
// "-vstreets", "-vbuildings", "-vintersections", // "-vstreets", "-vbuildings", "-vintersections",
// "-zoom=15", // "-zoom=15",
@ -535,16 +535,15 @@ public class BinaryInspector {
b.setLength(0); b.setLength(0);
b.append("Road "); b.append("Road ");
b.append(obj.id); b.append(obj.id);
for(int i = 0; i < obj.getTypes().length; i++) { for (int i = 0; i < obj.getTypes().length; i++) {
RouteTypeRule rr = obj.region.quickGetEncodingRule(obj.getTypes()[i]); RouteTypeRule rr = obj.region.quickGetEncodingRule(obj.getTypes()[i]);
b.append(" ").append(rr.getTag()).append("='").append(rr.getValue()).append("'"); b.append(" ").append(rr.getTag()).append("='").append(rr.getValue()).append("'");
} }
if (obj.getNames() != null) { int[] nameIds = obj.getNameIds();
TIntObjectIterator<String> it = obj.getNames().iterator(); if (nameIds != null) {
while (it.hasNext()) { for (int key : nameIds) {
it.advance(); RouteTypeRule rr = obj.region.quickGetEncodingRule(key);
RouteTypeRule rr = obj.region.quickGetEncodingRule(it.key()); b.append(" ").append(rr.getTag()).append("='").append(obj.getNames().get(key)).append("'");
b.append(" ").append(rr.getTag()).append("='").append(it.value()).append("'");
} }
} }
println(b.toString()); println(b.toString());

View file

@ -451,11 +451,14 @@ public class BinaryMapRouteReaderAdapter {
o.names = new TIntObjectHashMap<String>(); o.names = new TIntObjectHashMap<String>();
int sizeL = codedIS.readRawVarint32(); int sizeL = codedIS.readRawVarint32();
int old = codedIS.pushLimit(sizeL); int old = codedIS.pushLimit(sizeL);
TIntArrayList list = new TIntArrayList();
while (codedIS.getBytesUntilLimit() > 0) { while (codedIS.getBytesUntilLimit() > 0) {
int stag = codedIS.readRawVarint32(); int stag = codedIS.readRawVarint32();
int pId = codedIS.readRawVarint32(); int pId = codedIS.readRawVarint32();
o.names.put(stag, ((char)pId)+""); o.names.put(stag, ((char)pId)+"");
list.add(stag);
} }
o.nameIds = list.toArray();
codedIS.popLimit(old); codedIS.popLimit(old);
break; break;
case RouteData.POINTS_FIELD_NUMBER: case RouteData.POINTS_FIELD_NUMBER:

View file

@ -26,6 +26,7 @@ public class RouteDataObject {
public long id; public long id;
public TIntObjectHashMap<String> names; public TIntObjectHashMap<String> names;
public final static float NONE_MAX_SPEED = 40f; public final static float NONE_MAX_SPEED = 40f;
public int[] nameIds;
public RouteDataObject(RouteRegion region) { public RouteDataObject(RouteRegion region) {
this.region = region; this.region = region;
@ -33,6 +34,7 @@ public class RouteDataObject {
public RouteDataObject(RouteRegion region, int[] nameIds, String[] nameValues) { public RouteDataObject(RouteRegion region, int[] nameIds, String[] nameValues) {
this.region = region; this.region = region;
this.nameIds = nameIds;
if (nameIds.length > 0) { if (nameIds.length > 0) {
names = new TIntObjectHashMap<String>(); names = new TIntObjectHashMap<String>();
} }
@ -86,6 +88,10 @@ public class RouteDataObject {
return null; return null;
} }
public int[] getNameIds() {
return nameIds;
}
public TIntObjectHashMap<String> getNames() { public TIntObjectHashMap<String> getNames() {
return names; return names;
} }

View file

@ -219,6 +219,13 @@ public class Algorithms {
public static int parseColor(String colorString) { public static int parseColor(String colorString) {
if (colorString.charAt(0) == '#') { if (colorString.charAt(0) == '#') {
// Use a long to avoid rollovers on #ffXXXXXX // Use a long to avoid rollovers on #ffXXXXXX
if (colorString.length() == 4) {
colorString = "#" +
colorString.charAt(1) + colorString.charAt(1) +
colorString.charAt(2) + colorString.charAt(2) +
colorString.charAt(3) + colorString.charAt(3);
}
long color = Long.parseLong(colorString.substring(1), 16); long color = Long.parseLong(colorString.substring(1), 16);
if (colorString.length() == 7) { if (colorString.length() == 7) {
// Set the alpha value // Set the alpha value

View file

@ -1233,4 +1233,122 @@
<string name="poi_trees_oil">Пальмавы алей</string> <string name="poi_trees_oil">Пальмавы алей</string>
<string name="poi_trees_orange">Апельсін</string> <string name="poi_trees_orange">Апельсін</string>
<string name="poi_trees_banana">Банан</string> <string name="poi_trees_banana">Банан</string>
<string name="poi_aerialway_bubble_no">Няма шкленьня</string>
<string name="poi_aerialway_heating_yes">Абаграваньне</string>
<string name="poi_aerialway_heating_no">Без абаграваньня</string>
<string name="poi_aerialway_bicycle_yes">Правоз ровараў дазволены</string>
<string name="poi_aerialway_bicycle_no">Правоз ровараў забаронены</string>
<string name="poi_aerialway_bicycle_summer">Правоз ровараў дазволены толькі летам</string>
<string name="poi_aerialway_access_entry">Толькі ўваход</string>
<string name="poi_aerialway_access_exit">Толькі выхад</string>
<string name="poi_aerialway_access_both">Уваход і выхад</string>
<string name="poi_aerialway_summer_access_entry">Доступ летам: толькі ўваход</string>
<string name="poi_aerialway_summer_access_exit">Доступ летам: толькі выхад</string>
<string name="poi_aerialway_summer_access_both">Доступ летам: уваход і выхад</string>
<string name="poi_stars_1">Колькасьць зорак: 1 (турысцкі клас)</string>
<string name="poi_stars_1s">Колькасьць зорак: 1S (палепшаны турысцкі клас)</string>
<string name="poi_stars_2">Колькасьць зорак: 2 (стандартны кляс)</string>
<string name="poi_stars_2s">Колькасьць зорак: 2S (палепшаны стандартны кляс)</string>
<string name="poi_stars_3">Колькасьць зорак: 3 (камфортны кляс)</string>
<string name="poi_stars_3s">Колькасьць зорак: 3S (палепшаны камфортны кляс)</string>
<string name="poi_stars_4">Колькасьць зорак: 4 (першы кляс)</string>
<string name="poi_stars_4s">Колькасьць зорак: 4S (палепшаны першы кляс)</string>
<string name="poi_stars_5">Колькасьць зорак: 5 (катэгорыя люкс)</string>
<string name="poi_stars_5s">Колькасьць зорак: 5S (катэгорыя люкс +)</string>
<string name="poi_stars_6">Колькасьць зорак: 6</string>
<string name="poi_stars_7">Колькасьць зорак: 7</string>
<string name="poi_rooms">Колькасць нумароў</string>
<string name="poi_love_hotel">Love-гатэль</string>
<string name="poi_takeaway_no">На вынас: не</string>
<string name="poi_takeaway_only">Толькі на вынас</string>
<string name="poi_delivery_yes">З дастаўкай</string>
<string name="poi_delivery_no">Без дастаўкі</string>
<string name="poi_delivery_only">Толькі з дастаўкай</string>
<string name="poi_outdoor_seating_yes">Месцы на адкрытым паветры</string>
<string name="poi_outdoor_seating_no">Няма месцаў на адкрытым паветры</string>
<string name="poi_outdoor_seating_terrace">Месцы на адкрытым паветры: тэраса</string>
<string name="poi_outdoor_seating_sidewalk">Месцы на адкрытым паветры: тратуар</string>
<string name="poi_outdoor_seating_pedestrian_zone">Месцы на адкрытым паветры: пешаходная зона</string>
<string name="poi_outdoor_seating_garden">Месцы на адкрытым паветры: сад</string>
<string name="poi_outdoor_seating_patio">Месцы на адкрытым паветры: паціа</string>
<string name="poi_cocktails_yes">Кактэйлі</string>
<string name="poi_second_hand_yes">Ужываны тавар</string>
<string name="poi_second_hand_no">Ужываны тавар адсутнічае</string>
<string name="poi_second_hand_only">Толькі ўжываны тавар</string>
<string name="poi_service_parts">Запчасткі</string>
<string name="poi_service_dealer">Дылер</string>
<string name="poi_service_repair">Рамонт</string>
<string name="poi_service_repair_no">Рамонт не ажыцьцяўляецца</string>
<string name="poi_service_electrical">Рамонт электратранспарту</string>
<string name="poi_motorcycle_repair">Рамонт матацыклаў</string>
<string name="poi_self_service_yes">Самаабслугоўваньне</string>
<string name="poi_self_service_no">Самаабслугоўваньне: няма</string>
<string name="poi_automated_yes">Аўтаматызацыя</string>
<string name="poi_automated_no">Без аўтаматызацыі</string>
<string name="poi_full_service_yes">Поўны комплекс паслуг</string>
<string name="poi_brushless_yes">Безкантактная</string>
<string name="poi_brushless_no">Кантактная</string>
<string name="poi_car_wash_no">Без аўтамыйні</string>
<string name="poi_aeroway_fuel">Заправачная станцыя для паветранага транспарту</string>
<string name="poi_public_bath">Грамадзкая лазьня</string>
<string name="poi_male_yes">Для мужчын</string>
<string name="poi_male_no">Не для мужчын</string>
<string name="poi_female_yes">Для жанчын</string>
<string name="poi_female_no">Не для жанчын</string>
<string name="poi_indoor_yes">Унутры памяшканьня</string>
<string name="poi_indoor_no">Знадворку</string>
<string name="poi_toilets_yes">З прыбіральняй</string>
<string name="poi_toilets_no">Без прыбіральні</string>
<string name="poi_toilets_wheelchair_yes">Доступ у прыбіральню для інвалідных вазкоў: так</string>
<string name="poi_toilets_wheelchair_no">Доступ у прыбіральню для інвалідных вазкоў: не</string>
<string name="poi_toilets_access_customers">Доступ у прыбіральню: толькі для наведвальнікаў</string>
<string name="poi_toilets_access_permissive">Доступ у прыбіральню: з дазволу ўладальніка</string>
<string name="poi_toilets_access_public">Доступ у прыбіральню: агульны</string>
<string name="poi_maxstay">Максімальны час стаянкі</string>
<string name="poi_vending_parking_tickets">Парковачныя талоны</string>
<string name="poi_vending_cigarettes">Цыгарэты</string>
<string name="poi_vending_excrement_bags">Пакеты для экскрыментаў жывёл</string>
<string name="poi_vending_public_transport_tickets">Квіткі на грамадзкі транспарт</string>
<string name="poi_vending_drinks">Продаж напояў</string>
<string name="poi_vending_sweets">Саладосьці</string>
<string name="poi_vending_parcel_pickup_mail_in">Атрыманьне і адпраўленьне пасылак</string>
<string name="poi_vending_condoms">Прэзэрватывы</string>
<string name="poi_vending_stamps">Маркі</string>
<string name="poi_vending_bicycle_tube">Веласіпедныя камэры</string>
<string name="poi_vending_food">Харчаваньне</string>
<string name="poi_vending_drinks_food">Напоі і закускі</string>
<string name="poi_vending_fuel">Паліва</string>
<string name="poi_vending_parcel_pickup">Атрыманьне пасылак</string>
<string name="poi_memorial_plaque">Дошка</string>
<string name="poi_memorial_statue">Статуя</string>
<string name="poi_memorial_stone">Камень</string>
<string name="poi_memorial_stele">Стэла</string>
<string name="poi_memorial_bust">Бюст</string>
<string name="poi_memorial_blue_plaque">Сіняя шыльда</string>
<string name="poi_memorial_cross">Крыж</string>
<string name="poi_memorial_obelisk">Абеліск</string>
<string name="poi_inscription">Надпіс</string>
<string name="poi_trees_almond">Міндаль</string>
<string name="poi_trees_hazel">Лясны арэх</string>
<string name="poi_trees_coconut">Какос</string>
<string name="poi_trees_persimmon">Хурма</string>
<string name="poi_trees_cherry">Вішня</string>
<string name="poi_trees_walnut">Грэцкі арэх</string>
<string name="poi_trees_plum">Сліва</string>
<string name="poi_trees_meadow_orchard">Пладовы сад</string>
<string name="poi_trees_date">Фінікі</string>
</resources> </resources>

View file

@ -1545,4 +1545,59 @@
<string name="poi_inscription">Надпись</string> <string name="poi_inscription">Надпись</string>
<string name="poi_historic_quarry">Исторический карьер</string>
<string name="poi_resource_aggregate">Заполнители бетона</string>
<string name="poi_resource_antimony">Сурьма</string>
<string name="poi_resource_asbestos">Асбест</string>
<string name="poi_resource_barite">Барит</string>
<string name="poi_resource_basalt">Базальт</string>
<string name="poi_resource_bauxite">Бокситы</string>
<string name="poi_resource_beryl">Берил</string>
<string name="poi_resource_bismuth">Висмут</string>
<string name="poi_resource_cereal">Зерновые культуры</string>
<string name="poi_resource_chromite">Хромиты, хромовая руда</string>
<string name="poi_resource_clay">Глина</string>
<string name="poi_resource_coal">Уголь</string>
<string name="poi_resource_copper">Медь</string>
<string name="poi_resource_diamond">Алмазы</string>
<string name="poi_resource_dimension_stone">Строительный камень</string>
<string name="poi_resource_dolomite">Доломит</string>
<string name="poi_resource_gas">Природный газ</string>
<string name="poi_resource_gold">Золото</string>
<string name="poi_resource_graphite">Графит</string>
<string name="poi_resource_gravel">Гравий</string>
<string name="poi_resource_gypsum">Гипс</string>
<string name="poi_resource_iron_ore">Железная руда</string>
<string name="poi_resource_lead">Свинец</string>
<string name="poi_resource_lignite">Бурый уголь</string>
<string name="poi_resource_limestone">Известняк</string>
<string name="poi_resource_marble">Мрамор</string>
<string name="poi_resource_mercury">Ртуть</string>
<string name="poi_resource_mica">Слюда</string>
<string name="poi_resource_mineral_oil">Минеральное масло</string>
<string name="poi_resource_nickel">Никель</string>
<string name="poi_resource_oil">Нефть/масло</string>
<string name="poi_resource_opal">Опал</string>
<string name="poi_resource_peat">Торф</string>
<string name="poi_resource_platinum">Платина</string>
<string name="poi_resource_radium">Радий</string>
<string name="poi_resource_ruby">Рубин</string>
<string name="poi_resource_rutile">Рутил</string>
<string name="poi_resource_salt">Соль</string>
<string name="poi_resource_sand">Песок</string>
<string name="poi_resource_sandstone">Песчаник</string>
<string name="poi_resource_silica">Кремнезём, кварц</string>
<string name="poi_resource_silver">Серебро</string>
<string name="poi_resource_slate_iron_ore_copper">Сланец;железная руда;медь</string>
<string name="poi_resource_slate">Сланец</string>
<string name="poi_resource_stone">Камень (ресурс)</string>
<string name="poi_resource_tin">Олово</string>
<string name="poi_resource_tuff">Вулканический туф</string>
<string name="poi_resource_uranium">Уран</string>
<string name="poi_resource_vanadium">Ванадий</string>
<string name="poi_resource_water">Вода (ресурс)</string>
<string name="poi_resource_zinc">Цинк</string>
<string name="poi_resource_zircon">Циркон</string>
</resources> </resources>

View file

@ -2012,4 +2012,8 @@
<string name="min_km">min/km</string> <string name="min_km">min/km</string>
<string name="m_s">m/s</string> <string name="m_s">m/s</string>
</resources> <string name="downloading_number_of_files">Prejemanje datotek: %1$d</string>
<string name="show_free_version_banner">Pokaži pasico brezplačne različice</string>
<string name="srtm_plugin_disabled">Izris izohips je onemogočen</string>
<string name="show_free_version_banner_description">Četudi imate plačljivo različico, še vedno lahko prikažete pasico brezplačne različice.</string>
</resources>

View file

@ -1695,5 +1695,59 @@
<string name="poi_memorial_obelisk">Obelisk</string> <string name="poi_memorial_obelisk">Obelisk</string>
<string name="poi_inscription">Inscription</string> <string name="poi_inscription">Inscription</string>
<string name="poi_historic_quarry">Historic quarry</string>
<string name="poi_resource_aggregate">Aggregate</string>
<string name="poi_resource_antimony">Antimony</string>
<string name="poi_resource_asbestos">Asbestos</string>
<string name="poi_resource_barite">Barite</string>
<string name="poi_resource_basalt">Basalt</string>
<string name="poi_resource_bauxite">Bauxite</string>
<string name="poi_resource_beryl">Beryl</string>
<string name="poi_resource_bismuth">Bismuth</string>
<string name="poi_resource_cereal">Cereal</string>
<string name="poi_resource_chromite">Chromite</string>
<string name="poi_resource_clay">Clay</string>
<string name="poi_resource_coal">Coal</string>
<string name="poi_resource_copper">Copper</string>
<string name="poi_resource_diamond">Diamond</string>
<string name="poi_resource_dimension_stone">Dimension stone</string>
<string name="poi_resource_dolomite">Dolomite</string>
<string name="poi_resource_gas">Gas</string>
<string name="poi_resource_gold">Gold</string>
<string name="poi_resource_graphite">Graphite</string>
<string name="poi_resource_gravel">Gravel</string>
<string name="poi_resource_gypsum">Gypsum</string>
<string name="poi_resource_iron_ore">Iron ore</string>
<string name="poi_resource_lead">Lead</string>
<string name="poi_resource_lignite">Lignite</string>
<string name="poi_resource_limestone">Limestone</string>
<string name="poi_resource_marble">Marble</string>
<string name="poi_resource_mercury">Mercury</string>
<string name="poi_resource_mica">Mica</string>
<string name="poi_resource_mineral_oil">Mineral oil</string>
<string name="poi_resource_nickel">Nickel</string>
<string name="poi_resource_oil">Oil</string>
<string name="poi_resource_opal">Opal</string>
<string name="poi_resource_peat">Peat</string>
<string name="poi_resource_platinum">Platinum</string>
<string name="poi_resource_radium">Radium</string>
<string name="poi_resource_ruby">Ruby</string>
<string name="poi_resource_rutile">Rutile</string>
<string name="poi_resource_salt">Salt</string>
<string name="poi_resource_sand">Sand</string>
<string name="poi_resource_sandstone">Sandstone</string>
<string name="poi_resource_silica">Silica</string>
<string name="poi_resource_silver">Silver</string>
<string name="poi_resource_slate_iron_ore_copper">Slate;iron ore;copper</string>
<string name="poi_resource_slate">Slate</string>
<string name="poi_resource_stone">Stone</string>
<string name="poi_resource_tin">Tin</string>
<string name="poi_resource_tuff">Tuff</string>
<string name="poi_resource_uranium">Uranium</string>
<string name="poi_resource_vanadium">Vanadium</string>
<string name="poi_resource_water">Water</string>
<string name="poi_resource_zinc">Zinc</string>
<string name="poi_resource_zircon">Zircon</string>
</resources> </resources>

View file

@ -282,4 +282,17 @@ public class WorldRegion implements Serializable {
return s; return s;
} }
} }
public WorldRegion getRegionById(String regionId) {
if (regionId == null) {
return this;
} else {
for (WorldRegion region : flattenedSubregions) {
if (region.getRegionId().equals(regionId)) {
return region;
}
}
}
return null;
}
} }

View file

@ -19,6 +19,7 @@ import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.ActionBarProgressActivity; import net.osmand.plus.activities.ActionBarProgressActivity;
import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.items.ItemsListBuilder;
import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat; import net.osmand.plus.download.newimplementation.IndexItemCategoryWithSubcat;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -122,6 +123,24 @@ public class BaseDownloadActivity extends ActionBarProgressActivity {
} }
public ItemsListBuilder getItemsBuilder() {
if (downloadListIndexThread.isDataPrepared()) {
return new ItemsListBuilder(getMyApplication(), null, downloadListIndexThread.getResourcesByRegions(),
downloadListIndexThread.getVoiceRecItems(), downloadListIndexThread.getVoiceTTSItems());
} else {
return null;
}
}
public ItemsListBuilder getItemsBuilder(String regionId) {
if (downloadListIndexThread.isDataPrepared()) {
return new ItemsListBuilder(getMyApplication(), regionId, downloadListIndexThread.getResourcesByRegions(),
downloadListIndexThread.getVoiceRecItems(), downloadListIndexThread.getVoiceTTSItems());
} else {
return null;
}
}
public boolean startDownload(IndexItem item) { public boolean startDownload(IndexItem item) {
if (downloadListIndexThread.getCurrentRunningTask() != null && getEntriesToDownload().get(item) == null) { if (downloadListIndexThread.getCurrentRunningTask() != null && getEntriesToDownload().get(item) == null) {
downloadQueue.add(item); downloadQueue.add(item);

View file

@ -15,13 +15,17 @@ import android.os.StatFs;
import android.view.View; import android.view.View;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.Collator;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.OsmAndCollator;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.WorldRegion;
import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning; import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem; import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetIndexItem;
@ -39,13 +43,17 @@ import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@SuppressLint("NewApi") @SuppressLint("NewApi")
@ -64,6 +72,12 @@ public class DownloadIndexesThread {
private java.text.DateFormat dateFormat; private java.text.DateFormat dateFormat;
private List<IndexItem> itemsToUpdate = new ArrayList<IndexItem>(); private List<IndexItem> itemsToUpdate = new ArrayList<IndexItem>();
private Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions = new HashMap<>();
private List<IndexItem> voiceRecItems = new LinkedList<>();
private List<IndexItem> voiceTTSItems = new LinkedList<>();
private boolean dataPrepared;
DatabaseHelper dbHelper; DatabaseHelper dbHelper;
public DownloadIndexesThread(Context ctx) { public DownloadIndexesThread(Context ctx) {
@ -141,6 +155,107 @@ public class DownloadIndexesThread {
return itemsToUpdate; return itemsToUpdate;
} }
public boolean isDataPrepared() {
return dataPrepared;
}
public Map<WorldRegion, Map<String, IndexItem>> getResourcesByRegions() {
return resourcesByRegions;
}
public List<IndexItem> getVoiceRecItems() {
return voiceRecItems;
}
public List<IndexItem> getVoiceTTSItems() {
return voiceTTSItems;
}
private boolean prepareData(List<IndexItem> resources) {
List<IndexItem> resourcesInRepository;
if (resources != null) {
resourcesInRepository = resources;
} else {
resourcesInRepository = DownloadActivity.downloadListIndexThread.getCachedIndexFiles();
}
if (resourcesInRepository == null) {
return false;
}
resourcesByRegions.clear();
voiceRecItems.clear();
voiceTTSItems.clear();
List<WorldRegion> mergedRegions = app.getWorldRegion().getFlattenedSubregions();
mergedRegions.add(app.getWorldRegion());
boolean voiceFilesProcessed = false;
for (WorldRegion region : mergedRegions) {
String downloadsIdPrefix = region.getDownloadsIdPrefix();
Map<String, IndexItem> regionResources = new HashMap<>();
Set<DownloadActivityType> typesSet = new TreeSet<>(new Comparator<DownloadActivityType>() {
@Override
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
return dat1.getTag().compareTo(dat2.getTag());
}
});
for (IndexItem resource : resourcesInRepository) {
if (!voiceFilesProcessed) {
if (resource.getSimplifiedFileName().endsWith(".voice.zip")) {
voiceRecItems.add(resource);
continue;
} else if (resource.getSimplifiedFileName().contains(".ttsvoice.zip")) {
voiceTTSItems.add(resource);
continue;
}
}
if (!resource.getSimplifiedFileName().startsWith(downloadsIdPrefix)) {
continue;
}
typesSet.add(resource.getType());
regionResources.put(resource.getSimplifiedFileName(), resource);
}
voiceFilesProcessed = true;
if (region.getSuperregion() != null && region.getSuperregion().getSuperregion() != app.getWorldRegion()) {
if (region.getSuperregion().getResourceTypes() == null) {
region.getSuperregion().setResourceTypes(typesSet);
} else {
region.getSuperregion().getResourceTypes().addAll(typesSet);
}
}
region.setResourceTypes(typesSet);
resourcesByRegions.put(region, regionResources);
}
final Collator collator = OsmAndCollator.primaryCollator();
final OsmandRegions osmandRegions = app.getRegions();
Collections.sort(voiceRecItems, new Comparator<IndexItem>() {
@Override
public int compare(IndexItem lhs, IndexItem rhs) {
return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions),
rhs.getVisibleName(app.getApplicationContext(), osmandRegions));
}
});
Collections.sort(voiceTTSItems, new Comparator<IndexItem>() {
@Override
public int compare(IndexItem lhs, IndexItem rhs) {
return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions),
rhs.getVisibleName(app.getApplicationContext(), osmandRegions));
}
});
return true;
}
public class DownloadIndexesAsyncTask extends BasicProgressAsyncTask<IndexItem, Object, String> implements DownloadFileShowWarning { public class DownloadIndexesAsyncTask extends BasicProgressAsyncTask<IndexItem, Object, String> implements DownloadFileShowWarning {
@ -408,13 +523,14 @@ public class DownloadIndexesThread {
currentRunningTask.add(this); currentRunningTask.add(this);
super.onPreExecute(); super.onPreExecute();
this.message = ctx.getString(R.string.downloading_list_indexes); this.message = ctx.getString(R.string.downloading_list_indexes);
dataPrepared = false;
} }
@Override @Override
protected IndexFileList doInBackground(Void... params) { protected IndexFileList doInBackground(Void... params) {
IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx); IndexFileList indexFileList = DownloadOsmandIndexesHelper.getIndexesList(ctx);
if (indexFileList != null) { if (indexFileList != null) {
ItemsListBuilder.prepareData(app, indexFileList.getIndexFiles()); prepareData(indexFileList.getIndexFiles());
} }
return indexFileList; return indexFileList;
} }
@ -422,6 +538,7 @@ public class DownloadIndexesThread {
protected void onPostExecute(IndexFileList result) { protected void onPostExecute(IndexFileList result) {
indexFiles = result; indexFiles = result;
if (indexFiles != null && uiActivity != null) { if (indexFiles != null && uiActivity != null) {
dataPrepared = resourcesByRegions.size() > 0;
prepareFilesToUpdate(); prepareFilesToUpdate();
boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap(); boolean basemapExists = uiActivity.getMyApplication().getResourceManager().containsBasemap();
IndexItem basemap = indexFiles.getBasemap(); IndexItem basemap = indexFiles.getBasemap();

View file

@ -2,15 +2,12 @@ package net.osmand.plus.download.items;
import android.content.Context; import android.content.Context;
import net.osmand.Collator;
import net.osmand.OsmAndCollator;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.WorldRegion; import net.osmand.plus.WorldRegion;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin;
@ -18,20 +15,19 @@ import net.osmand.util.Algorithms;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class ItemsListBuilder { public class ItemsListBuilder {
public static final String WORLD_BASEMAP_KEY = "world_basemap.obf.zip"; public static final String WORLD_BASEMAP_KEY = "world_basemap.obf.zip";
public static final String WORLD_SEAMARKS_KEY = "world_seamarks_basemap.obf.zip"; public static final String WORLD_SEAMARKS_KEY = "world_seamarks_basemap.obf.zip";
private Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions;
private List<IndexItem> voiceRecItems;
private List<IndexItem> voiceTTSItems;
public class ResourceItem { public class ResourceItem {
private String resourceId; private String resourceId;
@ -101,15 +97,6 @@ public class ItemsListBuilder {
private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(ItemsListBuilder.class); private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(ItemsListBuilder.class);
private static Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions =
new HashMap<>();
private static List<WorldRegion> searchableWorldwideRegionItems = new LinkedList<>();
private static List<IndexItem> voiceRecItems = new LinkedList<>();
private static List<IndexItem> voiceTTSItems = new LinkedList<>();
private static final Lock lock = new ReentrantLock();
private List<ResourceItem> regionMapItems; private List<ResourceItem> regionMapItems;
private List<Object> allResourceItems; private List<Object> allResourceItems;
private List<WorldRegion> allSubregionItems; private List<WorldRegion> allSubregionItems;
@ -138,18 +125,18 @@ public class ItemsListBuilder {
return list; return list;
} }
public static String getVoicePromtName(Context context, VoicePromptsType type) { public String getVoicePromtName(VoicePromptsType type) {
switch (type) { switch (type) {
case RECORDED: case RECORDED:
return context.getResources().getString(R.string.index_name_voice); return app.getResources().getString(R.string.index_name_voice);
case TTS: case TTS:
return context.getResources().getString(R.string.index_name_tts_voice); return app.getResources().getString(R.string.index_name_tts_voice);
default: default:
return null; return null;
} }
} }
public static List<IndexItem> getVoicePromptsItems(VoicePromptsType type) { public List<IndexItem> getVoicePromptsItems(VoicePromptsType type) {
switch (type) { switch (type) {
case RECORDED: case RECORDED:
return voiceRecItems; return voiceRecItems;
@ -160,7 +147,7 @@ public class ItemsListBuilder {
} }
} }
public static boolean isVoicePromptsItemsEmpty(VoicePromptsType type) { public boolean isVoicePromptsItemsEmpty(VoicePromptsType type) {
switch (type) { switch (type) {
case RECORDED: case RECORDED:
return voiceRecItems.isEmpty(); return voiceRecItems.isEmpty();
@ -171,28 +158,22 @@ public class ItemsListBuilder {
} }
} }
public ItemsListBuilder(OsmandApplication app) { public ItemsListBuilder(OsmandApplication app, String regionId, Map<WorldRegion, Map<String, IndexItem>> resourcesByRegions,
List<IndexItem> voiceRecItems, List<IndexItem> voiceTTSItems) {
this.app = app; this.app = app;
regionMapItems = new LinkedList<>(); this.resourcesByRegions = resourcesByRegions;
allResourceItems = new LinkedList<Object>(); this.voiceRecItems = voiceRecItems;
allSubregionItems = new LinkedList<>(); this.voiceTTSItems = voiceTTSItems;
}
public ItemsListBuilder(OsmandApplication app, WorldRegion region) { regionMapItems = new LinkedList<>();
this(app); allResourceItems = new LinkedList<>();
this.region = region; allSubregionItems = new LinkedList<>();
region = app.getWorldRegion().getRegionById(regionId);
} }
public boolean build() { public boolean build() {
if (lock.tryLock()) { return obtainDataAndItems();
try {
return obtainDataAndItems();
} finally {
lock.unlock();
}
} else {
return false;
}
} }
private boolean obtainDataAndItems() { private boolean obtainDataAndItems() {
@ -206,92 +187,6 @@ public class ItemsListBuilder {
return true; return true;
} }
public static boolean prepareData(final OsmandApplication app, List<IndexItem> resources) {
lock.lock();
try {
List<IndexItem> resourcesInRepository;
if (resources != null) {
resourcesInRepository = resources;
} else {
resourcesInRepository = DownloadActivity.downloadListIndexThread.getCachedIndexFiles();
}
if (resourcesInRepository == null) {
return false;
}
resourcesByRegions.clear();
searchableWorldwideRegionItems.clear();
voiceRecItems.clear();
voiceTTSItems.clear();
List<WorldRegion> mergedRegions = app.getWorldRegion().getFlattenedSubregions();
mergedRegions.add(app.getWorldRegion());
boolean voiceFilesProcessed = false;
for (WorldRegion region : mergedRegions) {
searchableWorldwideRegionItems.add(region);
String downloadsIdPrefix = region.getDownloadsIdPrefix();
Map<String, IndexItem> regionResources = new HashMap<>();
Set<DownloadActivityType> typesSet = new TreeSet<>(new Comparator<DownloadActivityType>() {
@Override
public int compare(DownloadActivityType dat1, DownloadActivityType dat2) {
return dat1.getTag().compareTo(dat2.getTag());
}
});
for (IndexItem resource : resourcesInRepository) {
if (!voiceFilesProcessed) {
if (resource.getSimplifiedFileName().endsWith(".voice.zip")) {
voiceRecItems.add(resource);
continue;
} else if (resource.getSimplifiedFileName().contains(".ttsvoice.zip")) {
voiceTTSItems.add(resource);
continue;
}
}
if (!resource.getSimplifiedFileName().startsWith(downloadsIdPrefix)) {
continue;
}
typesSet.add(resource.getType());
regionResources.put(resource.getSimplifiedFileName(), resource);
}
voiceFilesProcessed = true;
if (region.getSuperregion() != null && region.getSuperregion().getSuperregion() != app.getWorldRegion()) {
if (region.getSuperregion().getResourceTypes() == null) {
region.getSuperregion().setResourceTypes(typesSet);
} else {
region.getSuperregion().getResourceTypes().addAll(typesSet);
}
}
region.setResourceTypes(typesSet);
resourcesByRegions.put(region, regionResources);
}
final Collator collator = OsmAndCollator.primaryCollator();
final OsmandRegions osmandRegions = app.getRegions();
Collections.sort(voiceRecItems, new Comparator<IndexItem>() {
@Override
public int compare(IndexItem lhs, IndexItem rhs) {
return collator.compare(lhs.getVisibleName(app.getApplicationContext(), osmandRegions),
rhs.getVisibleName(app.getApplicationContext(), osmandRegions));
}
});
return true;
} finally {
lock.unlock();
}
}
private void collectSubregionsDataAndItems() { private void collectSubregionsDataAndItems() {
srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null; srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
hasSrtm = false; hasSrtm = false;

View file

@ -21,8 +21,8 @@ import org.apache.commons.logging.Log;
public class RegionDialogFragment extends DialogFragment { public class RegionDialogFragment extends DialogFragment {
private static final Log LOG = PlatformUtil.getLog(RegionDialogFragment.class); private static final Log LOG = PlatformUtil.getLog(RegionDialogFragment.class);
public static final String TAG = "RegionDialogFragment"; public static final String TAG = "RegionDialogFragment";
private static final String REGION_DLG_KEY = "world_region_dialog_key"; private static final String REGION_ID_DLG_KEY = "world_region_dialog_key";
private WorldRegion region; private String regionId;
private DownloadsUiHelper.MapDownloadListener mProgressListener; private DownloadsUiHelper.MapDownloadListener mProgressListener;
@Override @Override
@ -39,22 +39,13 @@ public class RegionDialogFragment extends DialogFragment {
Bundle savedInstanceState) { Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false); final View view = inflater.inflate(R.layout.maps_in_category_fragment, container, false);
WorldRegion region = null;
if (savedInstanceState != null) { if (savedInstanceState != null) {
Object regionObj = savedInstanceState.getSerializable(REGION_DLG_KEY); regionId = savedInstanceState.getString(REGION_ID_DLG_KEY);
if (regionObj != null) {
region = (WorldRegion)regionObj;
}
} }
if (region == null) { if (regionId == null) {
Object regionObj = getArguments().getSerializable(REGION_DLG_KEY); regionId = getArguments().getString(REGION_ID_DLG_KEY);
if (regionObj != null) {
region = (WorldRegion)regionObj;
}
} }
this.region = region;
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha)); toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha));
toolbar.setNavigationOnClickListener(new View.OnClickListener() { toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@ -64,13 +55,16 @@ public class RegionDialogFragment extends DialogFragment {
} }
}); });
if (this.region != null) { if (regionId != null) {
Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainer); Fragment fragment = getChildFragmentManager().findFragmentById(R.id.fragmentContainer);
if (fragment == null) { if (fragment == null) {
getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer, getChildFragmentManager().beginTransaction().add(R.id.fragmentContainer,
RegionItemsFragment.createInstance(region)).commit(); RegionItemsFragment.createInstance(regionId)).commit();
}
WorldRegion region = getMyApplication().getWorldRegion().getRegionById(regionId);
if (region != null) {
toolbar.setTitle(region.getName());
} }
toolbar.setTitle(this.region.getName());
} }
DownloadsUiHelper.initFreeVersionBanner(view, getMyApplication(), DownloadsUiHelper.initFreeVersionBanner(view, getMyApplication(),
getResources()); getResources());
@ -95,7 +89,6 @@ public class RegionDialogFragment extends DialogFragment {
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
LOG.debug(region.getName() + " onResume()");
getMyActivity().setOnProgressUpdateListener(mProgressListener); getMyActivity().setOnProgressUpdateListener(mProgressListener);
} }
@ -107,7 +100,7 @@ public class RegionDialogFragment extends DialogFragment {
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
outState.putSerializable(REGION_DLG_KEY, region); outState.putString(REGION_ID_DLG_KEY, regionId);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@ -119,13 +112,13 @@ public class RegionDialogFragment extends DialogFragment {
return (DownloadActivity) getActivity(); return (DownloadActivity) getActivity();
} }
public void onRegionSelected(WorldRegion region) { public void onRegionSelected(String regionId) {
DownloadsUiHelper.showDialog(getActivity(), createInstance(region)); DownloadsUiHelper.showDialog(getActivity(), createInstance(regionId));
} }
public static RegionDialogFragment createInstance(WorldRegion region) { public static RegionDialogFragment createInstance(String regionId) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putSerializable(REGION_DLG_KEY, region); bundle.putString(REGION_ID_DLG_KEY, regionId);
RegionDialogFragment fragment = new RegionDialogFragment(); RegionDialogFragment fragment = new RegionDialogFragment();
fragment.setArguments(bundle); fragment.setArguments(bundle);
return fragment; return fragment;

View file

@ -38,13 +38,12 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
private static final Log LOG = PlatformUtil.getLog(RegionItemsFragment.class); private static final Log LOG = PlatformUtil.getLog(RegionItemsFragment.class);
private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US); private static final MessageFormat formatGb = new MessageFormat("{0, number,<b>#.##</b>} GB", Locale.US);
private ItemsListBuilder builder;
private RegionsItemsAdapter listAdapter; private RegionsItemsAdapter listAdapter;
private int regionMapsGroupPos = -1; private int regionMapsGroupPos = -1;
private int additionalMapsGroupPos = -1; private int additionalMapsGroupPos = -1;
private static final String REGION_KEY = "world_region_key"; private static final String REGION_ID_KEY = "world_region_id_key";
private WorldRegion region; private String regionId;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -56,33 +55,25 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.download_items_fragment, container, false); View view = inflater.inflate(R.layout.download_items_fragment, container, false);
WorldRegion region = null;
if (savedInstanceState != null) { if (savedInstanceState != null) {
Object regionObj = savedInstanceState.getSerializable(REGION_KEY); regionId = savedInstanceState.getString(REGION_ID_KEY);
if (regionObj != null) {
region = (WorldRegion) regionObj;
}
} }
if (region == null) { if (regionId == null) {
Object regionObj = getArguments().getSerializable(REGION_KEY); regionId = getArguments().getString(REGION_ID_KEY);
if (regionObj != null) {
region = (WorldRegion) regionObj;
}
} }
this.region = region;
builder = new ItemsListBuilder(getMyApplication(), this.region);
ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list); ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list);
listAdapter = new RegionsItemsAdapter(getActivity()); listAdapter = new RegionsItemsAdapter(getActivity());
listView.setAdapter(listAdapter); listView.setAdapter(listAdapter);
setListView(listView); setListView(listView);
if (builder.build()) { if (regionId != null) {
fillRegionItemsAdapter(); ItemsListBuilder builder = getDownloadActivity().getItemsBuilder(regionId);
listAdapter.notifyDataSetChanged(); if (builder != null && builder.build()) {
expandAllGroups(); fillRegionItemsAdapter(builder);
listAdapter.notifyDataSetChanged();
expandAllGroups();
}
} }
return view; return view;
@ -90,7 +81,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
outState.putSerializable(REGION_KEY, region); outState.putString(REGION_ID_KEY, regionId);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@ -100,7 +91,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
if (obj instanceof WorldRegion) { if (obj instanceof WorldRegion) {
WorldRegion region = (WorldRegion) obj; WorldRegion region = (WorldRegion) obj;
((RegionDialogFragment) getParentFragment()) ((RegionDialogFragment) getParentFragment())
.onRegionSelected(region); .onRegionSelected(region.getRegionId());
return true; return true;
} else { } else {
return false; return false;
@ -117,17 +108,12 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
private void fillRegionItemsAdapter() { private void fillRegionItemsAdapter(ItemsListBuilder builder) {
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.clear(); listAdapter.clear();
int nextAvailableGroupPos = 0; int nextAvailableGroupPos = 0;
if (builder.getRegionMapItems().size() > 0) { if (builder.getRegionMapItems().size() > 0) {
String sectionTitle; String sectionTitle = "Region maps";
if (builder.getAllResourceItems().size() > 0) {
sectionTitle = "Region maps";
} else {
sectionTitle = "";
}
regionMapsGroupPos = nextAvailableGroupPos++; regionMapsGroupPos = nextAvailableGroupPos++;
listAdapter.add(sectionTitle, builder.getRegionMapItems()); listAdapter.add(sectionTitle, builder.getRegionMapItems());
} }
@ -136,7 +122,7 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
if (builder.getRegionMapItems().size() > 0) { if (builder.getRegionMapItems().size() > 0) {
sectionTitle = "Additional maps"; sectionTitle = "Additional maps";
} else { } else {
sectionTitle = ""; sectionTitle = "Regions";
} }
additionalMapsGroupPos = nextAvailableGroupPos; additionalMapsGroupPos = nextAvailableGroupPos;
listAdapter.add(sectionTitle, builder.getAllResourceItems()); listAdapter.add(sectionTitle, builder.getAllResourceItems());
@ -148,9 +134,9 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
return (DownloadActivity) getActivity(); return (DownloadActivity) getActivity();
} }
public static RegionItemsFragment createInstance(WorldRegion region) { public static RegionItemsFragment createInstance(String regionId) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putSerializable(REGION_KEY, region); bundle.putString(REGION_ID_KEY, regionId);
RegionItemsFragment fragment = new RegionItemsFragment(); RegionItemsFragment fragment = new RegionItemsFragment();
fragment.setArguments(bundle); fragment.setArguments(bundle);
return fragment; return fragment;
@ -260,14 +246,6 @@ public class RegionItemsFragment extends OsmandExpandableListFragment {
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = convertView; View v = convertView;
String section = getGroup(groupPosition); String section = getGroup(groupPosition);
/*
if (section.length() == 0) {
LinearLayout emptyLL = new LinearLayout(parent.getContext());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
emptyLL.setLayoutParams(params);
return emptyLL;
}
*/
if (v == null) { if (v == null) {
LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); LayoutInflater inflater = (LayoutInflater) getDownloadActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View file

@ -43,7 +43,6 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
public static final int RELOAD_ID = 0; public static final int RELOAD_ID = 0;
private ItemsListBuilder builder;
private WorldItemsAdapter listAdapter; private WorldItemsAdapter listAdapter;
private int worldRegionsIndex = -1; private int worldRegionsIndex = -1;
@ -63,8 +62,6 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.download_index_fragment, container, false); View view = inflater.inflate(R.layout.download_index_fragment, container, false);
builder = new ItemsListBuilder(getMyApplication(), getMyApplication().getWorldRegion());
ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list); ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list);
listAdapter = new WorldItemsAdapter(getActivity()); listAdapter = new WorldItemsAdapter(getActivity());
listView.setAdapter(listAdapter); listView.setAdapter(listAdapter);
@ -98,7 +95,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }
private void fillWorldItemsAdapter() { private void fillWorldItemsAdapter(ItemsListBuilder builder) {
if (listAdapter != null) { if (listAdapter != null) {
listAdapter.clear(); listAdapter.clear();
if (builder.getRegionMapItems().size() > 0) { if (builder.getRegionMapItems().size() > 0) {
@ -110,12 +107,12 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
int unusedSubIndex = 0; int unusedSubIndex = 0;
List<String> voicePromptsItems = new LinkedList<>(); List<String> voicePromptsItems = new LinkedList<>();
if (!ItemsListBuilder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.RECORDED)) { if (!builder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.RECORDED)) {
voicePromptsItems.add(ItemsListBuilder.getVoicePromtName(getMyApplication(), ItemsListBuilder.VoicePromptsType.RECORDED)); voicePromptsItems.add(builder.getVoicePromtName(ItemsListBuilder.VoicePromptsType.RECORDED));
voicePromptsItemsRecordedSubIndex = unusedSubIndex++; voicePromptsItemsRecordedSubIndex = unusedSubIndex++;
} }
if (!ItemsListBuilder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.TTS)) { if (!builder.isVoicePromptsItemsEmpty(ItemsListBuilder.VoicePromptsType.TTS)) {
voicePromptsItems.add(ItemsListBuilder.getVoicePromtName(getMyApplication(), ItemsListBuilder.VoicePromptsType.TTS)); voicePromptsItems.add(builder.getVoicePromtName(ItemsListBuilder.VoicePromptsType.TTS));
voicePromptsItemsTTSSubIndex = unusedSubIndex; voicePromptsItemsTTSSubIndex = unusedSubIndex;
} }
if (!voicePromptsItems.isEmpty()) { if (!voicePromptsItems.isEmpty()) {
@ -131,7 +128,7 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
if (groupPosition == worldRegionsIndex) { if (groupPosition == worldRegionsIndex) {
WorldRegion region = (WorldRegion)listAdapter.getChild(groupPosition, childPosition); WorldRegion region = (WorldRegion)listAdapter.getChild(groupPosition, childPosition);
DownloadsUiHelper.showDialog(getActivity(), RegionDialogFragment.createInstance(region)); DownloadsUiHelper.showDialog(getActivity(), RegionDialogFragment.createInstance(region.getRegionId()));
return true; return true;
} else if (groupPosition == voicePromptsIndex) { } else if (groupPosition == voicePromptsIndex) {
// //
@ -161,8 +158,9 @@ public class WorldItemsFragment extends OsmandExpandableListFragment {
} }
public void onCategorizationFinished() { public void onCategorizationFinished() {
if (builder.build()) { ItemsListBuilder builder = getDownloadActivity().getItemsBuilder();
fillWorldItemsAdapter(); if (builder != null && builder.build()) {
fillWorldItemsAdapter(builder);
listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetChanged();
expandAllGroups(); expandAllGroups();
} }