add srtm map download option, refactoring p1

This commit is contained in:
nazar-kutz 2021-04-09 19:48:17 +03:00
parent ac3aeacca1
commit b14f62822b
10 changed files with 121 additions and 121 deletions

View file

@ -331,15 +331,16 @@ public class LocalIndexHelper {
if (mapPath.canRead()) {
for (File mapFile : listFilesSorted(mapPath)) {
if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) {
String fileName = mapFile.getName();
LocalIndexType lt = LocalIndexType.MAP_DATA;
if (mapFile.getName().endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)
|| mapFile.getName().endsWith(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT)) {
if (fileName.endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)
|| fileName.endsWith(IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT)) {
lt = LocalIndexType.SRTM_DATA;
} else if (mapFile.getName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) {
} else if (fileName.endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) {
lt = LocalIndexType.WIKI_DATA;
}
LocalIndexInfo info = new LocalIndexInfo(lt, mapFile, backup, app);
if (loadedMaps.containsKey(mapFile.getName()) && !backup) {
if (loadedMaps.containsKey(fileName) && !backup) {
info.setLoaded(true);
}
updateDescription(info);

View file

@ -70,42 +70,6 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
private OnRadioButtonSelectListener onRadioButtonSelectListener;
private SelectedItemsListener selectedItemsListener;
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
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
@ -392,6 +356,66 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen
this.selectedItemsListener = selectedItemsListener;
}
@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;
}
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;
}
public interface SelectionUpdateListener {
void onSelectionUpdate();
}
@ -435,27 +459,4 @@ 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

@ -207,9 +207,6 @@ public class DownloadOsmandIndexesHelper {
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) {
result.add(it);

View file

@ -139,4 +139,5 @@ public class MultipleIndexItem extends DownloadItem {
}
return result;
}
}

View file

@ -216,8 +216,8 @@ 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 allRegionsCountStr;
String leftToDownloadCountStr;
String allRegionsCount;
String leftToDownloadCount;
if (isSRTMItem(item)) {
List<IndexItem> items = new ArrayList<>();
for (IndexItem indexItem : item.getAllIndexes()) {
@ -226,7 +226,7 @@ public class ItemViewHolder {
items.add(indexItem);
}
}
allRegionsCountStr = String.valueOf(items.size());
allRegionsCount = String.valueOf(items.size());
items.clear();
for (IndexItem indexItem : item.getIndexesToDownload()) {
boolean baseItem = isBaseSRTMItem(indexItem);
@ -235,27 +235,27 @@ public class ItemViewHolder {
items.add(indexItem);
}
}
leftToDownloadCountStr = String.valueOf(items.size());
leftToDownloadCount = String.valueOf(items.size());
} else {
allRegionsCountStr = String.valueOf(item.getAllIndexes().size());
leftToDownloadCountStr = String.valueOf(item.getIndexesToDownload().size());
allRegionsCount = String.valueOf(item.getAllIndexes().size());
leftToDownloadCount = String.valueOf(item.getIndexesToDownload().size());
}
String header;
String count;
if (item.hasActualDataToDownload()) {
if (!item.isDownloaded()) {
header = allRegionsHeader;
count = leftToDownloadCountStr;
count = leftToDownloadCount;
} else {
header = regionsHeader;
count = String.format(
context.getString(R.string.ltr_or_rtl_combine_via_slash),
leftToDownloadCountStr,
allRegionsCountStr);
leftToDownloadCount,
allRegionsCount);
}
} else {
header = allRegionsHeader;
count = allRegionsCountStr;
count = allRegionsCount;
}
String fullDescription = context.getString(R.string.ltr_or_rtl_combine_via_colon, header, count);
if (srtmItem) {