add srtmf map download option p2

This commit is contained in:
Skalii 2021-04-05 19:21:17 +03:00
parent 684571ca34
commit 1813a99da1
13 changed files with 788 additions and 389 deletions

View file

@ -97,12 +97,12 @@
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_list_item_height" android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding" android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/content_padding_small" android:paddingTop="@dimen/content_padding_small"
android:paddingEnd="@dimen/content_padding"
android:paddingRight="@dimen/content_padding" android:paddingRight="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding_small" android:paddingBottom="@dimen/content_padding_small">
android:paddingStart="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/check_box_title" android:id="@+id/check_box_title"

View file

@ -143,8 +143,6 @@ public class LocalIndexHelper {
return null; return null;
} }
public List<LocalIndexInfo> getLocalIndexInfos(String downloadName) { public List<LocalIndexInfo> getLocalIndexInfos(String downloadName) {
List<LocalIndexInfo> list = new ArrayList<>(); List<LocalIndexInfo> list = new ArrayList<>();
LocalIndexInfo info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, false, false); LocalIndexInfo info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, false, false);
@ -334,7 +332,8 @@ public class LocalIndexHelper {
for (File mapFile : listFilesSorted(mapPath)) { for (File mapFile : listFilesSorted(mapPath)) {
if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
LocalIndexType lt = LocalIndexType.MAP_DATA; LocalIndexType lt = LocalIndexType.MAP_DATA;
if (mapFile.getName().endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)) { if (mapFile.getName().endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)
|| mapFile.getName().endsWith(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT)) {
lt = LocalIndexType.SRTM_DATA; lt = LocalIndexType.SRTM_DATA;
} else if (mapFile.getName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) { } else if (mapFile.getName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) {
lt = LocalIndexType.WIKI_DATA; lt = LocalIndexType.WIKI_DATA;
@ -430,5 +429,4 @@ public class LocalIndexHelper {
return fileName; return fileName;
} }
} }
} }

View file

@ -5,6 +5,7 @@ import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -21,8 +22,14 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton.Builder; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton.Builder;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.SimpleDividerItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.SimpleDividerItem;
import net.osmand.plus.download.MultipleIndexesUiHelper.SelectedItemsListener;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.widgets.MultiStateToggleButton;
import net.osmand.plus.widgets.MultiStateToggleButton.OnRadioItemClickListener;
import net.osmand.plus.widgets.MultiStateToggleButton.RadioItem;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.view.ThreeStateCheckbox; import net.osmand.view.ThreeStateCheckbox;
@ -35,6 +42,8 @@ import static net.osmand.view.ThreeStateCheckbox.State.UNCHECKED;
public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragment { public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = SelectMultipleItemsBottomSheet.class.getSimpleName();
private OsmandApplication app; private OsmandApplication app;
private UiUtilities uiUtilities; private UiUtilities uiUtilities;
@ -45,15 +54,57 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
private TextView selectedSize; private TextView selectedSize;
private ThreeStateCheckbox checkBox; private ThreeStateCheckbox checkBox;
private int sizeAboveList = 0;
private int activeColorRes; private int activeColorRes;
private int secondaryColorRes; private int secondaryColorRes;
private String addDescriptionText;
private String leftRadioButtonText;
private String rightRadioButtonText;
private boolean customOptionsVisible;
private boolean leftButtonSelected;
private final List<SelectableItem> allItems = new ArrayList<>(); private final List<SelectableItem> allItems = new ArrayList<>();
private final List<SelectableItem> selectedItems = new ArrayList<>(); private final List<SelectableItem> selectedItems = new ArrayList<>();
private SelectionUpdateListener selectionUpdateListener; private SelectionUpdateListener selectionUpdateListener;
private OnApplySelectionListener onApplySelectionListener; private OnApplySelectionListener onApplySelectionListener;
private OnRadioButtonSelectListener onRadioButtonSelectListener;
private SelectedItemsListener selectedItemsListener;
public static final String TAG = SelectMultipleItemsBottomSheet.class.getSimpleName(); public static SelectMultipleItemsBottomSheet showInstance(@NonNull AppCompatActivity activity,
@NonNull List<SelectableItem> items,
@Nullable List<SelectableItem> selected,
boolean usedOnMap) {
SelectMultipleItemsBottomSheet fragment = new SelectMultipleItemsBottomSheet();
fragment.setUsedOnMap(usedOnMap);
fragment.setItems(items);
fragment.setSelectedItems(selected);
FragmentManager fm = activity.getSupportFragmentManager();
fragment.show(fm, TAG);
return fragment;
}
public static SelectMultipleItemsBottomSheet showInstance(@NonNull AppCompatActivity activity,
@NonNull List<SelectableItem> items,
@Nullable List<SelectableItem> selected,
boolean usedOnMap,
String addDescription,
boolean customOptionsVisible,
boolean leftButtonSelected,
String leftRadioButtonText,
String rightRadioButtonText) {
SelectMultipleItemsBottomSheet fragment = new SelectMultipleItemsBottomSheet();
fragment.setUsedOnMap(usedOnMap);
fragment.setItems(items);
fragment.setSelectedItems(selected);
fragment.setAddDescriptionText(addDescription);
fragment.setCustomOptionsVisible(customOptionsVisible);
fragment.setLeftButtonSelected(leftButtonSelected);
fragment.setLeftRadioButtonText(leftRadioButtonText);
fragment.setRightRadioButtonText(rightRadioButtonText);
FragmentManager fm = activity.getSupportFragmentManager();
fragment.show(fm, TAG);
return fragment;
}
@Nullable @Nullable
@Override @Override
@ -72,9 +123,18 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
items.add(createTitleItem()); items.add(createTitleItem());
items.add(new SimpleDividerItem(app)); items.add(new SimpleDividerItem(app));
sizeAboveList = items.size();
createListItems(); createListItems();
} }
@Override
public void onPause() {
super.onPause();
if (requireActivity().isChangingConfigurations()) {
dismiss();
}
}
private BaseBottomSheetItem createTitleItem() { private BaseBottomSheetItem createTitleItem() {
LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode); LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode);
View view = themedInflater.inflate(R.layout.settings_group_title, null); View view = themedInflater.inflate(R.layout.settings_group_title, null);
@ -85,66 +145,111 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
selectedSize = view.findViewById(R.id.selected_size); selectedSize = view.findViewById(R.id.selected_size);
title = view.findViewById(R.id.title); title = view.findViewById(R.id.title);
View selectAllButton = view.findViewById(R.id.select_all_button); View selectAllButton = view.findViewById(R.id.select_all_button);
selectAllButton.setOnClickListener(new View.OnClickListener() { TextView addDescription = view.findViewById(R.id.additional_description);
@Override LinearLayout customRadioButtons = view.findViewById(R.id.custom_radio_buttons);
public void onClick(View v) {
checkBox.performClick(); if (!isMultipleItem()) {
boolean checked = checkBox.getState() == CHECKED; AndroidUiHelper.setVisibility(View.GONE, description, selectedSize, selectAllButton);
if (checked) { } else {
selectedItems.addAll(allItems); selectAllButton.setOnClickListener(new View.OnClickListener() {
} else { @Override
selectedItems.clear(); public void onClick(View v) {
checkBox.performClick();
boolean checked = checkBox.getState() == CHECKED;
if (checked) {
selectedItems.addAll(allItems);
} else {
selectedItems.clear();
}
onSelectedItemsChanged();
updateItems(checked);
} }
onSelectedItemsChanged(); });
updateItems(checked); }
}
}); if (!Algorithms.isEmpty(addDescriptionText)) {
addDescription.setText(addDescriptionText);
AndroidUiHelper.setVisibility(View.VISIBLE, addDescription);
}
if (customOptionsVisible) {
AndroidUiHelper.setVisibility(View.VISIBLE, customRadioButtons);
RadioItem leftRadioButton = new RadioItem(leftRadioButtonText);
RadioItem rightRadioButton = new RadioItem(rightRadioButtonText);
MultiStateToggleButton toggleButtons =
new MultiStateToggleButton(app, customRadioButtons, nightMode);
toggleButtons.setItems(leftRadioButton, rightRadioButton);
toggleButtons.updateView(true);
leftRadioButton.setOnClickListener(new OnRadioItemClickListener() {
@Override
public boolean onRadioItemClick(RadioItem radioItem, View view) {
onRadioButtonSelectListener.onSelect(leftButtonSelected = true);
updateSelectedSizeView();
updateSelectAllButton();
updateApplyButtonEnable();
return true;
}
});
rightRadioButton.setOnClickListener(new OnRadioItemClickListener() {
@Override
public boolean onRadioItemClick(RadioItem radioItem, View view) {
onRadioButtonSelectListener.onSelect(leftButtonSelected = false);
updateSelectedSizeView();
updateSelectAllButton();
updateApplyButtonEnable();
return true;
}
});
toggleButtons.setSelectedItem(leftButtonSelected ? leftRadioButton : rightRadioButton);
}
return new SimpleBottomSheetItem.Builder().setCustomView(view).create(); return new SimpleBottomSheetItem.Builder().setCustomView(view).create();
} }
private void createListItems() { private void createListItems() {
for (final SelectableItem item : allItems) { if (isMultipleItem()) {
boolean checked = selectedItems.contains(item); for (int i = 0; i < allItems.size(); i++) {
final BottomSheetItemWithCompoundButton[] uiItem = new BottomSheetItemWithCompoundButton[1]; final SelectableItem item = allItems.get(i);
final Builder builder = (BottomSheetItemWithCompoundButton.Builder) new Builder(); boolean checked = selectedItems.contains(item);
builder.setChecked(checked) final int finalI = i;
.setButtonTintList(AndroidUtils.createCheckedColorStateList(app, secondaryColorRes, activeColorRes)) items.add(new Builder()
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp) .setChecked(checked)
.setOnClickListener(new View.OnClickListener() { .setButtonTintList(AndroidUtils.createCheckedColorStateList(app, secondaryColorRes, activeColorRes))
@Override .setDescription(item.description)
public void onClick(View v) { .setIcon(uiUtilities.getIcon(item.iconId, activeColorRes))
boolean checked = !uiItem[0].isChecked(); .setTitle(item.title)
uiItem[0].setChecked(checked); .setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp)
SelectableItem tag = (SelectableItem) uiItem[0].getTag(); .setTag(item)
if (checked) { .setOnClickListener(new View.OnClickListener() {
selectedItems.add(tag); @Override
} else { public void onClick(View view) {
selectedItems.remove(tag); BottomSheetItemWithCompoundButton item = (BottomSheetItemWithCompoundButton) items.get(finalI + sizeAboveList);
boolean checked = item.isChecked();
item.setChecked(!checked);
SelectableItem tag = (SelectableItem) item.getTag();
if (!checked) {
selectedItems.add(tag);
} else {
selectedItems.remove(tag);
}
onSelectedItemsChanged();
} }
onSelectedItemsChanged(); })
} .create());
}) }
.setTag(item); } else if (allItems.size() == 1) {
setupListItem(builder, item); final SelectableItem item = allItems.get(0);
uiItem[0] = builder.create(); items.add(new Builder()
items.add(uiItem[0]); .setDescription(item.description)
.setDescriptionColorId(AndroidUtils.getSecondaryTextColorId(nightMode))
.setIcon(uiUtilities.getIcon(item.iconId, activeColorRes))
.setTitle(item.title)
.setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp)
.setTag(item)
.create());
} }
} }
@Override
protected void setupRightButton() {
super.setupRightButton();
applyButtonTitle = rightButton.findViewById(R.id.button_text);
}
@Override
protected void onRightBottomButtonClick() {
if (onApplySelectionListener != null) {
onApplySelectionListener.onSelectionApplied(selectedItems);
}
dismiss();
}
private void onSelectedItemsChanged() { private void onSelectedItemsChanged() {
updateSelectAllButton(); updateSelectAllButton();
updateSelectedSizeView(); updateSelectedSizeView();
@ -154,48 +259,32 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
} }
} }
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_apply;
}
@Override
protected boolean useVerticalButtons() {
return true;
}
private void setupListItem(Builder builder, SelectableItem item) {
builder.setTitle(item.title);
builder.setDescription(item.description);
builder.setIcon(uiUtilities.getIcon(item.iconId, activeColorRes));
}
private void updateSelectAllButton() { private void updateSelectAllButton() {
String checkBoxTitle; if (isMultipleItem()) {
if (Algorithms.isEmpty(selectedItems)) { String checkBoxTitle;
checkBox.setState(UNCHECKED); if (Algorithms.isEmpty(selectedItems)) {
checkBoxTitle = getString(R.string.shared_string_select_all); checkBox.setState(UNCHECKED);
} else { checkBoxTitle = getString(R.string.shared_string_select_all);
checkBox.setState(selectedItems.containsAll(allItems) ? CHECKED : MISC); } else {
checkBoxTitle = getString(R.string.shared_string_deselect_all); checkBox.setState(selectedItems.containsAll(allItems) ? CHECKED : MISC);
checkBoxTitle = getString(R.string.shared_string_deselect_all);
}
int checkBoxColor = checkBox.getState() == UNCHECKED ? secondaryColorRes : activeColorRes;
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, checkBoxColor)));
this.checkBoxTitle.setText(checkBoxTitle);
} }
int checkBoxColor = checkBox.getState() == UNCHECKED ? secondaryColorRes : activeColorRes;
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, checkBoxColor)));
this.checkBoxTitle.setText(checkBoxTitle);
} }
private void updateSelectedSizeView() { private void updateSelectedSizeView() {
String selected = String.valueOf(selectedItems.size()); if (isMultipleItem()) {
String all = String.valueOf(allItems.size()); String selected = String.valueOf(selectedItems.size());
selectedSize.setText(getString(R.string.ltr_or_rtl_combine_via_slash, selected, all)); String all = String.valueOf(allItems.size());
selectedSize.setText(getString(R.string.ltr_or_rtl_combine_via_slash, selected, all));
}
} }
private void updateApplyButtonEnable() { private void updateApplyButtonEnable() {
if (Algorithms.isEmpty(selectedItems)) { rightButton.setEnabled(!Algorithms.isEmpty(selectedItems));
rightButton.setEnabled(false);
} else {
rightButton.setEnabled(true);
}
} }
private void updateItems(boolean checked) { private void updateItems(boolean checked) {
@ -206,6 +295,59 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
} }
} }
public void setItems(List<SelectableItem> allItems) {
this.allItems.clear();
if (!Algorithms.isEmpty(allItems)) {
this.allItems.addAll(allItems);
}
}
private void setSelectedItems(List<SelectableItem> selected) {
this.selectedItems.clear();
if (!Algorithms.isEmpty(selected)) {
/*List<SelectableItem> prevDownloadItems = new ArrayList<>(this.selectedItems);
for (SelectableItem prevDownloadItem : selected) {
Object object = prevDownloadItem.getObject();
if (object instanceof IndexItem && ((IndexItem) object).isDownloaded()) {
prevDownloadItems.add(prevDownloadItem);
}
}
selected.removeAll(prevDownloadItems);*/
this.selectedItems.addAll(selected);
}
}
public void recreateList(List<SelectableItem> allItems) {
setItems(allItems);
if (selectedItemsListener != null) {
setSelectedItems(selectedItemsListener.createSelectedItems(this.allItems, leftButtonSelected));
}
if (items.size() > sizeAboveList) {
for (int i = 0; i < this.allItems.size(); i++) {
SelectableItem item = this.allItems.get(i);
BottomSheetItemWithDescription button = (BottomSheetItemWithDescription) items.get(i + sizeAboveList);
button.setDescription(item.description);
button.setTitle(item.title);
button.setTag(item);
if (isMultipleItem()) {
((BottomSheetItemWithCompoundButton) button).setChecked(selectedItems.contains(item));
}
}
}
}
public boolean isMultipleItem() {
return allItems.size() > 1;
}
public List<SelectableItem> getSelectedItems() {
return selectedItems;
}
public void setConfirmButtonTitle(@NonNull String confirmButtonTitle) {
applyButtonTitle.setText(confirmButtonTitle);
}
public void setTitle(@NonNull String title) { public void setTitle(@NonNull String title) {
this.title.setText(title); this.title.setText(title);
} }
@ -214,45 +356,24 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
this.description.setText(description); this.description.setText(description);
} }
public void setConfirmButtonTitle(@NonNull String confirmButtonTitle) { public void setAddDescriptionText(String addDescriptionText) {
applyButtonTitle.setText(confirmButtonTitle); this.addDescriptionText = addDescriptionText;
} }
private void setItems(List<SelectableItem> allItems) { public void setLeftRadioButtonText(String leftRadioButtonText) {
if (!Algorithms.isEmpty(allItems)) { this.leftRadioButtonText = leftRadioButtonText;
this.allItems.addAll(allItems);
}
} }
private void setSelectedItems(List<SelectableItem> selected) { public void setRightRadioButtonText(String rightRadioButtonText) {
if (!Algorithms.isEmpty(selected)) { this.rightRadioButtonText = rightRadioButtonText;
this.selectedItems.addAll(selected);
}
} }
public List<SelectableItem> getSelectedItems() { public void setCustomOptionsVisible(boolean customOptionsVisible) {
return selectedItems; this.customOptionsVisible = customOptionsVisible;
} }
@Override public void setLeftButtonSelected(boolean leftButtonSelected) {
public void onPause() { this.leftButtonSelected = leftButtonSelected;
super.onPause();
if (requireActivity().isChangingConfigurations()) {
dismiss();
}
}
public static SelectMultipleItemsBottomSheet showInstance(@NonNull AppCompatActivity activity,
@NonNull List<SelectableItem> items,
@Nullable List<SelectableItem> selected,
boolean usedOnMap) {
SelectMultipleItemsBottomSheet fragment = new SelectMultipleItemsBottomSheet();
fragment.setUsedOnMap(usedOnMap);
fragment.setItems(items);
fragment.setSelectedItems(selected);
FragmentManager fm = activity.getSupportFragmentManager();
fragment.show(fm, TAG);
return fragment;
} }
public void setSelectionUpdateListener(SelectionUpdateListener selectionUpdateListener) { public void setSelectionUpdateListener(SelectionUpdateListener selectionUpdateListener) {
@ -263,6 +384,14 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
this.onApplySelectionListener = onApplySelectionListener; this.onApplySelectionListener = onApplySelectionListener;
} }
public void setOnRadioButtonSelectListener(OnRadioButtonSelectListener onRadioButtonSelectListener) {
this.onRadioButtonSelectListener = onRadioButtonSelectListener;
}
public void setSelectedItemsListener(SelectedItemsListener selectedItemsListener) {
this.selectedItemsListener = selectedItemsListener;
}
public interface SelectionUpdateListener { public interface SelectionUpdateListener {
void onSelectionUpdate(); void onSelectionUpdate();
} }
@ -271,6 +400,10 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
void onSelectionApplied(List<SelectableItem> selectedItems); void onSelectionApplied(List<SelectableItem> selectedItems);
} }
public interface OnRadioButtonSelectListener {
void onSelect(boolean leftButton);
}
public static class SelectableItem { public static class SelectableItem {
private String title; private String title;
private String description; private String description;
@ -281,6 +414,10 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
this.title = title; this.title = title;
} }
public String getDescription() {
return description;
}
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
@ -298,4 +435,27 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
} }
} }
@Override
protected void setupRightButton() {
super.setupRightButton();
applyButtonTitle = rightButton.findViewById(R.id.button_text);
}
@Override
protected void onRightBottomButtonClick() {
if (onApplySelectionListener != null) {
onApplySelectionListener.onSelectionApplied(selectedItems);
}
dismiss();
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_apply;
}
@Override
protected boolean useVerticalButtons() {
return true;
}
} }

View file

@ -32,6 +32,10 @@ public class BaseBottomSheetItem {
return tag; return tag;
} }
public void setTag(Object tag) {
this.tag = tag;
}
public BaseBottomSheetItem(View view, public BaseBottomSheetItem(View view,
@LayoutRes int layoutId, @LayoutRes int layoutId,
Object tag, Object tag,

View file

@ -10,6 +10,7 @@ import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -27,6 +28,8 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import static net.osmand.IndexConstants.BINARY_MAP_INDEX_EXT; import static net.osmand.IndexConstants.BINARY_MAP_INDEX_EXT;
import static net.osmand.plus.activities.LocalIndexHelper.LocalIndexType.SRTM_DATA;
import static net.osmand.plus.download.MultipleIndexesUiHelper.getSRTMExt;
public class DownloadActivityType { public class DownloadActivityType {
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.US); private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.US);
@ -83,7 +86,7 @@ public class DownloadActivityType {
iconResource = R.drawable.ic_map; iconResource = R.drawable.ic_map;
} }
public int getStringResource(){ public int getStringResource() {
return stringResource; return stringResource;
} }
@ -101,7 +104,7 @@ public class DownloadActivityType {
public static boolean isCountedInDownloads(IndexItem es) { public static boolean isCountedInDownloads(IndexItem es) {
DownloadActivityType tp = es.getType(); DownloadActivityType tp = es.getType();
if(tp == NORMAL_FILE || tp == ROADS_FILE){ if (tp == NORMAL_FILE || tp == ROADS_FILE) {
if (!es.extra) { if (!es.extra) {
return true; return true;
} }
@ -126,11 +129,11 @@ public class DownloadActivityType {
} }
public boolean isAccepted(String fileName) { public boolean isAccepted(String fileName) {
if(NORMAL_FILE == this) { if (NORMAL_FILE == this) {
return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION)) return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION))
|| fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT) || fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)
|| fileName.endsWith(IndexConstants.SQLITE_EXT); || fileName.endsWith(IndexConstants.SQLITE_EXT);
} else if(ROADS_FILE == this) { } else if (ROADS_FILE == this) {
return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION)); return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_ROAD_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION));
} else if (VOICE_FILE == this) { } else if (VOICE_FILE == this) {
return fileName.endsWith(addVersionToExt(IndexConstants.VOICE_INDEX_EXT_ZIP, IndexConstants.VOICE_VERSION)); return fileName.endsWith(addVersionToExt(IndexConstants.VOICE_INDEX_EXT_ZIP, IndexConstants.VOICE_VERSION));
@ -145,8 +148,9 @@ public class DownloadActivityType {
return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT_ZIP, return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT_ZIP,
IndexConstants.BINARY_MAP_VERSION)); IndexConstants.BINARY_MAP_VERSION));
} else if (SRTM_COUNTRY_FILE == this) { } else if (SRTM_COUNTRY_FILE == this) {
return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP, boolean srtm = fileName.endsWith(addVersionToExt(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION));
IndexConstants.BINARY_MAP_VERSION)); boolean srtmf = fileName.endsWith(addVersionToExt(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION));
return srtm || srtmf;
} else if (HILLSHADE_FILE == this) { } else if (HILLSHADE_FILE == this) {
return fileName.endsWith(IndexConstants.SQLITE_EXT); return fileName.endsWith(IndexConstants.SQLITE_EXT);
} else if (SLOPE_FILE == this) { } else if (SLOPE_FILE == this) {
@ -196,7 +200,7 @@ public class DownloadActivityType {
} }
public boolean isZipStream(OsmandApplication ctx, IndexItem indexItem) { public boolean isZipStream(OsmandApplication ctx, IndexItem indexItem) {
return HILLSHADE_FILE != this && SLOPE_FILE != this && SQLITE_FILE != this && WIKIVOYAGE_FILE != this && GPX_FILE != this; return HILLSHADE_FILE != this && SLOPE_FILE != this && SQLITE_FILE != this && WIKIVOYAGE_FILE != this && GPX_FILE != this;
} }
public boolean isZipFolder(OsmandApplication ctx, IndexItem indexItem) { public boolean isZipFolder(OsmandApplication ctx, IndexItem indexItem) {
@ -217,7 +221,7 @@ public class DownloadActivityType {
return IndexConstants.EXTRA_EXT; return IndexConstants.EXTRA_EXT;
} else if (indexItem.fileName.endsWith(IndexConstants.SQLITE_EXT)) { } else if (indexItem.fileName.endsWith(IndexConstants.SQLITE_EXT)) {
return IndexConstants.SQLITE_EXT; return IndexConstants.SQLITE_EXT;
} else if (indexItem.fileName.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){ } else if (indexItem.fileName.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)) {
return ""; return "";
} }
} else if (ROADS_FILE == this) { } else if (ROADS_FILE == this) {
@ -227,7 +231,7 @@ public class DownloadActivityType {
} else if (FONT_FILE == this) { } else if (FONT_FILE == this) {
return IndexConstants.FONT_INDEX_EXT; return IndexConstants.FONT_INDEX_EXT;
} else if (SRTM_COUNTRY_FILE == this) { } else if (SRTM_COUNTRY_FILE == this) {
return IndexConstants.BINARY_SRTM_MAP_INDEX_EXT; return getSRTMExt(indexItem);
} else if (WIKIPEDIA_FILE == this) { } else if (WIKIPEDIA_FILE == this) {
return IndexConstants.BINARY_WIKI_MAP_INDEX_EXT; return IndexConstants.BINARY_WIKI_MAP_INDEX_EXT;
} else if (WIKIVOYAGE_FILE == this) { } else if (WIKIVOYAGE_FILE == this) {
@ -251,7 +255,7 @@ public class DownloadActivityType {
} }
public String getUrlSuffix(OsmandApplication ctx) { public String getUrlSuffix(OsmandApplication ctx) {
if (this== ROADS_FILE) { if (this == ROADS_FILE) {
return "&road=yes"; return "&road=yes";
} else if (this == LIVE_UPDATES_FILE) { } else if (this == LIVE_UPDATES_FILE) {
return "&aosmc=yes"; return "&aosmc=yes";
@ -280,7 +284,7 @@ public class DownloadActivityType {
public String getBaseUrl(OsmandApplication ctx, String fileName) { public String getBaseUrl(OsmandApplication ctx, String fileName) {
String url = "https://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN + "/download?event=2&" String url = "https://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN + "/download?event=2&"
+ Version.getVersionAsURLParam(ctx) + "&file=" + encode(fileName); + Version.getVersionAsURLParam(ctx) + "&file=" + encode(fileName);
if(this == LIVE_UPDATES_FILE && fileName.length() > 16) { if (this == LIVE_UPDATES_FILE && fileName.length() > 16) {
// DATE_AND_EXT_STR_LEN = "_18_06_02.obf.gz".length() // DATE_AND_EXT_STR_LEN = "_18_06_02.obf.gz".length()
String region = fileName.substring(0, fileName.length() - 16).toLowerCase(); String region = fileName.substring(0, fileName.length() - 16).toLowerCase();
url += "&region=" + encode(region); url += "&region=" + encode(region);
@ -423,7 +427,7 @@ public class DownloadActivityType {
} }
String baseNameWithoutVersion = fileName.substring(0, l); String baseNameWithoutVersion = fileName.substring(0, l);
if (this == SRTM_COUNTRY_FILE) { if (this == SRTM_COUNTRY_FILE) {
return baseNameWithoutVersion + IndexConstants.BINARY_SRTM_MAP_INDEX_EXT; return baseNameWithoutVersion + getSRTMExt(item);
} }
if (this == WIKIPEDIA_FILE) { if (this == WIKIPEDIA_FILE) {
return baseNameWithoutVersion + IndexConstants.BINARY_WIKI_MAP_INDEX_EXT; return baseNameWithoutVersion + IndexConstants.BINARY_WIKI_MAP_INDEX_EXT;
@ -487,7 +491,7 @@ public class DownloadActivityType {
return fileName.substring(0, l); return fileName.substring(0, l);
} }
if (this == LIVE_UPDATES_FILE) { if (this == LIVE_UPDATES_FILE) {
if(fileName.indexOf('.') > 0){ if (fileName.indexOf('.') > 0) {
return fileName.substring(0, fileName.indexOf('.')); return fileName.substring(0, fileName.indexOf('.'));
} }
return fileName; return fileName;
@ -495,10 +499,20 @@ public class DownloadActivityType {
int ls = fileName.lastIndexOf('_'); int ls = fileName.lastIndexOf('_');
if (ls >= 0) { if (ls >= 0) {
return fileName.substring(0, ls); return fileName.substring(0, ls);
} else if(fileName.indexOf('.') > 0){ } else if (fileName.indexOf('.') > 0) {
return fileName.substring(0, fileName.indexOf('.')); return fileName.substring(0, fileName.indexOf('.'));
} }
return fileName; return fileName;
} }
public static boolean isSRTMItem(Object item) {
if (item instanceof IndexItem) {
return ((IndexItem) item).getType() == SRTM_COUNTRY_FILE;
} else if (item instanceof DownloadItem) {
return ((DownloadItem) item).getType() == SRTM_COUNTRY_FILE;
} else if (item instanceof LocalIndexInfo) {
return ((LocalIndexInfo) item).getType() == SRTM_DATA;
}
return false;
}
} }

View file

@ -1,5 +1,26 @@
package net.osmand.plus.download; package net.osmand.plus.download;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetManager;
import android.provider.Settings.Secure;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -11,26 +32,6 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetManager;
import android.provider.Settings.Secure;
public class DownloadOsmandIndexesHelper { public class DownloadOsmandIndexesHelper {
private final static Log log = PlatformUtil.getLog(DownloadOsmandIndexesHelper.class); private final static Log log = PlatformUtil.getLog(DownloadOsmandIndexesHelper.class);
@ -42,18 +43,18 @@ public class DownloadOsmandIndexesHelper {
ArrayList<IndexItem> indexFiles = new ArrayList<IndexItem>(); ArrayList<IndexItem> indexFiles = new ArrayList<IndexItem>();
private String mapversion; private String mapversion;
private Comparator<IndexItem> comparator = new Comparator<IndexItem>(){ private Comparator<IndexItem> comparator = new Comparator<IndexItem>() {
@Override @Override
public int compare(IndexItem o1, IndexItem o2) { public int compare(IndexItem o1, IndexItem o2) {
String object1 = o1.getFileName(); String object1 = o1.getFileName();
String object2 = o2.getFileName(); String object2 = o2.getFileName();
if(object1.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){ if (object1.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)) {
if(object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){ if (object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)) {
return object1.compareTo(object2); return object1.compareTo(object2);
} else { } else {
return -1; return -1;
} }
} else if(object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){ } else if (object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)) {
return 1; return 1;
} }
return object1.compareTo(object2); return object1.compareTo(object2);
@ -75,12 +76,12 @@ public class DownloadOsmandIndexesHelper {
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
public void add(IndexItem indexItem) { public void add(IndexItem indexItem) {
indexFiles.add(indexItem); indexFiles.add(indexItem);
if(indexItem.getFileName().toLowerCase().startsWith("world_basemap")) { if (indexItem.getFileName().toLowerCase().startsWith("world_basemap")) {
basemap = indexItem; basemap = indexItem;
} }
} }
public void sort(){ public void sort() {
Collections.sort(indexFiles, comparator); Collections.sort(indexFiles, comparator);
} }
@ -141,7 +142,7 @@ public class DownloadOsmandIndexesHelper {
} }
private static void listVoiceAssets(IndexFileList result, AssetManager amanager, PackageManager pm, private static void listVoiceAssets(IndexFileList result, AssetManager amanager, PackageManager pm,
OsmandSettings settings) { OsmandSettings settings) {
try { try {
File voicePath = settings.getContext().getAppPath(IndexConstants.VOICE_INDEX_DIR); File voicePath = settings.getContext().getAppPath(IndexConstants.VOICE_INDEX_DIR);
// list = amanager.list("voice"); // list = amanager.list("voice");
@ -150,7 +151,7 @@ public class DownloadOsmandIndexesHelper {
try { try {
OsmandApplication app = settings.getContext(); OsmandApplication app = settings.getContext();
ApplicationInfo appInfo = pm.getApplicationInfo(app.getPackageName(), 0); ApplicationInfo appInfo = pm.getApplicationInfo(app.getPackageName(), 0);
dateModified = new File(appInfo.sourceDir).lastModified(); dateModified = new File(appInfo.sourceDir).lastModified();
date = AndroidUtils.formatDate((Context) settings.getContext(), dateModified); date = AndroidUtils.formatDate((Context) settings.getContext(), dateModified);
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
log.error(e); log.error(e);
@ -179,14 +180,14 @@ public class DownloadOsmandIndexesHelper {
} }
private static IndexFileList downloadIndexesListFromInternet(OsmandApplication ctx){ private static IndexFileList downloadIndexesListFromInternet(OsmandApplication ctx) {
try { try {
IndexFileList result = new IndexFileList(); IndexFileList result = new IndexFileList();
log.debug("Start loading list of index files"); //$NON-NLS-1$ log.debug("Start loading list of index files"); //$NON-NLS-1$
try { try {
String strUrl = ctx.getAppCustomization().getIndexesUrl(); String strUrl = ctx.getAppCustomization().getIndexesUrl();
long nd = ctx.getAppInitializer().getFirstInstalledDays(); long nd = ctx.getAppInitializer().getFirstInstalledDays();
if(nd > 0) { if (nd > 0) {
strUrl += "&nd=" + nd; strUrl += "&nd=" + nd;
} }
strUrl += "&ns=" + ctx.getAppInitializer().getNumberOfStarts(); strUrl += "&ns=" + ctx.getAppInitializer().getNumberOfStarts();
@ -202,12 +203,15 @@ public class DownloadOsmandIndexesHelper {
GZIPInputStream gzin = new GZIPInputStream(in); GZIPInputStream gzin = new GZIPInputStream(in);
parser.setInput(gzin, "UTF-8"); //$NON-NLS-1$ parser.setInput(gzin, "UTF-8"); //$NON-NLS-1$
int next; int next;
while((next = parser.next()) != XmlPullParser.END_DOCUMENT) { while ((next = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (next == XmlPullParser.START_TAG) { if (next == XmlPullParser.START_TAG) {
DownloadActivityType tp = DownloadActivityType.getIndexType(parser.getAttributeValue(null, "type")); DownloadActivityType tp = DownloadActivityType.getIndexType(parser.getAttributeValue(null, "type"));
if (tp != null) { if (tp != null) {
if (tp == DownloadActivityType.SRTM_COUNTRY_FILE) {
log.debug("strUrl = " + strUrl);
}
IndexItem it = tp.parseIndexItem(ctx, parser); IndexItem it = tp.parseIndexItem(ctx, parser);
if(it != null) { if (it != null) {
result.add(it); result.add(it);
} }
} else if ("osmand_regions".equals(parser.getName())) { } else if ("osmand_regions".equals(parser.getName())) {
@ -245,7 +249,7 @@ public class DownloadOsmandIndexesHelper {
private final long dateModified; private final long dateModified;
public AssetIndexItem(String fileName, String description, String date, public AssetIndexItem(String fileName, String description, String date,
long dateModified, String size, long sizeL, String assetName, String destFile, DownloadActivityType type) { long dateModified, String size, long sizeL, String assetName, String destFile, DownloadActivityType type) {
super(fileName, description, dateModified, size, sizeL, sizeL, type); super(fileName, description, dateModified, size, sizeL, sizeL, type);
this.dateModified = dateModified; this.dateModified = dateModified;
this.assetName = assetName; this.assetName = assetName;
@ -261,7 +265,7 @@ public class DownloadOsmandIndexesHelper {
return new DownloadEntry(assetName, destFile, dateModified); return new DownloadEntry(assetName, destFile, dateModified);
} }
public String getDestFile(){ public String getDestFile() {
return destFile; return destFile;
} }
} }

View file

@ -264,7 +264,7 @@ public class DownloadResources extends DownloadResourceGroup {
} }
private Map<String, String> listWithAlternatives(final java.text.DateFormat dateFormat, File file, private Map<String, String> listWithAlternatives(final java.text.DateFormat dateFormat, File file,
final String ext, final Map<String, String> files) { final String ext, final Map<String, String> files) {
if (file.isDirectory()) { if (file.isDirectory()) {
file.list(new FilenameFilter() { file.list(new FilenameFilter() {
@Override @Override
@ -518,7 +518,7 @@ public class DownloadResources extends DownloadResourceGroup {
@Nullable @Nullable
private List<IndexItem> collectIndexesOfType(@NonNull List<WorldRegion> regions, private List<IndexItem> collectIndexesOfType(@NonNull List<WorldRegion> regions,
@NonNull DownloadActivityType type) { @NonNull DownloadActivityType type) {
List<IndexItem> collectedIndexes = new ArrayList<>(); List<IndexItem> collectedIndexes = new ArrayList<>();
for (WorldRegion region : regions) { for (WorldRegion region : regions) {
List<IndexItem> regionIndexes = getIndexItems(region); List<IndexItem> regionIndexes = getIndexItems(region);
@ -528,7 +528,6 @@ public class DownloadResources extends DownloadResourceGroup {
if (index.getType() == type) { if (index.getType() == type) {
found = true; found = true;
collectedIndexes.add(index); collectedIndexes.add(index);
break;
} }
} }
} }
@ -646,10 +645,10 @@ public class DownloadResources extends DownloadResourceGroup {
} }
public static List<IndexItem> findIndexItemsAt(OsmandApplication app, public static List<IndexItem> findIndexItemsAt(OsmandApplication app,
List<String> names, List<String> names,
DownloadActivityType type, DownloadActivityType type,
boolean includeDownloaded, boolean includeDownloaded,
int limit) { int limit) {
List<IndexItem> res = new ArrayList<>(); List<IndexItem> res = new ArrayList<>();
OsmandRegions regions = app.getRegions(); OsmandRegions regions = app.getRegions();
DownloadIndexesThread downloadThread = app.getDownloadThread(); DownloadIndexesThread downloadThread = app.getDownloadThread();
@ -666,9 +665,9 @@ public class DownloadResources extends DownloadResourceGroup {
} }
private static boolean isIndexItemDownloaded(DownloadIndexesThread downloadThread, private static boolean isIndexItemDownloaded(DownloadIndexesThread downloadThread,
DownloadActivityType type, DownloadActivityType type,
WorldRegion downloadRegion, WorldRegion downloadRegion,
List<IndexItem> res) { List<IndexItem> res) {
List<IndexItem> otherIndexItems = List<IndexItem> otherIndexItems =
new ArrayList<>(downloadThread.getIndexes().getIndexItems(downloadRegion)); new ArrayList<>(downloadThread.getIndexes().getIndexItems(downloadRegion));
for (IndexItem indexItem : otherIndexItems) { for (IndexItem indexItem : otherIndexItems) {
@ -681,7 +680,7 @@ public class DownloadResources extends DownloadResourceGroup {
} }
private boolean doesListContainIndexWithType(List<IndexItem> indexItems, private boolean doesListContainIndexWithType(List<IndexItem> indexItems,
DownloadActivityType type) { DownloadActivityType type) {
if (indexItems != null) { if (indexItems != null) {
for (IndexItem indexItem : indexItems) { for (IndexItem indexItem : indexItems) {
if (indexItem.getType() == type) { if (indexItem.getType() == type) {
@ -693,9 +692,9 @@ public class DownloadResources extends DownloadResourceGroup {
} }
private static boolean addIndexItem(DownloadIndexesThread downloadThread, private static boolean addIndexItem(DownloadIndexesThread downloadThread,
DownloadActivityType type, DownloadActivityType type,
WorldRegion downloadRegion, WorldRegion downloadRegion,
List<IndexItem> res) { List<IndexItem> res) {
List<IndexItem> otherIndexItems = List<IndexItem> otherIndexItems =
new ArrayList<>(downloadThread.getIndexes().getIndexItems(downloadRegion)); new ArrayList<>(downloadThread.getIndexes().getIndexItems(downloadRegion));
for (IndexItem indexItem : otherIndexItems) { for (IndexItem indexItem : otherIndexItems) {

View file

@ -1,5 +1,7 @@
package net.osmand.plus.download; package net.osmand.plus.download;
import android.content.Context;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import net.osmand.map.WorldRegion; import net.osmand.map.WorldRegion;
@ -9,13 +11,16 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE;
import static net.osmand.plus.download.MultipleIndexesUiHelper.isBaseSRTMItem;
public class MultipleIndexItem extends DownloadItem { public class MultipleIndexItem extends DownloadItem {
private final List<IndexItem> items; private final List<IndexItem> items;
public MultipleIndexItem(@NonNull WorldRegion region, public MultipleIndexItem(@NonNull WorldRegion region,
@NonNull List<IndexItem> items, @NonNull List<IndexItem> items,
@NonNull DownloadActivityType type) { @NonNull DownloadActivityType type) {
super(type); super(type);
this.items = items; this.items = items;
} }
@ -110,6 +115,22 @@ public class MultipleIndexItem extends DownloadItem {
return totalSizeMb; return totalSizeMb;
} }
@NonNull
public String getSizeDescription(Context ctx, boolean baseSRTM) {
double totalSizeMb = 0.0d;
if (this.type == SRTM_COUNTRY_FILE) {
for (IndexItem item : items) {
if (item.hasActualDataToDownload()) {
if (baseSRTM && isBaseSRTMItem(item) || !baseSRTM && !isBaseSRTMItem(item)) {
totalSizeMb += item.getSizeToDownloadInMb();
}
}
}
return getFormattedMb(ctx, totalSizeMb);
}
return getFormattedMb(ctx, getSizeToDownloadInMb());
}
@Override @Override
public double getArchiveSizeMB() { public double getArchiveSizeMB() {
double result = 0.0d; double result = 0.0d;
@ -118,5 +139,4 @@ public class MultipleIndexItem extends DownloadItem {
} }
return result; return result;
} }
} }

View file

@ -1,28 +1,52 @@
package net.osmand.plus.download; package net.osmand.plus.download;
import android.content.Context;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import net.osmand.IndexConstants;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.base.SelectMultipleItemsBottomSheet; import net.osmand.plus.base.SelectMultipleItemsBottomSheet;
import net.osmand.plus.base.SelectMultipleItemsBottomSheet.OnApplySelectionListener; import net.osmand.plus.base.SelectMultipleItemsBottomSheet.OnApplySelectionListener;
import net.osmand.plus.base.SelectMultipleItemsBottomSheet.OnRadioButtonSelectListener;
import net.osmand.plus.base.SelectMultipleItemsBottomSheet.SelectableItem; import net.osmand.plus.base.SelectMultipleItemsBottomSheet.SelectableItem;
import net.osmand.plus.base.SelectMultipleItemsBottomSheet.SelectionUpdateListener; import net.osmand.plus.base.SelectMultipleItemsBottomSheet.SelectionUpdateListener;
import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.util.Algorithms;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static net.osmand.IndexConstants.BINARY_SRTM_MAP_INDEX_EXT;
import static net.osmand.IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP;
import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE;
public class MultipleIndexesUiHelper { public class MultipleIndexesUiHelper {
public static void showDialog(@NonNull MultipleIndexItem multipleIndexItem, public static void showDialog(@NonNull DownloadItem item,
@NonNull AppCompatActivity activity, @NonNull AppCompatActivity activity,
@NonNull final OsmandApplication app, @NonNull final OsmandApplication app,
@NonNull DateFormat dateFormat, @NonNull DateFormat dateFormat,
boolean showRemoteDate, boolean showRemoteDate,
@NonNull final SelectItemsToDownloadListener listener) { @NonNull final SelectItemsToDownloadListener listener) {
if (item.getType() == SRTM_COUNTRY_FILE) {
showSRTMDialog(item, activity, app, dateFormat, showRemoteDate, listener);
} else if (item instanceof MultipleIndexItem) {
showBaseDialog((MultipleIndexItem) item, activity, app, dateFormat, showRemoteDate, listener);
}
}
public static void showBaseDialog(@NonNull MultipleIndexItem multipleIndexItem,
@NonNull AppCompatActivity activity,
@NonNull final OsmandApplication app,
@NonNull DateFormat dateFormat,
boolean showRemoteDate,
@NonNull final SelectItemsToDownloadListener listener) {
List<IndexItem> indexesToDownload = getIndexesToDownload(multipleIndexItem); List<IndexItem> indexesToDownload = getIndexesToDownload(multipleIndexItem);
List<SelectableItem> allItems = new ArrayList<>(); List<SelectableItem> allItems = new ArrayList<>();
List<SelectableItem> selectedItems = new ArrayList<>(); List<SelectableItem> selectedItems = new ArrayList<>();
@ -30,12 +54,10 @@ public class MultipleIndexesUiHelper {
for (IndexItem indexItem : multipleIndexItem.getAllIndexes()) { for (IndexItem indexItem : multipleIndexItem.getAllIndexes()) {
SelectableItem selectableItem = new SelectableItem(); SelectableItem selectableItem = new SelectableItem();
selectableItem.setTitle(indexItem.getVisibleName(app, osmandRegions, false)); selectableItem.setTitle(indexItem.getVisibleName(app, osmandRegions, false));
String size = indexItem.getSizeDescription(app); String size = indexItem.getSizeDescription(app);
String date = indexItem.getDate(dateFormat, showRemoteDate); String date = indexItem.getDate(dateFormat, showRemoteDate);
String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date); String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date);
selectableItem.setDescription(description); selectableItem.setDescription(description);
selectableItem.setIconId(indexItem.getType().getIconResource()); selectableItem.setIconId(indexItem.getType().getIconResource());
selectableItem.setObject(indexItem); selectableItem.setObject(indexItem);
allItems.add(selectableItem); allItems.add(selectableItem);
@ -51,22 +73,102 @@ public class MultipleIndexesUiHelper {
dialog.setSelectionUpdateListener(new SelectionUpdateListener() { dialog.setSelectionUpdateListener(new SelectionUpdateListener() {
@Override @Override
public void onSelectionUpdate() { public void onSelectionUpdate() {
dialog.setTitle(app.getString(R.string.welmode_download_maps)); updateSize(app, dialog);
String total = app.getString(R.string.shared_string_total);
double sizeToDownload = getDownloadSizeInMb(dialog.getSelectedItems());
String size = DownloadItem.getFormattedMb(app, sizeToDownload);
String description =
app.getString(R.string.ltr_or_rtl_combine_via_colon, total, size);
dialog.setDescription(description);
String btnTitle = app.getString(R.string.shared_string_download);
if (sizeToDownload > 0) {
btnTitle = app.getString(R.string.ltr_or_rtl_combine_via_dash, btnTitle, size);
}
dialog.setConfirmButtonTitle(btnTitle);
} }
}); });
dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
}
dialog.setOnApplySelectionListener(new OnApplySelectionListener() { public static void showSRTMDialog(@NonNull final DownloadItem downloadItem,
@NonNull AppCompatActivity activity,
@NonNull final OsmandApplication app,
@NonNull final DateFormat dateFormat,
final boolean showRemoteDate,
@NonNull final SelectItemsToDownloadListener listener) {
List<SelectableItem> selectedItems = new ArrayList<>();
final List<SelectableItem> leftItems = new ArrayList<>();
final List<SelectableItem> rightItems = new ArrayList<>();
List<IndexItem> indexesToDownload = getIndexesToDownload(downloadItem);
boolean baseSRTM = isBaseSRTMMetricSystem(app);
List<IndexItem> allIndexes = new ArrayList<>();
if (downloadItem instanceof MultipleIndexItem) {
allIndexes.addAll(((MultipleIndexItem) downloadItem).getAllIndexes());
} else {
for (IndexItem indexItem : downloadItem.getRelatedGroup().getIndividualResources()) {
if (indexItem.getType() == SRTM_COUNTRY_FILE) {
allIndexes.add(indexItem);
}
}
}
for (IndexItem indexItem : allIndexes) {
boolean baseItem = isBaseSRTMItem(indexItem);
SelectableItem selectableItem = new SelectableItem();
selectableItem.setTitle(indexItem.getVisibleName(app, app.getRegions(), false));
String size = indexItem.getSizeDescription(app);
size += " (" + getSRTMAbbrev(app, baseItem) + ")";
String date = indexItem.getDate(dateFormat, showRemoteDate);
String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date);
selectableItem.setDescription(description);
selectableItem.setIconId(indexItem.getType().getIconResource());
selectableItem.setObject(indexItem);
if (baseItem) {
leftItems.add(selectableItem);
} else {
rightItems.add(selectableItem);
}
if (indexesToDownload.contains(indexItem)
&& (baseSRTM && baseItem || !baseSRTM && !baseItem)) {
selectedItems.add(selectableItem);
}
}
String addDescription = app.getString(isListDialog(app, leftItems, rightItems)
? R.string.srtm_download_list_help_message : R.string.srtm_download_single_help_message);
final SelectMultipleItemsBottomSheet dialog = SelectMultipleItemsBottomSheet.showInstance(
activity, baseSRTM ? leftItems : rightItems, selectedItems, true,
addDescription, true, baseSRTM,
Algorithms.capitalizeFirstLetter(app.getString(R.string.shared_string_meters)),
Algorithms.capitalizeFirstLetter(app.getString(R.string.shared_string_feets)));
dialog.setSelectionUpdateListener(new SelectionUpdateListener() {
@Override
public void onSelectionUpdate() {
updateSize(app, dialog);
}
});
dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
dialog.setOnRadioButtonSelectListener(new OnRadioButtonSelectListener() {
@Override
public void onSelect(boolean leftButton) {
dialog.recreateList(leftButton ? leftItems : rightItems);
updateSize(app, dialog);
}
});
dialog.setSelectedItemsListener(new SelectedItemsListener() {
@Override
public List<SelectableItem> createSelectedItems(List<SelectableItem> currentAllItems, boolean baseSRTM) {
List<IndexItem> indexesToDownload = getIndexesToDownload(downloadItem);
List<SelectableItem> selectedItems = new ArrayList<>();
for (SelectableItem currentItem : currentAllItems) {
IndexItem indexItem = (IndexItem) currentItem.getObject();
boolean baseItem = isBaseSRTMItem(indexItem);
if (indexesToDownload.contains(indexItem)
&& (baseSRTM && baseItem || !baseSRTM && !baseItem)) {
selectedItems.add(currentItem);
}
}
return selectedItems;
}
});
}
private static OnApplySelectionListener getOnApplySelectionListener(final SelectItemsToDownloadListener listener) {
return new OnApplySelectionListener() {
@Override @Override
public void onSelectionApplied(List<SelectableItem> selectedItems) { public void onSelectionApplied(List<SelectableItem> selectedItems) {
List<IndexItem> indexItems = new ArrayList<>(); List<IndexItem> indexItems = new ArrayList<>();
@ -78,16 +180,70 @@ public class MultipleIndexesUiHelper {
} }
listener.onItemsToDownloadSelected(indexItems); listener.onItemsToDownloadSelected(indexItems);
} }
}); };
} }
private static List<IndexItem> getIndexesToDownload(MultipleIndexItem multipleIndexItem) { private static void updateSize(OsmandApplication app, SelectMultipleItemsBottomSheet dialog) {
if (multipleIndexItem.hasActualDataToDownload()) { boolean isListDialog = dialog.isMultipleItem();
// download left regions dialog.setTitle(app.getString(isListDialog ? R.string.welmode_download_maps : R.string.srtm_unit_format));
return multipleIndexItem.getIndexesToDownload(); double sizeToDownload = getDownloadSizeInMb(dialog.getSelectedItems());
String size = DownloadItem.getFormattedMb(app, sizeToDownload);
if (isListDialog) {
String total = app.getString(R.string.shared_string_total);
String description = app.getString(R.string.ltr_or_rtl_combine_via_colon, total, size);
dialog.setDescription(description);
}
String btnTitle = app.getString(R.string.shared_string_download);
if (sizeToDownload > 0) {
btnTitle = app.getString(R.string.ltr_or_rtl_combine_via_dash, btnTitle, size);
}
dialog.setConfirmButtonTitle(btnTitle);
}
private static boolean isListDialog(OsmandApplication app,
List<SelectableItem> leftItems, List<SelectableItem> rightItems) {
return (isBaseSRTMMetricSystem(app) ? leftItems : rightItems).size() > 1;
}
public static String getSRTMAbbrev(Context context, boolean base) {
return context.getString(base ? R.string.m : R.string.foot);
}
public static String getSRTMExt(IndexItem indexItem) {
return isBaseSRTMItem(indexItem)
? IndexConstants.BINARY_SRTM_MAP_INDEX_EXT : IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT;
}
public static boolean isBaseSRTMItem(Object item) {
if (item instanceof IndexItem) {
return ((IndexItem) item).getFileName().endsWith(BINARY_SRTM_MAP_INDEX_EXT_ZIP);
} else if (item instanceof LocalIndexInfo) {
return ((LocalIndexInfo) item).getFileName().endsWith(BINARY_SRTM_MAP_INDEX_EXT);
}
return false;
}
public static boolean isBaseSRTMMetricSystem(OsmandApplication app) {
return app.getSettings().METRIC_SYSTEM.get() != MetricsConstants.MILES_AND_FEET;
}
private static List<IndexItem> getIndexesToDownload(DownloadItem downloadItem) {
if (downloadItem instanceof MultipleIndexItem) {
if (downloadItem.hasActualDataToDownload()) {
// download left regions
return ((MultipleIndexItem) downloadItem).getIndexesToDownload();
} else {
// download all regions again
return ((MultipleIndexItem) downloadItem).getAllIndexes();
}
} else { } else {
// download all regions again List<IndexItem> indexesToDownload = new ArrayList<>();
return multipleIndexItem.getAllIndexes(); for (IndexItem indexItem : downloadItem.getRelatedGroup().getIndividualResources()) {
if (indexItem.getType() == SRTM_COUNTRY_FILE && indexItem.hasActualDataToDownload()) {
indexesToDownload.add(indexItem);
}
}
return indexesToDownload;
} }
} }
@ -110,4 +266,7 @@ public class MultipleIndexesUiHelper {
void onItemsToDownloadSelected(List<IndexItem> items); void onItemsToDownloadSelected(List<IndexItem> items);
} }
public interface SelectedItemsListener {
List<SelectableItem> createSelectedItems(List<SelectableItem> currentAllItems, boolean base);
}
} }

View file

@ -51,8 +51,15 @@ import net.osmand.util.Algorithms;
import java.io.File; import java.io.File;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE;
import static net.osmand.plus.download.DownloadActivityType.isSRTMItem;
import static net.osmand.plus.download.MultipleIndexesUiHelper.getSRTMAbbrev;
import static net.osmand.plus.download.MultipleIndexesUiHelper.isBaseSRTMItem;
import static net.osmand.plus.download.MultipleIndexesUiHelper.isBaseSRTMMetricSystem;
public class ItemViewHolder { public class ItemViewHolder {
protected final TextView nameTextView; protected final TextView nameTextView;
@ -160,20 +167,20 @@ public class ItemViewHolder {
boolean disabled = checkDisabledAndClickAction(downloadItem); boolean disabled = checkDisabledAndClickAction(downloadItem);
/// name and left item /// name and left item
String name; String name;
if(showTypeInName) { if (showTypeInName) {
name = downloadItem.getType().getString(context); name = downloadItem.getType().getString(context);
} else { } else {
name = downloadItem.getVisibleName(context, context.getMyApplication().getRegions(), showParentRegionName); name = downloadItem.getVisibleName(context, context.getMyApplication().getRegions(), showParentRegionName);
} }
String text = (!Algorithms.isEmpty(cityName) && !cityName.equals(name) ? cityName + "\n" : "") + name; String text = (!Algorithms.isEmpty(cityName) && !cityName.equals(name) ? cityName + "\n" : "") + name;
nameTextView.setText(text); nameTextView.setText(text);
if(!disabled) { if (!disabled) {
nameTextView.setTextColor(textColorPrimary); nameTextView.setTextColor(textColorPrimary);
} else { } else {
nameTextView.setTextColor(textColorSecondary); nameTextView.setTextColor(textColorSecondary);
} }
int color = textColorSecondary; int color = textColorSecondary;
if(downloadItem.isDownloaded() && !isDownloading) { if (downloadItem.isDownloaded() && !isDownloading) {
int colorId = downloadItem.isOutdated() ? R.color.color_distance : R.color.color_ok; int colorId = downloadItem.isOutdated() ? R.color.color_distance : R.color.color_ok;
color = context.getResources().getColor(colorId); color = context.getResources().getColor(colorId);
} }
@ -189,6 +196,8 @@ public class ItemViewHolder {
} }
descrTextView.setTextColor(textColorSecondary); descrTextView.setTextColor(textColorSecondary);
if (!isDownloading) { if (!isDownloading) {
boolean srtmItem = isSRTMItem(downloadItem);
boolean baseMetricSystem = isBaseSRTMMetricSystem(context.getMyApplication());
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
descrTextView.setVisibility(View.VISIBLE); descrTextView.setVisibility(View.VISIBLE);
if (downloadItem instanceof CustomIndexItem && (((CustomIndexItem) downloadItem).getSubName(context) != null)) { if (downloadItem instanceof CustomIndexItem && (((CustomIndexItem) downloadItem).getSubName(context) != null)) {
@ -207,31 +216,55 @@ public class ItemViewHolder {
MultipleIndexItem item = (MultipleIndexItem) downloadItem; MultipleIndexItem item = (MultipleIndexItem) downloadItem;
String allRegionsHeader = context.getString(R.string.shared_strings_all_regions); String allRegionsHeader = context.getString(R.string.shared_strings_all_regions);
String regionsHeader = context.getString(R.string.regions); String regionsHeader = context.getString(R.string.regions);
String allRegionsCount = String.valueOf(item.getAllIndexes().size()); String allRegionsCountStr;
String leftToDownloadCount = String.valueOf(item.getIndexesToDownload().size()); String leftToDownloadCountStr;
if (isSRTMItem(item)) {
List<IndexItem> items = new ArrayList<>();
for (IndexItem indexItem : item.getAllIndexes()) {
boolean baseItem = isBaseSRTMItem(indexItem);
if (baseMetricSystem && baseItem || !baseMetricSystem && !baseItem) {
items.add(indexItem);
}
}
allRegionsCountStr = String.valueOf(items.size());
items.clear();
for (IndexItem indexItem : item.getIndexesToDownload()) {
boolean baseItem = isBaseSRTMItem(indexItem);
if (!indexItem.isDownloaded()
&& (baseMetricSystem && baseItem || !baseMetricSystem && !baseItem)) {
items.add(indexItem);
}
}
leftToDownloadCountStr = String.valueOf(items.size());
} else {
allRegionsCountStr = String.valueOf(item.getAllIndexes().size());
leftToDownloadCountStr = String.valueOf(item.getIndexesToDownload().size());
}
String header; String header;
String count; String count;
if (item.hasActualDataToDownload()) { if (item.hasActualDataToDownload()) {
if (!item.isDownloaded()) { if (!item.isDownloaded()) {
header = allRegionsHeader; header = allRegionsHeader;
count = leftToDownloadCount; count = leftToDownloadCountStr;
} else { } else {
header = regionsHeader; header = regionsHeader;
count = String.format( count = String.format(
context.getString(R.string.ltr_or_rtl_combine_via_slash), context.getString(R.string.ltr_or_rtl_combine_via_slash),
leftToDownloadCount, leftToDownloadCountStr,
allRegionsCount); allRegionsCountStr);
} }
} else { } else {
header = allRegionsHeader; header = allRegionsHeader;
count = allRegionsCount; count = allRegionsCountStr;
}
String fullDescription = context.getString(R.string.ltr_or_rtl_combine_via_colon, header, count);
if (srtmItem) {
fullDescription += " (" + getSRTMAbbrev(context, baseMetricSystem) + ")";
} }
String fullDescription =
context.getString(R.string.ltr_or_rtl_combine_via_colon, header, count);
if (item.hasActualDataToDownload()) { if (item.hasActualDataToDownload()) {
fullDescription = context.getString( fullDescription = context.getString(
R.string.ltr_or_rtl_combine_via_bold_point, fullDescription, R.string.ltr_or_rtl_combine_via_bold_point, fullDescription, srtmItem
item.getSizeDescription(context)); ? item.getSizeDescription(context, baseMetricSystem) : item.getSizeDescription(context));
} }
descrTextView.setText(fullDescription); descrTextView.setText(fullDescription);
} else { } else {
@ -239,6 +272,9 @@ public class ItemViewHolder {
String pattern = context.getString(R.string.ltr_or_rtl_combine_via_bold_point); String pattern = context.getString(R.string.ltr_or_rtl_combine_via_bold_point);
String type = item.getType().getString(context); String type = item.getType().getString(context);
String size = item.getSizeDescription(context); String size = item.getSizeDescription(context);
if (srtmItem) {
size += " (" + getSRTMAbbrev(context, isBaseSRTMItem(item)) + ")";
}
String date = item.getDate(dateFormat, showRemoteDate); String date = item.getDate(dateFormat, showRemoteDate);
String fullDescription = String.format(pattern, size, date); String fullDescription = String.format(pattern, size, date);
if (showTypeInDesc) { if (showTypeInDesc) {
@ -254,14 +290,14 @@ public class ItemViewHolder {
if (showProgressInDesc) { if (showProgressInDesc) {
double mb = downloadItem.getArchiveSizeMB(); double mb = downloadItem.getArchiveSizeMB();
String v ; String v;
if (progress != -1) { if (progress != -1) {
v = context.getString(R.string.value_downloaded_of_max, mb * progress / 100, mb); v = context.getString(R.string.value_downloaded_of_max, mb * progress / 100, mb);
} else { } else {
v = context.getString(R.string.file_size_in_mb, mb); v = context.getString(R.string.file_size_in_mb, mb);
} }
String fullDescription = v; String fullDescription = v;
if(showTypeInDesc && downloadItem.getType() == DownloadActivityType.ROADS_FILE) { if (showTypeInDesc && downloadItem.getType() == DownloadActivityType.ROADS_FILE) {
fullDescription = context.getString(R.string.ltr_or_rtl_combine_via_bold_point, fullDescription = context.getString(R.string.ltr_or_rtl_combine_via_bold_point,
downloadItem.getType().getString(context), fullDescription); downloadItem.getType().getString(context), fullDescription);
} }
@ -302,7 +338,7 @@ public class ItemViewHolder {
if (isDownloading) { if (isDownloading) {
rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_remove_dark)); rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_remove_dark));
rightImageButton.setContentDescription(context.getString(R.string.shared_string_cancel)); rightImageButton.setContentDescription(context.getString(R.string.shared_string_cancel));
} else if(!item.hasActualDataToDownload()) { } else if (!item.hasActualDataToDownload()) {
rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_overflow_menu_white)); rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_overflow_menu_white));
rightImageButton.setContentDescription(context.getString(R.string.shared_string_more)); rightImageButton.setContentDescription(context.getString(R.string.shared_string_more));
} else { } else {
@ -318,7 +354,7 @@ public class ItemViewHolder {
private int getDownloadActionIconId(@NonNull DownloadItem item) { private int getDownloadActionIconId(@NonNull DownloadItem item) {
return item instanceof MultipleIndexItem ? return item instanceof MultipleIndexItem ?
R.drawable.ic_action_multi_download : R.drawable.ic_action_multi_download :
R.drawable.ic_action_import; R.drawable.ic_action_gsave_dark;
} }
@SuppressLint("DefaultLocale") @SuppressLint("DefaultLocale")
@ -389,13 +425,13 @@ public class ItemViewHolder {
return new View.OnClickListener() { return new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if(isDownloading) { if (isDownloading) {
if(silentCancelDownload) { if (silentCancelDownload) {
context.getDownloadThread().cancelDownload(item); context.getDownloadThread().cancelDownload(item);
} else { } else {
context.makeSureUserCancelDownload(item); context.makeSureUserCancelDownload(item);
} }
} else if(!item.hasActualDataToDownload()){ } else if (!item.hasActualDataToDownload()) {
showContextMenu(v, item, item.getRelatedGroup()); showContextMenu(v, item, item.getRelatedGroup());
} else { } else {
download(item, item.getRelatedGroup()); download(item, item.getRelatedGroup());
@ -406,8 +442,8 @@ public class ItemViewHolder {
} }
protected void showContextMenu(View v, protected void showContextMenu(View v,
final DownloadItem downloadItem, final DownloadItem downloadItem,
final DownloadResourceGroup parentOptional) { final DownloadResourceGroup parentOptional) {
OsmandApplication app = context.getMyApplication(); OsmandApplication app = context.getMyApplication();
PopupMenu optionsMenu = new PopupMenu(context, v); PopupMenu optionsMenu = new PopupMenu(context, v);
MenuItem item; MenuItem item;
@ -455,10 +491,11 @@ public class ItemViewHolder {
} }
} }
} }
if(!handled) { if (!handled) {
startDownload(item); startDownload(item);
} }
} }
private void confirmDownload(final DownloadItem item) { private void confirmDownload(final DownloadItem item) {
AlertDialog.Builder builder = new AlertDialog.Builder(context); AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.are_you_sure); builder.setTitle(R.string.are_you_sure);
@ -476,15 +513,15 @@ public class ItemViewHolder {
} }
private void startDownload(DownloadItem item) { private void startDownload(DownloadItem item) {
if (item instanceof MultipleIndexItem) { if (item instanceof MultipleIndexItem || item.getType() == SRTM_COUNTRY_FILE) {
selectIndexesToDownload((MultipleIndexItem) item); selectIndexesToDownload(item);
} else if (item instanceof IndexItem) { } else if (item instanceof IndexItem) {
IndexItem indexItem = (IndexItem) item; IndexItem indexItem = (IndexItem) item;
context.startDownload(indexItem); context.startDownload(indexItem);
} }
} }
private void selectIndexesToDownload(MultipleIndexItem item) { private void selectIndexesToDownload(DownloadItem item) {
OsmandApplication app = context.getMyApplication(); OsmandApplication app = context.getMyApplication();
MultipleIndexesUiHelper.showDialog(item, context, app, dateFormat, showRemoteDate, MultipleIndexesUiHelper.showDialog(item, context, app, dateFormat, showRemoteDate,
new SelectItemsToDownloadListener() { new SelectItemsToDownloadListener() {
@ -498,7 +535,7 @@ public class ItemViewHolder {
} }
private void confirmRemove(@NonNull final DownloadItem downloadItem, private void confirmRemove(@NonNull final DownloadItem downloadItem,
@NonNull final List<File> downloadedFiles) { @NonNull final List<File> downloadedFiles) {
OsmandApplication app = context.getMyApplication(); OsmandApplication app = context.getMyApplication();
AlertDialog.Builder confirm = new AlertDialog.Builder(context); AlertDialog.Builder confirm = new AlertDialog.Builder(context);
@ -526,7 +563,7 @@ public class ItemViewHolder {
} }
private void remove(@NonNull LocalIndexType type, private void remove(@NonNull LocalIndexType type,
@NonNull List<File> filesToDelete) { @NonNull List<File> filesToDelete) {
OsmandApplication app = context.getMyApplication(); OsmandApplication app = context.getMyApplication();
LocalIndexOperationTask removeTask = new LocalIndexOperationTask( LocalIndexOperationTask removeTask = new LocalIndexOperationTask(
context, context,

View file

@ -74,6 +74,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static net.osmand.plus.download.DownloadActivityType.isSRTMItem;
import static net.osmand.plus.download.MultipleIndexesUiHelper.getSRTMAbbrev;
import static net.osmand.plus.download.MultipleIndexesUiHelper.isBaseSRTMItem;
public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents, public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents,
OnMapSourceUpdateListener, RenameCallback { OnMapSourceUpdateListener, RenameCallback {
private LoadLocalIndexTask asyncLoader; private LoadLocalIndexTask asyncLoader;
@ -351,10 +355,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
getMyApplication().getResourceManager().closeFile(info.getFileName()); getMyApplication().getResourceManager().closeFile(info.getFileName());
File tShm = new File(f.getParentFile(), f.getName() + "-shm"); File tShm = new File(f.getParentFile(), f.getName() + "-shm");
File tWal = new File(f.getParentFile(), f.getName() + "-wal"); File tWal = new File(f.getParentFile(), f.getName() + "-wal");
if(tShm.exists()) { if (tShm.exists()) {
Algorithms.removeAllFiles(tShm); Algorithms.removeAllFiles(tShm);
} }
if(tWal.exists()) { if (tWal.exists()) {
Algorithms.removeAllFiles(tWal); Algorithms.removeAllFiles(tWal);
} }
} }
@ -370,8 +374,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
getMyApplication().getResourceManager().closeFile(info.getFileName()); getMyApplication().getResourceManager().closeFile(info.getFileName());
} }
} else if (operation == CLEAR_TILES_OPERATION) { } else if (operation == CLEAR_TILES_OPERATION) {
ITileSource src = (ITileSource) info.getAttachedObject(); ITileSource src = (ITileSource) info.getAttachedObject();
if(src != null) { if (src != null) {
src.deleteTiles(info.getPathToData()); src.deleteTiles(info.getPathToData());
} }
} }
@ -419,7 +423,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
@Override @Override
protected void onPostExecute(String result) { protected void onPostExecute(String result) {
a.setProgressBarIndeterminateVisibility(false); a.setProgressBarIndeterminateVisibility(false);
if(result != null && result.length() > 0) { if (result != null && result.length() > 0) {
Toast.makeText(a, result, Toast.LENGTH_LONG).show(); Toast.makeText(a, result, Toast.LENGTH_LONG).show();
} }
@ -878,8 +882,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
private String getNameToDisplay(LocalIndexInfo child) { private String getNameToDisplay(LocalIndexInfo child) {
return child.getType() == LocalIndexType.VOICE_DATA ? FileNameTranslationHelper.getVoiceName(ctx, child.getFileName()) : return child.getType() == LocalIndexType.VOICE_DATA ? FileNameTranslationHelper.getVoiceName(ctx, child.getFileName()) :
FileNameTranslationHelper.getFileName(ctx, FileNameTranslationHelper.getFileName(ctx,
ctx.getMyApplication().getResourceManager().getOsmandRegions(), ctx.getMyApplication().getResourceManager().getOsmandRegions(),
child.getFileName()); child.getFileName());
} }
@Override @Override
@ -963,7 +967,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
return ctx.getString(R.string.download_roads_only_item); return ctx.getString(R.string.download_roads_only_item);
} else if (child.isBackupedData() && child.getFileName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) { } else if (child.isBackupedData() && child.getFileName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) {
return ctx.getString(R.string.download_wikipedia_maps); return ctx.getString(R.string.download_wikipedia_maps);
} else if (child.isBackupedData() && child.getFileName().endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)) { } else if (child.isBackupedData() && (child.getFileName().endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)
|| child.getFileName().endsWith(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT))) {
return ctx.getString(R.string.download_srtm_maps); return ctx.getString(R.string.download_srtm_maps);
} }
return ""; return "";
@ -1029,6 +1034,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
builder.append(AndroidUtils.formatSize(ctx, child.getSize() * 1024l)); builder.append(AndroidUtils.formatSize(ctx, child.getSize() * 1024l));
} }
if (isSRTMItem(child)) {
builder.append(" (").append(getSRTMAbbrev(ctx, isBaseSRTMItem(child))).append(")");
}
if (!Algorithms.isEmpty(child.getDescription())) { if (!Algorithms.isEmpty(child.getDescription())) {
if (builder.length() > 0) { if (builder.length() > 0) {
builder.append(""); builder.append("");
@ -1150,5 +1159,4 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
private DownloadActivity getDownloadActivity() { private DownloadActivity getDownloadActivity() {
return (DownloadActivity) getActivity(); return (DownloadActivity) getActivity();
} }
} }

View file

@ -82,7 +82,7 @@ import static net.osmand.IndexConstants.VOICE_INDEX_DIR;
* that could consume memory (especially with file resources). * that could consume memory (especially with file resources).
* Such as indexes, tiles. * Such as indexes, tiles.
* Also it is responsible to create cache for that resources if they * Also it is responsible to create cache for that resources if they
* can't be loaded fully into memory & clear them on request. * can't be loaded fully into memory & clear them on request.
*/ */
public class ResourceManager { public class ResourceManager {
@ -94,7 +94,7 @@ public class ResourceManager {
protected static ResourceManager manager = null; protected static ResourceManager manager = null;
protected File dirWithTiles ; protected File dirWithTiles;
private List<TilesCache> tilesCacheList = new ArrayList<>(); private List<TilesCache> tilesCacheList = new ArrayList<>();
private BitmapTilesCache bitmapTilesCache; private BitmapTilesCache bitmapTilesCache;
@ -126,10 +126,11 @@ public class ResourceManager {
private List<BinaryMapIndexReader> readers = new ArrayList<>(BinaryMapReaderResourceType.values().length); private List<BinaryMapIndexReader> readers = new ArrayList<>(BinaryMapReaderResourceType.values().length);
private boolean useForRouting; private boolean useForRouting;
private boolean useForPublicTransport; private boolean useForPublicTransport;
public BinaryMapReaderResource(File f, BinaryMapIndexReader initialReader) { public BinaryMapReaderResource(File f, BinaryMapIndexReader initialReader) {
this.filename = f; this.filename = f;
this.initialReader = initialReader; this.initialReader = initialReader;
while(readers.size() < BinaryMapReaderResourceType.values().length) { while (readers.size() < BinaryMapReaderResourceType.values().length) {
readers.add(null); readers.add(null);
} }
} }
@ -205,16 +206,14 @@ public class ResourceManager {
protected final Map<String, BinaryMapReaderResource> fileReaders = new ConcurrentHashMap<String, BinaryMapReaderResource>(); protected final Map<String, BinaryMapReaderResource> fileReaders = new ConcurrentHashMap<String, BinaryMapReaderResource>();
private final Map<String, RegionAddressRepository> addressMap = new ConcurrentHashMap<String, RegionAddressRepository>(); private final Map<String, RegionAddressRepository> addressMap = new ConcurrentHashMap<String, RegionAddressRepository>();
protected final Map<String, AmenityIndexRepository> amenityRepositories = new ConcurrentHashMap<String, AmenityIndexRepository>(); protected final Map<String, AmenityIndexRepository> amenityRepositories = new ConcurrentHashMap<String, AmenityIndexRepository>();
// protected final Map<String, BinaryMapIndexReader> routingMapFiles = new ConcurrentHashMap<String, BinaryMapIndexReader>(); // protected final Map<String, BinaryMapIndexReader> routingMapFiles = new ConcurrentHashMap<String, BinaryMapIndexReader>();
protected final Map<String, BinaryMapReaderResource> transportRepositories = new ConcurrentHashMap<String, BinaryMapReaderResource>(); protected final Map<String, BinaryMapReaderResource> transportRepositories = new ConcurrentHashMap<String, BinaryMapReaderResource>();
protected final Map<String, BinaryMapReaderResource> travelRepositories = new ConcurrentHashMap<String, BinaryMapReaderResource>(); protected final Map<String, BinaryMapReaderResource> travelRepositories = new ConcurrentHashMap<String, BinaryMapReaderResource>();
protected final Map<String, String> indexFileNames = new ConcurrentHashMap<String, String>(); protected final Map<String, String> indexFileNames = new ConcurrentHashMap<String, String>();
protected final Map<String, String> basemapFileNames = new ConcurrentHashMap<String, String>(); protected final Map<String, String> basemapFileNames = new ConcurrentHashMap<String, String>();
protected final IncrementalChangesManager changesManager = new IncrementalChangesManager(this); protected final IncrementalChangesManager changesManager = new IncrementalChangesManager(this);
protected final MapRenderRepositories renderer; protected final MapRenderRepositories renderer;
@ -293,7 +292,7 @@ public class ResourceManager {
// ".nomedia" indicates there are no pictures and no music to list in this dir for the Gallery app // ".nomedia" indicates there are no pictures and no music to list in this dir for the Gallery app
try { try {
context.getAppPath(".nomedia").createNewFile(); //$NON-NLS-1$ context.getAppPath(".nomedia").createNewFile(); //$NON-NLS-1$
} catch( Exception e ) { } catch (Exception e) {
} }
for (TilesCache tilesCache : tilesCacheList) { for (TilesCache tilesCache : tilesCacheList) {
tilesCache.setDirWithTiles(dirWithTiles); tilesCache.setDirWithTiles(dirWithTiles);
@ -323,7 +322,7 @@ public class ResourceManager {
return null; return null;
} }
public synchronized void tileDownloaded(DownloadRequest request){ public synchronized void tileDownloaded(DownloadRequest request) {
if (request instanceof TileLoadDownloadRequest) { if (request instanceof TileLoadDownloadRequest) {
TileLoadDownloadRequest req = ((TileLoadDownloadRequest) request); TileLoadDownloadRequest req = ((TileLoadDownloadRequest) request);
TilesCache cache = getTilesCache(req.tileSource); TilesCache cache = getTilesCache(req.tileSource);
@ -338,7 +337,7 @@ public class ResourceManager {
return cache != null && cache.tileExistOnFileSystem(file, map, x, y, zoom); return cache != null && cache.tileExistOnFileSystem(file, map, x, y, zoom);
} }
public void clearTileForMap(String file, ITileSource map, int x, int y, int zoom){ public void clearTileForMap(String file, ITileSource map, int x, int y, int zoom) {
TilesCache cache = getTilesCache(map); TilesCache cache = getTilesCache(map);
if (cache != null) { if (cache != null) {
cache.getTileForMap(file, map, x, y, zoom, true, false, true, true); cache.getTileForMap(file, map, x, y, zoom, true, false, true, true);
@ -376,7 +375,7 @@ public class ResourceManager {
////////////////////////////////////////////// Working with indexes //////////////////////////////////////////////// ////////////////////////////////////////////// Working with indexes ////////////////////////////////////////////////
public List<String> reloadIndexesOnStart(AppInitializer progress, List<String> warnings){ public List<String> reloadIndexesOnStart(AppInitializer progress, List<String> warnings) {
close(); close();
// check we have some assets to copy to sdcard // check we have some assets to copy to sdcard
warnings.addAll(checkAssets(progress, false)); warnings.addAll(checkAssets(progress, false));
@ -429,7 +428,7 @@ public class ResourceManager {
return warnings; return warnings;
} }
public List<String> indexFontFiles(IProgress progress){ public List<String> indexFontFiles(IProgress progress) {
File file = context.getAppPath(IndexConstants.FONT_INDEX_DIR); File file = context.getAppPath(IndexConstants.FONT_INDEX_DIR);
file.mkdirs(); file.mkdirs();
List<String> warnings = new ArrayList<String>(); List<String> warnings = new ArrayList<String>();
@ -476,7 +475,7 @@ public class ResourceManager {
public List<String> checkAssets(IProgress progress, boolean forceUpdate) { public List<String> checkAssets(IProgress progress, boolean forceUpdate) {
String fv = Version.getFullVersion(context); String fv = Version.getFullVersion(context);
if(context.getAppInitializer().isAppVersionChanged()) { if (context.getAppInitializer().isAppVersionChanged()) {
copyMissingJSAssets(); copyMissingJSAssets();
} }
if (!fv.equalsIgnoreCase(context.getSettings().PREVIOUS_INSTALLED_VERSION.get()) || forceUpdate) { if (!fv.equalsIgnoreCase(context.getSettings().PREVIOUS_INSTALLED_VERSION.get()) || forceUpdate) {
@ -540,6 +539,7 @@ public class ResourceManager {
private final static String ASSET_COPY_MODE__overwriteOnlyIfExists = "overwriteOnlyIfExists"; private final static String ASSET_COPY_MODE__overwriteOnlyIfExists = "overwriteOnlyIfExists";
private final static String ASSET_COPY_MODE__alwaysOverwriteOrCopy = "alwaysOverwriteOrCopy"; private final static String ASSET_COPY_MODE__alwaysOverwriteOrCopy = "alwaysOverwriteOrCopy";
private final static String ASSET_COPY_MODE__copyOnlyIfDoesNotExist = "copyOnlyIfDoesNotExist"; private final static String ASSET_COPY_MODE__copyOnlyIfDoesNotExist = "copyOnlyIfDoesNotExist";
private void unpackBundledAssets(AssetManager assetManager, File appDataDir, IProgress progress, boolean isFirstInstall) throws IOException, XmlPullParserException { private void unpackBundledAssets(AssetManager assetManager, File appDataDir, IProgress progress, boolean isFirstInstall) throws IOException, XmlPullParserException {
List<AssetEntry> assetEntries = DownloadOsmandIndexesHelper.getBundledAssets(assetManager); List<AssetEntry> assetEntries = DownloadOsmandIndexesHelper.getBundledAssets(assetManager);
for (AssetEntry asset : assetEntries) { for (AssetEntry asset : assetEntries) {
@ -581,7 +581,7 @@ public class ResourceManager {
} }
public static void copyAssets(AssetManager assetManager, String assetName, File file) throws IOException { public static void copyAssets(AssetManager assetManager, String assetName, File file) throws IOException {
if(file.exists()){ if (file.exists()) {
Algorithms.removeAllFiles(file); Algorithms.removeAllFiles(file);
} }
file.getParentFile().mkdirs(); file.getParentFile().mkdirs();
@ -593,9 +593,9 @@ public class ResourceManager {
} }
private List<File> collectFiles(File dir, String ext, List<File> files) { private List<File> collectFiles(File dir, String ext, List<File> files) {
if(dir.exists() && dir.canRead()) { if (dir.exists() && dir.canRead()) {
File[] lf = dir.listFiles(); File[] lf = dir.listFiles();
if(lf == null || lf.length == 0) { if (lf == null || lf.length == 0) {
return files; return files;
} }
for (File f : lf) { for (File f : lf) {
@ -607,11 +607,9 @@ public class ResourceManager {
return files; return files;
} }
private void renameRoadsFiles(ArrayList<File> files, File roadsPath) { private void renameRoadsFiles(ArrayList<File> files, File roadsPath) {
Iterator<File> it = files.iterator(); Iterator<File> it = files.iterator();
while(it.hasNext()) { while (it.hasNext()) {
File f = it.next(); File f = it.next();
if (f.getName().endsWith("-roads" + IndexConstants.BINARY_MAP_INDEX_EXT)) { if (f.getName().endsWith("-roads" + IndexConstants.BINARY_MAP_INDEX_EXT)) {
f.renameTo(new File(roadsPath, f.getName().replace("-roads" + IndexConstants.BINARY_MAP_INDEX_EXT, f.renameTo(new File(roadsPath, f.getName().replace("-roads" + IndexConstants.BINARY_MAP_INDEX_EXT,
@ -703,7 +701,8 @@ public class ResourceManager {
log.error(String.format("File %s could not be read", f.getName()), e); log.error(String.format("File %s could not be read", f.getName()), e);
} }
boolean wikiMap = (f.getName().contains("_wiki") || f.getName().contains(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)); boolean wikiMap = (f.getName().contains("_wiki") || f.getName().contains(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT));
boolean srtmMap = f.getName().contains(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT); boolean srtmMap = f.getName().contains(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)
|| f.getName().contains(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT);
if (mapReader == null || (!Version.isPaidVersion(context) && wikiMap && !f.getName().equals(DEFAULT_WIKIVOYAGE_TRAVEL_OBF))) { if (mapReader == null || (!Version.isPaidVersion(context) && wikiMap && !f.getName().equals(DEFAULT_WIKIVOYAGE_TRAVEL_OBF))) {
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$ warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
} else { } else {
@ -714,9 +713,9 @@ public class ResourceManager {
if (dateCreated == 0) { if (dateCreated == 0) {
dateCreated = f.lastModified(); dateCreated = f.lastModified();
} }
if(f.getParentFile().getName().equals(liveDir.getName())) { if (f.getParentFile().getName().equals(liveDir.getName())) {
boolean toUse = changesManager.index(f, dateCreated, mapReader); boolean toUse = changesManager.index(f, dateCreated, mapReader);
if(!toUse) { if (!toUse) {
try { try {
mapReader.close(); mapReader.close();
} catch (IOException e) { } catch (IOException e) {
@ -724,7 +723,7 @@ public class ResourceManager {
} }
continue; continue;
} }
} else if(!wikiMap && !srtmMap) { } else if (!wikiMap && !srtmMap) {
changesManager.indexMainMap(f, dateCreated); changesManager.indexMainMap(f, dateCreated);
} }
indexFileNames.put(f.getName(), dateFormat.format(dateCreated)); //$NON-NLS-1$ indexFileNames.put(f.getName(), dateFormat.format(dateCreated)); //$NON-NLS-1$
@ -733,7 +732,7 @@ public class ResourceManager {
} }
renderer.initializeNewResource(progress, f, mapReader); renderer.initializeNewResource(progress, f, mapReader);
BinaryMapReaderResource resource = new BinaryMapReaderResource(f, mapReader); BinaryMapReaderResource resource = new BinaryMapReaderResource(f, mapReader);
if (collectTravelFiles(resource)){ if (collectTravelFiles(resource)) {
//travel files are indexed //travel files are indexed
continue; continue;
} }
@ -789,7 +788,7 @@ public class ResourceManager {
} }
} }
Iterator<Entry<PoiCategory, Map<String, PoiType>>> it = toAddPoiTypes.entrySet().iterator(); Iterator<Entry<PoiCategory, Map<String, PoiType>>> it = toAddPoiTypes.entrySet().iterator();
while(it.hasNext()) { while (it.hasNext()) {
Entry<PoiCategory, Map<String, PoiType>> next = it.next(); Entry<PoiCategory, Map<String, PoiType>> next = it.next();
PoiCategory category = next.getKey(); PoiCategory category = next.getKey();
category.addExtraPoiTypes(next.getValue()); category.addExtraPoiTypes(next.getValue());
@ -839,7 +838,7 @@ public class ResourceManager {
} }
private boolean collectTravelFiles(BinaryMapReaderResource resource) { private boolean collectTravelFiles(BinaryMapReaderResource resource) {
if (resource.getFileName().contains(IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT)){ if (resource.getFileName().contains(IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT)) {
travelRepositories.put(resource.getFileName(), resource); travelRepositories.put(resource.getFileName(), resource);
return true; return true;
} }
@ -872,7 +871,7 @@ public class ResourceManager {
} }
public List<Amenity> searchAmenities(SearchPoiTypeFilter filter, public List<Amenity> searchAmenities(SearchPoiTypeFilter filter,
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) { double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, final ResultMatcher<Amenity> matcher) {
final List<Amenity> amenities = new ArrayList<Amenity>(); final List<Amenity> amenities = new ArrayList<Amenity>();
searchAmenitiesInProgress = true; searchAmenitiesInProgress = true;
try { try {
@ -901,8 +900,8 @@ public class ResourceManager {
return amenities; return amenities;
} }
public List<Amenity> searchAmenitiesOnThePath(List<Location> locations, double radius, SearchPoiTypeFilter filter, public List<Amenity> searchAmenitiesOnThePath(List<Location> locations, double radius, SearchPoiTypeFilter filter,
ResultMatcher<Amenity> matcher) { ResultMatcher<Amenity> matcher) {
searchAmenitiesInProgress = true; searchAmenitiesInProgress = true;
final List<Amenity> amenities = new ArrayList<Amenity>(); final List<Amenity> amenities = new ArrayList<Amenity>();
try { try {
@ -931,7 +930,7 @@ public class ResourceManager {
if (!repos.isEmpty()) { if (!repos.isEmpty()) {
for (AmenityIndexRepository r : repos) { for (AmenityIndexRepository r : repos) {
List<Amenity> res = r.searchAmenitiesOnThePath(locations, radius, filter, matcher); List<Amenity> res = r.searchAmenitiesOnThePath(locations, radius, filter, matcher);
if(res != null) { if (res != null) {
amenities.addAll(res); amenities.addAll(res);
} }
} }
@ -944,11 +943,10 @@ public class ResourceManager {
return amenities; return amenities;
} }
public boolean containsAmenityRepositoryToSearch(boolean searchByName) {
public boolean containsAmenityRepositoryToSearch(boolean searchByName){
for (AmenityIndexRepository index : getAmenityRepositories()) { for (AmenityIndexRepository index : getAmenityRepositories()) {
if(searchByName){ if (searchByName) {
if(index instanceof AmenityIndexRepositoryBinary){ if (index instanceof AmenityIndexRepositoryBinary) {
return true; return true;
} }
} else { } else {
@ -959,8 +957,8 @@ public class ResourceManager {
} }
public List<Amenity> searchAmenitiesByName(String searchQuery, public List<Amenity> searchAmenitiesByName(String searchQuery,
double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude,
double lat, double lon, ResultMatcher<Amenity> matcher) { double lat, double lon, ResultMatcher<Amenity> matcher) {
List<Amenity> amenities = new ArrayList<Amenity>(); List<Amenity> amenities = new ArrayList<Amenity>();
List<AmenityIndexRepositoryBinary> list = new ArrayList<AmenityIndexRepositoryBinary>(); List<AmenityIndexRepositoryBinary> list = new ArrayList<AmenityIndexRepositoryBinary>();
int left = MapUtils.get31TileNumberX(leftLongitude); int left = MapUtils.get31TileNumberX(leftLongitude);
@ -973,7 +971,7 @@ public class ResourceManager {
} }
if (index instanceof AmenityIndexRepositoryBinary) { if (index instanceof AmenityIndexRepositoryBinary) {
if (index.checkContainsInt(top, left, bottom, right)) { if (index.checkContainsInt(top, left, bottom, right)) {
if(index.checkContains(lat, lon)){ if (index.checkContains(lat, lon)) {
list.add(0, (AmenityIndexRepositoryBinary) index); list.add(0, (AmenityIndexRepositoryBinary) index);
} else { } else {
list.add((AmenityIndexRepositoryBinary) index); list.add((AmenityIndexRepositoryBinary) index);
@ -1019,11 +1017,11 @@ public class ResourceManager {
////////////////////////////////////////////// Working with address /////////////////////////////////////////// ////////////////////////////////////////////// Working with address ///////////////////////////////////////////
public RegionAddressRepository getRegionRepository(String name){ public RegionAddressRepository getRegionRepository(String name) {
return addressMap.get(name); return addressMap.get(name);
} }
public Collection<RegionAddressRepository> getAddressRepositories(){ public Collection<RegionAddressRepository> getAddressRepositories() {
return addressMap.values(); return addressMap.values();
} }
@ -1040,7 +1038,6 @@ public class ResourceManager {
return res; return res;
} }
////////////////////////////////////////////// Working with transport //////////////////////////////////////////////// ////////////////////////////////////////////// Working with transport ////////////////////////////////////////////////
private List<BinaryMapIndexReader> getTransportRepositories(double topLat, double leftLon, double bottomLat, double rightLon) { private List<BinaryMapIndexReader> getTransportRepositories(double topLat, double leftLon, double bottomLat, double rightLon) {
@ -1076,7 +1073,7 @@ public class ResourceManager {
public List<TransportRoute> getRoutesForStop(TransportStop stop) { public List<TransportRoute> getRoutesForStop(TransportStop stop) {
List<TransportRoute> rts = stop.getRoutes(); List<TransportRoute> rts = stop.getRoutes();
if(rts != null) { if (rts != null) {
return rts; return rts;
} }
return Collections.emptyList(); return Collections.emptyList();
@ -1087,12 +1084,12 @@ public class ResourceManager {
return renderer.updateMapIsNeeded(rotatedTileBox, drawSettings); return renderer.updateMapIsNeeded(rotatedTileBox, drawSettings);
} }
public void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener){ public void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener) {
renderer.interruptLoadingMap(); renderer.interruptLoadingMap();
asyncLoadingThread.requestToLoadMap(new MapLoadRequest(rotatedTileBox, mapLoadedListener)); asyncLoadingThread.requestToLoadMap(new MapLoadRequest(rotatedTileBox, mapLoadedListener));
} }
public void interruptRendering(){ public void interruptRendering() {
renderer.interruptLoadingMap(); renderer.interruptLoadingMap();
} }
@ -1114,12 +1111,12 @@ public class ResourceManager {
travelRepositories.remove(fileName); travelRepositories.remove(fileName);
renderer.closeConnection(fileName); renderer.closeConnection(fileName);
BinaryMapReaderResource resource = fileReaders.remove(fileName); BinaryMapReaderResource resource = fileReaders.remove(fileName);
if(resource != null) { if (resource != null) {
resource.close(); resource.close();
} }
} }
public synchronized void close(){ public synchronized void close() {
for (TilesCache tc : tilesCacheList) { for (TilesCache tc : tilesCacheList) {
tc.close(); tc.close();
} }
@ -1130,7 +1127,7 @@ public class ResourceManager {
travelRepositories.clear(); travelRepositories.clear();
addressMap.clear(); addressMap.clear();
amenityRepositories.clear(); amenityRepositories.clear();
for(BinaryMapReaderResource res : fileReaders.values()) { for (BinaryMapReaderResource res : fileReaders.values()) {
res.close(); res.close();
} }
fileReaders.clear(); fileReaders.clear();
@ -1154,7 +1151,7 @@ public class ResourceManager {
Collection<BinaryMapReaderResource> fileReaders = getFileReaders(); Collection<BinaryMapReaderResource> fileReaders = getFileReaders();
List<BinaryMapIndexReader> readers = new ArrayList<>(fileReaders.size()); List<BinaryMapIndexReader> readers = new ArrayList<>(fileReaders.size());
for (BinaryMapReaderResource r : fileReaders) { for (BinaryMapReaderResource r : fileReaders) {
if (r.isUseForPublicTransport()) { if (r.isUseForPublicTransport()) {
BinaryMapIndexReader reader = r.getReader(BinaryMapReaderResourceType.TRANSPORT_ROUTING); BinaryMapIndexReader reader = r.getReader(BinaryMapReaderResourceType.TRANSPORT_ROUTING);
if (reader != null) { if (reader != null) {
readers.add(reader); readers.add(reader);
@ -1183,8 +1180,7 @@ public class ResourceManager {
return new LinkedHashMap<String, String>(indexFileNames); return new LinkedHashMap<String, String>(indexFileNames);
} }
public boolean containsBasemap() {
public boolean containsBasemap(){
return !basemapFileNames.isEmpty(); return !basemapFileNames.isEmpty();
} }

View file

@ -200,7 +200,7 @@ public class DataStorageHelper {
terrainMemory = MemoryItem.builder() terrainMemory = MemoryItem.builder()
.setKey(TERRAIN_MEMORY) .setKey(TERRAIN_MEMORY)
.setExtensions(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT) .setExtensions(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT, IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT)
.setDirectories( .setDirectories(
createDirectory(SRTM_INDEX_DIR, true, EXTENSIONS, true), createDirectory(SRTM_INDEX_DIR, true, EXTENSIONS, true),
createDirectory(TILES_INDEX_DIR, false, PREFIX, false)) createDirectory(TILES_INDEX_DIR, false, PREFIX, false))
@ -302,9 +302,9 @@ public class DataStorageHelper {
} }
public DirectoryItem createDirectory(@NonNull String relativePath, public DirectoryItem createDirectory(@NonNull String relativePath,
boolean processInternalDirectories, boolean processInternalDirectories,
CheckingType checkingType, CheckingType checkingType,
boolean addUnmatchedToOtherMemory) { boolean addUnmatchedToOtherMemory) {
String path = app.getAppPath(relativePath).getAbsolutePath(); String path = app.getAppPath(relativePath).getAbsolutePath();
return new DirectoryItem(path, processInternalDirectories, checkingType, addUnmatchedToOtherMemory); return new DirectoryItem(path, processInternalDirectories, checkingType, addUnmatchedToOtherMemory);
} }