diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index 715d2f02f5..8024709969 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -29,7 +29,6 @@ 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.SelectIndexesUiHelper.getSRTMExt; public class DownloadActivityType { private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.US); @@ -231,7 +230,7 @@ public class DownloadActivityType { } else if (FONT_FILE == this) { return IndexConstants.FONT_INDEX_EXT; } else if (SRTM_COUNTRY_FILE == this) { - return getSRTMExt(indexItem); + return SrtmDownloadItem.getExtension(indexItem); } else if (WIKIPEDIA_FILE == this) { return IndexConstants.BINARY_WIKI_MAP_INDEX_EXT; } else if (WIKIVOYAGE_FILE == this) { @@ -427,7 +426,7 @@ public class DownloadActivityType { } String baseNameWithoutVersion = fileName.substring(0, l); if (this == SRTM_COUNTRY_FILE) { - return baseNameWithoutVersion + getSRTMExt(item); + return baseNameWithoutVersion + SrtmDownloadItem.getExtension(item); } if (this == WIKIPEDIA_FILE) { return baseNameWithoutVersion + IndexConstants.BINARY_WIKI_MAP_INDEX_EXT; @@ -505,14 +504,4 @@ public class DownloadActivityType { 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; - } } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index fc4ddc2a01..cc8647804b 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -471,14 +471,49 @@ public class DownloadResources extends DownloadResourceGroup { addGroup(otherGroup); createHillshadeSRTMGroups(); - collectMultipleIndexesItems(); + replaceIndividualSrtmWithGroups(region); + collectMultipleIndexesItems(region); trimEmptyGroups(); updateLoadedFiles(); return true; } - private void collectMultipleIndexesItems() { - collectMultipleIndexesItems(region); + private void replaceIndividualSrtmWithGroups(@NonNull WorldRegion region) { + DownloadResourceGroup group = getRegionMapsGroup(region); + if (group != null) { + boolean useMetersByDefault = SrtmDownloadItem.shouldUseMetersByDefault(app); + boolean listModified = false; + DownloadActivityType srtmType = DownloadActivityType.SRTM_COUNTRY_FILE; + List indexesList = group.getIndividualResources(); + List individualDownloadItems = group.getIndividualDownloadItems(); + if (doesListContainIndexWithType(indexesList, srtmType)) { + IndexItem meters = null; + IndexItem feet = null; + for (IndexItem item : indexesList) { + if (item.getType() == srtmType) { + if (SrtmDownloadItem.isMetersItem(item)) { + meters = item; + } else { + feet = item; + } + } + } + individualDownloadItems.remove(meters); + individualDownloadItems.remove(feet); + group.addItem(new SrtmDownloadItem(meters, feet, useMetersByDefault)); + listModified = true; + } + if (listModified) { + sortDownloadItems(individualDownloadItems); + } + } + + List subRegions = region.getSubregions(); + if (!Algorithms.isEmpty(subRegions)) { + for (WorldRegion subRegion : subRegions) { + replaceIndividualSrtmWithGroups(subRegion); + } + } } private void collectMultipleIndexesItems(@NonNull WorldRegion region) { diff --git a/OsmAnd/src/net/osmand/plus/download/MultipleIndexItem.java b/OsmAnd/src/net/osmand/plus/download/MultipleIndexItem.java index caf47d71f5..c9530cb9e0 100644 --- a/OsmAnd/src/net/osmand/plus/download/MultipleIndexItem.java +++ b/OsmAnd/src/net/osmand/plus/download/MultipleIndexItem.java @@ -12,7 +12,6 @@ import java.util.ArrayList; import java.util.List; import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE; -import static net.osmand.plus.download.SelectIndexesUiHelper.isBaseSRTMItem; public class MultipleIndexItem extends DownloadItem { @@ -121,7 +120,8 @@ public class MultipleIndexItem extends DownloadItem { if (this.type == SRTM_COUNTRY_FILE) { for (IndexItem item : items) { if (item.hasActualDataToDownload()) { - if (baseSRTM && isBaseSRTMItem(item) || !baseSRTM && !isBaseSRTMItem(item)) { + boolean isBase = SrtmDownloadItem.isMetersItem(item); + if (baseSRTM && isBase || !baseSRTM && !isBase) { totalSizeMb += item.getSizeToDownloadInMb(); } } diff --git a/OsmAnd/src/net/osmand/plus/download/SelectIndexesUiHelper.java b/OsmAnd/src/net/osmand/plus/download/SelectIndexesUiHelper.java index ff0401215d..357eb4f377 100644 --- a/OsmAnd/src/net/osmand/plus/download/SelectIndexesUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/SelectIndexesUiHelper.java @@ -6,11 +6,9 @@ import android.view.View; 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.SelectionUpdateListener; import net.osmand.plus.base.SelectModeBottomSheet; @@ -19,7 +17,6 @@ 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.SelectableItem; -import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.widgets.MultiStateToggleButton.OnRadioItemClickListener; import net.osmand.plus.widgets.MultiStateToggleButton.RadioItem; import net.osmand.util.Algorithms; @@ -29,35 +26,56 @@ import java.util.ArrayList; import java.util.Collections; 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 SelectIndexesUiHelper { - public static void showDialog(@NonNull DownloadItem item, + private OsmandApplication app; + private AppCompatActivity activity; + + private DateFormat dateFormat; + private boolean showRemoteDate; + private DownloadItem downloadItem; + private SelectItemsToDownloadListener listener; + private SelectionBottomSheet dialog; + + private SelectIndexesUiHelper(@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) { - if (item instanceof MultipleIndexItem) { - showMultipleSrtmDialog(item, activity, app, dateFormat, showRemoteDate, listener); + @NonNull SelectItemsToDownloadListener listener) { + this.activity = activity; + this.app = (OsmandApplication) activity.getApplicationContext(); + this.downloadItem = item; + this.dateFormat = dateFormat; + this.showRemoteDate = showRemoteDate; + this.listener = listener; + } + + public static void showDialog(@NonNull DownloadItem item, + @NonNull AppCompatActivity activity, + @NonNull DateFormat dateFormat, + boolean showRemoteDate, + @NonNull SelectItemsToDownloadListener listener) { + SelectIndexesUiHelper helper = + new SelectIndexesUiHelper(item, activity, dateFormat, showRemoteDate, listener); + helper.showDialogInternal(); + } + + private void showDialogInternal() { + if (downloadItem.getType() == SRTM_COUNTRY_FILE) { + if (downloadItem instanceof MultipleIndexItem) { + showMultipleSrtmDialog(); } else { - showSingleSrtmDialog(item, activity, app, dateFormat, showRemoteDate, listener); + showSingleSrtmDialog(); } - } else if (item instanceof MultipleIndexItem) { - showBaseDialog((MultipleIndexItem) item, activity, app, dateFormat, showRemoteDate, listener); + } else if (downloadItem instanceof MultipleIndexItem) { + showBaseDialog(); } } - public static void showBaseDialog(@NonNull MultipleIndexItem multipleIndexItem, - @NonNull AppCompatActivity activity, - @NonNull final OsmandApplication app, - @NonNull DateFormat dateFormat, - boolean showRemoteDate, - @NonNull final SelectItemsToDownloadListener listener) { + private void showBaseDialog() { + MultipleIndexItem multipleIndexItem = (MultipleIndexItem) downloadItem; List indexesToDownload = getIndexesToDownload(multipleIndexItem); List allItems = new ArrayList<>(); List selectedItems = new ArrayList<>(); @@ -65,10 +83,12 @@ public class SelectIndexesUiHelper { 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); @@ -91,90 +111,37 @@ public class SelectIndexesUiHelper { dialog.setSelectionUpdateListener(new SelectionUpdateListener() { @Override public void onSelectionUpdate() { - updateSize(app, dialog, true); + updateSize(dialog, true); } }); dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener)); } - public static void showSingleSrtmDialog(@NonNull final DownloadItem downloadItem, - @NonNull AppCompatActivity activity, - @NonNull final OsmandApplication app, - @NonNull final DateFormat dateFormat, - final boolean showRemoteDate, - @NonNull final SelectItemsToDownloadListener listener) { - List allIndexes = getIndexesToDownload(downloadItem); - boolean baseSRTM = isBaseSRTMMetricSystem(app); + private void showSingleSrtmDialog() { + boolean baseSRTM = SrtmDownloadItem.shouldUseMetersByDefault(app); + SrtmDownloadItem srtmItem = (SrtmDownloadItem) downloadItem; + + SelectableItem meterItem = createSrtmSelectableItem(srtmItem.getMeterItem()); + SelectableItem feetItem = createSrtmSelectableItem(srtmItem.getFeetItem()); List radioItems = new ArrayList<>(); - final RadioItem meters = new RadioItem(Algorithms.capitalizeFirstLetter(app.getString(R.string.shared_string_meters))); - RadioItem feet = new RadioItem(Algorithms.capitalizeFirstLetter(app.getString(R.string.shared_string_feets))); + RadioItem meters = createRadioItem(meterItem, R.string.shared_string_meters); + RadioItem feet = createRadioItem(feetItem, R.string.shared_string_feets); radioItems.add(meters); radioItems.add(feet); - SelectableItem meterItem = null; - SelectableItem feetItem = null; - 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) { - meterItem = selectableItem; - } else { - feetItem = selectableItem; - } - } - final SelectableItem initMeter = meterItem; - final SelectableItem initFeet = feetItem; - - final SelectModeBottomSheet dialog = SelectModeBottomSheet.showInstance(activity, + dialog = SelectModeBottomSheet.showInstance(activity, baseSRTM ? meterItem : feetItem, radioItems, true); - meters.setOnClickListener(new OnRadioItemClickListener() { - @Override - public boolean onRadioItemClick(RadioItem radioItem, View view) { - dialog.setPreviewItem(initMeter); - updateSize(app, dialog, false); - return true; - } - }); - - feet.setOnClickListener(new OnRadioItemClickListener() { - @Override - public boolean onRadioItemClick(RadioItem radioItem, View view) { - dialog.setPreviewItem(initFeet); - - double sizeToDownload = getDownloadSizeInMb(Collections.singletonList(initFeet)); - String size = DownloadItem.getFormattedMb(app, sizeToDownload); - 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.setApplyButtonTitle(btnTitle); - return true; - } - }); - final RadioItem initRadio = baseSRTM ? meters : feet; + final SelectableItem initItem = baseSRTM ? meterItem : feetItem; dialog.setUiInitializedListener(new OnUiInitializedListener() { @Override public void onUiInitialized() { + SelectModeBottomSheet dialog = (SelectModeBottomSheet) SelectIndexesUiHelper.this.dialog; dialog.setTitle(app.getString(R.string.srtm_unit_format)); dialog.setDescription(app.getString(R.string.srtm_download_single_help_message)); - double sizeToDownload = getDownloadSizeInMb(Collections.singletonList(initFeet)); - String size = DownloadItem.getFormattedMb(app, sizeToDownload); - 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.setApplyButtonTitle(btnTitle); + updateSize(dialog, false); dialog.setSelectedMode(initRadio); } }); @@ -182,17 +149,40 @@ public class SelectIndexesUiHelper { dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener)); } - public static void showMultipleSrtmDialog(@NonNull final DownloadItem downloadItem, - @NonNull AppCompatActivity activity, - @NonNull final OsmandApplication app, - @NonNull final DateFormat dateFormat, - final boolean showRemoteDate, - @NonNull final SelectItemsToDownloadListener listener) { + private SelectableItem createSrtmSelectableItem(IndexItem indexItem) { + boolean baseItem = SrtmDownloadItem.isMetersItem(indexItem); + SelectableItem selectableItem = new SelectableItem(); + selectableItem.setTitle(indexItem.getVisibleName(app, app.getRegions(), false)); + String size = indexItem.getSizeDescription(app); + size += " (" + SrtmDownloadItem.getAbbreviation(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); + return selectableItem; + } + + private RadioItem createRadioItem(final SelectableItem selectableItem, int titleId) { + String title = Algorithms.capitalizeFirstLetter(app.getString(titleId)); + RadioItem radioItem = new RadioItem(title); + radioItem.setOnClickListener(new OnRadioItemClickListener() { + @Override + public boolean onRadioItemClick(RadioItem radioItem, View view) { + ((SelectModeBottomSheet)dialog).setPreviewItem(selectableItem); + updateSize(dialog, false); + return true; + } + }); + return radioItem; + } + + private void showMultipleSrtmDialog() { List selectedItems = new ArrayList<>(); final List meterItems = new ArrayList<>(); final List feetItems = new ArrayList<>(); List indexesToDownload = getIndexesToDownload(downloadItem); - boolean baseSRTM = isBaseSRTMMetricSystem(app); + boolean baseSRTM = SrtmDownloadItem.shouldUseMetersByDefault(app); List allIndexes = new ArrayList<>(); if (downloadItem instanceof MultipleIndexItem) { @@ -206,11 +196,11 @@ public class SelectIndexesUiHelper { } for (IndexItem indexItem : allIndexes) { - boolean baseItem = isBaseSRTMItem(indexItem); + boolean baseItem = SrtmDownloadItem.isMetersItem(indexItem); SelectableItem selectableItem = new SelectableItem(); selectableItem.setTitle(indexItem.getVisibleName(app, app.getRegions(), false)); String size = indexItem.getSizeDescription(app); - size += " (" + getSRTMAbbrev(app, baseItem) + ")"; + size += " (" + SrtmDownloadItem.getAbbreviation(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); @@ -232,7 +222,7 @@ public class SelectIndexesUiHelper { List radioItems = new ArrayList<>(); RadioItem meters = new RadioItem(Algorithms.capitalizeFirstLetter(app.getString(R.string.shared_string_meters))); RadioItem feet = new RadioItem(Algorithms.capitalizeFirstLetter(app.getString(R.string.shared_string_feets))); - final RadioItem selectedMode = isBaseSRTMItem(downloadItem) ? meters : feet; + final RadioItem selectedMode = SrtmDownloadItem.isMetersItem(downloadItem) ? meters : feet; radioItems.add(meters); radioItems.add(feet); @@ -267,13 +257,13 @@ public class SelectIndexesUiHelper { dialog.setSelectionUpdateListener(new SelectionUpdateListener() { @Override public void onSelectionUpdate() { - updateSize(app, dialog, true); + updateSize(dialog, true); } }); dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener)); } - private static OnApplySelectionListener getOnApplySelectionListener(final SelectItemsToDownloadListener listener) { + private OnApplySelectionListener getOnApplySelectionListener(final SelectItemsToDownloadListener listener) { return new OnApplySelectionListener() { @Override public void onSelectionApplied(List selectedItems) { @@ -289,9 +279,8 @@ public class SelectIndexesUiHelper { }; } - private static void updateSize(OsmandApplication app, - SelectionBottomSheet dialog, - boolean updateDescription) { + private void updateSize(SelectionBottomSheet dialog, + boolean updateDescription) { double sizeToDownload = getDownloadSizeInMb(dialog.getSelection()); String size = DownloadItem.getFormattedMb(app, sizeToDownload); if (updateDescription) { @@ -306,28 +295,6 @@ public class SelectIndexesUiHelper { dialog.setApplyButtonTitle(btnTitle); } - 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 getIndexesToDownload(DownloadItem downloadItem) { if (downloadItem instanceof MultipleIndexItem) { if (downloadItem.hasActualDataToDownload()) { diff --git a/OsmAnd/src/net/osmand/plus/download/SrtmDownloadItem.java b/OsmAnd/src/net/osmand/plus/download/SrtmDownloadItem.java new file mode 100644 index 0000000000..2f528423d1 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/download/SrtmDownloadItem.java @@ -0,0 +1,137 @@ +package net.osmand.plus.download; + +import android.content.Context; + +import androidx.annotation.NonNull; + +import net.osmand.IndexConstants; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.activities.LocalIndexInfo; +import net.osmand.plus.helpers.enums.MetricsConstants; + +import java.io.File; +import java.text.DateFormat; +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.activities.LocalIndexHelper.LocalIndexType.SRTM_DATA; +import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE; + +public class SrtmDownloadItem extends DownloadItem { + + private IndexItem meterItem; + private IndexItem feetItem; + + private boolean useMetersByDefault; + + public SrtmDownloadItem(IndexItem meterItem, + IndexItem feetItem, + boolean useMetersByDefault) { + super(SRTM_COUNTRY_FILE); + this.meterItem = meterItem; + this.feetItem = feetItem; + this.useMetersByDefault = useMetersByDefault; + } + + public boolean isUseMetersByDefault() { + return useMetersByDefault; + } + + public void setUseMetersByDefault(boolean useMetersByDefault) { + this.useMetersByDefault = useMetersByDefault; + } + + public IndexItem getIndexItem() { + return useMetersByDefault ? getMeterItem() : getFeetItem(); + } + + public IndexItem getMeterItem() { + return meterItem; + } + + public IndexItem getFeetItem() { + return feetItem; + } + + @Override + protected double getSizeToDownloadInMb() { + return getIndexItem().getSizeToDownloadInMb(); + } + + @Override + public double getArchiveSizeMB() { + return getIndexItem().getArchiveSizeMB(); + } + + @Override + public boolean isDownloaded() { + return getIndexItem().isDownloaded(); + } + + @Override + public boolean isOutdated() { + return getIndexItem().isOutdated(); + } + + @Override + public boolean hasActualDataToDownload() { + return getIndexItem().hasActualDataToDownload(); + } + + @Override + public boolean isDownloading(@NonNull DownloadIndexesThread thread) { + return getMeterItem().isDownloading(thread) || getFeetItem().isDownloading(thread); + } + + @Override + public String getFileName() { + return getIndexItem().getFileName(); + } + + @NonNull + @Override + public List getDownloadedFiles(@NonNull OsmandApplication app) { + return getIndexItem().getDownloadedFiles(app); + } + + public String getDate(@NonNull DateFormat dateFormat, boolean remote) { + return getIndexItem().getDate(dateFormat, remote); + } + + public static boolean shouldUseMetersByDefault(@NonNull OsmandApplication app) { + return app.getSettings().METRIC_SYSTEM.get() != MetricsConstants.MILES_AND_FEET; + } + + public static String getAbbreviation(Context context, boolean base) { + return context.getString(base ? R.string.m : R.string.foot); + } + + public static String getExtension(IndexItem indexItem) { + return isMetersItem(indexItem) ? + IndexConstants.BINARY_SRTM_MAP_INDEX_EXT : + IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT; + } + + 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); + } + return false; + } + + 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; + } + +} diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index 498b122547..872234795d 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -44,6 +44,7 @@ import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.SelectIndexesUiHelper; import net.osmand.plus.download.SelectIndexesUiHelper.SelectItemsToDownloadListener; import net.osmand.plus.download.MultipleIndexItem; +import net.osmand.plus.download.SrtmDownloadItem; import net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask; import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.inapp.InAppPurchaseHelper; @@ -55,10 +56,6 @@ 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.SelectIndexesUiHelper.getSRTMAbbrev; -import static net.osmand.plus.download.SelectIndexesUiHelper.isBaseSRTMItem; -import static net.osmand.plus.download.SelectIndexesUiHelper.isBaseSRTMMetricSystem; public class ItemViewHolder { @@ -196,8 +193,8 @@ public class ItemViewHolder { } descrTextView.setTextColor(textColorSecondary); if (!isDownloading) { - boolean srtmItem = isSRTMItem(downloadItem); - boolean baseMetricSystem = isBaseSRTMMetricSystem(context.getMyApplication()); + boolean srtmItem = SrtmDownloadItem.isSRTMItem(downloadItem); + boolean baseMetricSystem = SrtmDownloadItem.shouldUseMetersByDefault(context.getMyApplication()); progressBar.setVisibility(View.GONE); descrTextView.setVisibility(View.VISIBLE); if (downloadItem instanceof CustomIndexItem && (((CustomIndexItem) downloadItem).getSubName(context) != null)) { @@ -218,10 +215,10 @@ public class ItemViewHolder { String regionsHeader = context.getString(R.string.regions); String allRegionsCount; String leftToDownloadCount; - if (isSRTMItem(item)) { + if (SrtmDownloadItem.isSRTMItem(item)) { List items = new ArrayList<>(); for (IndexItem indexItem : item.getAllIndexes()) { - boolean baseItem = isBaseSRTMItem(indexItem); + boolean baseItem = SrtmDownloadItem.isMetersItem(indexItem); if (baseMetricSystem && baseItem || !baseMetricSystem && !baseItem) { items.add(indexItem); } @@ -229,7 +226,7 @@ public class ItemViewHolder { allRegionsCount = String.valueOf(items.size()); items.clear(); for (IndexItem indexItem : item.getIndexesToDownload()) { - boolean baseItem = isBaseSRTMItem(indexItem); + boolean baseItem = SrtmDownloadItem.isMetersItem(indexItem); if (!indexItem.isDownloaded() && (baseMetricSystem && baseItem || !baseMetricSystem && !baseItem)) { items.add(indexItem); @@ -259,7 +256,7 @@ public class ItemViewHolder { } String fullDescription = context.getString(R.string.ltr_or_rtl_combine_via_colon, header, count); if (srtmItem) { - fullDescription += " (" + getSRTMAbbrev(context, baseMetricSystem) + ")"; + fullDescription += " (" + SrtmDownloadItem.getAbbreviation(context, baseMetricSystem) + ")"; } if (item.hasActualDataToDownload()) { fullDescription = context.getString( @@ -267,14 +264,23 @@ public class ItemViewHolder { ? item.getSizeDescription(context, baseMetricSystem) : item.getSizeDescription(context)); } descrTextView.setText(fullDescription); + } else if (downloadItem instanceof SrtmDownloadItem) { + SrtmDownloadItem item = (SrtmDownloadItem) downloadItem; + String pattern = context.getString(R.string.ltr_or_rtl_combine_via_bold_point); + String type = item.getType().getString(context); + String size = item.getSizeDescription(context) + + " (" + SrtmDownloadItem.getAbbreviation(context, SrtmDownloadItem.isMetersItem(item)) + ")"; + String date = item.getDate(dateFormat, showRemoteDate); + String fullDescription = String.format(pattern, size, date); + if (showTypeInDesc) { + fullDescription = String.format(pattern, type, fullDescription); + } + descrTextView.setText(fullDescription); } else { IndexItem item = (IndexItem) downloadItem; 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) { @@ -522,8 +528,7 @@ public class ItemViewHolder { } private void selectIndexesToDownload(DownloadItem item) { - OsmandApplication app = context.getMyApplication(); - SelectIndexesUiHelper.showDialog(item, context, app, dateFormat, showRemoteDate, + SelectIndexesUiHelper.showDialog(item, context, dateFormat, showRemoteDate, new SelectItemsToDownloadListener() { @Override public void onItemsToDownloadSelected(List indexes) { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index d56420c29c..2c695cd1e6 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -55,6 +55,7 @@ import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; import net.osmand.plus.download.IndexItem; +import net.osmand.plus.download.SrtmDownloadItem; import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.mapsource.EditMapSourceDialogFragment.OnMapSourceUpdateListener; @@ -74,9 +75,6 @@ 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.SelectIndexesUiHelper.getSRTMAbbrev; -import static net.osmand.plus.download.SelectIndexesUiHelper.isBaseSRTMItem; public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents, OnMapSourceUpdateListener, RenameCallback { @@ -1034,8 +1032,8 @@ 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 (SrtmDownloadItem.isSRTMItem(child)) { + builder.append(" (").append(SrtmDownloadItem.getAbbreviation(ctx, SrtmDownloadItem.isMetersItem(child))).append(")"); } if (!Algorithms.isEmpty(child.getDescription())) { diff --git a/OsmAnd/src/net/osmand/plus/widgets/MultiStateToggleButton.java b/OsmAnd/src/net/osmand/plus/widgets/MultiStateToggleButton.java index 605584f5b8..75ac8410d5 100644 --- a/OsmAnd/src/net/osmand/plus/widgets/MultiStateToggleButton.java +++ b/OsmAnd/src/net/osmand/plus/widgets/MultiStateToggleButton.java @@ -18,6 +18,7 @@ import net.osmand.plus.UiUtilities; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; public class MultiStateToggleButton { @@ -37,6 +38,13 @@ public class MultiStateToggleButton { this.nightMode = nightMode; } + public void setItems(Collection radioItems) { + if (radioItems == null || radioItems.size() < 2) return; + items.clear(); + items.addAll(radioItems); + initView(); + } + public void setItems(RadioItem firstBtn, RadioItem secondBtn, RadioItem... other) { items.clear(); items.add(firstBtn);