SRTM Meter / Feet dialogs - fix bugs and refactoring
This commit is contained in:
parent
658b157bb2
commit
fed2e356c3
8 changed files with 157 additions and 94 deletions
|
@ -94,9 +94,9 @@ public class MultipleSelectionBottomSheet extends SelectionBottomSheet {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void notifyUiInitialized() {
|
protected void notifyUiCreated() {
|
||||||
onSelectedItemsChanged();
|
onSelectedItemsChanged();
|
||||||
super.notifyUiInitialized();
|
super.notifyUiCreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSelectedItemsChanged() {
|
private void onSelectedItemsChanged() {
|
||||||
|
|
|
@ -52,7 +52,7 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
|
||||||
protected int activeColorRes;
|
protected int activeColorRes;
|
||||||
protected int secondaryColorRes;
|
protected int secondaryColorRes;
|
||||||
|
|
||||||
private OnUiInitializedAdapter onUiInitializedAdapter;
|
private DialogStateListener dialogStateListener;
|
||||||
private OnApplySelectionListener onApplySelectionListener;
|
private OnApplySelectionListener onApplySelectionListener;
|
||||||
|
|
||||||
protected List<SelectableItem> allItems = new ArrayList<>();
|
protected List<SelectableItem> allItems = new ArrayList<>();
|
||||||
|
@ -64,7 +64,7 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
||||||
View mainView = super.onCreateView(inflater, parent, savedInstanceState);
|
View mainView = super.onCreateView(inflater, parent, savedInstanceState);
|
||||||
createSelectionListIfPossible();
|
createSelectionListIfPossible();
|
||||||
notifyUiInitialized();
|
notifyUiCreated();
|
||||||
return mainView;
|
return mainView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,8 +153,8 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnUiInitializedAdapter(OnUiInitializedAdapter onUiInitializedAdapter) {
|
public void setDialogStateListener(DialogStateListener dialogStateListener) {
|
||||||
this.onUiInitializedAdapter = onUiInitializedAdapter;
|
this.dialogStateListener = dialogStateListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnApplySelectionListener(OnApplySelectionListener onApplySelectionListener) {
|
public void setOnApplySelectionListener(OnApplySelectionListener onApplySelectionListener) {
|
||||||
|
@ -194,9 +194,9 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
|
||||||
|
|
||||||
protected abstract boolean shouldShowDivider();
|
protected abstract boolean shouldShowDivider();
|
||||||
|
|
||||||
protected void notifyUiInitialized() {
|
protected void notifyUiCreated() {
|
||||||
if (onUiInitializedAdapter != null) {
|
if (dialogStateListener != null) {
|
||||||
onUiInitializedAdapter.onUiInitialized();
|
dialogStateListener.onDialogCreated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,8 +240,17 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnUiInitializedAdapter {
|
@Override
|
||||||
void onUiInitialized();
|
public void onDestroy() {
|
||||||
|
if (dialogStateListener != null) {
|
||||||
|
dialogStateListener.onCloseDialog();
|
||||||
|
}
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface DialogStateListener {
|
||||||
|
void onDialogCreated();
|
||||||
|
void onCloseDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnApplySelectionListener {
|
public interface OnApplySelectionListener {
|
||||||
|
|
|
@ -490,7 +490,7 @@ public class DownloadResources extends DownloadResourceGroup {
|
||||||
private void replaceIndividualSrtmWithGroups(@NonNull WorldRegion region) {
|
private void replaceIndividualSrtmWithGroups(@NonNull WorldRegion region) {
|
||||||
DownloadResourceGroup group = getRegionMapsGroup(region);
|
DownloadResourceGroup group = getRegionMapsGroup(region);
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
boolean useMetersByDefault = SrtmDownloadItem.shouldUseMetersByDefault(app);
|
boolean useMetersByDefault = SrtmDownloadItem.isUseMetricByDefault(app);
|
||||||
boolean listModified = false;
|
boolean listModified = false;
|
||||||
DownloadActivityType srtmType = DownloadActivityType.SRTM_COUNTRY_FILE;
|
DownloadActivityType srtmType = DownloadActivityType.SRTM_COUNTRY_FILE;
|
||||||
List<DownloadItem> individualItems = group.getIndividualDownloadItems();
|
List<DownloadItem> individualItems = group.getIndividualDownloadItems();
|
||||||
|
|
|
@ -233,6 +233,9 @@ public class IndexItem extends DownloadItem implements Comparable<IndexItem> {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getAdditionalDescription(Context ctx) {
|
public String getAdditionalDescription(Context ctx) {
|
||||||
|
if (getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||||
|
return SrtmDownloadItem.getAbbreviationInScopes(ctx, this);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -147,9 +147,6 @@ public class MultipleDownloadItem extends DownloadItem {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String getAdditionalDescription(Context ctx) {
|
public String getAdditionalDescription(Context ctx) {
|
||||||
for (DownloadItem item : items) {
|
|
||||||
return item.getAdditionalDescription(ctx);
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import net.osmand.plus.base.ModeSelectionBottomSheet;
|
||||||
import net.osmand.plus.base.MultipleSelectionWithModeBottomSheet;
|
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.OnUiInitializedAdapter;
|
import net.osmand.plus.base.SelectionBottomSheet.DialogStateListener;
|
||||||
import net.osmand.plus.base.SelectionBottomSheet.SelectableItem;
|
import net.osmand.plus.base.SelectionBottomSheet.SelectableItem;
|
||||||
import net.osmand.plus.widgets.multistatetoggle.RadioItem;
|
import net.osmand.plus.widgets.multistatetoggle.RadioItem;
|
||||||
import net.osmand.plus.widgets.multistatetoggle.RadioItem.OnRadioItemClickListener;
|
import net.osmand.plus.widgets.multistatetoggle.RadioItem.OnRadioItemClickListener;
|
||||||
|
@ -22,11 +22,12 @@ import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.osmand.plus.download.MultipleDownloadItem.getIndexItem;
|
import static net.osmand.plus.download.MultipleDownloadItem.getIndexItem;
|
||||||
|
|
||||||
public class SelectIndexesUiHelper {
|
public class SelectIndexesHelper {
|
||||||
|
|
||||||
private final OsmandApplication app;
|
private final OsmandApplication app;
|
||||||
private final AppCompatActivity activity;
|
private final AppCompatActivity activity;
|
||||||
|
@ -34,58 +35,70 @@ public class SelectIndexesUiHelper {
|
||||||
private final ItemsToDownloadSelectedListener listener;
|
private final ItemsToDownloadSelectedListener listener;
|
||||||
private final DateFormat dateFormat;
|
private final DateFormat dateFormat;
|
||||||
private final boolean showRemoteDate;
|
private final boolean showRemoteDate;
|
||||||
|
private final List<DownloadItem> itemsToDownload;
|
||||||
private final DownloadItem downloadItem;
|
private final DownloadItem downloadItem;
|
||||||
|
private final boolean useMetricByDefault;
|
||||||
|
|
||||||
private SelectionBottomSheet dialog;
|
private SelectionBottomSheet dialog;
|
||||||
|
|
||||||
private SelectIndexesUiHelper(@NonNull DownloadItem downloadItem,
|
private SelectIndexesHelper(@NonNull DownloadItem downloadItem,
|
||||||
@NonNull AppCompatActivity activity,
|
@NonNull AppCompatActivity activity,
|
||||||
@NonNull DateFormat dateFormat,
|
@NonNull DateFormat dateFormat,
|
||||||
boolean showRemoteDate,
|
boolean showRemoteDate,
|
||||||
@NonNull ItemsToDownloadSelectedListener listener) {
|
@NonNull ItemsToDownloadSelectedListener listener) {
|
||||||
this.app = (OsmandApplication) activity.getApplicationContext();
|
this.app = (OsmandApplication) activity.getApplicationContext();
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
this.downloadItem = downloadItem;
|
|
||||||
this.dateFormat = dateFormat;
|
this.dateFormat = dateFormat;
|
||||||
this.showRemoteDate = showRemoteDate;
|
this.showRemoteDate = showRemoteDate;
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
this.downloadItem = downloadItem;
|
||||||
|
this.itemsToDownload = getItemsToDownload(downloadItem);
|
||||||
|
this.useMetricByDefault = SrtmDownloadItem.isUseMetricByDefault(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showDialog(@NonNull DownloadItem i,
|
public static void showDialog(@NonNull DownloadItem di,
|
||||||
@NonNull AppCompatActivity a,
|
@NonNull AppCompatActivity a,
|
||||||
@NonNull DateFormat df,
|
@NonNull DateFormat df,
|
||||||
boolean showRemoteDate,
|
boolean showRemoteDate,
|
||||||
@NonNull ItemsToDownloadSelectedListener l) {
|
@NonNull ItemsToDownloadSelectedListener l) {
|
||||||
|
|
||||||
new SelectIndexesUiHelper(i, a, df, showRemoteDate, l).showDialogInternal();
|
SelectIndexesHelper h = new SelectIndexesHelper(di, a, df, showRemoteDate, l);
|
||||||
}
|
if (di.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
||||||
|
if (di instanceof MultipleDownloadItem) {
|
||||||
private void showDialogInternal() {
|
h.showSrtmMultipleSelectionDialog();
|
||||||
if (downloadItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
|
|
||||||
if (downloadItem instanceof MultipleDownloadItem) {
|
|
||||||
showSrtmMultipleSelectionDialog();
|
|
||||||
} else {
|
} else {
|
||||||
showSrtmModeSelectionDialog();
|
h.showSrtmTypeSelectionDialog();
|
||||||
}
|
}
|
||||||
} else if (downloadItem instanceof MultipleDownloadItem) {
|
} else if (di instanceof MultipleDownloadItem) {
|
||||||
showMultipleSelectionDialog();
|
h.showMultipleSelectionDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showMultipleSelectionDialog() {
|
private void showMultipleSelectionDialog() {
|
||||||
|
MultipleDownloadItem mdi = (MultipleDownloadItem) downloadItem;
|
||||||
List<SelectableItem> allItems = new ArrayList<>();
|
List<SelectableItem> allItems = new ArrayList<>();
|
||||||
List<SelectableItem> selectedItems = new ArrayList<>();
|
List<SelectableItem> selectedItems = new ArrayList<>();
|
||||||
prepareItems(allItems, selectedItems);
|
|
||||||
|
|
||||||
MultipleSelectionBottomSheet msDialog = MultipleSelectionBottomSheet.showInstance(
|
for (DownloadItem di : mdi.getAllItems()) {
|
||||||
activity, allItems, selectedItems, true);
|
SelectableItem si = createSelectableItem(di);
|
||||||
|
allItems.add(si);
|
||||||
|
if (itemsToDownload.contains(di)) {
|
||||||
|
selectedItems.add(si);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MultipleSelectionBottomSheet msDialog =
|
||||||
|
MultipleSelectionBottomSheet.showInstance(activity, allItems, selectedItems, true);
|
||||||
this.dialog = msDialog;
|
this.dialog = msDialog;
|
||||||
|
|
||||||
msDialog.setOnUiInitializedAdapter(new OnUiInitializedAdapter() {
|
msDialog.setDialogStateListener(new DialogStateListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onUiInitialized() {
|
public void onDialogCreated() {
|
||||||
dialog.setTitle(app.getString(R.string.welmode_download_maps));
|
dialog.setTitle(app.getString(R.string.welmode_download_maps));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCloseDialog() { }
|
||||||
});
|
});
|
||||||
|
|
||||||
msDialog.setSelectionUpdateListener(new SelectionUpdateListener() {
|
msDialog.setSelectionUpdateListener(new SelectionUpdateListener() {
|
||||||
|
@ -99,25 +112,40 @@ public class SelectIndexesUiHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSrtmMultipleSelectionDialog() {
|
private void showSrtmMultipleSelectionDialog() {
|
||||||
|
MultipleDownloadItem mdi = (MultipleDownloadItem) downloadItem;
|
||||||
List<SelectableItem> allItems = new ArrayList<>();
|
List<SelectableItem> allItems = new ArrayList<>();
|
||||||
List<SelectableItem> selectedItems = new ArrayList<>();
|
List<SelectableItem> selectedItems = new ArrayList<>();
|
||||||
prepareItems(allItems, selectedItems);
|
|
||||||
|
|
||||||
SrtmDownloadItem srtmItem = (SrtmDownloadItem) ((MultipleDownloadItem)downloadItem).getAllItems().get(0);
|
for (DownloadItem di : mdi.getAllItems()) {
|
||||||
final int selectedModeOrder = srtmItem.isUseMetric() ? 0 : 1;
|
SelectableItem si = createSrtmSelectableItem((SrtmDownloadItem) di);
|
||||||
final List<RadioItem> radioItems = createSrtmRadioItems();
|
allItems.add(si);
|
||||||
|
if (itemsToDownload.contains(di)) {
|
||||||
|
selectedItems.add(si);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final RadioItem meterBtn = createSrtmRadioBtn(true);
|
||||||
|
final RadioItem feetBtn = createSrtmRadioBtn(false);
|
||||||
|
List<RadioItem> radioItems = new ArrayList<>();
|
||||||
|
radioItems.add(meterBtn);
|
||||||
|
radioItems.add(feetBtn);
|
||||||
|
|
||||||
MultipleSelectionBottomSheet msDialog = MultipleSelectionWithModeBottomSheet.showInstance(
|
MultipleSelectionBottomSheet msDialog = MultipleSelectionWithModeBottomSheet.showInstance(
|
||||||
activity, allItems, selectedItems, radioItems, true);
|
activity, allItems, selectedItems, radioItems, true);
|
||||||
this.dialog = msDialog;
|
this.dialog = msDialog;
|
||||||
|
|
||||||
msDialog.setOnUiInitializedAdapter(new OnUiInitializedAdapter() {
|
msDialog.setDialogStateListener(new DialogStateListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onUiInitialized() {
|
public void onDialogCreated() {
|
||||||
dialog.setTitle(app.getString(R.string.welmode_download_maps));
|
dialog.setTitle(app.getString(R.string.welmode_download_maps));
|
||||||
dialog.setSelectedMode(radioItems.get(selectedModeOrder));
|
dialog.setSelectedMode(useMetricByDefault ? meterBtn : feetBtn);
|
||||||
dialog.setSecondaryDescription(app.getString(R.string.srtm_download_list_help_message));
|
dialog.setSecondaryDescription(app.getString(R.string.srtm_download_list_help_message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCloseDialog() {
|
||||||
|
resetUseMeters();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
msDialog.setSelectionUpdateListener(new SelectionUpdateListener() {
|
msDialog.setSelectionUpdateListener(new SelectionUpdateListener() {
|
||||||
|
@ -130,58 +158,47 @@ public class SelectIndexesUiHelper {
|
||||||
msDialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
|
msDialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSrtmModeSelectionDialog() {
|
private void showSrtmTypeSelectionDialog() {
|
||||||
SrtmDownloadItem srtmItem = (SrtmDownloadItem) downloadItem;
|
SrtmDownloadItem srtmItem = (SrtmDownloadItem) downloadItem;
|
||||||
final int selectedModeOrder = srtmItem.isUseMetric() ? 0 : 1;
|
|
||||||
|
|
||||||
final List<RadioItem> radioItems = createSrtmRadioItems();
|
final RadioItem meterBtn = createSrtmRadioBtn(true);
|
||||||
SelectableItem preview = createSelectableItem(srtmItem);
|
final RadioItem feetBtn = createSrtmRadioBtn(false);
|
||||||
|
List<RadioItem> radioItems = new ArrayList<>();
|
||||||
|
radioItems.add(meterBtn);
|
||||||
|
radioItems.add(feetBtn);
|
||||||
|
|
||||||
|
SelectableItem preview = createSrtmSelectableItem(srtmItem);
|
||||||
|
|
||||||
dialog = ModeSelectionBottomSheet.showInstance(activity, preview, radioItems, true);
|
dialog = ModeSelectionBottomSheet.showInstance(activity, preview, radioItems, true);
|
||||||
|
|
||||||
dialog.setOnUiInitializedAdapter(new OnUiInitializedAdapter() {
|
dialog.setDialogStateListener(new DialogStateListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onUiInitialized() {
|
public void onDialogCreated() {
|
||||||
ModeSelectionBottomSheet dialog = (ModeSelectionBottomSheet) SelectIndexesUiHelper.this.dialog;
|
ModeSelectionBottomSheet dialog = (ModeSelectionBottomSheet) SelectIndexesHelper.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();
|
updateSize();
|
||||||
dialog.setSelectedMode(radioItems.get(selectedModeOrder));
|
dialog.setSelectedMode(useMetricByDefault ? meterBtn : feetBtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCloseDialog() {
|
||||||
|
resetUseMeters();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
|
dialog.setOnApplySelectionListener(getOnApplySelectionListener(listener));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareItems(List<SelectableItem> allItems,
|
private RadioItem createSrtmRadioBtn(final boolean useMeters) {
|
||||||
List<SelectableItem> selectedItems) {
|
int titleId = useMeters ? R.string.shared_string_meters : R.string.shared_string_feet;
|
||||||
final MultipleDownloadItem multipleDownloadItem = (MultipleDownloadItem) downloadItem;
|
|
||||||
final List<DownloadItem> itemsToDownload = getItemsToDownload(multipleDownloadItem);
|
|
||||||
for (DownloadItem downloadItem : multipleDownloadItem.getAllItems()) {
|
|
||||||
SelectableItem selectableItem = createSelectableItem(downloadItem);
|
|
||||||
allItems.add(selectableItem);
|
|
||||||
|
|
||||||
if (itemsToDownload.contains(downloadItem)) {
|
|
||||||
selectedItems.add(selectableItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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_feet, 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 TextRadioItem(title);
|
RadioItem radioItem = new TextRadioItem(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) {
|
||||||
updateDialogListItems(useMeters);
|
setUseMetersForAllItems(useMeters);
|
||||||
|
updateListItems();
|
||||||
updateSize();
|
updateSize();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -189,22 +206,45 @@ public class SelectIndexesUiHelper {
|
||||||
return radioItem;
|
return radioItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDialogListItems(boolean useMeters) {
|
private SelectableItem createSelectableItem(DownloadItem item) {
|
||||||
List<SelectableItem> items = new ArrayList<>(dialog.getAllItems());
|
SelectableItem selectableItem = new SelectableItem();
|
||||||
for (SelectableItem item : items) {
|
updateSelectableItem(selectableItem, item);
|
||||||
DownloadItem downloadItem = (DownloadItem) item.getObject();
|
selectableItem.setObject(item);
|
||||||
if (downloadItem instanceof SrtmDownloadItem) {
|
return selectableItem;
|
||||||
((SrtmDownloadItem) downloadItem).setUseMetric(useMeters);
|
|
||||||
updateSelectableItem(item, downloadItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SelectableItem createSrtmSelectableItem(SrtmDownloadItem item) {
|
||||||
|
SelectableItem selectableItem = new SelectableItem();
|
||||||
|
updateSelectableItem(selectableItem, item.getDefaultIndexItem());
|
||||||
|
selectableItem.setObject(item);
|
||||||
|
return selectableItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateListItems() {
|
||||||
|
List<SelectableItem> items = new ArrayList<>(dialog.getAllItems());
|
||||||
|
for (SelectableItem selectableItem : items) {
|
||||||
|
DownloadItem di = (DownloadItem) selectableItem.getObject();
|
||||||
|
if (di instanceof SrtmDownloadItem) {
|
||||||
|
di = ((SrtmDownloadItem) di).getDefaultIndexItem();
|
||||||
|
}
|
||||||
|
updateSelectableItem(selectableItem, di);
|
||||||
}
|
}
|
||||||
dialog.setItems(items);
|
dialog.setItems(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
private SelectableItem createSelectableItem(DownloadItem item) {
|
private void resetUseMeters() {
|
||||||
SelectableItem selectableItem = new SelectableItem();
|
boolean useMeters = SrtmDownloadItem.isUseMetricByDefault(app);
|
||||||
updateSelectableItem(selectableItem, item);
|
setUseMetersForAllItems(useMeters);
|
||||||
return selectableItem;
|
}
|
||||||
|
|
||||||
|
private void setUseMetersForAllItems(boolean useMeters) {
|
||||||
|
for (SelectableItem item : dialog.getAllItems()) {
|
||||||
|
DownloadItem downloadItem = (DownloadItem) item.getObject();
|
||||||
|
if (downloadItem instanceof SrtmDownloadItem) {
|
||||||
|
SrtmDownloadItem srtmItem = (SrtmDownloadItem) downloadItem;
|
||||||
|
srtmItem.setUseMetric(useMeters);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSelectableItem(SelectableItem selectableItem,
|
private void updateSelectableItem(SelectableItem selectableItem,
|
||||||
|
@ -221,7 +261,6 @@ public class SelectIndexesUiHelper {
|
||||||
selectableItem.setDescription(description);
|
selectableItem.setDescription(description);
|
||||||
|
|
||||||
selectableItem.setIconId(downloadItem.getType().getIconResource());
|
selectableItem.setIconId(downloadItem.getType().getIconResource());
|
||||||
selectableItem.setObject(downloadItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private OnApplySelectionListener getOnApplySelectionListener(final ItemsToDownloadSelectedListener listener) {
|
private OnApplySelectionListener getOnApplySelectionListener(final ItemsToDownloadSelectedListener listener) {
|
||||||
|
@ -257,13 +296,23 @@ public class SelectIndexesUiHelper {
|
||||||
double totalSizeMb = 0.0d;
|
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 SrtmDownloadItem) {
|
||||||
|
SrtmDownloadItem srtm = (SrtmDownloadItem) obj;
|
||||||
|
totalSizeMb += srtm.getDefaultIndexItem().getSizeToDownloadInMb();
|
||||||
|
} else if (obj instanceof DownloadItem) {
|
||||||
totalSizeMb += ((DownloadItem) obj).getSizeToDownloadInMb();
|
totalSizeMb += ((DownloadItem) obj).getSizeToDownloadInMb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return totalSizeMb;
|
return totalSizeMb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<DownloadItem> getItemsToDownload(DownloadItem di) {
|
||||||
|
if (di instanceof MultipleDownloadItem) {
|
||||||
|
return getItemsToDownload((MultipleDownloadItem) di);
|
||||||
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
private static List<DownloadItem> getItemsToDownload(MultipleDownloadItem md) {
|
private static List<DownloadItem> getItemsToDownload(MultipleDownloadItem md) {
|
||||||
if (md.hasActualDataToDownload()) {
|
if (md.hasActualDataToDownload()) {
|
||||||
// download left regions
|
// download left regions
|
|
@ -53,6 +53,11 @@ public class SrtmDownloadItem extends DownloadItem {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return getDefaultIndexItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public IndexItem getDefaultIndexItem() {
|
||||||
for (IndexItem index : indexes) {
|
for (IndexItem index : indexes) {
|
||||||
if (useMetric && isMetricItem(index) || !useMetric && !isMetricItem(index)) {
|
if (useMetric && isMetricItem(index) || !useMetric && !isMetricItem(index)) {
|
||||||
return index;
|
return index;
|
||||||
|
@ -135,7 +140,7 @@ public class SrtmDownloadItem extends DownloadItem {
|
||||||
return getAbbreviationInScopes(ctx, this);
|
return getAbbreviationInScopes(ctx, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldUseMetersByDefault(@NonNull OsmandApplication app) {
|
public static boolean isUseMetricByDefault(@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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,8 @@ import net.osmand.plus.download.DownloadActivityType;
|
||||||
import net.osmand.plus.download.DownloadResourceGroup;
|
import net.osmand.plus.download.DownloadResourceGroup;
|
||||||
import net.osmand.plus.download.DownloadResources;
|
import net.osmand.plus.download.DownloadResources;
|
||||||
import net.osmand.plus.download.IndexItem;
|
import net.osmand.plus.download.IndexItem;
|
||||||
import net.osmand.plus.download.SelectIndexesUiHelper;
|
import net.osmand.plus.download.SelectIndexesHelper;
|
||||||
import net.osmand.plus.download.SelectIndexesUiHelper.ItemsToDownloadSelectedListener;
|
import net.osmand.plus.download.SelectIndexesHelper.ItemsToDownloadSelectedListener;
|
||||||
import net.osmand.plus.download.MultipleDownloadItem;
|
import net.osmand.plus.download.MultipleDownloadItem;
|
||||||
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;
|
||||||
|
@ -492,7 +492,7 @@ public class ItemViewHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectIndexesToDownload(DownloadItem item) {
|
private void selectIndexesToDownload(DownloadItem item) {
|
||||||
SelectIndexesUiHelper.showDialog(item, context, dateFormat, showRemoteDate,
|
SelectIndexesHelper.showDialog(item, context, dateFormat, showRemoteDate,
|
||||||
new ItemsToDownloadSelectedListener() {
|
new ItemsToDownloadSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemsToDownloadSelected(List<IndexItem> indexes) {
|
public void onItemsToDownloadSelected(List<IndexItem> indexes) {
|
||||||
|
|
Loading…
Reference in a new issue