refactoring p.3

This commit is contained in:
nazar-kutz 2021-04-15 21:55:52 +03:00
parent 1ec3189a86
commit 4a6ab0c6bb
20 changed files with 151 additions and 95 deletions

View file

@ -31,7 +31,7 @@
tools:text="Some title" /> tools:text="Some title" />
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/description" android:id="@+id/title_description"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/title" android:layout_below="@+id/title"
@ -61,7 +61,25 @@
</RelativeLayout> </RelativeLayout>
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx
android:id="@+id/additional_description" android:id="@+id/primary_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dialog_content_margin"
android:letterSpacing="@dimen/description_letter_spacing"
android:orientation="vertical"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:visibility="gone"
app:typeface="@string/font_roboto_regular"
tools:text="@string/srtm_download_single_help_message"
tools:visibility="visible" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/secondary_description"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding_small" android:layout_marginBottom="@dimen/content_padding_small"

View file

@ -13,6 +13,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.download.SrtmDownloadItem;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
import net.osmand.plus.voice.JSMediaCommandPlayerImpl; import net.osmand.plus.voice.JSMediaCommandPlayerImpl;
import net.osmand.plus.voice.JSTTSCommandPlayerImpl; import net.osmand.plus.voice.JSTTSCommandPlayerImpl;
@ -333,8 +334,7 @@ public class LocalIndexHelper {
if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
String fileName = mapFile.getName(); String fileName = mapFile.getName();
LocalIndexType lt = LocalIndexType.MAP_DATA; LocalIndexType lt = LocalIndexType.MAP_DATA;
if (fileName.endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT) if (SrtmDownloadItem.isSrtmFile(fileName)) {
|| fileName.endsWith(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT)) {
lt = LocalIndexType.SRTM_DATA; lt = LocalIndexType.SRTM_DATA;
} else if (fileName.endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) { } else if (fileName.endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) {
lt = LocalIndexType.WIKI_DATA; lt = LocalIndexType.WIKI_DATA;

View file

@ -28,10 +28,10 @@ public class SelectModeBottomSheet extends SelectionBottomSheet {
protected void initHeaderUi() { protected void initHeaderUi() {
radioGroup.setItems(modes); radioGroup.setItems(modes);
AndroidUiHelper.setVisibility(View.VISIBLE, secondaryDescription, toggleContainer); AndroidUiHelper.setVisibility(View.VISIBLE, primaryDescription, toggleContainer);
AndroidUiHelper.setVisibility(View.GONE, checkBox, checkBoxTitle, AndroidUiHelper.setVisibility(View.GONE, checkBox, checkBoxTitle,
primaryDescription, selectedSize, selectAllButton); titleDescription, secondaryDescription, selectedSize, selectAllButton);
} }
@Override @Override
@ -69,17 +69,17 @@ public class SelectModeBottomSheet extends SelectionBottomSheet {
} }
} }
@Override
public void setDescription(@NonNull String description) {
secondaryDescription.setText(description);
}
@NonNull @NonNull
@Override @Override
public List<SelectableItem> getSelection() { public List<SelectableItem> getSelection() {
return Collections.singletonList(previewItem); return Collections.singletonList(previewItem);
} }
@Override
protected boolean shouldShowDivider() {
return false;
}
public static SelectModeBottomSheet showInstance(@NonNull AppCompatActivity activity, public static SelectModeBottomSheet showInstance(@NonNull AppCompatActivity activity,
@NonNull SelectableItem previewItem, @NonNull SelectableItem previewItem,
@NonNull List<RadioItem> radioItems, @NonNull List<RadioItem> radioItems,

View file

@ -122,11 +122,8 @@ public class SelectMultipleItemsBottomSheet extends SelectionBottomSheet {
} }
private void updateApplyButtonEnable() { private void updateApplyButtonEnable() {
if (Algorithms.isEmpty(selectedItems)) { boolean noEmptySelection = !Algorithms.isEmpty(selectedItems);
rightButton.setEnabled(false); rightButton.setEnabled(noEmptySelection);
} else {
rightButton.setEnabled(true);
}
} }
private void updateItems(boolean checked) { private void updateItems(boolean checked) {

View file

@ -24,7 +24,7 @@ public class SelectMultipleWithModeBottomSheet extends SelectMultipleItemsBottom
radioGroup.setItems(modes); radioGroup.setItems(modes);
AndroidUiHelper.setVisibility(View.VISIBLE, secondaryDescription, toggleContainer, AndroidUiHelper.setVisibility(View.VISIBLE, secondaryDescription, toggleContainer,
checkBox, checkBoxTitle, primaryDescription, selectedSize, selectAllButton); checkBox, checkBoxTitle, titleDescription, selectedSize, selectAllButton);
} }
private void setModes(@NonNull List<RadioItem> modes) { private void setModes(@NonNull List<RadioItem> modes) {

View file

@ -27,6 +27,7 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
protected UiUtilities uiUtilities; protected UiUtilities uiUtilities;
protected TextView title; protected TextView title;
protected TextView titleDescription;
protected TextView primaryDescription; protected TextView primaryDescription;
protected TextView secondaryDescription; protected TextView secondaryDescription;
protected TextView selectedSize; protected TextView selectedSize;
@ -35,7 +36,7 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
protected View selectAllButton; protected View selectAllButton;
protected TextView checkBoxTitle; protected TextView checkBoxTitle;
protected ThreeStateCheckbox checkBox; protected ThreeStateCheckbox checkBox;
protected LinearLayout selectionListView; protected LinearLayout listContainer;
protected TextView applyButtonTitle; protected TextView applyButtonTitle;
protected int activeColorRes; protected int activeColorRes;
@ -60,7 +61,9 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
secondaryColorRes = nightMode ? R.color.icon_color_secondary_dark : R.color.icon_color_secondary_light; secondaryColorRes = nightMode ? R.color.icon_color_secondary_dark : R.color.icon_color_secondary_light;
items.add(createHeaderUi()); items.add(createHeaderUi());
items.add(new SimpleDividerItem(app)); if (shouldShowDivider()) {
items.add(new SimpleDividerItem(app));
}
createSelectionUi(); createSelectionUi();
} }
@ -77,8 +80,9 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
View view = themedInflater.inflate(R.layout.settings_group_title, null); View view = themedInflater.inflate(R.layout.settings_group_title, null);
title = view.findViewById(R.id.title); title = view.findViewById(R.id.title);
primaryDescription = view.findViewById(R.id.description); titleDescription = view.findViewById(R.id.title_description);
secondaryDescription = view.findViewById(R.id.additional_description); primaryDescription = view.findViewById(R.id.primary_description);
secondaryDescription = view.findViewById(R.id.secondary_description);
selectedSize = view.findViewById(R.id.selected_size); selectedSize = view.findViewById(R.id.selected_size);
toggleContainer = view.findViewById(R.id.custom_radio_buttons); toggleContainer = view.findViewById(R.id.custom_radio_buttons);
radioGroup = new MultiStateToggleButton(app, toggleContainer, nightMode); radioGroup = new MultiStateToggleButton(app, toggleContainer, nightMode);
@ -94,6 +98,10 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
protected abstract void initHeaderUi(); protected abstract void initHeaderUi();
protected boolean shouldShowDivider() {
return true;
}
@Override @Override
protected void setupRightButton() { protected void setupRightButton() {
super.setupRightButton(); super.setupRightButton();
@ -104,12 +112,16 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
this.title.setText(title); this.title.setText(title);
} }
public void setDescription(@NonNull String description) { public void setTitleDescription(@NonNull String description) {
this.primaryDescription.setText(description); titleDescription.setText(description);
}
public void setPrimaryDescription(@NonNull String description) {
primaryDescription.setText(description);
} }
public void setSecondaryDescription(@NonNull String description) { public void setSecondaryDescription(@NonNull String description) {
this.secondaryDescription.setText(description); secondaryDescription.setText(description);
} }
public void setApplyButtonTitle(@NonNull String title) { public void setApplyButtonTitle(@NonNull String title) {

View file

@ -210,6 +210,10 @@ public class DownloadActivityType {
return this == VOICE_FILE && indexItem.fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP); return this == VOICE_FILE && indexItem.fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP);
} }
public boolean mayProvideSeveralIndexes() {
return this == SRTM_COUNTRY_FILE;
}
public String getUnzipExtension(OsmandApplication ctx, IndexItem indexItem) { public String getUnzipExtension(OsmandApplication ctx, IndexItem indexItem) {
if (NORMAL_FILE == this) { if (NORMAL_FILE == this) {
if (indexItem.fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) { if (indexItem.fileName.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)) {

View file

@ -487,20 +487,14 @@ public class DownloadResources extends DownloadResourceGroup {
List<IndexItem> indexesList = group.getIndividualResources(); List<IndexItem> indexesList = group.getIndividualResources();
List<DownloadItem> individualDownloadItems = group.getIndividualDownloadItems(); List<DownloadItem> individualDownloadItems = group.getIndividualDownloadItems();
if (doesListContainIndexWithType(indexesList, srtmType)) { if (doesListContainIndexWithType(indexesList, srtmType)) {
IndexItem meters = null; List<IndexItem> srtmIndexes = new ArrayList<>();
IndexItem feet = null;
for (IndexItem item : indexesList) { for (IndexItem item : indexesList) {
if (item.getType() == srtmType) { if (item.getType() == srtmType) {
if (SrtmDownloadItem.isMetersItem(item)) { srtmIndexes.add(item);
meters = item;
} else {
feet = item;
}
} }
} }
individualDownloadItems.remove(meters); individualDownloadItems.removeAll(srtmIndexes);
individualDownloadItems.remove(feet); group.addItem(new SrtmDownloadItem(srtmIndexes, useMetersByDefault));
group.addItem(new SrtmDownloadItem(meters, feet, useMetersByDefault));
listModified = true; listModified = true;
} }
if (listModified) { if (listModified) {
@ -563,6 +557,7 @@ public class DownloadResources extends DownloadResourceGroup {
if (index.getType() == type) { if (index.getType() == type) {
found = true; found = true;
collectedIndexes.add(index); collectedIndexes.add(index);
if (!type.mayProvideSeveralIndexes()) break;
} }
} }
} }

View file

@ -1,6 +1,5 @@
package net.osmand.plus.download; package net.osmand.plus.download;
import android.content.Context;
import android.view.View; import android.view.View;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -23,7 +22,6 @@ import net.osmand.util.Algorithms;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE; import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE;
@ -36,14 +34,14 @@ public class SelectIndexesUiHelper {
private DateFormat dateFormat; private DateFormat dateFormat;
private boolean showRemoteDate; private boolean showRemoteDate;
private DownloadItem downloadItem; private DownloadItem downloadItem;
private SelectItemsToDownloadListener listener; private ItemsToDownloadSelectedListener listener;
private SelectionBottomSheet dialog; private SelectionBottomSheet dialog;
private SelectIndexesUiHelper(@NonNull DownloadItem item, private SelectIndexesUiHelper(@NonNull DownloadItem item,
@NonNull AppCompatActivity activity, @NonNull AppCompatActivity activity,
@NonNull DateFormat dateFormat, @NonNull DateFormat dateFormat,
boolean showRemoteDate, boolean showRemoteDate,
@NonNull SelectItemsToDownloadListener listener) { @NonNull ItemsToDownloadSelectedListener listener) {
this.activity = activity; this.activity = activity;
this.app = (OsmandApplication) activity.getApplicationContext(); this.app = (OsmandApplication) activity.getApplicationContext();
this.downloadItem = item; this.downloadItem = item;
@ -56,7 +54,7 @@ public class SelectIndexesUiHelper {
@NonNull AppCompatActivity activity, @NonNull AppCompatActivity activity,
@NonNull DateFormat dateFormat, @NonNull DateFormat dateFormat,
boolean showRemoteDate, boolean showRemoteDate,
@NonNull SelectItemsToDownloadListener listener) { @NonNull ItemsToDownloadSelectedListener listener) {
SelectIndexesUiHelper helper = SelectIndexesUiHelper helper =
new SelectIndexesUiHelper(item, activity, dateFormat, showRemoteDate, listener); new SelectIndexesUiHelper(item, activity, dateFormat, showRemoteDate, listener);
helper.showDialogInternal(); helper.showDialogInternal();
@ -140,7 +138,7 @@ public class SelectIndexesUiHelper {
public void onUiInitialized() { public void onUiInitialized() {
SelectModeBottomSheet dialog = (SelectModeBottomSheet) SelectIndexesUiHelper.this.dialog; SelectModeBottomSheet dialog = (SelectModeBottomSheet) SelectIndexesUiHelper.this.dialog;
dialog.setTitle(app.getString(R.string.srtm_unit_format)); dialog.setTitle(app.getString(R.string.srtm_unit_format));
dialog.setDescription(app.getString(R.string.srtm_download_single_help_message)); dialog.setPrimaryDescription(app.getString(R.string.srtm_download_single_help_message));
updateSize(dialog, false); updateSize(dialog, false);
dialog.setSelectedMode(initRadio); dialog.setSelectedMode(initRadio);
} }
@ -154,7 +152,7 @@ public class SelectIndexesUiHelper {
SelectableItem selectableItem = new SelectableItem(); SelectableItem selectableItem = new SelectableItem();
selectableItem.setTitle(indexItem.getVisibleName(app, app.getRegions(), false)); selectableItem.setTitle(indexItem.getVisibleName(app, app.getRegions(), false));
String size = indexItem.getSizeDescription(app); String size = indexItem.getSizeDescription(app);
size += " (" + SrtmDownloadItem.getAbbreviation(app, baseItem) + ")"; size += " " + SrtmDownloadItem.getAbbreviationInScopes(app, baseItem);
String date = indexItem.getDate(dateFormat, showRemoteDate); String date = indexItem.getDate(dateFormat, showRemoteDate);
String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date); String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date);
selectableItem.setDescription(description); selectableItem.setDescription(description);
@ -200,7 +198,7 @@ public class SelectIndexesUiHelper {
SelectableItem selectableItem = new SelectableItem(); SelectableItem selectableItem = new SelectableItem();
selectableItem.setTitle(indexItem.getVisibleName(app, app.getRegions(), false)); selectableItem.setTitle(indexItem.getVisibleName(app, app.getRegions(), false));
String size = indexItem.getSizeDescription(app); String size = indexItem.getSizeDescription(app);
size += " (" + SrtmDownloadItem.getAbbreviation(app, baseItem) + ")"; size += " " + SrtmDownloadItem.getAbbreviationInScopes(app, baseItem);
String date = indexItem.getDate(dateFormat, showRemoteDate); String date = indexItem.getDate(dateFormat, showRemoteDate);
String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date); String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date);
selectableItem.setDescription(description); selectableItem.setDescription(description);
@ -263,7 +261,7 @@ public class SelectIndexesUiHelper {
dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener)); dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
} }
private OnApplySelectionListener getOnApplySelectionListener(final SelectItemsToDownloadListener listener) { private OnApplySelectionListener getOnApplySelectionListener(final ItemsToDownloadSelectedListener listener) {
return new OnApplySelectionListener() { return new OnApplySelectionListener() {
@Override @Override
public void onSelectionApplied(List<SelectableItem> selectedItems) { public void onSelectionApplied(List<SelectableItem> selectedItems) {
@ -286,7 +284,7 @@ public class SelectIndexesUiHelper {
if (updateDescription) { if (updateDescription) {
String total = app.getString(R.string.shared_string_total); String total = app.getString(R.string.shared_string_total);
String description = app.getString(R.string.ltr_or_rtl_combine_via_colon, total, size); String description = app.getString(R.string.ltr_or_rtl_combine_via_colon, total, size);
dialog.setDescription(description); dialog.setTitleDescription(description);
} }
String btnTitle = app.getString(R.string.shared_string_download); String btnTitle = app.getString(R.string.shared_string_download);
if (sizeToDownload > 0) { if (sizeToDownload > 0) {
@ -330,7 +328,7 @@ public class SelectIndexesUiHelper {
return totalSizeMb; return totalSizeMb;
} }
public interface SelectItemsToDownloadListener { public interface ItemsToDownloadSelectedListener {
void onItemsToDownloadSelected(List<IndexItem> items); void onItemsToDownloadSelected(List<IndexItem> items);
} }

View file

@ -3,6 +3,7 @@ package net.osmand.plus.download;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -21,38 +22,53 @@ import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE;
public class SrtmDownloadItem extends DownloadItem { public class SrtmDownloadItem extends DownloadItem {
private IndexItem meterItem; private List<IndexItem> indexes;
private IndexItem feetItem; private IndexItem meter;
private IndexItem feet;
private boolean useMetersByDefault; private boolean shouldUseMeters;
public SrtmDownloadItem(IndexItem meterItem, public SrtmDownloadItem(List<IndexItem> indexes,
IndexItem feetItem, boolean shouldUseMeters) {
boolean useMetersByDefault) {
super(SRTM_COUNTRY_FILE); super(SRTM_COUNTRY_FILE);
this.meterItem = meterItem; this.indexes = indexes;
this.feetItem = feetItem; this.shouldUseMeters = shouldUseMeters;
this.useMetersByDefault = useMetersByDefault;
} }
public boolean isUseMetersByDefault() { public boolean isShouldUseMeters() {
return useMetersByDefault; return shouldUseMeters;
} }
public void setUseMetersByDefault(boolean useMetersByDefault) { public void setShouldUseMeters(boolean shouldUseMeters) {
this.useMetersByDefault = useMetersByDefault; this.shouldUseMeters = shouldUseMeters;
} }
public IndexItem getIndexItem() { public IndexItem getIndexItem() {
return useMetersByDefault ? getMeterItem() : getFeetItem(); return shouldUseMeters ? getMeterItem() : getFeetItem();
} }
@Nullable
public IndexItem getMeterItem() { public IndexItem getMeterItem() {
return meterItem; if (meter == null && indexes != null) {
for (IndexItem index : indexes) {
if (isMetersItem(index)) {
meter = index;
}
}
}
return meter;
} }
@Nullable
public IndexItem getFeetItem() { public IndexItem getFeetItem() {
return feetItem; if (feet == null && indexes != null) {
for (IndexItem index : indexes) {
if (!isMetersItem(index)) {
feet = index;
}
}
}
return feet;
} }
@Override @Override
@ -67,12 +83,12 @@ public class SrtmDownloadItem extends DownloadItem {
@Override @Override
public boolean isDownloaded() { public boolean isDownloaded() {
return getIndexItem().isDownloaded(); return meter.isDownloaded() || feet.isDownloaded();
} }
@Override @Override
public boolean isOutdated() { public boolean isOutdated() {
return getIndexItem().isOutdated(); return meter.isOutdated() || feet.isOutdated();
} }
@Override @Override
@ -104,14 +120,14 @@ public class SrtmDownloadItem extends DownloadItem {
return app.getSettings().METRIC_SYSTEM.get() != MetricsConstants.MILES_AND_FEET; return app.getSettings().METRIC_SYSTEM.get() != MetricsConstants.MILES_AND_FEET;
} }
public static String getAbbreviation(Context context, boolean base) { @NonNull
return context.getString(base ? R.string.m : R.string.foot); public static String getAbbreviationInScopes(Context ctx, boolean base) {
return "(" + getAbbreviation(ctx, base) + ")";
} }
public static String getExtension(IndexItem indexItem) { @NonNull
return isMetersItem(indexItem) ? public static String getAbbreviation(Context context, boolean base) {
IndexConstants.BINARY_SRTM_MAP_INDEX_EXT : return context.getString(base ? R.string.m : R.string.foot);
IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT;
} }
public static boolean isMetersItem(Object item) { public static boolean isMetersItem(Object item) {
@ -123,6 +139,23 @@ public class SrtmDownloadItem extends DownloadItem {
return false; return false;
} }
public static boolean containsSrtmExtension(@NonNull String fileName) {
return fileName.contains(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)
|| fileName.contains(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT);
}
public static boolean isSrtmFile(@NonNull String fileName) {
return fileName.endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)
|| fileName.endsWith(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT);
}
@NonNull
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 isSRTMItem(Object item) { public static boolean isSRTMItem(Object item) {
if (item instanceof IndexItem) { if (item instanceof IndexItem) {
return ((IndexItem) item).getType() == SRTM_COUNTRY_FILE; return ((IndexItem) item).getType() == SRTM_COUNTRY_FILE;

View file

@ -87,7 +87,7 @@ public class ActiveDownloadsDialogFragment extends DialogFragment implements Dow
} }
ItemViewHolder viewHolder = (ItemViewHolder) convertView.getTag(); ItemViewHolder viewHolder = (ItemViewHolder) convertView.getTag();
IndexItem item = getItem(position); IndexItem item = getItem(position);
viewHolder.bindIndexItem(item); viewHolder.bindDownloadItem(item);
return convertView; return convertView;
} }

View file

@ -78,7 +78,7 @@ public class DownloadResourceGroupAdapter extends OsmandBaseExpandableListAdapte
} else { } else {
viewHolder.setShowTypeInDesc(true); viewHolder.setShowTypeInDesc(true);
} }
viewHolder.bindIndexItem(item); viewHolder.bindDownloadItem(item);
} else { } else {
DownloadResourceGroup group = (DownloadResourceGroup) child; DownloadResourceGroup group = (DownloadResourceGroup) child;
DownloadGroupViewHolder viewHolder; DownloadGroupViewHolder viewHolder;

View file

@ -42,7 +42,7 @@ import net.osmand.plus.download.DownloadResourceGroup;
import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.download.SelectIndexesUiHelper; import net.osmand.plus.download.SelectIndexesUiHelper;
import net.osmand.plus.download.SelectIndexesUiHelper.SelectItemsToDownloadListener; import net.osmand.plus.download.SelectIndexesUiHelper.ItemsToDownloadSelectedListener;
import net.osmand.plus.download.MultipleIndexItem; import net.osmand.plus.download.MultipleIndexItem;
import net.osmand.plus.download.SrtmDownloadItem; import net.osmand.plus.download.SrtmDownloadItem;
import net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask; import net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask;
@ -150,11 +150,11 @@ public class ItemViewHolder {
depthContoursPurchased = InAppPurchaseHelper.isDepthContoursPurchased(context.getMyApplication()); depthContoursPurchased = InAppPurchaseHelper.isDepthContoursPurchased(context.getMyApplication());
} }
public void bindIndexItem(final DownloadItem downloadItem) { public void bindDownloadItem(final DownloadItem downloadItem) {
bindIndexItem(downloadItem, null); bindDownloadItem(downloadItem, null);
} }
public void bindIndexItem(final DownloadItem downloadItem, final String cityName) { public void bindDownloadItem(final DownloadItem downloadItem, final String cityName) {
initAppStatusVariables(); initAppStatusVariables();
boolean isDownloading = downloadItem.isDownloading(context.getDownloadThread()); boolean isDownloading = downloadItem.isDownloading(context.getDownloadThread());
int progress = -1; int progress = -1;
@ -256,7 +256,7 @@ public class ItemViewHolder {
} }
String fullDescription = context.getString(R.string.ltr_or_rtl_combine_via_colon, header, count); String fullDescription = context.getString(R.string.ltr_or_rtl_combine_via_colon, header, count);
if (srtmItem) { if (srtmItem) {
fullDescription += " (" + SrtmDownloadItem.getAbbreviation(context, baseMetricSystem) + ")"; fullDescription += " " + SrtmDownloadItem.getAbbreviationInScopes(context, baseMetricSystem);
} }
if (item.hasActualDataToDownload()) { if (item.hasActualDataToDownload()) {
fullDescription = context.getString( fullDescription = context.getString(
@ -269,7 +269,7 @@ public class ItemViewHolder {
String pattern = context.getString(R.string.ltr_or_rtl_combine_via_bold_point); String pattern = context.getString(R.string.ltr_or_rtl_combine_via_bold_point);
String type = item.getType().getString(context); String type = item.getType().getString(context);
String size = item.getSizeDescription(context) String size = item.getSizeDescription(context)
+ " (" + SrtmDownloadItem.getAbbreviation(context, SrtmDownloadItem.isMetersItem(item)) + ")"; + " " + SrtmDownloadItem.getAbbreviationInScopes(context, SrtmDownloadItem.isMetersItem(item));
String date = item.getDate(dateFormat, showRemoteDate); String date = item.getDate(dateFormat, showRemoteDate);
String fullDescription = String.format(pattern, size, date); String fullDescription = String.format(pattern, size, date);
if (showTypeInDesc) { if (showTypeInDesc) {
@ -316,9 +316,9 @@ public class ItemViewHolder {
} }
} }
public void bindIndexItem(final CityItem cityItem) { public void bindDownloadItem(final CityItem cityItem) {
if (cityItem.getIndexItem() != null) { if (cityItem.getIndexItem() != null) {
bindIndexItem(cityItem.getIndexItem(), cityItem.getName()); bindDownloadItem(cityItem.getIndexItem(), cityItem.getName());
} else { } else {
nameTextView.setText(cityItem.getName()); nameTextView.setText(cityItem.getName());
nameTextView.setTextColor(textColorPrimary); nameTextView.setTextColor(textColorPrimary);
@ -529,7 +529,7 @@ public class ItemViewHolder {
private void selectIndexesToDownload(DownloadItem item) { private void selectIndexesToDownload(DownloadItem item) {
SelectIndexesUiHelper.showDialog(item, context, dateFormat, showRemoteDate, SelectIndexesUiHelper.showDialog(item, context, dateFormat, showRemoteDate,
new SelectItemsToDownloadListener() { new ItemsToDownloadSelectedListener() {
@Override @Override
public void onItemsToDownloadSelected(List<IndexItem> indexes) { public void onItemsToDownloadSelected(List<IndexItem> indexes) {
IndexItem[] indexesArray = new IndexItem[indexes.size()]; IndexItem[] indexesArray = new IndexItem[indexes.size()];

View file

@ -965,8 +965,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
return ctx.getString(R.string.download_roads_only_item); return ctx.getString(R.string.download_roads_only_item);
} else if (child.isBackupedData() && child.getFileName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) { } else if (child.isBackupedData() && child.getFileName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) {
return ctx.getString(R.string.download_wikipedia_maps); return ctx.getString(R.string.download_wikipedia_maps);
} else if (child.isBackupedData() && (child.getFileName().endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT) } else if (child.isBackupedData() && (SrtmDownloadItem.isSrtmFile(child.getFileName()))) {
|| child.getFileName().endsWith(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT))) {
return ctx.getString(R.string.download_srtm_maps); return ctx.getString(R.string.download_srtm_maps);
} }
return ""; return "";
@ -1033,7 +1032,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
} }
if (SrtmDownloadItem.isSRTMItem(child)) { if (SrtmDownloadItem.isSRTMItem(child)) {
builder.append(" (").append(SrtmDownloadItem.getAbbreviation(ctx, SrtmDownloadItem.isMetersItem(child))).append(")"); builder.append(" ").append(SrtmDownloadItem.getAbbreviationInScopes(ctx, SrtmDownloadItem.isMetersItem(child)));
} }
if (!Algorithms.isEmpty(child.getDescription())) { if (!Algorithms.isEmpty(child.getDescription())) {

View file

@ -382,10 +382,10 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
if (obj instanceof IndexItem) { if (obj instanceof IndexItem) {
IndexItem item = (IndexItem) obj; IndexItem item = (IndexItem) obj;
viewHolder.setShowTypeInDesc(true); viewHolder.setShowTypeInDesc(true);
viewHolder.bindIndexItem(item); viewHolder.bindDownloadItem(item);
} else { } else {
CityItem item = (CityItem) obj; CityItem item = (CityItem) obj;
viewHolder.bindIndexItem(item); viewHolder.bindDownloadItem(item);
if (item.getIndexItem() == null) { if (item.getIndexItem() == null) {
new IndexItemResolverTask(viewHolder, item).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new IndexItemResolverTask(viewHolder, item).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
@ -461,7 +461,7 @@ public class SearchDialogFragment extends DialogFragment implements DownloadEven
if (viewHolder != null) { if (viewHolder != null) {
if (indexItem != null) { if (indexItem != null) {
cityItem.setIndexItem(indexItem); cityItem.setIndexItem(indexItem);
viewHolder.bindIndexItem(indexItem, cityItem.getName()); viewHolder.bindDownloadItem(indexItem, cityItem.getName());
} }
} }
} }

View file

@ -410,7 +410,7 @@ public class UpdatesIndexFragment extends OsmAndListFragment implements Download
holder.setShowRemoteDate(true); holder.setShowRemoteDate(true);
holder.setShowTypeInDesc(true); holder.setShowTypeInDesc(true);
holder.setShowParentRegionName(true); holder.setShowParentRegionName(true);
holder.bindIndexItem(getItem(position)); holder.bindDownloadItem(getItem(position));
} }
return view; return view;
} }

View file

@ -5,6 +5,7 @@ import net.osmand.PlatformUtil;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.osm.io.NetworkUtils; import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.download.SrtmDownloadItem;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -45,8 +46,7 @@ public class IncrementalChangesManager {
Set<String> existingFiles = new HashSet<String>(); Set<String> existingFiles = new HashSet<String>();
for (File f : files) { for (File f : files) {
if (!f.getName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT) && if (!f.getName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT) &&
!f.getName().endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT) && !SrtmDownloadItem.isSrtmFile(f.getName())) {
!f.getName().endsWith(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT)) {
existingFiles.add(Algorithms.getFileNameWithoutExtension(f)); existingFiles.add(Algorithms.getFileNameWithoutExtension(f));
} }
} }

View file

@ -41,6 +41,7 @@ import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.download.DownloadOsmandIndexesHelper; import net.osmand.plus.download.DownloadOsmandIndexesHelper;
import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetEntry; import net.osmand.plus.download.DownloadOsmandIndexesHelper.AssetEntry;
import net.osmand.plus.download.SrtmDownloadItem;
import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.render.MapRenderRepositories;
import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.plus.render.NativeOsmandLibrary;
@ -701,8 +702,7 @@ public class ResourceManager {
log.error(String.format("File %s could not be read", f.getName()), e); log.error(String.format("File %s could not be read", f.getName()), e);
} }
boolean wikiMap = (f.getName().contains("_wiki") || f.getName().contains(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)); boolean wikiMap = (f.getName().contains("_wiki") || f.getName().contains(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT));
boolean srtmMap = f.getName().contains(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT) boolean srtmMap = SrtmDownloadItem.containsSrtmExtension(f.getName());
|| f.getName().contains(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT);
if (mapReader == null || (!Version.isPaidVersion(context) && wikiMap && !f.getName().equals(DEFAULT_WIKIVOYAGE_TRAVEL_OBF))) { if (mapReader == null || (!Version.isPaidVersion(context) && wikiMap && !f.getName().equals(DEFAULT_WIKIVOYAGE_TRAVEL_OBF))) {
warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$ warnings.add(MessageFormat.format(context.getString(R.string.version_index_is_not_supported), f.getName())); //$NON-NLS-1$
} else { } else {

View file

@ -7,6 +7,7 @@ import androidx.annotation.Nullable;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.download.SrtmDownloadItem;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.json.JSONException; import org.json.JSONException;
@ -92,8 +93,7 @@ public class FileSettingsItem extends StreamSettingsItem {
case OTHER: case OTHER:
break; break;
case SRTM_MAP: case SRTM_MAP:
if (name.endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT) if (SrtmDownloadItem.isSrtmFile(name)) {
|| name.endsWith(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT)) {
return subtype; return subtype;
} }
break; break;

View file

@ -36,6 +36,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton.Bu
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.SimpleDividerItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.SimpleDividerItem;
import net.osmand.plus.download.SrtmDownloadItem;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
@ -530,8 +531,7 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
return getString(R.string.download_roads_only_item); return getString(R.string.download_roads_only_item);
} else if (file.getName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) { } else if (file.getName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) {
return getString(R.string.download_wikipedia_maps); return getString(R.string.download_wikipedia_maps);
} else if (file.getName().endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT) } else if (SrtmDownloadItem.isSrtmFile(file.getName())) {
|| file.getName().endsWith(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT)) {
return getString(R.string.download_srtm_maps); return getString(R.string.download_srtm_maps);
} else if (file.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { } else if (file.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
return getString(R.string.download_regular_maps); return getString(R.string.download_regular_maps);