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,6 +145,12 @@ 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);
TextView addDescription = view.findViewById(R.id.additional_description);
LinearLayout customRadioButtons = view.findViewById(R.id.custom_radio_buttons);
if (!isMultipleItem()) {
AndroidUiHelper.setVisibility(View.GONE, description, selectedSize, selectAllButton);
} else {
selectAllButton.setOnClickListener(new View.OnClickListener() { selectAllButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -99,24 +165,69 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
updateItems(checked); 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()) {
for (int i = 0; i < allItems.size(); i++) {
final SelectableItem item = allItems.get(i);
boolean checked = selectedItems.contains(item); boolean checked = selectedItems.contains(item);
final BottomSheetItemWithCompoundButton[] uiItem = new BottomSheetItemWithCompoundButton[1]; final int finalI = i;
final Builder builder = (BottomSheetItemWithCompoundButton.Builder) new Builder(); items.add(new Builder()
builder.setChecked(checked) .setChecked(checked)
.setButtonTintList(AndroidUtils.createCheckedColorStateList(app, secondaryColorRes, activeColorRes)) .setButtonTintList(AndroidUtils.createCheckedColorStateList(app, secondaryColorRes, activeColorRes))
.setDescription(item.description)
.setIcon(uiUtilities.getIcon(item.iconId, activeColorRes))
.setTitle(item.title)
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp) .setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp)
.setTag(item)
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View view) {
boolean checked = !uiItem[0].isChecked(); BottomSheetItemWithCompoundButton item = (BottomSheetItemWithCompoundButton) items.get(finalI + sizeAboveList);
uiItem[0].setChecked(checked); boolean checked = item.isChecked();
SelectableItem tag = (SelectableItem) uiItem[0].getTag(); item.setChecked(!checked);
if (checked) { SelectableItem tag = (SelectableItem) item.getTag();
if (!checked) {
selectedItems.add(tag); selectedItems.add(tag);
} else { } else {
selectedItems.remove(tag); selectedItems.remove(tag);
@ -124,25 +235,19 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
onSelectedItemsChanged(); onSelectedItemsChanged();
} }
}) })
.setTag(item); .create());
setupListItem(builder, item);
uiItem[0] = builder.create();
items.add(uiItem[0]);
} }
} else if (allItems.size() == 1) {
final SelectableItem item = allItems.get(0);
items.add(new Builder()
.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() {
@ -154,23 +259,8 @@ 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() {
if (isMultipleItem()) {
String checkBoxTitle; String checkBoxTitle;
if (Algorithms.isEmpty(selectedItems)) { if (Algorithms.isEmpty(selectedItems)) {
checkBox.setState(UNCHECKED); checkBox.setState(UNCHECKED);
@ -183,19 +273,18 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, checkBoxColor))); CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, checkBoxColor)));
this.checkBoxTitle.setText(checkBoxTitle); this.checkBoxTitle.setText(checkBoxTitle);
} }
}
private void updateSelectedSizeView() { private void updateSelectedSizeView() {
if (isMultipleItem()) {
String selected = String.valueOf(selectedItems.size()); String selected = String.valueOf(selectedItems.size());
String all = String.valueOf(allItems.size()); String all = String.valueOf(allItems.size());
selectedSize.setText(getString(R.string.ltr_or_rtl_combine_via_slash, selected, all)); 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);
@ -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) {
@ -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) {
@ -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;
@ -501,4 +505,14 @@ public class DownloadActivityType {
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);
@ -206,6 +207,9 @@ public class DownloadOsmandIndexesHelper {
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);

View file

@ -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;
} }
} }
} }

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,6 +11,9 @@ 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;
@ -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,23 +1,47 @@
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 final OsmandApplication app,
@NonNull DateFormat dateFormat,
boolean showRemoteDate,
@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 AppCompatActivity activity,
@NonNull final OsmandApplication app, @NonNull final OsmandApplication app,
@NonNull DateFormat dateFormat, @NonNull DateFormat dateFormat,
@ -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();
dialog.setTitle(app.getString(isListDialog ? R.string.welmode_download_maps : R.string.srtm_unit_format));
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 // download left regions
return multipleIndexItem.getIndexesToDownload(); return ((MultipleIndexItem) downloadItem).getIndexesToDownload();
} else { } else {
// download all regions again // download all regions again
return multipleIndexItem.getAllIndexes(); return ((MultipleIndexItem) downloadItem).getAllIndexes();
}
} else {
List<IndexItem> indexesToDownload = new ArrayList<>();
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;
@ -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) {
@ -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")
@ -459,6 +495,7 @@ public class ItemViewHolder {
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() {

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;
@ -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

@ -126,6 +126,7 @@ 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;
@ -205,7 +206,6 @@ 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>();
@ -214,7 +214,6 @@ public class ResourceManager {
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;
@ -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) {
@ -607,8 +607,6 @@ 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()) {
@ -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 {
@ -944,7 +943,6 @@ 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) {
@ -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) {
@ -1183,7 +1180,6 @@ 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))