diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index db67d2bf0d..b6598b916b 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -20,7 +20,7 @@
Please select the needed format. You will need to re-download the file to change the format.
OsmAnd provides contour lines data in meters and feet. You will need to re-download the file to change the format.
Contour lines unit format
- feets
+ feet
Update all maps added to %1$s?
• OsmAnd Live updates moved to \"Downloads > Updates\"\n\n
diff --git a/OsmAnd/src/net/osmand/plus/base/MultipleSelectionBottomSheet.java b/OsmAnd/src/net/osmand/plus/base/MultipleSelectionBottomSheet.java
index 728dfbaa65..fc7d75416a 100644
--- a/OsmAnd/src/net/osmand/plus/base/MultipleSelectionBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/base/MultipleSelectionBottomSheet.java
@@ -144,8 +144,8 @@ public class MultipleSelectionBottomSheet extends SelectionBottomSheet {
}
protected void setSelectedItems(List selected) {
+ selectedItems.clear();
if (!Algorithms.isEmpty(selected)) {
- selectedItems.clear();
selectedItems.addAll(selected);
}
}
diff --git a/OsmAnd/src/net/osmand/plus/base/SelectionBottomSheet.java b/OsmAnd/src/net/osmand/plus/base/SelectionBottomSheet.java
index f4bea22e62..18c91f8cf5 100644
--- a/OsmAnd/src/net/osmand/plus/base/SelectionBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/base/SelectionBottomSheet.java
@@ -51,8 +51,8 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
protected int activeColorRes;
protected int secondaryColorRes;
- private OnUiInitializedListener uiInitializedListener;
- private OnApplySelectionListener applySelectionListener;
+ private OnUiInitializedAdapter onUiInitializedAdapter;
+ private OnApplySelectionListener onApplySelectionListener;
protected List allItems = new ArrayList<>();
protected Map listViews = new HashMap<>();
@@ -145,19 +145,19 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
}
public void setItems(List allItems) {
+ this.allItems.clear();
if (!Algorithms.isEmpty(allItems)) {
- this.allItems.clear();
this.allItems.addAll(allItems);
createSelectionListIfPossible();
}
}
- public void setUiInitializedListener(OnUiInitializedListener uiInitializedListener) {
- this.uiInitializedListener = uiInitializedListener;
+ public void setOnUiInitializedAdapter(OnUiInitializedAdapter onUiInitializedAdapter) {
+ this.onUiInitializedAdapter = onUiInitializedAdapter;
}
public void setOnApplySelectionListener(OnApplySelectionListener onApplySelectionListener) {
- this.applySelectionListener = onApplySelectionListener;
+ this.onApplySelectionListener = onApplySelectionListener;
}
private void createSelectionListIfPossible() {
@@ -194,8 +194,8 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
protected abstract boolean shouldShowDivider();
protected void notifyUiInitialized() {
- if (uiInitializedListener != null) {
- uiInitializedListener.onUiInitialized();
+ if (onUiInitializedAdapter != null) {
+ onUiInitializedAdapter.onUiInitialized();
}
}
@@ -215,8 +215,8 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
@Override
protected void onRightBottomButtonClick() {
- if (applySelectionListener != null) {
- applySelectionListener.onSelectionApplied(getSelectedItems());
+ if (onApplySelectionListener != null) {
+ onApplySelectionListener.onSelectionApplied(getSelectedItems());
}
dismiss();
}
@@ -239,7 +239,7 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
}
}
- public interface OnUiInitializedListener {
+ public interface OnUiInitializedAdapter {
void onUiInitialized();
}
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadItem.java b/OsmAnd/src/net/osmand/plus/download/DownloadItem.java
index 46b3855a10..6b758f8af8 100644
--- a/OsmAnd/src/net/osmand/plus/download/DownloadItem.java
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadItem.java
@@ -3,6 +3,7 @@ package net.osmand.plus.download;
import android.content.Context;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication;
@@ -59,9 +60,8 @@ public abstract class DownloadItem {
@NonNull
public abstract List getDownloadedFiles(@NonNull OsmandApplication app);
- public abstract boolean isUseAbbreviation();
-
- public abstract String getAbbreviationInScopes(Context ctx);
+ @Nullable
+ public abstract String getAdditionalDescription(Context ctx);
protected abstract double getSizeToDownloadInMb();
diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java
index e59e5f9de9..e2320b16a8 100644
--- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java
+++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java
@@ -25,6 +25,7 @@ import java.io.InputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
@@ -121,7 +122,7 @@ public class DownloadResources extends DownloadResourceGroup {
if (group != null) {
return group.getIndividualDownloadItems();
}
- return new LinkedList<>();
+ return Collections.emptyList();
}
@NonNull
@@ -132,7 +133,7 @@ public class DownloadResources extends DownloadResourceGroup {
return res;
}
}
- return new LinkedList<>();
+ return Collections.emptyList();
}
public void updateLoadedFiles() {
@@ -500,7 +501,7 @@ public class DownloadResources extends DownloadResourceGroup {
srtmIndexes.add((IndexItem) item);
}
}
- if (srtmIndexes.size() == 2) {
+ if (srtmIndexes.size() > 1) {
individualItems.removeAll(srtmIndexes);
group.addItem(new SrtmDownloadItem(srtmIndexes, useMetersByDefault));
}
diff --git a/OsmAnd/src/net/osmand/plus/download/IndexItem.java b/OsmAnd/src/net/osmand/plus/download/IndexItem.java
index 2cd75b2a5e..82da2619a3 100644
--- a/OsmAnd/src/net/osmand/plus/download/IndexItem.java
+++ b/OsmAnd/src/net/osmand/plus/download/IndexItem.java
@@ -3,6 +3,7 @@ package net.osmand.plus.download;
import android.content.Context;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
@@ -229,14 +230,10 @@ public class IndexItem extends DownloadItem implements Comparable {
return format.format(new Date(timestamp));
}
+ @Nullable
@Override
- public boolean isUseAbbreviation() {
- return false;
- }
-
- @Override
- public String getAbbreviationInScopes(Context ctx) {
- return "";
+ public String getAdditionalDescription(Context ctx) {
+ return null;
}
public static class DownloadEntry {
diff --git a/OsmAnd/src/net/osmand/plus/download/MultipleDownloadItem.java b/OsmAnd/src/net/osmand/plus/download/MultipleDownloadItem.java
index 268ae412b8..d30c9fc83b 100644
--- a/OsmAnd/src/net/osmand/plus/download/MultipleDownloadItem.java
+++ b/OsmAnd/src/net/osmand/plus/download/MultipleDownloadItem.java
@@ -144,28 +144,17 @@ public class MultipleDownloadItem extends DownloadItem {
return null;
}
+ @Nullable
@Override
- public boolean isUseAbbreviation() {
+ public String getAdditionalDescription(Context ctx) {
for (DownloadItem item : items) {
- if (item.isUseAbbreviation()) {
- return true;
- }
+ return item.getAdditionalDescription(ctx);
}
- return false;
- }
-
- @Override
- public String getAbbreviationInScopes(Context ctx) {
- for (DownloadItem item : items) {
- return item.getAbbreviationInScopes(ctx);
- }
- return "";
+ return null;
}
@Override
public String getDate(@NonNull DateFormat dateFormat, boolean remote) {
return "";
}
-
-
}
diff --git a/OsmAnd/src/net/osmand/plus/download/SelectIndexesUiHelper.java b/OsmAnd/src/net/osmand/plus/download/SelectIndexesUiHelper.java
index fc062c7ddc..f7835ce348 100644
--- a/OsmAnd/src/net/osmand/plus/download/SelectIndexesUiHelper.java
+++ b/OsmAnd/src/net/osmand/plus/download/SelectIndexesUiHelper.java
@@ -13,7 +13,7 @@ import net.osmand.plus.base.ModeSelectionBottomSheet;
import net.osmand.plus.base.MultipleSelectionWithModeBottomSheet;
import net.osmand.plus.base.SelectionBottomSheet;
import net.osmand.plus.base.SelectionBottomSheet.OnApplySelectionListener;
-import net.osmand.plus.base.SelectionBottomSheet.OnUiInitializedListener;
+import net.osmand.plus.base.SelectionBottomSheet.OnUiInitializedAdapter;
import net.osmand.plus.base.SelectionBottomSheet.SelectableItem;
import net.osmand.plus.widgets.MultiStateToggleButton.OnRadioItemClickListener;
import net.osmand.plus.widgets.MultiStateToggleButton.RadioItem;
@@ -80,7 +80,7 @@ public class SelectIndexesUiHelper {
activity, allItems, selectedItems, true);
this.dialog = msDialog;
- msDialog.setUiInitializedListener(new OnUiInitializedListener() {
+ msDialog.setOnUiInitializedAdapter(new OnUiInitializedAdapter() {
@Override
public void onUiInitialized() {
dialog.setTitle(app.getString(R.string.welmode_download_maps));
@@ -103,14 +103,14 @@ public class SelectIndexesUiHelper {
prepareItems(allItems, selectedItems);
SrtmDownloadItem srtmItem = (SrtmDownloadItem) ((MultipleDownloadItem)downloadItem).getAllItems().get(0);
- final int selectedModeOrder = srtmItem.isUseMeters() ? 0 : 1;
+ final int selectedModeOrder = srtmItem.isUseMetric() ? 0 : 1;
final List radioItems = createSrtmRadioItems();
MultipleSelectionBottomSheet msDialog = MultipleSelectionWithModeBottomSheet.showInstance(
activity, allItems, selectedItems, radioItems, true);
this.dialog = msDialog;
- msDialog.setUiInitializedListener(new OnUiInitializedListener() {
+ msDialog.setOnUiInitializedAdapter(new OnUiInitializedAdapter() {
@Override
public void onUiInitialized() {
dialog.setTitle(app.getString(R.string.welmode_download_maps));
@@ -131,14 +131,14 @@ public class SelectIndexesUiHelper {
private void showSrtmModeSelectionDialog() {
SrtmDownloadItem srtmItem = (SrtmDownloadItem) downloadItem;
- final int selectedModeOrder = srtmItem.isUseMeters() ? 0 : 1;
+ final int selectedModeOrder = srtmItem.isUseMetric() ? 0 : 1;
final List radioItems = createSrtmRadioItems();
SelectableItem preview = createSelectableItem(srtmItem);
dialog = ModeSelectionBottomSheet.showInstance(activity, preview, radioItems, true);
- dialog.setUiInitializedListener(new OnUiInitializedListener() {
+ dialog.setOnUiInitializedAdapter(new OnUiInitializedAdapter() {
@Override
public void onUiInitialized() {
ModeSelectionBottomSheet dialog = (ModeSelectionBottomSheet) SelectIndexesUiHelper.this.dialog;
@@ -169,7 +169,7 @@ public class SelectIndexesUiHelper {
private List createSrtmRadioItems() {
List radioItems = new ArrayList<>();
radioItems.add(createSrtmRadioBtn(R.string.shared_string_meters, true));
- radioItems.add(createSrtmRadioBtn(R.string.shared_string_feets, false));
+ radioItems.add(createSrtmRadioBtn(R.string.shared_string_feet, false));
return radioItems;
}
@@ -193,7 +193,7 @@ public class SelectIndexesUiHelper {
for (SelectableItem item : items) {
DownloadItem downloadItem = (DownloadItem) item.getObject();
if (downloadItem instanceof SrtmDownloadItem) {
- ((SrtmDownloadItem) downloadItem).setUseMeters(useMeters);
+ ((SrtmDownloadItem) downloadItem).setUseMetric(useMeters);
updateSelectableItem(item, downloadItem);
}
}
@@ -208,12 +208,12 @@ public class SelectIndexesUiHelper {
private void updateSelectableItem(SelectableItem selectableItem,
DownloadItem downloadItem) {
- selectableItem.setTitle(
- downloadItem.getVisibleName(app, app.getRegions(), false));
+ selectableItem.setTitle(downloadItem.getVisibleName(app, app.getRegions(), false));
String size = downloadItem.getSizeDescription(app);
- if (downloadItem.isUseAbbreviation()) {
- size += " " + downloadItem.getAbbreviationInScopes(app);
+ String addDescr = downloadItem.getAdditionalDescription(app);
+ if (addDescr != null) {
+ size += " " + addDescr;
}
String date = downloadItem.getDate(dateFormat, showRemoteDate);
String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date);
diff --git a/OsmAnd/src/net/osmand/plus/download/SrtmDownloadItem.java b/OsmAnd/src/net/osmand/plus/download/SrtmDownloadItem.java
index a9a184d57c..8567f97409 100644
--- a/OsmAnd/src/net/osmand/plus/download/SrtmDownloadItem.java
+++ b/OsmAnd/src/net/osmand/plus/download/SrtmDownloadItem.java
@@ -10,6 +10,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.helpers.enums.MetricsConstants;
+import net.osmand.util.Algorithms;
import java.io.File;
import java.text.DateFormat;
@@ -24,31 +25,40 @@ import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE;
public class SrtmDownloadItem extends DownloadItem {
private final List indexes;
- private boolean useMeters;
+ private boolean useMetric;
- public SrtmDownloadItem(List indexes,
- boolean useMeters) {
+ public SrtmDownloadItem(List indexes, boolean useMetric) {
super(SRTM_COUNTRY_FILE);
this.indexes = indexes;
- this.useMeters = useMeters;
+ this.useMetric = useMetric;
}
- public void setUseMeters(boolean useMeters) {
- this.useMeters = useMeters;
+ public void setUseMetric(boolean useMetric) {
+ this.useMetric = useMetric;
}
- public boolean isUseMeters() {
- return useMeters;
+ public boolean isUseMetric() {
+ for (IndexItem index : indexes) {
+ if (index.isDownloaded()) {
+ return isMetricItem(index);
+ }
+ }
+ return useMetric;
}
- @Nullable
+ @NonNull
public IndexItem getIndexItem() {
for (IndexItem index : indexes) {
- if (useMeters && isMetersItem(index) || !useMeters && !isMetersItem(index)) {
+ if (index.isDownloaded()) {
return index;
}
}
- return null;
+ for (IndexItem index : indexes) {
+ if (useMetric && isMetricItem(index) || !useMetric && !isMetricItem(index)) {
+ return index;
+ }
+ }
+ return indexes.get(0);
}
@Override
@@ -83,13 +93,12 @@ public class SrtmDownloadItem extends DownloadItem {
@Override
public boolean hasActualDataToDownload() {
- // may be check only downloaded items if any downloaded
for (IndexItem item : indexes) {
- if (item.hasActualDataToDownload()) {
- return true;
+ if (!item.hasActualDataToDownload()) {
+ return false;
}
}
- return false;
+ return true;
}
@Override
@@ -110,7 +119,6 @@ public class SrtmDownloadItem extends DownloadItem {
@NonNull
@Override
public List getDownloadedFiles(@NonNull OsmandApplication app) {
- // may be check both indexes files
List result = new ArrayList<>();
for (IndexItem index : indexes) {
result.addAll(index.getDownloadedFiles(app));
@@ -119,17 +127,11 @@ public class SrtmDownloadItem extends DownloadItem {
}
public String getDate(@NonNull DateFormat dateFormat, boolean remote) {
- // may be check only downloaded items if any downloaded
return getIndexItem().getDate(dateFormat, remote);
}
@Override
- public boolean isUseAbbreviation() {
- return true;
- }
-
- @Override
- public String getAbbreviationInScopes(Context ctx) {
+ public @Nullable String getAdditionalDescription(Context ctx) {
return getAbbreviationInScopes(ctx, this);
}
@@ -140,27 +142,8 @@ public class SrtmDownloadItem extends DownloadItem {
@NonNull
public static String getAbbreviationInScopes(Context ctx, Object obj) {
- return "(" + getAbbreviation(ctx, obj) + ")";
- }
-
- @NonNull
- public static String getAbbreviation(Context context, Object obj) {
- return context.getString(isMetersItem(obj) ? R.string.m : R.string.foot);
- }
-
- public static boolean isMetersItem(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);
- } else if (item instanceof SrtmDownloadItem) {
- return ((SrtmDownloadItem) item).useMeters;
- } else if (item instanceof MultipleDownloadItem) {
- for (DownloadItem downloadItem : ((MultipleDownloadItem) item).getAllItems()) {
- return isMetersItem(downloadItem);
- }
- }
- return false;
+ String abbreviation = ctx.getString(isMetricItem(obj) ? R.string.m : R.string.foot);
+ return "(" + abbreviation + ")";
}
public static boolean containsSrtmExtension(@NonNull String fileName) {
@@ -175,15 +158,13 @@ public class SrtmDownloadItem extends DownloadItem {
@NonNull
public static String getExtension(IndexItem indexItem) {
- return isMetersItem(indexItem) ?
+ return isMetricItem(indexItem) ?
IndexConstants.BINARY_SRTM_MAP_INDEX_EXT :
IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT;
}
public static boolean isSRTMItem(Object item) {
- if (item instanceof IndexItem) {
- return ((IndexItem) item).getType() == SRTM_COUNTRY_FILE;
- } else if (item instanceof DownloadItem) {
+ if (item instanceof DownloadItem) {
return ((DownloadItem) item).getType() == SRTM_COUNTRY_FILE;
} else if (item instanceof LocalIndexInfo) {
return ((LocalIndexInfo) item).getType() == SRTM_DATA;
@@ -191,4 +172,20 @@ public class SrtmDownloadItem extends DownloadItem {
return false;
}
+ private static boolean isMetricItem(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);
+ } else if (item instanceof SrtmDownloadItem) {
+ return isMetricItem(((SrtmDownloadItem) item).getIndexItem());
+ } else if (item instanceof MultipleDownloadItem) {
+ List items = ((MultipleDownloadItem) item).getAllItems();
+ if (!Algorithms.isEmpty(items)) {
+ return isMetricItem(items.get(0));
+ }
+ }
+ return false;
+ }
+
}
diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java
index 1bca97cfe1..135db84bc9 100644
--- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java
+++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java
@@ -227,8 +227,9 @@ public class ItemViewHolder {
count = allRegionsCount;
}
String fullDescription = context.getString(R.string.ltr_or_rtl_combine_via_colon, header, count);
- if (item.isUseAbbreviation()) {
- fullDescription += " " + item.getAbbreviationInScopes(context);
+ String addDescr = item.getAdditionalDescription(context);
+ if (addDescr != null) {
+ fullDescription += " " + addDescr;
}
if (item.hasActualDataToDownload()) {
fullDescription = context.getString(
@@ -240,8 +241,9 @@ public class ItemViewHolder {
String pattern = context.getString(R.string.ltr_or_rtl_combine_via_bold_point);
String type = downloadItem.getType().getString(context);
String size = downloadItem.getSizeDescription(context);
- if (downloadItem.isUseAbbreviation()) {
- size += " " + downloadItem.getAbbreviationInScopes(context);
+ String addDescr = downloadItem.getAdditionalDescription(context);
+ if (addDescr != null) {
+ size += " " + addDescr;
}
String date = downloadItem.getDate(dateFormat, showRemoteDate);
String fullDescription = String.format(pattern, size, date);