diff --git a/android/src/app/organicmaps/downloader/DownloaderAdapter.java b/android/src/app/organicmaps/downloader/DownloaderAdapter.java index 856727d9af..0948308715 100644 --- a/android/src/app/organicmaps/downloader/DownloaderAdapter.java +++ b/android/src/app/organicmaps/downloader/DownloaderAdapter.java @@ -41,10 +41,8 @@ import java.util.Stack; class DownloaderAdapter extends RecyclerView.Adapter { - private static final int HEADER_ADVERTISMENT_ID = CountryItem.CATEGORY__LAST + 1; - private static final int HEADER_ADS_OFFSET = 10; - private static final int TYPE_COUNTRY = 0; + private static final int TYPE_HEADER = 1; private static final String DOWNLOADER_MENU_ID = "DOWNLOADER_BOTTOM_SHEET"; @@ -55,18 +53,33 @@ class DownloaderAdapter extends RecyclerView.Adapter mItemsAndHeader = new ArrayList<>(); + private final List mItems = new ArrayList<>(); // Core Country.id String -> List mapping index for updateItem function. // Use List, because we have multiple search results now for a single country. private final Map> mCountryIndex = new HashMap<>(); - private final SparseArray mHeaders = new SparseArray<>(); private final Stack mPath = new Stack<>(); // Holds navigation history. The last element is the current level. - private int mNearMeCount; private int mListenerSlot; private CountryItem mSelectedItem; + private static class GenericItem { + @Nullable + public final String mHeaderText; + @Nullable + public final CountryItem mItem; + public GenericItem(@Nullable CountryItem item) { + mItem = item; + mHeaderText = null; + } + public GenericItem(@Nullable String headerText) { + mItem = null; + mHeaderText = headerText; + } + } + private void onDownloadActionSelected(final CountryItem item, DownloaderAdapter adapter) { MapManager.warn3gAndDownload(adapter.mActivity, item.id, null); @@ -220,7 +233,11 @@ class DownloaderAdapter extends RecyclerView.Adapter { @NonNull private final TextView mTitle; HeaderViewHolder(@NonNull View frame) { - super(frame); mTitle = frame.findViewById(R.id.title); } - void bind(int position) + void bind(String text) { - CountryItem ci = mItems.get(position); - mTitle.setText(mHeaders.get(ci.headerId)); + mTitle.setText(text); } } private void collectHeaders() { - mNearMeCount = 0; - mHeaders.clear(); - if (mSearchResultsMode) - return; + mItemsAndHeader.clear(); int headerId = 0; int prev = -1; for (CountryItem ci: mItems) { - switch (ci.category) - { - case CountryItem.CATEGORY_NEAR_ME: - if (ci.category != prev) + // Disable headers when using the search + if (!mSearchResultsMode) { + switch (ci.category) { - headerId = CountryItem.CATEGORY_NEAR_ME; - mHeaders.put(headerId, mActivity.getString(R.string.downloader_near_me_subtitle)); - prev = ci.category; + case CountryItem.CATEGORY_NEAR_ME: + if (ci.category != prev) + { + headerId = CountryItem.CATEGORY_NEAR_ME; + mItemsAndHeader.add(new GenericItem(mActivity.getString(R.string.downloader_near_me_subtitle))); + prev = ci.category; + } + break; + + case CountryItem.CATEGORY_DOWNLOADED: + if (ci.category != prev) + { + headerId = CountryItem.CATEGORY_DOWNLOADED; + mItemsAndHeader.add(new GenericItem(mActivity.getString(R.string.downloader_downloaded_subtitle))); + prev = ci.category; + } + break; + default: + int prevHeader = headerId; + headerId = CountryItem.CATEGORY_AVAILABLE + ci.name.charAt(0); + + if (headerId != prevHeader) + mItemsAndHeader.add(new GenericItem(StringUtils.toUpperCase(ci.name.substring(0, 1)))); + + prev = ci.category; } - - mNearMeCount++; - break; - - case CountryItem.CATEGORY_DOWNLOADED: - if (ci.category != prev) - { - headerId = CountryItem.CATEGORY_DOWNLOADED; - mHeaders.put(headerId, mActivity.getString(R.string.downloader_downloaded_subtitle)); - prev = ci.category; - } - break; - - default: - int prevHeader = headerId; - headerId = CountryItem.CATEGORY_AVAILABLE * HEADER_ADS_OFFSET + ci.name.charAt(0); - - if (headerId != prevHeader) - mHeaders.put(headerId, StringUtils.toUpperCase(ci.name.substring(0, 1))); - - prev = ci.category; + ci.headerId = headerId; } - - ci.headerId = headerId; + mItemsAndHeader.add(new GenericItem(ci)); } } @@ -676,7 +695,10 @@ class DownloaderAdapter extends RecyclerView.Adapter