From 86ee2c1c9283e0b1db330dad49b081d2feeb8f4f Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Mon, 15 Feb 2021 21:45:56 +0200 Subject: [PATCH] Add dialog to choose multiple maps to download --- OsmAnd/res/layout/settings_group_title.xml | 1 + .../base/MenuBottomSheetDialogFragment.java | 2 +- .../base/SelectMultipleItemsBottomSheet.java | 301 ++++++++++++++++++ .../plus/download/DownloadActivityType.java | 8 +- .../osmand/plus/download/DownloadItem.java | 14 +- .../plus/download/DownloadResources.java | 24 +- .../net/osmand/plus/download/IndexItem.java | 10 +- .../plus/download/MultipleIndexItem.java | 4 +- .../download/MultipleIndexesUiHelper.java | 113 +++++++ .../ui/DownloadResourceGroupFragment.java | 7 +- .../plus/download/ui/ItemViewHolder.java | 57 ++-- 11 files changed, 487 insertions(+), 54 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/base/SelectMultipleItemsBottomSheet.java create mode 100644 OsmAnd/src/net/osmand/plus/download/MultipleIndexesUiHelper.java diff --git a/OsmAnd/res/layout/settings_group_title.xml b/OsmAnd/res/layout/settings_group_title.xml index 32629ed2de..456a3aace1 100644 --- a/OsmAnd/res/layout/settings_group_title.xml +++ b/OsmAnd/res/layout/settings_group_title.xml @@ -73,6 +73,7 @@ android:paddingBottom="@dimen/content_padding_small"> allItems = new ArrayList<>(); + private final List selectedItems = new ArrayList<>(); + private SelectionUpdateListener selectionUpdateListener; + private OnApplySelectionListener onApplySelectionListener; + + public static final String TAG = SelectMultipleItemsBottomSheet.class.getSimpleName(); + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { + View mainView = super.onCreateView(inflater, parent, savedInstanceState); + onSelectedItemsChanged(); + return mainView; + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + app = requiredMyApplication(); + uiUtilities = app.getUIUtilities(); + activeColorRes = nightMode ? R.color.icon_color_active_dark : R.color.icon_color_active_light; + secondaryColorRes = nightMode ? R.color.icon_color_secondary_dark : R.color.icon_color_secondary_light; + + items.add(createTitleItem()); + items.add(new SimpleDividerItem(app)); + createListItems(); + } + + private BaseBottomSheetItem createTitleItem() { + LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode); + View view = themedInflater.inflate(R.layout.settings_group_title, null); + + checkBox = view.findViewById(R.id.check_box); + checkBoxTitle = view.findViewById(R.id.check_box_title); + description = view.findViewById(R.id.description); + selectedSize = view.findViewById(R.id.selected_size); + title = view.findViewById(R.id.title); + View selectAllButton = view.findViewById(R.id.select_all_button); + selectAllButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + checkBox.performClick(); + boolean checked = checkBox.getState() == CHECKED; + if (checked) { + selectedItems.addAll(allItems); + } else { + selectedItems.clear(); + } + onSelectedItemsChanged(); + updateItems(checked); + } + }); + return new SimpleBottomSheetItem.Builder().setCustomView(view).create(); + } + + private void createListItems() { + for (final SelectableItem item : allItems) { + boolean checked = selectedItems.contains(item); + final BottomSheetItemWithCompoundButton[] uiItem = new BottomSheetItemWithCompoundButton[1]; + final Builder builder = (BottomSheetItemWithCompoundButton.Builder) new Builder(); + builder.setChecked(checked) + .setButtonTintList(AndroidUtils.createCheckedColorStateList(app, secondaryColorRes, activeColorRes)) + .setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + boolean checked = !uiItem[0].isChecked(); + uiItem[0].setChecked(checked); + SelectableItem tag = (SelectableItem) uiItem[0].getTag(); + if (checked) { + selectedItems.add(tag); + } else { + selectedItems.remove(tag); + } + onSelectedItemsChanged(); + } + }) + .setTag(item); + setupListItem(builder, item); + uiItem[0] = builder.create(); + items.add(uiItem[0]); + } + } + + @Override + protected void setupRightButton() { + super.setupRightButton(); + applyButtonTitle = rightButton.findViewById(R.id.button_text); + } + + @Override + protected void onRightBottomButtonClick() { + if (onApplySelectionListener != null) { + onApplySelectionListener.onSelectionApplied(selectedItems); + } + dismiss(); + } + + private void onSelectedItemsChanged() { + updateSelectAllButton(); + updateSelectedSizeView(); + updateApplyButtonEnable(); + if (selectionUpdateListener != null) { + selectionUpdateListener.onSelectionUpdate(); + } + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_apply; + } + + @Override + protected boolean useVerticalButtons() { + return true; + } + + private void setupListItem(Builder builder, SelectableItem item) { + builder.setTitle(item.title); + builder.setDescription(item.description); + builder.setIcon(uiUtilities.getIcon(item.iconId, activeColorRes)); + } + + private void updateSelectAllButton() { + String checkBoxTitle; + if (Algorithms.isEmpty(selectedItems)) { + checkBox.setState(UNCHECKED); + checkBoxTitle = getString(R.string.shared_string_select_all); + } else { + checkBox.setState(selectedItems.containsAll(allItems) ? CHECKED : MISC); + checkBoxTitle = getString(R.string.shared_string_deselect_all); + } + int checkBoxColor = checkBox.getState() == UNCHECKED ? secondaryColorRes : activeColorRes; + CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, checkBoxColor))); + this.checkBoxTitle.setText(checkBoxTitle); + } + + private void updateSelectedSizeView() { + String selected = String.valueOf(selectedItems.size()); + String all = String.valueOf(allItems.size()); + selectedSize.setText(getString(R.string.ltr_or_rtl_combine_via_slash, selected, all)); + } + + private void updateApplyButtonEnable() { + if (Algorithms.isEmpty(selectedItems)) { + rightButton.setEnabled(false); + } else { + rightButton.setEnabled(true); + } + } + + private void updateItems(boolean checked) { + for (BaseBottomSheetItem item : items) { + if (item instanceof BottomSheetItemWithCompoundButton) { + ((BottomSheetItemWithCompoundButton) item).setChecked(checked); + } + } + } + + public void setTitle(@NonNull String title) { + this.title.setText(title); + } + + public void setDescription(@NonNull String description) { + this.description.setText(description); + } + + public void setConfirmButtonTitle(@NonNull String confirmButtonTitle) { + applyButtonTitle.setText(confirmButtonTitle); + } + + private void setItems(List allItems) { + if (!Algorithms.isEmpty(allItems)) { + this.allItems.addAll(allItems); + } + } + + private void setSelectedItems(List selected) { + if (!Algorithms.isEmpty(selected)) { + this.selectedItems.addAll(selected); + } + } + + public List getSelectedItems() { + return selectedItems; + } + + @Override + public void onPause() { + super.onPause(); + if (requireActivity().isChangingConfigurations()) { + dismiss(); + } + } + + 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 void setSelectionUpdateListener(SelectionUpdateListener selectionUpdateListener) { + this.selectionUpdateListener = selectionUpdateListener; + } + + public void setOnApplySelectionListener(OnApplySelectionListener onApplySelectionListener) { + this.onApplySelectionListener = onApplySelectionListener; + } + + public interface SelectionUpdateListener { + void onSelectionUpdate(); + } + + public interface OnApplySelectionListener { + void onSelectionApplied(List selectedItems); + } + + public static class SelectableItem { + private String title; + private String description; + private int iconId; + private Object object; + + public void setTitle(String title) { + this.title = title; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setIconId(int iconId) { + this.iconId = iconId; + } + + public void setObject(Object object) { + this.object = object; + } + + public Object getObject() { + return object; + } + } + +} diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index b78617d426..071a856454 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -2,6 +2,8 @@ package net.osmand.plus.download; import android.content.Context; +import androidx.annotation.NonNull; + import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.map.OsmandRegions; @@ -446,9 +448,11 @@ public class DownloadActivityType { return fileName; } - - public String getBasename(DownloadItem downloadItem) { + @NonNull + public String getBasename(@NonNull DownloadItem downloadItem) { String fileName = downloadItem.getFileName(); + if (Algorithms.isEmpty(fileName)) return fileName; + if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) { return fileName.substring(0, fileName.length() - IndexConstants.EXTRA_ZIP_EXT.length()); } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadItem.java b/OsmAnd/src/net/osmand/plus/download/DownloadItem.java index 23e9f410a7..366f3554a7 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadItem.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadItem.java @@ -35,8 +35,7 @@ public abstract class DownloadItem { @NonNull public String getSizeDescription(Context ctx) { - String size = String.format(Locale.US, "%.2f", getSizeToDownloadInMb()); - return ctx.getString(R.string.ltr_or_rtl_combine_via_space, size, "MB"); + return getFormattedMb(ctx, getSizeToDownloadInMb()); } public String getVisibleName(Context ctx, OsmandRegions osmandRegions) { @@ -51,6 +50,7 @@ public abstract class DownloadItem { return type.getVisibleDescription(this, ctx); } + @NonNull public String getBasename() { return type.getBasename(this); } @@ -65,11 +65,17 @@ public abstract class DownloadItem { public abstract boolean hasActualDataToDownload(); - public abstract boolean isDownloading(DownloadIndexesThread thread); + public abstract boolean isDownloading(@NonNull DownloadIndexesThread thread); public abstract String getFileName(); @NonNull - public abstract List getDownloadedFiles(OsmandApplication app); + public abstract List getDownloadedFiles(@NonNull OsmandApplication app); + + @NonNull + public static String getFormattedMb(@NonNull Context ctx, double sizeInMb) { + String size = String.format(Locale.US, "%.2f", sizeInMb); + return ctx.getString(R.string.ltr_or_rtl_combine_via_space, size, "MB"); + } } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java index 86c89f9cc5..66a6621851 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadResources.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadResources.java @@ -481,9 +481,10 @@ public class DownloadResources extends DownloadResourceGroup { if (group != null) { boolean listModified = false; List indexesList = group.getIndividualResources(); + List regionsToCollect = removeDuplicateRegions(subRegions); for (DownloadActivityType type : DownloadActivityType.values()) { if (!doesListContainIndexWithType(indexesList, type)) { - List indexesFromSubRegions = collectIndexesOfType(subRegions, type); + List indexesFromSubRegions = collectIndexesOfType(regionsToCollect, type); if (indexesFromSubRegions != null) { group.addItem(new MultipleIndexItem(region, indexesFromSubRegions, type)); listModified = true; @@ -510,7 +511,7 @@ public class DownloadResources extends DownloadResourceGroup { @Nullable private List collectIndexesOfType(@NonNull List regions, @NonNull DownloadActivityType type) { - Map collectedIndexes = new LinkedHashMap<>(); + List collectedIndexes = new ArrayList<>(); for (WorldRegion region : regions) { List regionIndexes = getIndexItems(region); boolean found = false; @@ -518,36 +519,33 @@ public class DownloadResources extends DownloadResourceGroup { for (IndexItem index : regionIndexes) { if (index.getType() == type) { found = true; - collectedIndexes.put(region, index); + collectedIndexes.add(index); break; } } } if (!found) return null; } - return removeDuplicates(collectedIndexes); + return collectedIndexes; } - private List removeDuplicates(Map collectedIndexes) { - List regions = new ArrayList<>(collectedIndexes.keySet()); - // collect duplicates + private List removeDuplicateRegions(List regions) { Set duplicates = new HashSet<>(); for (int i = 0; i < regions.size() - 1; i++) { WorldRegion r1 = regions.get(i); for (int j = i + 1; j < regions.size(); j++) { WorldRegion r2 = regions.get(j); if (r1.containsRegion(r2)) { - duplicates.add(r1); - } else if (r2.containsRegion(r1)) { duplicates.add(r2); + } else if (r2.containsRegion(r1)) { + duplicates.add(r1); } } } - // remove duplicates - for (WorldRegion key : duplicates) { - collectedIndexes.remove(key); + for (WorldRegion region : duplicates) { + regions.remove(region); } - return new ArrayList<>(collectedIndexes.values()); + return regions; } private void buildRegionsGroups(WorldRegion region, DownloadResourceGroup group) { diff --git a/OsmAnd/src/net/osmand/plus/download/IndexItem.java b/OsmAnd/src/net/osmand/plus/download/IndexItem.java index 637b1f5467..da0103fdb0 100644 --- a/OsmAnd/src/net/osmand/plus/download/IndexItem.java +++ b/OsmAnd/src/net/osmand/plus/download/IndexItem.java @@ -57,7 +57,7 @@ public class IndexItem extends DownloadItem implements Comparable { @NonNull @Override - public List getDownloadedFiles(OsmandApplication app) { + public List getDownloadedFiles(@NonNull OsmandApplication app) { File targetFile = getTargetFile(app); if (targetFile.exists()) { return Collections.singletonList(targetFile); @@ -166,6 +166,10 @@ public class IndexItem extends DownloadItem implements Comparable { } return ""; } + + public String getDate(@NonNull DateFormat dateFormat, boolean remote) { + return remote ? getRemoteDate(dateFormat) : getLocalDate(dateFormat); + } public String getRemoteDate(DateFormat dateFormat) { if(timestamp <= 0) { @@ -175,7 +179,7 @@ public class IndexItem extends DownloadItem implements Comparable { } - public String getLocalDate(DateFormat dateFormat) { + private String getLocalDate(@NonNull DateFormat dateFormat) { if(localTimestamp <= 0) { return ""; } @@ -214,7 +218,7 @@ public class IndexItem extends DownloadItem implements Comparable { } @Override - public boolean isDownloading(DownloadIndexesThread thread) { + public boolean isDownloading(@NonNull DownloadIndexesThread thread) { return thread.isDownloading(this); } diff --git a/OsmAnd/src/net/osmand/plus/download/MultipleIndexItem.java b/OsmAnd/src/net/osmand/plus/download/MultipleIndexItem.java index 9e58db0655..5f5ff9c297 100644 --- a/OsmAnd/src/net/osmand/plus/download/MultipleIndexItem.java +++ b/OsmAnd/src/net/osmand/plus/download/MultipleIndexItem.java @@ -45,7 +45,7 @@ public class MultipleIndexItem extends DownloadItem { } @Override - public boolean isDownloading(DownloadIndexesThread thread) { + public boolean isDownloading(@NonNull DownloadIndexesThread thread) { for (IndexItem item : items) { if (thread.isDownloading(item)) { return true; @@ -76,7 +76,7 @@ public class MultipleIndexItem extends DownloadItem { @NonNull @Override - public List getDownloadedFiles(OsmandApplication app) { + public List getDownloadedFiles(@NonNull OsmandApplication app) { List result = new ArrayList<>(); for (IndexItem item : items) { result.addAll(item.getDownloadedFiles(app)); diff --git a/OsmAnd/src/net/osmand/plus/download/MultipleIndexesUiHelper.java b/OsmAnd/src/net/osmand/plus/download/MultipleIndexesUiHelper.java new file mode 100644 index 0000000000..c7e9a05b66 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/download/MultipleIndexesUiHelper.java @@ -0,0 +1,113 @@ +package net.osmand.plus.download; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import net.osmand.map.OsmandRegions; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.base.SelectMultipleItemsBottomSheet; +import net.osmand.plus.base.SelectMultipleItemsBottomSheet.OnApplySelectionListener; +import net.osmand.plus.base.SelectMultipleItemsBottomSheet.SelectableItem; +import net.osmand.plus.base.SelectMultipleItemsBottomSheet.SelectionUpdateListener; + +import java.text.DateFormat; +import java.util.ArrayList; +import java.util.List; + +public class MultipleIndexesUiHelper { + + public static void showDialog(@NonNull MultipleIndexItem multipleIndexItem, + @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<>(); + OsmandRegions osmandRegions = app.getRegions(); + for (IndexItem indexItem : multipleIndexItem.getAllIndexes()) { + SelectableItem selectableItem = new SelectableItem(); + selectableItem.setTitle(indexItem.getVisibleName(app, osmandRegions)); + + 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); + + if (indexesToDownload.contains(indexItem)) { + selectedItems.add(selectableItem); + } + } + + final SelectMultipleItemsBottomSheet dialog = + SelectMultipleItemsBottomSheet.showInstance(activity, allItems, selectedItems, true); + + dialog.setSelectionUpdateListener(new SelectionUpdateListener() { + @Override + public void onSelectionUpdate() { + dialog.setTitle(app.getString(R.string.welmode_download_maps)); + String total = app.getString(R.string.shared_string_total); + double sizeToDownload = getDownloadSizeInMb(dialog.getSelectedItems()); + String size = DownloadItem.getFormattedMb(app, sizeToDownload); + String description = + app.getString(R.string.ltr_or_rtl_combine_via_colon, total, size); + dialog.setDescription(description); + 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.setConfirmButtonTitle(btnTitle); + } + }); + + dialog.setOnApplySelectionListener(new OnApplySelectionListener() { + @Override + public void onSelectionApplied(List selectedItems) { + List indexItems = new ArrayList<>(); + for (SelectableItem item : selectedItems) { + Object obj = item.getObject(); + if (obj instanceof IndexItem) { + indexItems.add((IndexItem) obj); + } + } + listener.onItemsToDownloadSelected(indexItems); + } + }); + } + + private static List getIndexesToDownload(MultipleIndexItem multipleIndexItem) { + if (multipleIndexItem.hasActualDataToDownload()) { + // download left regions + return multipleIndexItem.getIndexesToDownload(); + } else { + // download all regions again + return multipleIndexItem.getAllIndexes(); + } + } + + private static double getDownloadSizeInMb(@NonNull List selectableItems) { + List indexItems = new ArrayList<>(); + for (SelectableItem i : selectableItems) { + Object obj = i.getObject(); + if (obj instanceof IndexItem) { + indexItems.add((IndexItem) obj); + } + } + double totalSizeMb = 0.0d; + for (IndexItem item : indexItems) { + totalSizeMb += item.getSizeToDownloadInMb(); + } + return totalSizeMb; + } + + public interface SelectItemsToDownloadListener { + void onItemsToDownloadSelected(List items); + } + +} diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java index 388efca2bb..fd5d4bc365 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java @@ -35,6 +35,7 @@ import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity.BannerAndDownloadFreeVersion; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; +import net.osmand.plus.download.DownloadItem; import net.osmand.plus.download.DownloadResourceGroup; import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadValidationManager; @@ -504,10 +505,10 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow DownloadItemFragment downloadItemFragment = DownloadItemFragment.createInstance(regionId, childPosition); ((DownloadActivity) getActivity()).showDialog(getActivity(), downloadItemFragment); - } else if (child instanceof IndexItem) { - IndexItem indexItem = (IndexItem) child; + } else if (child instanceof DownloadItem) { + DownloadItem downloadItem = (DownloadItem) child; ItemViewHolder vh = (ItemViewHolder) v.getTag(); - OnClickListener ls = vh.getRightButtonAction(indexItem, vh.getClickAction(indexItem)); + OnClickListener ls = vh.getRightButtonAction(downloadItem, vh.getClickAction(downloadItem)); ls.onClick(v); return true; } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index 5c71fa342b..1a4449132d 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -40,6 +40,8 @@ import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadResourceGroup; import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.IndexItem; +import net.osmand.plus.download.MultipleIndexesUiHelper; +import net.osmand.plus.download.MultipleIndexesUiHelper.SelectItemsToDownloadListener; import net.osmand.plus.download.MultipleIndexItem; import net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask; import net.osmand.plus.helpers.FileNameTranslationHelper; @@ -65,17 +67,17 @@ public class ItemViewHolder { private boolean depthContoursPurchased; protected final DownloadActivity context; - + private int textColorPrimary; private int textColorSecondary; - + boolean showTypeInDesc; boolean showTypeInName; boolean showParentRegionName; boolean showRemoteDate; boolean silentCancelDownload; boolean showProgressInDesc; - + private DateFormat dateFormat; @@ -87,7 +89,7 @@ public class ItemViewHolder { ASK_FOR_FULL_VERSION_PURCHASE, ASK_FOR_DEPTH_CONTOURS_PURCHASE } - + public ItemViewHolder(View view, DownloadActivity context) { this.context = context; @@ -110,28 +112,28 @@ public class ItemViewHolder { theme.resolveAttribute(android.R.attr.textColorSecondary, typedValue, true); textColorSecondary = typedValue.data; } - + public void setShowRemoteDate(boolean showRemoteDate) { this.showRemoteDate = showRemoteDate; } - - + + public void setShowParentRegionName(boolean showParentRegionName) { this.showParentRegionName = showParentRegionName; } - + public void setShowProgressInDescr(boolean b) { showProgressInDesc = b; } - + public void setSilentCancelDownload(boolean silentCancelDownload) { this.silentCancelDownload = silentCancelDownload; } - + public void setShowTypeInDesc(boolean showTypeInDesc) { this.showTypeInDesc = showTypeInDesc; } - + public void setShowTypeInName(boolean showTypeInName) { this.showTypeInName = showTypeInName; } @@ -236,7 +238,7 @@ public class ItemViewHolder { String pattern = context.getString(R.string.ltr_or_rtl_combine_via_bold_point); String type = item.getType().getString(context); String size = item.getSizeDescription(context); - String date = showRemoteDate ? item.getRemoteDate(dateFormat) : item.getLocalDate(dateFormat); + String date = item.getDate(dateFormat, showRemoteDate); String fullDescription = String.format(pattern, size, date); if (showTypeInDesc) { fullDescription = String.format(pattern, type, fullDescription); @@ -248,7 +250,7 @@ public class ItemViewHolder { progressBar.setVisibility(View.VISIBLE); progressBar.setIndeterminate(progress == -1); progressBar.setProgress(progress); - + if (showProgressInDesc) { double mb = downloadItem.getArchiveSizeMB(); String v ; @@ -267,7 +269,7 @@ public class ItemViewHolder { } else { descrTextView.setVisibility(View.GONE); } - + } } @@ -308,7 +310,7 @@ public class ItemViewHolder { } rightImageButton.setOnClickListener(action); } - + return disabled; } @@ -473,23 +475,26 @@ public class ItemViewHolder { private void startDownload(DownloadItem item) { if (item instanceof MultipleIndexItem) { - MultipleIndexItem multipleIndexItem = (MultipleIndexItem) item; - List indexes; - if (multipleIndexItem.hasActualDataToDownload()) { - // download left regions - indexes = multipleIndexItem.getIndexesToDownload(); - } else { - // download all regions again - indexes = multipleIndexItem.getAllIndexes(); - } - IndexItem[] indexesArray = new IndexItem[indexes.size()]; - context.startDownload(indexes.toArray(indexesArray)); + selectIndexesToDownload((MultipleIndexItem) item); } else if (item instanceof IndexItem) { IndexItem indexItem = (IndexItem) item; context.startDownload(indexItem); } } + private void selectIndexesToDownload(MultipleIndexItem item) { + OsmandApplication app = context.getMyApplication(); + MultipleIndexesUiHelper.showDialog(item, context, app, dateFormat, showRemoteDate, + new SelectItemsToDownloadListener() { + @Override + public void onItemsToDownloadSelected(List indexes) { + IndexItem[] indexesArray = new IndexItem[indexes.size()]; + context.startDownload(indexes.toArray(indexesArray)); + } + } + ); + } + private void confirmRemove(@NonNull final DownloadItem downloadItem, @NonNull final List downloadedFiles) { OsmandApplication app = context.getMyApplication();