refactoring p.6: dialog preparation and update
This commit is contained in:
parent
ae2eef75f3
commit
2f1e43147d
8 changed files with 214 additions and 192 deletions
|
@ -12,22 +12,23 @@ import net.osmand.plus.widgets.MultiStateToggleButton.RadioItem;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class MultipleWithModeBottomSheet extends MultipleSelectionBottomSheet {
|
public class MultipleSelectionWithModeBottomSheet extends MultipleSelectionBottomSheet {
|
||||||
|
|
||||||
public static final String TAG = MultipleWithModeBottomSheet.class.getSimpleName();
|
public static final String TAG = MultipleSelectionWithModeBottomSheet.class.getSimpleName();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
showElements(secondaryDescription, toggleContainer, checkBox,
|
showElements(secondaryDescription, toggleContainer, checkBox,
|
||||||
checkBoxTitle, titleDescription, selectedSize, selectAllButton);
|
checkBoxTitle, titleDescription, selectedSize, selectAllButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MultipleWithModeBottomSheet showInstance(@NonNull AppCompatActivity activity,
|
public static MultipleSelectionWithModeBottomSheet showInstance(@NonNull AppCompatActivity activity,
|
||||||
@NonNull List<SelectableItem> items,
|
@NonNull List<SelectableItem> items,
|
||||||
@Nullable List<SelectableItem> selected,
|
@Nullable List<SelectableItem> selected,
|
||||||
@NonNull List<RadioItem> modes,
|
@NonNull List<RadioItem> modes,
|
||||||
boolean usedOnMap) {
|
boolean usedOnMap) {
|
||||||
MultipleWithModeBottomSheet fragment = new MultipleWithModeBottomSheet();
|
MultipleSelectionWithModeBottomSheet fragment = new MultipleSelectionWithModeBottomSheet();
|
||||||
fragment.setUsedOnMap(usedOnMap);
|
fragment.setUsedOnMap(usedOnMap);
|
||||||
fragment.setItems(items);
|
fragment.setItems(items);
|
||||||
fragment.setSelectedItems(selected);
|
fragment.setSelectedItems(selected);
|
|
@ -180,6 +180,10 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
|
||||||
listContainer.addView(view);
|
listContainer.addView(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<SelectableItem> getAllItems() {
|
||||||
|
return allItems;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public abstract List<SelectableItem> getSelectedItems();
|
public abstract List<SelectableItem> getSelectedItems();
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.text.DateFormat;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@ -55,6 +56,13 @@ public abstract class DownloadItem {
|
||||||
return type.getBasename(this);
|
return type.getBasename(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public abstract List<File> getDownloadedFiles(@NonNull OsmandApplication app);
|
||||||
|
|
||||||
|
public abstract boolean isUseAbbreviation();
|
||||||
|
|
||||||
|
public abstract String getAbbreviationInScopes(Context ctx);
|
||||||
|
|
||||||
protected abstract double getSizeToDownloadInMb();
|
protected abstract double getSizeToDownloadInMb();
|
||||||
|
|
||||||
public abstract double getArchiveSizeMB();
|
public abstract double getArchiveSizeMB();
|
||||||
|
@ -69,8 +77,7 @@ public abstract class DownloadItem {
|
||||||
|
|
||||||
public abstract String getFileName();
|
public abstract String getFileName();
|
||||||
|
|
||||||
@NonNull
|
public abstract String getDate(@NonNull DateFormat dateFormat, boolean remote);
|
||||||
public abstract List<File> getDownloadedFiles(@NonNull OsmandApplication app);
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static String getFormattedMb(@NonNull Context ctx, double sizeInMb) {
|
public static String getFormattedMb(@NonNull Context ctx, double sizeInMb) {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package net.osmand.plus.download;
|
package net.osmand.plus.download;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
|
@ -19,6 +21,7 @@ import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class IndexItem extends DownloadItem implements Comparable<IndexItem> {
|
public class IndexItem extends DownloadItem implements Comparable<IndexItem> {
|
||||||
|
|
||||||
private static final Log log = PlatformUtil.getLog(IndexItem.class);
|
private static final Log log = PlatformUtil.getLog(IndexItem.class);
|
||||||
|
|
||||||
String description;
|
String description;
|
||||||
|
@ -226,6 +229,16 @@ public class IndexItem extends DownloadItem implements Comparable<IndexItem> {
|
||||||
return format.format(new Date(timestamp));
|
return format.format(new Date(timestamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUseAbbreviation() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAbbreviationInScopes(Context ctx) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public static class DownloadEntry {
|
public static class DownloadEntry {
|
||||||
public long dateModified;
|
public long dateModified;
|
||||||
public double sizeMB;
|
public double sizeMB;
|
||||||
|
@ -254,5 +267,4 @@ public class IndexItem extends DownloadItem implements Comparable<IndexItem> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package net.osmand.plus.download;
|
package net.osmand.plus.download;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -7,6 +9,7 @@ import net.osmand.map.WorldRegion;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -32,7 +35,7 @@ public class MultipleDownloadItem extends DownloadItem {
|
||||||
return indexes;
|
return indexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DownloadItem> getItems() {
|
public List<DownloadItem> getAllItems() {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,19 +99,19 @@ public class MultipleDownloadItem extends DownloadItem {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IndexItem> getIndexesToDownload() {
|
public List<DownloadItem> getItemsToDownload() {
|
||||||
List<IndexItem> indexesToDownload = new ArrayList<>();
|
List<DownloadItem> itemsToDownload = new ArrayList<>();
|
||||||
for (IndexItem item : getAllIndexes()) {
|
for (DownloadItem item : getAllItems()) {
|
||||||
if (item.hasActualDataToDownload()) {
|
if (item.hasActualDataToDownload()) {
|
||||||
indexesToDownload.add(item);
|
itemsToDownload.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return indexesToDownload;
|
return itemsToDownload;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasActualDataToDownload() {
|
public boolean hasActualDataToDownload() {
|
||||||
return getIndexesToDownload().size() > 0;
|
return getItemsToDownload().size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -141,4 +144,28 @@ public class MultipleDownloadItem extends DownloadItem {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUseAbbreviation() {
|
||||||
|
for (DownloadItem item : items) {
|
||||||
|
if (item.isUseAbbreviation()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAbbreviationInScopes(Context ctx) {
|
||||||
|
for (DownloadItem item : items) {
|
||||||
|
return item.getAbbreviationInScopes(ctx);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDate(@NonNull DateFormat dateFormat, boolean remote) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,12 @@ import android.view.View;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import net.osmand.map.OsmandRegions;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.MultipleSelectionBottomSheet;
|
import net.osmand.plus.base.MultipleSelectionBottomSheet;
|
||||||
import net.osmand.plus.base.MultipleSelectionBottomSheet.SelectionUpdateListener;
|
import net.osmand.plus.base.MultipleSelectionBottomSheet.SelectionUpdateListener;
|
||||||
import net.osmand.plus.base.ModeSelectionBottomSheet;
|
import net.osmand.plus.base.ModeSelectionBottomSheet;
|
||||||
import net.osmand.plus.base.MultipleWithModeBottomSheet;
|
import net.osmand.plus.base.MultipleSelectionWithModeBottomSheet;
|
||||||
import net.osmand.plus.base.SelectionBottomSheet;
|
import net.osmand.plus.base.SelectionBottomSheet;
|
||||||
import net.osmand.plus.base.SelectionBottomSheet.OnApplySelectionListener;
|
import net.osmand.plus.base.SelectionBottomSheet.OnApplySelectionListener;
|
||||||
import net.osmand.plus.base.SelectionBottomSheet.OnUiInitializedListener;
|
import net.osmand.plus.base.SelectionBottomSheet.OnUiInitializedListener;
|
||||||
|
@ -24,7 +23,6 @@ import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE;
|
|
||||||
import static net.osmand.plus.download.MultipleDownloadItem.getIndexItem;
|
import static net.osmand.plus.download.MultipleDownloadItem.getIndexItem;
|
||||||
|
|
||||||
public class SelectIndexesUiHelper {
|
public class SelectIndexesUiHelper {
|
||||||
|
@ -57,221 +55,196 @@ public class SelectIndexesUiHelper {
|
||||||
@NonNull DateFormat df,
|
@NonNull DateFormat df,
|
||||||
boolean showRemoteDate,
|
boolean showRemoteDate,
|
||||||
@NonNull ItemsToDownloadSelectedListener l) {
|
@NonNull ItemsToDownloadSelectedListener l) {
|
||||||
|
|
||||||
new SelectIndexesUiHelper(i, a, df, showRemoteDate, l).showDialogInternal();
|
new SelectIndexesUiHelper(i, a, df, showRemoteDate, l).showDialogInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDialogInternal() {
|
private void showDialogInternal() {
|
||||||
if (downloadItem.getType() == SRTM_COUNTRY_FILE) {
|
if (downloadItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||||
if (downloadItem instanceof MultipleDownloadItem) {
|
if (downloadItem instanceof MultipleDownloadItem) {
|
||||||
showMultipleSrtmDialog();
|
showSrtmMultipleSelectionDialog();
|
||||||
} else {
|
} else {
|
||||||
showSingleSrtmDialog();
|
showSrtmModeSelectionDialog();
|
||||||
}
|
}
|
||||||
} else if (downloadItem instanceof MultipleDownloadItem) {
|
} else if (downloadItem instanceof MultipleDownloadItem) {
|
||||||
showBaseDialog();
|
showMultipleSelectionDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showBaseDialog() {
|
private void showMultipleSelectionDialog() {
|
||||||
MultipleDownloadItem multipleDownloadItem = (MultipleDownloadItem) downloadItem;
|
|
||||||
List<IndexItem> indexesToDownload = getIndexesToDownload(multipleDownloadItem);
|
|
||||||
List<SelectableItem> allItems = new ArrayList<>();
|
List<SelectableItem> allItems = new ArrayList<>();
|
||||||
List<SelectableItem> selectedItems = new ArrayList<>();
|
List<SelectableItem> selectedItems = new ArrayList<>();
|
||||||
OsmandRegions osmandRegions = app.getRegions();
|
prepareItems(allItems, selectedItems);
|
||||||
for (IndexItem indexItem : multipleDownloadItem.getAllIndexes()) {
|
|
||||||
SelectableItem selectableItem = new SelectableItem();
|
|
||||||
selectableItem.setTitle(indexItem.getVisibleName(app, osmandRegions, false));
|
|
||||||
|
|
||||||
String size = indexItem.getSizeDescription(app);
|
MultipleSelectionBottomSheet msDialog = MultipleSelectionBottomSheet.showInstance(
|
||||||
String date = indexItem.getDate(dateFormat, showRemoteDate);
|
activity, allItems, selectedItems, true);
|
||||||
String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date);
|
this.dialog = msDialog;
|
||||||
selectableItem.setDescription(description);
|
|
||||||
|
|
||||||
selectableItem.setIconId(indexItem.getType().getIconResource());
|
msDialog.setUiInitializedListener(new OnUiInitializedListener() {
|
||||||
selectableItem.setObject(indexItem);
|
|
||||||
allItems.add(selectableItem);
|
|
||||||
|
|
||||||
if (indexesToDownload.contains(indexItem)) {
|
|
||||||
selectedItems.add(selectableItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final MultipleSelectionBottomSheet dialog =
|
|
||||||
MultipleSelectionBottomSheet.showInstance(activity, allItems, selectedItems, true);
|
|
||||||
|
|
||||||
dialog.setUiInitializedListener(new OnUiInitializedListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onUiInitialized() {
|
public void onUiInitialized() {
|
||||||
dialog.setTitle(app.getString(R.string.welmode_download_maps));
|
dialog.setTitle(app.getString(R.string.welmode_download_maps));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dialog.setSelectionUpdateListener(new SelectionUpdateListener() {
|
msDialog.setSelectionUpdateListener(new SelectionUpdateListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSelectionUpdate() {
|
public void onSelectionUpdate() {
|
||||||
updateSize(dialog, true);
|
updateSize();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
|
|
||||||
|
msDialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSingleSrtmDialog() {
|
private void showSrtmMultipleSelectionDialog() {
|
||||||
boolean baseSRTM = SrtmDownloadItem.shouldUseMetersByDefault(app);
|
List<SelectableItem> allItems = new ArrayList<>();
|
||||||
|
List<SelectableItem> selectedItems = new ArrayList<>();
|
||||||
|
prepareItems(allItems, selectedItems);
|
||||||
|
|
||||||
|
SrtmDownloadItem srtmItem = (SrtmDownloadItem) ((MultipleDownloadItem)downloadItem).getAllItems().get(0);
|
||||||
|
final int selectedModeOrder = srtmItem.isUseMeters() ? 0 : 1;
|
||||||
|
final List<RadioItem> radioItems = createSrtmRadioItems();
|
||||||
|
|
||||||
|
MultipleSelectionBottomSheet msDialog = MultipleSelectionWithModeBottomSheet.showInstance(
|
||||||
|
activity, allItems, selectedItems, radioItems, true);
|
||||||
|
this.dialog = msDialog;
|
||||||
|
|
||||||
|
msDialog.setUiInitializedListener(new OnUiInitializedListener() {
|
||||||
|
@Override
|
||||||
|
public void onUiInitialized() {
|
||||||
|
dialog.setTitle(app.getString(R.string.welmode_download_maps));
|
||||||
|
dialog.setSelectedMode(radioItems.get(selectedModeOrder));
|
||||||
|
dialog.setSecondaryDescription(app.getString(R.string.srtm_download_list_help_message));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
msDialog.setSelectionUpdateListener(new SelectionUpdateListener() {
|
||||||
|
@Override
|
||||||
|
public void onSelectionUpdate() {
|
||||||
|
updateSize();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
msDialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showSrtmModeSelectionDialog() {
|
||||||
SrtmDownloadItem srtmItem = (SrtmDownloadItem) downloadItem;
|
SrtmDownloadItem srtmItem = (SrtmDownloadItem) downloadItem;
|
||||||
|
final int selectedModeOrder = srtmItem.isUseMeters() ? 0 : 1;
|
||||||
|
|
||||||
srtmItem.setUseMeters(true);
|
final List<RadioItem> radioItems = createSrtmRadioItems();
|
||||||
SelectableItem meterItem = createSrtmSelectableItem(srtmItem.getIndexItem());
|
SelectableItem preview = createSelectableItem(srtmItem);
|
||||||
srtmItem.setUseMeters(false);
|
|
||||||
SelectableItem feetItem = createSrtmSelectableItem(srtmItem.getIndexItem());
|
|
||||||
srtmItem.setUseMeters(baseSRTM);
|
|
||||||
|
|
||||||
List<RadioItem> radioItems = new ArrayList<>();
|
dialog = ModeSelectionBottomSheet.showInstance(activity, preview, radioItems, true);
|
||||||
RadioItem meters = createRadioItem(meterItem, R.string.shared_string_meters);
|
|
||||||
RadioItem feet = createRadioItem(feetItem, R.string.shared_string_feets);
|
|
||||||
radioItems.add(meters);
|
|
||||||
radioItems.add(feet);
|
|
||||||
|
|
||||||
dialog = ModeSelectionBottomSheet.showInstance(activity,
|
|
||||||
baseSRTM ? meterItem : feetItem, radioItems, true);
|
|
||||||
|
|
||||||
final RadioItem initRadio = baseSRTM ? meters : feet;
|
|
||||||
final SelectableItem initItem = baseSRTM ? meterItem : feetItem;
|
|
||||||
dialog.setUiInitializedListener(new OnUiInitializedListener() {
|
dialog.setUiInitializedListener(new OnUiInitializedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onUiInitialized() {
|
public void onUiInitialized() {
|
||||||
ModeSelectionBottomSheet dialog = (ModeSelectionBottomSheet) SelectIndexesUiHelper.this.dialog;
|
ModeSelectionBottomSheet dialog = (ModeSelectionBottomSheet) SelectIndexesUiHelper.this.dialog;
|
||||||
dialog.setTitle(app.getString(R.string.srtm_unit_format));
|
dialog.setTitle(app.getString(R.string.srtm_unit_format));
|
||||||
dialog.setPrimaryDescription(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.setSelectedMode(initRadio);
|
dialog.setSelectedMode(radioItems.get(selectedModeOrder));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
|
dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
private SelectableItem createSrtmSelectableItem(IndexItem indexItem) {
|
private void prepareItems(List<SelectableItem> allItems,
|
||||||
SelectableItem selectableItem = new SelectableItem();
|
List<SelectableItem> selectedItems) {
|
||||||
selectableItem.setTitle(indexItem.getVisibleName(app, app.getRegions(), false));
|
final MultipleDownloadItem multipleDownloadItem = (MultipleDownloadItem) downloadItem;
|
||||||
String size = indexItem.getSizeDescription(app);
|
final List<DownloadItem> itemsToDownload = getItemsToDownload(multipleDownloadItem);
|
||||||
size += " " + SrtmDownloadItem.getAbbreviationInScopes(app, indexItem);
|
for (DownloadItem downloadItem : multipleDownloadItem.getAllItems()) {
|
||||||
String date = indexItem.getDate(dateFormat, showRemoteDate);
|
SelectableItem selectableItem = createSelectableItem(downloadItem);
|
||||||
String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date);
|
allItems.add(selectableItem);
|
||||||
selectableItem.setDescription(description);
|
|
||||||
selectableItem.setIconId(indexItem.getType().getIconResource());
|
if (itemsToDownload.contains(downloadItem)) {
|
||||||
selectableItem.setObject(indexItem);
|
selectedItems.add(selectableItem);
|
||||||
return selectableItem;
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RadioItem createRadioItem(final SelectableItem selectableItem, int titleId) {
|
private List<RadioItem> createSrtmRadioItems() {
|
||||||
|
List<RadioItem> radioItems = new ArrayList<>();
|
||||||
|
radioItems.add(createSrtmRadioBtn(R.string.shared_string_meters, true));
|
||||||
|
radioItems.add(createSrtmRadioBtn(R.string.shared_string_feets, false));
|
||||||
|
return radioItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RadioItem createSrtmRadioBtn(int titleId,
|
||||||
|
final boolean useMeters) {
|
||||||
String title = Algorithms.capitalizeFirstLetter(app.getString(titleId));
|
String title = Algorithms.capitalizeFirstLetter(app.getString(titleId));
|
||||||
RadioItem radioItem = new RadioItem(title);
|
RadioItem radioItem = new RadioItem(title);
|
||||||
radioItem.setOnClickListener(new OnRadioItemClickListener() {
|
radioItem.setOnClickListener(new OnRadioItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onRadioItemClick(RadioItem radioItem, View view) {
|
public boolean onRadioItemClick(RadioItem radioItem, View view) {
|
||||||
((ModeSelectionBottomSheet)dialog).setItem(selectableItem);
|
updateDialogListItems(useMeters);
|
||||||
updateSize(dialog, false);
|
updateSize();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return radioItem;
|
return radioItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showMultipleSrtmDialog() {
|
private void updateDialogListItems(boolean useMeters) {
|
||||||
List<SelectableItem> selectedItems = new ArrayList<>();
|
List<SelectableItem> items = new ArrayList<>(dialog.getAllItems());
|
||||||
List<IndexItem> indexesToDownload = getIndexesToDownload((MultipleDownloadItem) downloadItem);
|
for (SelectableItem item : items) {
|
||||||
|
DownloadItem downloadItem = (DownloadItem) item.getObject();
|
||||||
List<DownloadItem> allItems = new ArrayList<>(((MultipleDownloadItem) downloadItem).getItems());
|
if (downloadItem instanceof SrtmDownloadItem) {
|
||||||
List<SelectableItem> itemsList = new ArrayList<>();
|
((SrtmDownloadItem) downloadItem).setUseMeters(useMeters);
|
||||||
|
updateSelectableItem(item, downloadItem);
|
||||||
for (DownloadItem downloadItem : allItems) {
|
|
||||||
SrtmDownloadItem srtmItem = (SrtmDownloadItem) downloadItem;
|
|
||||||
SelectableItem selectableItem = new SelectableItem();
|
|
||||||
selectableItem.setTitle(downloadItem.getVisibleName(app, app.getRegions(), false));
|
|
||||||
String size = downloadItem.getSizeDescription(app);
|
|
||||||
size += " " + SrtmDownloadItem.getAbbreviationInScopes(app, srtmItem);
|
|
||||||
String date = srtmItem.getDate(dateFormat, showRemoteDate);
|
|
||||||
String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date);
|
|
||||||
selectableItem.setDescription(description);
|
|
||||||
selectableItem.setIconId(downloadItem.getType().getIconResource());
|
|
||||||
selectableItem.setObject(downloadItem);
|
|
||||||
|
|
||||||
itemsList.add(selectableItem);
|
|
||||||
|
|
||||||
if (indexesToDownload.contains(downloadItem)) {
|
|
||||||
selectedItems.add(selectableItem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
dialog.setItems(items);
|
||||||
|
}
|
||||||
|
|
||||||
List<RadioItem> radioItems = new ArrayList<>();
|
private SelectableItem createSelectableItem(DownloadItem item) {
|
||||||
RadioItem meters = new RadioItem(Algorithms.capitalizeFirstLetter(app.getString(R.string.shared_string_meters)));
|
SelectableItem selectableItem = new SelectableItem();
|
||||||
RadioItem feet = new RadioItem(Algorithms.capitalizeFirstLetter(app.getString(R.string.shared_string_feets)));
|
updateSelectableItem(selectableItem, item);
|
||||||
final RadioItem selectedMode = SrtmDownloadItem.isMetersItem(downloadItem) ? meters : feet;
|
return selectableItem;
|
||||||
radioItems.add(meters);
|
}
|
||||||
radioItems.add(feet);
|
|
||||||
|
|
||||||
final MultipleWithModeBottomSheet dialog = MultipleWithModeBottomSheet.showInstance(
|
private void updateSelectableItem(SelectableItem selectableItem,
|
||||||
activity, itemsList, selectedItems, radioItems, true);
|
DownloadItem downloadItem) {
|
||||||
|
selectableItem.setTitle(
|
||||||
|
downloadItem.getVisibleName(app, app.getRegions(), false));
|
||||||
|
|
||||||
meters.setOnClickListener(new OnRadioItemClickListener() {
|
String size = downloadItem.getSizeDescription(app);
|
||||||
@Override
|
if (downloadItem.isUseAbbreviation()) {
|
||||||
public boolean onRadioItemClick(RadioItem radioItem, View view) {
|
size += " " + downloadItem.getAbbreviationInScopes(app);
|
||||||
// dialog.recreateList(meterItems);
|
}
|
||||||
return true;
|
String date = downloadItem.getDate(dateFormat, showRemoteDate);
|
||||||
}
|
String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date);
|
||||||
});
|
selectableItem.setDescription(description);
|
||||||
|
|
||||||
feet.setOnClickListener(new OnRadioItemClickListener() {
|
selectableItem.setIconId(downloadItem.getType().getIconResource());
|
||||||
@Override
|
selectableItem.setObject(downloadItem);
|
||||||
public boolean onRadioItemClick(RadioItem radioItem, View view) {
|
|
||||||
// dialog.recreateList(feetItems);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.setUiInitializedListener(new OnUiInitializedListener() {
|
|
||||||
@Override
|
|
||||||
public void onUiInitialized() {
|
|
||||||
dialog.setTitle(app.getString(R.string.welmode_download_maps));
|
|
||||||
dialog.setSelectedMode(selectedMode);
|
|
||||||
dialog.setSecondaryDescription(app.getString(R.string.srtm_download_list_help_message));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
dialog.setSelectionUpdateListener(new SelectionUpdateListener() {
|
|
||||||
@Override
|
|
||||||
public void onSelectionUpdate() {
|
|
||||||
updateSize(dialog, true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private OnApplySelectionListener getOnApplySelectionListener(final ItemsToDownloadSelectedListener 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) {
|
||||||
List<IndexItem> indexItems = new ArrayList<>();
|
List<IndexItem> indexes = new ArrayList<>();
|
||||||
for (SelectableItem item : selectedItems) {
|
for (SelectableItem item : selectedItems) {
|
||||||
IndexItem index = getIndexItem((DownloadItem) item.getObject());
|
IndexItem index = getIndexItem((DownloadItem) item.getObject());
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
indexItems.add(index);
|
indexes.add(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
listener.onItemsToDownloadSelected(indexItems);
|
listener.onItemsToDownloadSelected(indexes);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSize(SelectionBottomSheet dialog,
|
private void updateSize() {
|
||||||
boolean updateDescription) {
|
|
||||||
double sizeToDownload = getDownloadSizeInMb(dialog.getSelectedItems());
|
double sizeToDownload = getDownloadSizeInMb(dialog.getSelectedItems());
|
||||||
String size = DownloadItem.getFormattedMb(app, sizeToDownload);
|
String size = DownloadItem.getFormattedMb(app, sizeToDownload);
|
||||||
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.setTitleDescription(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) {
|
||||||
btnTitle = app.getString(R.string.ltr_or_rtl_combine_via_dash, btnTitle, size);
|
btnTitle = app.getString(R.string.ltr_or_rtl_combine_via_dash, btnTitle, size);
|
||||||
|
@ -280,27 +253,23 @@ public class SelectIndexesUiHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getDownloadSizeInMb(@NonNull List<SelectableItem> selectableItems) {
|
private double getDownloadSizeInMb(@NonNull List<SelectableItem> selectableItems) {
|
||||||
List<DownloadItem> downloadItems = new ArrayList<>();
|
double totalSizeMb = 0.0d;
|
||||||
for (SelectableItem i : selectableItems) {
|
for (SelectableItem i : selectableItems) {
|
||||||
Object obj = i.getObject();
|
Object obj = i.getObject();
|
||||||
if (obj instanceof DownloadItem) {
|
if (obj instanceof DownloadItem) {
|
||||||
downloadItems.add((DownloadItem) obj);
|
totalSizeMb += ((DownloadItem) obj).getSizeToDownloadInMb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
double totalSizeMb = 0.0d;
|
|
||||||
for (DownloadItem item : downloadItems) {
|
|
||||||
totalSizeMb += item.getSizeToDownloadInMb();
|
|
||||||
}
|
|
||||||
return totalSizeMb;
|
return totalSizeMb;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<IndexItem> getIndexesToDownload(MultipleDownloadItem multipleDownloadItem) {
|
private static List<DownloadItem> getItemsToDownload(MultipleDownloadItem md) {
|
||||||
if (multipleDownloadItem.hasActualDataToDownload()) {
|
if (md.hasActualDataToDownload()) {
|
||||||
// download left regions
|
// download left regions
|
||||||
return multipleDownloadItem.getIndexesToDownload();
|
return md.getItemsToDownload();
|
||||||
} else {
|
} else {
|
||||||
// download all regions again
|
// download all regions again
|
||||||
return multipleDownloadItem.getAllIndexes();
|
return md.getAllItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,10 @@ public class SrtmDownloadItem extends DownloadItem {
|
||||||
this.useMeters = useMeters;
|
this.useMeters = useMeters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isUseMeters() {
|
||||||
|
return useMeters;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public IndexItem getIndexItem() {
|
public IndexItem getIndexItem() {
|
||||||
for (IndexItem index : indexes) {
|
for (IndexItem index : indexes) {
|
||||||
|
@ -124,6 +128,16 @@ public class SrtmDownloadItem extends DownloadItem {
|
||||||
return getIndexItem().getDate(dateFormat, remote);
|
return getIndexItem().getDate(dateFormat, remote);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUseAbbreviation() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAbbreviationInScopes(Context ctx) {
|
||||||
|
return getAbbreviationInScopes(ctx, this);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean shouldUseMetersByDefault(@NonNull OsmandApplication app) {
|
public static boolean shouldUseMetersByDefault(@NonNull OsmandApplication app) {
|
||||||
MetricsConstants metricSystem = app.getSettings().METRIC_SYSTEM.get();
|
MetricsConstants metricSystem = app.getSettings().METRIC_SYSTEM.get();
|
||||||
return metricSystem != MetricsConstants.MILES_AND_FEET;
|
return metricSystem != MetricsConstants.MILES_AND_FEET;
|
||||||
|
@ -147,7 +161,9 @@ public class SrtmDownloadItem extends DownloadItem {
|
||||||
} else if (item instanceof SrtmDownloadItem) {
|
} else if (item instanceof SrtmDownloadItem) {
|
||||||
return ((SrtmDownloadItem) item).useMeters;
|
return ((SrtmDownloadItem) item).useMeters;
|
||||||
} else if (item instanceof MultipleDownloadItem) {
|
} else if (item instanceof MultipleDownloadItem) {
|
||||||
return isMetersItem(((MultipleDownloadItem) item).getItems().get(0));
|
for (DownloadItem downloadItem : ((MultipleDownloadItem) item).getAllItems()) {
|
||||||
|
return isMetersItem(downloadItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,6 @@ import net.osmand.plus.download.IndexItem;
|
||||||
import net.osmand.plus.download.SelectIndexesUiHelper;
|
import net.osmand.plus.download.SelectIndexesUiHelper;
|
||||||
import net.osmand.plus.download.SelectIndexesUiHelper.ItemsToDownloadSelectedListener;
|
import net.osmand.plus.download.SelectIndexesUiHelper.ItemsToDownloadSelectedListener;
|
||||||
import net.osmand.plus.download.MultipleDownloadItem;
|
import net.osmand.plus.download.MultipleDownloadItem;
|
||||||
import net.osmand.plus.download.SrtmDownloadItem;
|
|
||||||
import net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask;
|
import net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask;
|
||||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||||
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
import net.osmand.plus.inapp.InAppPurchaseHelper;
|
||||||
|
@ -52,11 +51,8 @@ import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE;
|
|
||||||
|
|
||||||
public class ItemViewHolder {
|
public class ItemViewHolder {
|
||||||
|
|
||||||
protected final TextView nameTextView;
|
protected final TextView nameTextView;
|
||||||
|
@ -211,8 +207,8 @@ public class ItemViewHolder {
|
||||||
MultipleDownloadItem item = (MultipleDownloadItem) downloadItem;
|
MultipleDownloadItem item = (MultipleDownloadItem) downloadItem;
|
||||||
String allRegionsHeader = context.getString(R.string.shared_strings_all_regions);
|
String allRegionsHeader = context.getString(R.string.shared_strings_all_regions);
|
||||||
String regionsHeader = context.getString(R.string.regions);
|
String regionsHeader = context.getString(R.string.regions);
|
||||||
String allRegionsCount = String.valueOf(item.getItems().size());
|
String allRegionsCount = String.valueOf(item.getAllItems().size());
|
||||||
String leftToDownloadCount = String.valueOf(item.getIndexesToDownload().size());
|
String leftToDownloadCount = String.valueOf(item.getItemsToDownload().size());
|
||||||
String header;
|
String header;
|
||||||
String count;
|
String count;
|
||||||
if (item.hasActualDataToDownload()) {
|
if (item.hasActualDataToDownload()) {
|
||||||
|
@ -231,8 +227,8 @@ public class ItemViewHolder {
|
||||||
count = allRegionsCount;
|
count = allRegionsCount;
|
||||||
}
|
}
|
||||||
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 (SrtmDownloadItem.isSRTMItem(downloadItem)) {
|
if (item.isUseAbbreviation()) {
|
||||||
fullDescription += " " + SrtmDownloadItem.getAbbreviationInScopes(context, item);
|
fullDescription += " " + item.getAbbreviationInScopes(context);
|
||||||
}
|
}
|
||||||
if (item.hasActualDataToDownload()) {
|
if (item.hasActualDataToDownload()) {
|
||||||
fullDescription = context.getString(
|
fullDescription = context.getString(
|
||||||
|
@ -240,24 +236,14 @@ public class ItemViewHolder {
|
||||||
item.getSizeDescription(context));
|
item.getSizeDescription(context));
|
||||||
}
|
}
|
||||||
descrTextView.setText(fullDescription);
|
descrTextView.setText(fullDescription);
|
||||||
} else if (downloadItem instanceof SrtmDownloadItem) {
|
|
||||||
SrtmDownloadItem item = (SrtmDownloadItem) downloadItem;
|
|
||||||
String pattern = context.getString(R.string.ltr_or_rtl_combine_via_bold_point);
|
|
||||||
String type = item.getType().getString(context);
|
|
||||||
String size = item.getSizeDescription(context)
|
|
||||||
+ " " + SrtmDownloadItem.getAbbreviationInScopes(context, item);
|
|
||||||
String date = item.getDate(dateFormat, showRemoteDate);
|
|
||||||
String fullDescription = String.format(pattern, size, date);
|
|
||||||
if (showTypeInDesc) {
|
|
||||||
fullDescription = String.format(pattern, type, fullDescription);
|
|
||||||
}
|
|
||||||
descrTextView.setText(fullDescription);
|
|
||||||
} else {
|
} else {
|
||||||
IndexItem item = (IndexItem) downloadItem;
|
|
||||||
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 = downloadItem.getType().getString(context);
|
||||||
String size = item.getSizeDescription(context);
|
String size = downloadItem.getSizeDescription(context);
|
||||||
String date = item.getDate(dateFormat, showRemoteDate);
|
if (downloadItem.isUseAbbreviation()) {
|
||||||
|
size += " " + downloadItem.getAbbreviationInScopes(context);
|
||||||
|
}
|
||||||
|
String date = downloadItem.getDate(dateFormat, showRemoteDate);
|
||||||
String fullDescription = String.format(pattern, size, date);
|
String fullDescription = String.format(pattern, size, date);
|
||||||
if (showTypeInDesc) {
|
if (showTypeInDesc) {
|
||||||
fullDescription = String.format(pattern, type, fullDescription);
|
fullDescription = String.format(pattern, type, fullDescription);
|
||||||
|
|
Loading…
Reference in a new issue