From b14f62822bc31763285469eef2fb3dc706fb1cf2 Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Fri, 9 Apr 2021 19:48:17 +0300 Subject: [PATCH] add srtm map download option, refactoring p1 --- .../plus/activities/LocalIndexHelper.java | 9 +- .../base/SelectMultipleItemsBottomSheet.java | 119 +++++++++--------- .../download/DownloadOsmandIndexesHelper.java | 7 +- .../plus/download/DownloadResources.java | 26 ++-- .../plus/download/MultipleIndexItem.java | 5 +- .../download/MultipleIndexesUiHelper.java | 32 ++--- .../plus/download/ui/ItemViewHolder.java | 20 +-- .../download/ui/LocalIndexesFragment.java | 8 +- .../plus/resources/ResourceManager.java | 10 +- .../datastorage/DataStorageHelper.java | 6 +- 10 files changed, 121 insertions(+), 121 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java index 87bfa5f698..3ffced9201 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/base/SelectMultipleItemsBottomSheet.java b/OsmAnd/src/net/osmand/plus/base/SelectMultipleItemsBottomSheet.java index d09c4a3d6c..7629f80169 100644 --- a/OsmAnd/src/net/osmand/plus/base/SelectMultipleItemsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/base/SelectMultipleItemsBottomSheet.java @@ -70,42 +70,6 @@ public class SelectMultipleItemsBottomSheet extends MenuBottomSheetDialogFragmen private OnRadioButtonSelectListener onRadioButtonSelectListener; private SelectedItemsListener selectedItemsListener; - public static SelectMultipleItemsBottomSheet showInstance(@NonNull AppCompatActivity activity, - @NonNull List items, - @Nullable List 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 items, - @Nullable List 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 items, + @Nullable List 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 items, + @Nullable List 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; - } } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java index 8af9f9eb6b..a67de8b8d7 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java @@ -142,7 +142,7 @@ public class DownloadOsmandIndexesHelper { } private static void listVoiceAssets(IndexFileList result, AssetManager amanager, PackageManager pm, - OsmandSettings settings) { + OsmandSettings settings) { try { File voicePath = settings.getContext().getAppPath(IndexConstants.VOICE_INDEX_DIR); // list = amanager.list("voice"); @@ -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); @@ -249,7 +246,7 @@ public class DownloadOsmandIndexesHelper { private final long dateModified; public AssetIndexItem(String fileName, String description, String date, - long dateModified, String size, long sizeL, String assetName, String destFile, DownloadActivityType type) { + long dateModified, String size, long sizeL, String assetName, String destFile, DownloadActivityType type) { super(fileName, description, dateModified, size, sizeL, sizeL, type); this.dateModified = dateModified; this.assetName = assetName; diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index 7293d46659..fc4ddc2a01 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -264,7 +264,7 @@ public class DownloadResources extends DownloadResourceGroup { } private Map listWithAlternatives(final java.text.DateFormat dateFormat, File file, - final String ext, final Map files) { + final String ext, final Map files) { if (file.isDirectory()) { file.list(new FilenameFilter() { @Override @@ -518,7 +518,7 @@ public class DownloadResources extends DownloadResourceGroup { @Nullable private List collectIndexesOfType(@NonNull List regions, - @NonNull DownloadActivityType type) { + @NonNull DownloadActivityType type) { List collectedIndexes = new ArrayList<>(); for (WorldRegion region : regions) { List regionIndexes = getIndexItems(region); @@ -645,10 +645,10 @@ public class DownloadResources extends DownloadResourceGroup { } public static List findIndexItemsAt(OsmandApplication app, - List names, - DownloadActivityType type, - boolean includeDownloaded, - int limit) { + List names, + DownloadActivityType type, + boolean includeDownloaded, + int limit) { List res = new ArrayList<>(); OsmandRegions regions = app.getRegions(); DownloadIndexesThread downloadThread = app.getDownloadThread(); @@ -665,9 +665,9 @@ public class DownloadResources extends DownloadResourceGroup { } private static boolean isIndexItemDownloaded(DownloadIndexesThread downloadThread, - DownloadActivityType type, - WorldRegion downloadRegion, - List res) { + DownloadActivityType type, + WorldRegion downloadRegion, + List res) { List otherIndexItems = new ArrayList<>(downloadThread.getIndexes().getIndexItems(downloadRegion)); for (IndexItem indexItem : otherIndexItems) { @@ -680,7 +680,7 @@ public class DownloadResources extends DownloadResourceGroup { } private boolean doesListContainIndexWithType(List indexItems, - DownloadActivityType type) { + DownloadActivityType type) { if (indexItems != null) { for (IndexItem indexItem : indexItems) { if (indexItem.getType() == type) { @@ -692,9 +692,9 @@ public class DownloadResources extends DownloadResourceGroup { } private static boolean addIndexItem(DownloadIndexesThread downloadThread, - DownloadActivityType type, - WorldRegion downloadRegion, - List res) { + DownloadActivityType type, + WorldRegion downloadRegion, + List res) { List otherIndexItems = new ArrayList<>(downloadThread.getIndexes().getIndexItems(downloadRegion)); for (IndexItem indexItem : otherIndexItems) { diff --git a/OsmAnd/src/net/osmand/plus/download/MultipleIndexItem.java b/OsmAnd/src/net/osmand/plus/download/MultipleIndexItem.java index 309f5210b9..a6a0a46686 100644 --- a/OsmAnd/src/net/osmand/plus/download/MultipleIndexItem.java +++ b/OsmAnd/src/net/osmand/plus/download/MultipleIndexItem.java @@ -19,8 +19,8 @@ public class MultipleIndexItem extends DownloadItem { private final List items; public MultipleIndexItem(@NonNull WorldRegion region, - @NonNull List items, - @NonNull DownloadActivityType type) { + @NonNull List items, + @NonNull DownloadActivityType type) { super(type); this.items = items; } @@ -139,4 +139,5 @@ public class MultipleIndexItem extends DownloadItem { } return result; } + } diff --git a/OsmAnd/src/net/osmand/plus/download/MultipleIndexesUiHelper.java b/OsmAnd/src/net/osmand/plus/download/MultipleIndexesUiHelper.java index 575507d7d8..509609bd94 100644 --- a/OsmAnd/src/net/osmand/plus/download/MultipleIndexesUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/MultipleIndexesUiHelper.java @@ -29,11 +29,11 @@ import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE; public class MultipleIndexesUiHelper { public static void showDialog(@NonNull DownloadItem item, - @NonNull AppCompatActivity activity, - @NonNull final OsmandApplication app, - @NonNull DateFormat dateFormat, - boolean showRemoteDate, - @NonNull final SelectItemsToDownloadListener listener) { + @NonNull AppCompatActivity activity, + @NonNull final OsmandApplication app, + @NonNull DateFormat dateFormat, + boolean showRemoteDate, + @NonNull final SelectItemsToDownloadListener listener) { if (item.getType() == SRTM_COUNTRY_FILE) { showSRTMDialog(item, activity, app, dateFormat, showRemoteDate, listener); } else if (item instanceof MultipleIndexItem) { @@ -42,11 +42,11 @@ public class MultipleIndexesUiHelper { } public static void showBaseDialog(@NonNull MultipleIndexItem multipleIndexItem, - @NonNull AppCompatActivity activity, - @NonNull final OsmandApplication app, - @NonNull DateFormat dateFormat, - boolean showRemoteDate, - @NonNull final SelectItemsToDownloadListener listener) { + @NonNull AppCompatActivity activity, + @NonNull final OsmandApplication app, + @NonNull DateFormat dateFormat, + boolean showRemoteDate, + @NonNull final SelectItemsToDownloadListener listener) { List indexesToDownload = getIndexesToDownload(multipleIndexItem); List allItems = new ArrayList<>(); List selectedItems = new ArrayList<>(); @@ -80,11 +80,11 @@ public class MultipleIndexesUiHelper { } public static void showSRTMDialog(@NonNull final DownloadItem downloadItem, - @NonNull AppCompatActivity activity, - @NonNull final OsmandApplication app, - @NonNull final DateFormat dateFormat, - final boolean showRemoteDate, - @NonNull final SelectItemsToDownloadListener listener) { + @NonNull AppCompatActivity activity, + @NonNull final OsmandApplication app, + @NonNull final DateFormat dateFormat, + final boolean showRemoteDate, + @NonNull final SelectItemsToDownloadListener listener) { List selectedItems = new ArrayList<>(); final List leftItems = new ArrayList<>(); final List rightItems = new ArrayList<>(); @@ -201,7 +201,7 @@ public class MultipleIndexesUiHelper { } private static boolean isListDialog(OsmandApplication app, - List leftItems, List rightItems) { + List leftItems, List rightItems) { return (isBaseSRTMMetricSystem(app) ? leftItems : rightItems).size() > 1; } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index 767f116dda..07aab7de88 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -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 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) { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index f67f4de704..91b1aabc76 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -511,7 +511,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() { @Override public boolean onContextMenuClick(ArrayAdapter adapter, - int itemId, int pos, boolean isChecked, int[] viewCoordinates) { + int itemId, int pos, boolean isChecked, int[] viewCoordinates) { localOptionsMenu(itemId); return true; } @@ -612,7 +612,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement } private void openSelectionMode(final int actionResId, final int actionIconId, - final DialogInterface.OnClickListener listener) { + final DialogInterface.OnClickListener listener) { final int colorResId = getMyApplication().getSettings().isLightContent() ? R.color.active_buttons_and_links_text_light : R.color.active_buttons_and_links_text_dark; String value = getString(actionResId); if (value.endsWith("...")) { @@ -713,7 +713,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement } public void openSelectionMode(int stringRes, int darkIcon, DialogInterface.OnClickListener listener, - EnumSet filter) { + EnumSet filter) { if (filter != null) { listAdapter.filterCategories(filter); } @@ -864,7 +864,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement @Override public View getChildView(final int groupPosition, final int childPosition, - boolean isLastChild, View convertView, ViewGroup parent) { + boolean isLastChild, View convertView, ViewGroup parent) { LocalIndexInfoViewHolder viewHolder; if (convertView == null) { LayoutInflater inflater = LayoutInflater.from(ctx); diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 33bddc97a6..9271a3b1c2 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -871,7 +871,7 @@ public class ResourceManager { } public List searchAmenities(SearchPoiTypeFilter filter, - double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, final ResultMatcher matcher) { + double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, int zoom, final ResultMatcher matcher) { final List amenities = new ArrayList(); searchAmenitiesInProgress = true; try { @@ -901,7 +901,7 @@ public class ResourceManager { } public List searchAmenitiesOnThePath(List locations, double radius, SearchPoiTypeFilter filter, - ResultMatcher matcher) { + ResultMatcher matcher) { searchAmenitiesInProgress = true; final List amenities = new ArrayList(); try { @@ -957,8 +957,8 @@ public class ResourceManager { } public List searchAmenitiesByName(String searchQuery, - double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, - double lat, double lon, ResultMatcher matcher) { + double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, + double lat, double lon, ResultMatcher matcher) { List amenities = new ArrayList(); List list = new ArrayList(); int left = MapUtils.get31TileNumberX(leftLongitude); @@ -1056,7 +1056,7 @@ public class ResourceManager { public List searchTransportSync(double topLat, double leftLon, double bottomLat, double rightLon, - ResultMatcher matcher) throws IOException { + ResultMatcher matcher) throws IOException { TransportStopsRouteReader readers = new TransportStopsRouteReader(getTransportRepositories(topLat, leftLon, bottomLat, rightLon)); List stops = new ArrayList<>(); diff --git a/OsmAnd/src/net/osmand/plus/settings/datastorage/DataStorageHelper.java b/OsmAnd/src/net/osmand/plus/settings/datastorage/DataStorageHelper.java index bd424210f9..763f8ff996 100644 --- a/OsmAnd/src/net/osmand/plus/settings/datastorage/DataStorageHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/datastorage/DataStorageHelper.java @@ -302,9 +302,9 @@ public class DataStorageHelper { } public DirectoryItem createDirectory(@NonNull String relativePath, - boolean processInternalDirectories, - CheckingType checkingType, - boolean addUnmatchedToOtherMemory) { + boolean processInternalDirectories, + CheckingType checkingType, + boolean addUnmatchedToOtherMemory) { String path = app.getAppPath(relativePath).getAbsolutePath(); return new DirectoryItem(path, processInternalDirectories, checkingType, addUnmatchedToOtherMemory); }