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:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/content_padding_small"
android:paddingEnd="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding_small"
android:paddingStart="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding">
android:paddingBottom="@dimen/content_padding_small">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/check_box_title"

View file

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

View file

@ -5,6 +5,7 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
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.BottomSheetItemWithCompoundButton;
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.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.view.ThreeStateCheckbox;
@ -35,6 +42,8 @@ import static net.osmand.view.ThreeStateCheckbox.State.UNCHECKED;
public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = SelectMultipleItemsBottomSheet.class.getSimpleName();
private OsmandApplication app;
private UiUtilities uiUtilities;
@ -45,15 +54,57 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
private TextView selectedSize;
private ThreeStateCheckbox checkBox;
private int sizeAboveList = 0;
private int activeColorRes;
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> selectedItems = new ArrayList<>();
private SelectionUpdateListener selectionUpdateListener;
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
@Override
@ -72,9 +123,18 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
items.add(createTitleItem());
items.add(new SimpleDividerItem(app));
sizeAboveList = items.size();
createListItems();
}
@Override
public void onPause() {
super.onPause();
if (requireActivity().isChangingConfigurations()) {
dismiss();
}
}
private BaseBottomSheetItem createTitleItem() {
LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode);
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);
title = view.findViewById(R.id.title);
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() {
@Override
public void onClick(View v) {
@ -99,24 +165,69 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
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();
}
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);
final BottomSheetItemWithCompoundButton[] uiItem = new BottomSheetItemWithCompoundButton[1];
final Builder builder = (BottomSheetItemWithCompoundButton.Builder) new Builder();
builder.setChecked(checked)
final int finalI = i;
items.add(new Builder()
.setChecked(checked)
.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)
.setTag(item)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean checked = !uiItem[0].isChecked();
uiItem[0].setChecked(checked);
SelectableItem tag = (SelectableItem) uiItem[0].getTag();
if (checked) {
public void onClick(View view) {
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);
@ -124,25 +235,19 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
onSelectedItemsChanged();
}
})
.setTag(item);
setupListItem(builder, item);
uiItem[0] = builder.create();
items.add(uiItem[0]);
.create());
}
} 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() {
@ -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() {
if (isMultipleItem()) {
String checkBoxTitle;
if (Algorithms.isEmpty(selectedItems)) {
checkBox.setState(UNCHECKED);
@ -183,19 +273,18 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, checkBoxColor)));
this.checkBoxTitle.setText(checkBoxTitle);
}
}
private void updateSelectedSizeView() {
if (isMultipleItem()) {
String selected = String.valueOf(selectedItems.size());
String all = String.valueOf(allItems.size());
selectedSize.setText(getString(R.string.ltr_or_rtl_combine_via_slash, selected, all));
}
}
private void updateApplyButtonEnable() {
if (Algorithms.isEmpty(selectedItems)) {
rightButton.setEnabled(false);
} else {
rightButton.setEnabled(true);
}
rightButton.setEnabled(!Algorithms.isEmpty(selectedItems));
}
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) {
this.title.setText(title);
}
@ -214,45 +356,24 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
this.description.setText(description);
}
public void setConfirmButtonTitle(@NonNull String confirmButtonTitle) {
applyButtonTitle.setText(confirmButtonTitle);
public void setAddDescriptionText(String addDescriptionText) {
this.addDescriptionText = addDescriptionText;
}
private void setItems(List<SelectableItem> allItems) {
if (!Algorithms.isEmpty(allItems)) {
this.allItems.addAll(allItems);
}
public void setLeftRadioButtonText(String leftRadioButtonText) {
this.leftRadioButtonText = leftRadioButtonText;
}
private void setSelectedItems(List<SelectableItem> selected) {
if (!Algorithms.isEmpty(selected)) {
this.selectedItems.addAll(selected);
}
public void setRightRadioButtonText(String rightRadioButtonText) {
this.rightRadioButtonText = rightRadioButtonText;
}
public List<SelectableItem> getSelectedItems() {
return selectedItems;
public void setCustomOptionsVisible(boolean customOptionsVisible) {
this.customOptionsVisible = customOptionsVisible;
}
@Override
public void onPause() {
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 setLeftButtonSelected(boolean leftButtonSelected) {
this.leftButtonSelected = leftButtonSelected;
}
public void setSelectionUpdateListener(SelectionUpdateListener selectionUpdateListener) {
@ -263,6 +384,14 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
this.onApplySelectionListener = onApplySelectionListener;
}
public void setOnRadioButtonSelectListener(OnRadioButtonSelectListener onRadioButtonSelectListener) {
this.onRadioButtonSelectListener = onRadioButtonSelectListener;
}
public void setSelectedItemsListener(SelectedItemsListener selectedItemsListener) {
this.selectedItemsListener = selectedItemsListener;
}
public interface SelectionUpdateListener {
void onSelectionUpdate();
}
@ -271,6 +400,10 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
void onSelectionApplied(List<SelectableItem> selectedItems);
}
public interface OnRadioButtonSelectListener {
void onSelect(boolean leftButton);
}
public static class SelectableItem {
private String title;
private String description;
@ -281,6 +414,10 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String 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;
}
public void setTag(Object tag) {
this.tag = tag;
}
public BaseBottomSheetItem(View view,
@LayoutRes int layoutId,
Object tag,

View file

@ -10,6 +10,7 @@ import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.util.Algorithms;
@ -27,6 +28,8 @@ import java.util.Locale;
import java.util.Map;
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 {
private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.US);
@ -83,7 +86,7 @@ public class DownloadActivityType {
iconResource = R.drawable.ic_map;
}
public int getStringResource(){
public int getStringResource() {
return stringResource;
}
@ -101,7 +104,7 @@ public class DownloadActivityType {
public static boolean isCountedInDownloads(IndexItem es) {
DownloadActivityType tp = es.getType();
if(tp == NORMAL_FILE || tp == ROADS_FILE){
if (tp == NORMAL_FILE || tp == ROADS_FILE) {
if (!es.extra) {
return true;
}
@ -126,11 +129,11 @@ public class DownloadActivityType {
}
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))
|| fileName.endsWith(IndexConstants.EXTRA_ZIP_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));
} else if (VOICE_FILE == this) {
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,
IndexConstants.BINARY_MAP_VERSION));
} else if (SRTM_COUNTRY_FILE == this) {
return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP,
IndexConstants.BINARY_MAP_VERSION));
boolean srtm = fileName.endsWith(addVersionToExt(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP, 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) {
return fileName.endsWith(IndexConstants.SQLITE_EXT);
} else if (SLOPE_FILE == this) {
@ -217,7 +221,7 @@ public class DownloadActivityType {
return IndexConstants.EXTRA_EXT;
} else if (indexItem.fileName.endsWith(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 "";
}
} else if (ROADS_FILE == this) {
@ -227,7 +231,7 @@ public class DownloadActivityType {
} else if (FONT_FILE == this) {
return IndexConstants.FONT_INDEX_EXT;
} else if (SRTM_COUNTRY_FILE == this) {
return IndexConstants.BINARY_SRTM_MAP_INDEX_EXT;
return getSRTMExt(indexItem);
} else if (WIKIPEDIA_FILE == this) {
return IndexConstants.BINARY_WIKI_MAP_INDEX_EXT;
} else if (WIKIVOYAGE_FILE == this) {
@ -251,7 +255,7 @@ public class DownloadActivityType {
}
public String getUrlSuffix(OsmandApplication ctx) {
if (this== ROADS_FILE) {
if (this == ROADS_FILE) {
return "&road=yes";
} else if (this == LIVE_UPDATES_FILE) {
return "&aosmc=yes";
@ -280,7 +284,7 @@ public class DownloadActivityType {
public String getBaseUrl(OsmandApplication ctx, String fileName) {
String url = "https://" + IndexConstants.INDEX_DOWNLOAD_DOMAIN + "/download?event=2&"
+ 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()
String region = fileName.substring(0, fileName.length() - 16).toLowerCase();
url += "&region=" + encode(region);
@ -423,7 +427,7 @@ public class DownloadActivityType {
}
String baseNameWithoutVersion = fileName.substring(0, l);
if (this == SRTM_COUNTRY_FILE) {
return baseNameWithoutVersion + IndexConstants.BINARY_SRTM_MAP_INDEX_EXT;
return baseNameWithoutVersion + getSRTMExt(item);
}
if (this == WIKIPEDIA_FILE) {
return baseNameWithoutVersion + IndexConstants.BINARY_WIKI_MAP_INDEX_EXT;
@ -487,7 +491,7 @@ public class DownloadActivityType {
return fileName.substring(0, l);
}
if (this == LIVE_UPDATES_FILE) {
if(fileName.indexOf('.') > 0){
if (fileName.indexOf('.') > 0) {
return fileName.substring(0, fileName.indexOf('.'));
}
return fileName;
@ -495,10 +499,20 @@ public class DownloadActivityType {
int ls = fileName.lastIndexOf('_');
if (ls >= 0) {
return fileName.substring(0, ls);
} else if(fileName.indexOf('.') > 0){
} else if (fileName.indexOf('.') > 0) {
return fileName.substring(0, fileName.indexOf('.'));
}
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;
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.IOException;
import java.io.InputStream;
@ -11,26 +32,6 @@ import java.util.Comparator;
import java.util.List;
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 {
private final static Log log = PlatformUtil.getLog(DownloadOsmandIndexesHelper.class);
@ -42,18 +43,18 @@ public class DownloadOsmandIndexesHelper {
ArrayList<IndexItem> indexFiles = new ArrayList<IndexItem>();
private String mapversion;
private Comparator<IndexItem> comparator = new Comparator<IndexItem>(){
private Comparator<IndexItem> comparator = new Comparator<IndexItem>() {
@Override
public int compare(IndexItem o1, IndexItem o2) {
String object1 = o1.getFileName();
String object2 = o2.getFileName();
if(object1.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
if(object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
if (object1.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)) {
if (object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)) {
return object1.compareTo(object2);
} else {
return -1;
}
} else if(object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)){
} else if (object2.endsWith(IndexConstants.ANYVOICE_INDEX_EXT_ZIP)) {
return 1;
}
return object1.compareTo(object2);
@ -75,12 +76,12 @@ public class DownloadOsmandIndexesHelper {
@SuppressLint("DefaultLocale")
public void add(IndexItem indexItem) {
indexFiles.add(indexItem);
if(indexItem.getFileName().toLowerCase().startsWith("world_basemap")) {
if (indexItem.getFileName().toLowerCase().startsWith("world_basemap")) {
basemap = indexItem;
}
}
public void sort(){
public void sort() {
Collections.sort(indexFiles, comparator);
}
@ -179,14 +180,14 @@ public class DownloadOsmandIndexesHelper {
}
private static IndexFileList downloadIndexesListFromInternet(OsmandApplication ctx){
private static IndexFileList downloadIndexesListFromInternet(OsmandApplication ctx) {
try {
IndexFileList result = new IndexFileList();
log.debug("Start loading list of index files"); //$NON-NLS-1$
try {
String strUrl = ctx.getAppCustomization().getIndexesUrl();
long nd = ctx.getAppInitializer().getFirstInstalledDays();
if(nd > 0) {
if (nd > 0) {
strUrl += "&nd=" + nd;
}
strUrl += "&ns=" + ctx.getAppInitializer().getNumberOfStarts();
@ -202,12 +203,15 @@ public class DownloadOsmandIndexesHelper {
GZIPInputStream gzin = new GZIPInputStream(in);
parser.setInput(gzin, "UTF-8"); //$NON-NLS-1$
int next;
while((next = parser.next()) != XmlPullParser.END_DOCUMENT) {
while ((next = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (next == XmlPullParser.START_TAG) {
DownloadActivityType tp = DownloadActivityType.getIndexType(parser.getAttributeValue(null, "type"));
if (tp != null) {
if (tp == DownloadActivityType.SRTM_COUNTRY_FILE) {
log.debug("strUrl = " + strUrl);
}
IndexItem it = tp.parseIndexItem(ctx, parser);
if(it != null) {
if (it != null) {
result.add(it);
}
} else if ("osmand_regions".equals(parser.getName())) {
@ -261,7 +265,7 @@ public class DownloadOsmandIndexesHelper {
return new DownloadEntry(assetName, destFile, dateModified);
}
public String getDestFile(){
public String getDestFile() {
return destFile;
}
}

View file

@ -528,7 +528,6 @@ public class DownloadResources extends DownloadResourceGroup {
if (index.getType() == type) {
found = true;
collectedIndexes.add(index);
break;
}
}
}

View file

@ -1,5 +1,7 @@
package net.osmand.plus.download;
import android.content.Context;
import androidx.annotation.NonNull;
import net.osmand.map.WorldRegion;
@ -9,6 +11,9 @@ import java.io.File;
import java.util.ArrayList;
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 {
private final List<IndexItem> items;
@ -110,6 +115,22 @@ public class MultipleIndexItem extends DownloadItem {
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
public double getArchiveSizeMB() {
double result = 0.0d;
@ -118,5 +139,4 @@ public class MultipleIndexItem extends DownloadItem {
}
return result;
}
}

View file

@ -1,23 +1,47 @@
package net.osmand.plus.download;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import net.osmand.IndexConstants;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.base.SelectMultipleItemsBottomSheet;
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.SelectionUpdateListener;
import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.util.Algorithms;
import java.text.DateFormat;
import java.util.ArrayList;
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 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 final OsmandApplication app,
@NonNull DateFormat dateFormat,
@ -30,12 +54,10 @@ public class MultipleIndexesUiHelper {
for (IndexItem indexItem : multipleIndexItem.getAllIndexes()) {
SelectableItem selectableItem = new SelectableItem();
selectableItem.setTitle(indexItem.getVisibleName(app, osmandRegions, false));
String size = indexItem.getSizeDescription(app);
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);
allItems.add(selectableItem);
@ -51,22 +73,102 @@ public class MultipleIndexesUiHelper {
dialog.setSelectionUpdateListener(new SelectionUpdateListener() {
@Override
public void onSelectionUpdate() {
dialog.setTitle(app.getString(R.string.welmode_download_maps));
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);
updateSize(app, dialog);
}
});
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
public void onSelectionApplied(List<SelectableItem> selectedItems) {
List<IndexItem> indexItems = new ArrayList<>();
@ -78,16 +180,70 @@ public class MultipleIndexesUiHelper {
}
listener.onItemsToDownloadSelected(indexItems);
}
});
};
}
private static List<IndexItem> getIndexesToDownload(MultipleIndexItem multipleIndexItem) {
if (multipleIndexItem.hasActualDataToDownload()) {
private static void updateSize(OsmandApplication app, SelectMultipleItemsBottomSheet dialog) {
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
return multipleIndexItem.getIndexesToDownload();
return ((MultipleIndexItem) downloadItem).getIndexesToDownload();
} else {
// 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);
}
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.text.DateFormat;
import java.util.ArrayList;
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 {
protected final TextView nameTextView;
@ -160,20 +167,20 @@ public class ItemViewHolder {
boolean disabled = checkDisabledAndClickAction(downloadItem);
/// name and left item
String name;
if(showTypeInName) {
if (showTypeInName) {
name = downloadItem.getType().getString(context);
} else {
name = downloadItem.getVisibleName(context, context.getMyApplication().getRegions(), showParentRegionName);
}
String text = (!Algorithms.isEmpty(cityName) && !cityName.equals(name) ? cityName + "\n" : "") + name;
nameTextView.setText(text);
if(!disabled) {
if (!disabled) {
nameTextView.setTextColor(textColorPrimary);
} else {
nameTextView.setTextColor(textColorSecondary);
}
int color = textColorSecondary;
if(downloadItem.isDownloaded() && !isDownloading) {
if (downloadItem.isDownloaded() && !isDownloading) {
int colorId = downloadItem.isOutdated() ? R.color.color_distance : R.color.color_ok;
color = context.getResources().getColor(colorId);
}
@ -189,6 +196,8 @@ public class ItemViewHolder {
}
descrTextView.setTextColor(textColorSecondary);
if (!isDownloading) {
boolean srtmItem = isSRTMItem(downloadItem);
boolean baseMetricSystem = isBaseSRTMMetricSystem(context.getMyApplication());
progressBar.setVisibility(View.GONE);
descrTextView.setVisibility(View.VISIBLE);
if (downloadItem instanceof CustomIndexItem && (((CustomIndexItem) downloadItem).getSubName(context) != null)) {
@ -207,31 +216,55 @@ public class ItemViewHolder {
MultipleIndexItem item = (MultipleIndexItem) downloadItem;
String allRegionsHeader = context.getString(R.string.shared_strings_all_regions);
String regionsHeader = context.getString(R.string.regions);
String allRegionsCount = String.valueOf(item.getAllIndexes().size());
String leftToDownloadCount = String.valueOf(item.getIndexesToDownload().size());
String allRegionsCountStr;
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 count;
if (item.hasActualDataToDownload()) {
if (!item.isDownloaded()) {
header = allRegionsHeader;
count = leftToDownloadCount;
count = leftToDownloadCountStr;
} else {
header = regionsHeader;
count = String.format(
context.getString(R.string.ltr_or_rtl_combine_via_slash),
leftToDownloadCount,
allRegionsCount);
leftToDownloadCountStr,
allRegionsCountStr);
}
} else {
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()) {
fullDescription = context.getString(
R.string.ltr_or_rtl_combine_via_bold_point, fullDescription,
item.getSizeDescription(context));
R.string.ltr_or_rtl_combine_via_bold_point, fullDescription, srtmItem
? item.getSizeDescription(context, baseMetricSystem) : item.getSizeDescription(context));
}
descrTextView.setText(fullDescription);
} else {
@ -239,6 +272,9 @@ public class ItemViewHolder {
String pattern = context.getString(R.string.ltr_or_rtl_combine_via_bold_point);
String type = item.getType().getString(context);
String size = item.getSizeDescription(context);
if (srtmItem) {
size += " (" + getSRTMAbbrev(context, isBaseSRTMItem(item)) + ")";
}
String date = item.getDate(dateFormat, showRemoteDate);
String fullDescription = String.format(pattern, size, date);
if (showTypeInDesc) {
@ -254,14 +290,14 @@ public class ItemViewHolder {
if (showProgressInDesc) {
double mb = downloadItem.getArchiveSizeMB();
String v ;
String v;
if (progress != -1) {
v = context.getString(R.string.value_downloaded_of_max, mb * progress / 100, mb);
} else {
v = context.getString(R.string.file_size_in_mb, mb);
}
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,
downloadItem.getType().getString(context), fullDescription);
}
@ -302,7 +338,7 @@ public class ItemViewHolder {
if (isDownloading) {
rightImageButton.setImageDrawable(getContentIcon(context, R.drawable.ic_action_remove_dark));
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.setContentDescription(context.getString(R.string.shared_string_more));
} else {
@ -318,7 +354,7 @@ public class ItemViewHolder {
private int getDownloadActionIconId(@NonNull DownloadItem item) {
return item instanceof MultipleIndexItem ?
R.drawable.ic_action_multi_download :
R.drawable.ic_action_import;
R.drawable.ic_action_gsave_dark;
}
@SuppressLint("DefaultLocale")
@ -389,13 +425,13 @@ public class ItemViewHolder {
return new View.OnClickListener() {
@Override
public void onClick(View v) {
if(isDownloading) {
if(silentCancelDownload) {
if (isDownloading) {
if (silentCancelDownload) {
context.getDownloadThread().cancelDownload(item);
} else {
context.makeSureUserCancelDownload(item);
}
} else if(!item.hasActualDataToDownload()){
} else if (!item.hasActualDataToDownload()) {
showContextMenu(v, item, item.getRelatedGroup());
} else {
download(item, item.getRelatedGroup());
@ -455,10 +491,11 @@ public class ItemViewHolder {
}
}
}
if(!handled) {
if (!handled) {
startDownload(item);
}
}
private void confirmDownload(final DownloadItem item) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.are_you_sure);
@ -476,15 +513,15 @@ public class ItemViewHolder {
}
private void startDownload(DownloadItem item) {
if (item instanceof MultipleIndexItem) {
selectIndexesToDownload((MultipleIndexItem) item);
if (item instanceof MultipleIndexItem || item.getType() == SRTM_COUNTRY_FILE) {
selectIndexesToDownload(item);
} else if (item instanceof IndexItem) {
IndexItem indexItem = (IndexItem) item;
context.startDownload(indexItem);
}
}
private void selectIndexesToDownload(MultipleIndexItem item) {
private void selectIndexesToDownload(DownloadItem item) {
OsmandApplication app = context.getMyApplication();
MultipleIndexesUiHelper.showDialog(item, context, app, dateFormat, showRemoteDate,
new SelectItemsToDownloadListener() {

View file

@ -74,6 +74,10 @@ import java.util.List;
import java.util.Map;
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,
OnMapSourceUpdateListener, RenameCallback {
private LoadLocalIndexTask asyncLoader;
@ -351,10 +355,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
getMyApplication().getResourceManager().closeFile(info.getFileName());
File tShm = new File(f.getParentFile(), f.getName() + "-shm");
File tWal = new File(f.getParentFile(), f.getName() + "-wal");
if(tShm.exists()) {
if (tShm.exists()) {
Algorithms.removeAllFiles(tShm);
}
if(tWal.exists()) {
if (tWal.exists()) {
Algorithms.removeAllFiles(tWal);
}
}
@ -371,7 +375,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
}
} else if (operation == CLEAR_TILES_OPERATION) {
ITileSource src = (ITileSource) info.getAttachedObject();
if(src != null) {
if (src != null) {
src.deleteTiles(info.getPathToData());
}
}
@ -419,7 +423,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
@Override
protected void onPostExecute(String result) {
a.setProgressBarIndeterminateVisibility(false);
if(result != null && result.length() > 0) {
if (result != null && result.length() > 0) {
Toast.makeText(a, result, Toast.LENGTH_LONG).show();
}
@ -963,7 +967,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
return ctx.getString(R.string.download_roads_only_item);
} else if (child.isBackupedData() && child.getFileName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) {
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 "";
@ -1029,6 +1034,10 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
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 (builder.length() > 0) {
builder.append("");
@ -1150,5 +1159,4 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
private DownloadActivity getDownloadActivity() {
return (DownloadActivity) getActivity();
}
}

View file

@ -94,7 +94,7 @@ public class ResourceManager {
protected static ResourceManager manager = null;
protected File dirWithTiles ;
protected File dirWithTiles;
private List<TilesCache> tilesCacheList = new ArrayList<>();
private BitmapTilesCache bitmapTilesCache;
@ -126,10 +126,11 @@ public class ResourceManager {
private List<BinaryMapIndexReader> readers = new ArrayList<>(BinaryMapReaderResourceType.values().length);
private boolean useForRouting;
private boolean useForPublicTransport;
public BinaryMapReaderResource(File f, BinaryMapIndexReader initialReader) {
this.filename = f;
this.initialReader = initialReader;
while(readers.size() < BinaryMapReaderResourceType.values().length) {
while (readers.size() < BinaryMapReaderResourceType.values().length) {
readers.add(null);
}
}
@ -205,16 +206,14 @@ public class ResourceManager {
protected final Map<String, BinaryMapReaderResource> fileReaders = new ConcurrentHashMap<String, BinaryMapReaderResource>();
private final Map<String, RegionAddressRepository> addressMap = new ConcurrentHashMap<String, RegionAddressRepository>();
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> travelRepositories = new ConcurrentHashMap<String, BinaryMapReaderResource>();
protected final Map<String, String> indexFileNames = new ConcurrentHashMap<String, String>();
protected final Map<String, String> basemapFileNames = new ConcurrentHashMap<String, String>();
protected final IncrementalChangesManager changesManager = new IncrementalChangesManager(this);
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
try {
context.getAppPath(".nomedia").createNewFile(); //$NON-NLS-1$
} catch( Exception e ) {
} catch (Exception e) {
}
for (TilesCache tilesCache : tilesCacheList) {
tilesCache.setDirWithTiles(dirWithTiles);
@ -323,7 +322,7 @@ public class ResourceManager {
return null;
}
public synchronized void tileDownloaded(DownloadRequest request){
public synchronized void tileDownloaded(DownloadRequest request) {
if (request instanceof TileLoadDownloadRequest) {
TileLoadDownloadRequest req = ((TileLoadDownloadRequest) request);
TilesCache cache = getTilesCache(req.tileSource);
@ -338,7 +337,7 @@ public class ResourceManager {
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);
if (cache != null) {
cache.getTileForMap(file, map, x, y, zoom, true, false, true, true);
@ -376,7 +375,7 @@ public class ResourceManager {
////////////////////////////////////////////// Working with indexes ////////////////////////////////////////////////
public List<String> reloadIndexesOnStart(AppInitializer progress, List<String> warnings){
public List<String> reloadIndexesOnStart(AppInitializer progress, List<String> warnings) {
close();
// check we have some assets to copy to sdcard
warnings.addAll(checkAssets(progress, false));
@ -429,7 +428,7 @@ public class ResourceManager {
return warnings;
}
public List<String> indexFontFiles(IProgress progress){
public List<String> indexFontFiles(IProgress progress) {
File file = context.getAppPath(IndexConstants.FONT_INDEX_DIR);
file.mkdirs();
List<String> warnings = new ArrayList<String>();
@ -476,7 +475,7 @@ public class ResourceManager {
public List<String> checkAssets(IProgress progress, boolean forceUpdate) {
String fv = Version.getFullVersion(context);
if(context.getAppInitializer().isAppVersionChanged()) {
if (context.getAppInitializer().isAppVersionChanged()) {
copyMissingJSAssets();
}
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__alwaysOverwriteOrCopy = "alwaysOverwriteOrCopy";
private final static String ASSET_COPY_MODE__copyOnlyIfDoesNotExist = "copyOnlyIfDoesNotExist";
private void unpackBundledAssets(AssetManager assetManager, File appDataDir, IProgress progress, boolean isFirstInstall) throws IOException, XmlPullParserException {
List<AssetEntry> assetEntries = DownloadOsmandIndexesHelper.getBundledAssets(assetManager);
for (AssetEntry asset : assetEntries) {
@ -581,7 +581,7 @@ public class ResourceManager {
}
public static void copyAssets(AssetManager assetManager, String assetName, File file) throws IOException {
if(file.exists()){
if (file.exists()) {
Algorithms.removeAllFiles(file);
}
file.getParentFile().mkdirs();
@ -593,9 +593,9 @@ public class ResourceManager {
}
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();
if(lf == null || lf.length == 0) {
if (lf == null || lf.length == 0) {
return files;
}
for (File f : lf) {
@ -607,11 +607,9 @@ public class ResourceManager {
return files;
}
private void renameRoadsFiles(ArrayList<File> files, File roadsPath) {
Iterator<File> it = files.iterator();
while(it.hasNext()) {
while (it.hasNext()) {
File f = it.next();
if (f.getName().endsWith("-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);
}
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))) {
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
} else {
@ -714,9 +713,9 @@ public class ResourceManager {
if (dateCreated == 0) {
dateCreated = f.lastModified();
}
if(f.getParentFile().getName().equals(liveDir.getName())) {
if (f.getParentFile().getName().equals(liveDir.getName())) {
boolean toUse = changesManager.index(f, dateCreated, mapReader);
if(!toUse) {
if (!toUse) {
try {
mapReader.close();
} catch (IOException e) {
@ -724,7 +723,7 @@ public class ResourceManager {
}
continue;
}
} else if(!wikiMap && !srtmMap) {
} else if (!wikiMap && !srtmMap) {
changesManager.indexMainMap(f, dateCreated);
}
indexFileNames.put(f.getName(), dateFormat.format(dateCreated)); //$NON-NLS-1$
@ -733,7 +732,7 @@ public class ResourceManager {
}
renderer.initializeNewResource(progress, f, mapReader);
BinaryMapReaderResource resource = new BinaryMapReaderResource(f, mapReader);
if (collectTravelFiles(resource)){
if (collectTravelFiles(resource)) {
//travel files are indexed
continue;
}
@ -789,7 +788,7 @@ public class ResourceManager {
}
}
Iterator<Entry<PoiCategory, Map<String, PoiType>>> it = toAddPoiTypes.entrySet().iterator();
while(it.hasNext()) {
while (it.hasNext()) {
Entry<PoiCategory, Map<String, PoiType>> next = it.next();
PoiCategory category = next.getKey();
category.addExtraPoiTypes(next.getValue());
@ -839,7 +838,7 @@ public class ResourceManager {
}
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);
return true;
}
@ -931,7 +930,7 @@ public class ResourceManager {
if (!repos.isEmpty()) {
for (AmenityIndexRepository r : repos) {
List<Amenity> res = r.searchAmenitiesOnThePath(locations, radius, filter, matcher);
if(res != null) {
if (res != null) {
amenities.addAll(res);
}
}
@ -944,11 +943,10 @@ public class ResourceManager {
return amenities;
}
public boolean containsAmenityRepositoryToSearch(boolean searchByName){
public boolean containsAmenityRepositoryToSearch(boolean searchByName) {
for (AmenityIndexRepository index : getAmenityRepositories()) {
if(searchByName){
if(index instanceof AmenityIndexRepositoryBinary){
if (searchByName) {
if (index instanceof AmenityIndexRepositoryBinary) {
return true;
}
} else {
@ -973,7 +971,7 @@ public class ResourceManager {
}
if (index instanceof AmenityIndexRepositoryBinary) {
if (index.checkContainsInt(top, left, bottom, right)) {
if(index.checkContains(lat, lon)){
if (index.checkContains(lat, lon)) {
list.add(0, (AmenityIndexRepositoryBinary) index);
} else {
list.add((AmenityIndexRepositoryBinary) index);
@ -1019,11 +1017,11 @@ public class ResourceManager {
////////////////////////////////////////////// Working with address ///////////////////////////////////////////
public RegionAddressRepository getRegionRepository(String name){
public RegionAddressRepository getRegionRepository(String name) {
return addressMap.get(name);
}
public Collection<RegionAddressRepository> getAddressRepositories(){
public Collection<RegionAddressRepository> getAddressRepositories() {
return addressMap.values();
}
@ -1040,7 +1038,6 @@ public class ResourceManager {
return res;
}
////////////////////////////////////////////// Working with transport ////////////////////////////////////////////////
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) {
List<TransportRoute> rts = stop.getRoutes();
if(rts != null) {
if (rts != null) {
return rts;
}
return Collections.emptyList();
@ -1087,12 +1084,12 @@ public class ResourceManager {
return renderer.updateMapIsNeeded(rotatedTileBox, drawSettings);
}
public void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener){
public void updateRendererMap(RotatedTileBox rotatedTileBox, OnMapLoadedListener mapLoadedListener) {
renderer.interruptLoadingMap();
asyncLoadingThread.requestToLoadMap(new MapLoadRequest(rotatedTileBox, mapLoadedListener));
}
public void interruptRendering(){
public void interruptRendering() {
renderer.interruptLoadingMap();
}
@ -1114,12 +1111,12 @@ public class ResourceManager {
travelRepositories.remove(fileName);
renderer.closeConnection(fileName);
BinaryMapReaderResource resource = fileReaders.remove(fileName);
if(resource != null) {
if (resource != null) {
resource.close();
}
}
public synchronized void close(){
public synchronized void close() {
for (TilesCache tc : tilesCacheList) {
tc.close();
}
@ -1130,7 +1127,7 @@ public class ResourceManager {
travelRepositories.clear();
addressMap.clear();
amenityRepositories.clear();
for(BinaryMapReaderResource res : fileReaders.values()) {
for (BinaryMapReaderResource res : fileReaders.values()) {
res.close();
}
fileReaders.clear();
@ -1183,8 +1180,7 @@ public class ResourceManager {
return new LinkedHashMap<String, String>(indexFileNames);
}
public boolean containsBasemap(){
public boolean containsBasemap() {
return !basemapFileNames.isEmpty();
}

View file

@ -200,7 +200,7 @@ public class DataStorageHelper {
terrainMemory = MemoryItem.builder()
.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(
createDirectory(SRTM_INDEX_DIR, true, EXTENSIONS, true),
createDirectory(TILES_INDEX_DIR, false, PREFIX, false))