Fix after code review
This commit is contained in:
parent
6bf7da4290
commit
8aeb8b16a3
10 changed files with 91 additions and 105 deletions
|
@ -20,7 +20,7 @@
|
|||
<string name="srtm_download_single_help_message">Please select the needed format. You will need to re-download the file to change the format.</string>
|
||||
<string name="srtm_download_list_help_message">OsmAnd provides contour lines data in meters and feet. You will need to re-download the file to change the format.</string>
|
||||
<string name="srtm_unit_format">Contour lines unit format</string>
|
||||
<string name="shared_string_feets">feets</string>
|
||||
<string name="shared_string_feet">feet</string>
|
||||
<string name="update_all_maps_added">Update all maps added to %1$s?</string>
|
||||
<string name="release_4_0_beta">
|
||||
• OsmAnd Live updates moved to \"Downloads > Updates\"\n\n
|
||||
|
|
|
@ -144,8 +144,8 @@ public class MultipleSelectionBottomSheet extends SelectionBottomSheet {
|
|||
}
|
||||
|
||||
protected void setSelectedItems(List<SelectableItem> selected) {
|
||||
if (!Algorithms.isEmpty(selected)) {
|
||||
selectedItems.clear();
|
||||
if (!Algorithms.isEmpty(selected)) {
|
||||
selectedItems.addAll(selected);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
|
|||
protected int activeColorRes;
|
||||
protected int secondaryColorRes;
|
||||
|
||||
private OnUiInitializedListener uiInitializedListener;
|
||||
private OnApplySelectionListener applySelectionListener;
|
||||
private OnUiInitializedAdapter onUiInitializedAdapter;
|
||||
private OnApplySelectionListener onApplySelectionListener;
|
||||
|
||||
protected List<SelectableItem> allItems = new ArrayList<>();
|
||||
protected Map<SelectableItem, View> listViews = new HashMap<>();
|
||||
|
@ -145,19 +145,19 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
|
|||
}
|
||||
|
||||
public void setItems(List<SelectableItem> allItems) {
|
||||
if (!Algorithms.isEmpty(allItems)) {
|
||||
this.allItems.clear();
|
||||
if (!Algorithms.isEmpty(allItems)) {
|
||||
this.allItems.addAll(allItems);
|
||||
createSelectionListIfPossible();
|
||||
}
|
||||
}
|
||||
|
||||
public void setUiInitializedListener(OnUiInitializedListener uiInitializedListener) {
|
||||
this.uiInitializedListener = uiInitializedListener;
|
||||
public void setOnUiInitializedAdapter(OnUiInitializedAdapter onUiInitializedAdapter) {
|
||||
this.onUiInitializedAdapter = onUiInitializedAdapter;
|
||||
}
|
||||
|
||||
public void setOnApplySelectionListener(OnApplySelectionListener onApplySelectionListener) {
|
||||
this.applySelectionListener = onApplySelectionListener;
|
||||
this.onApplySelectionListener = onApplySelectionListener;
|
||||
}
|
||||
|
||||
private void createSelectionListIfPossible() {
|
||||
|
@ -194,8 +194,8 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
|
|||
protected abstract boolean shouldShowDivider();
|
||||
|
||||
protected void notifyUiInitialized() {
|
||||
if (uiInitializedListener != null) {
|
||||
uiInitializedListener.onUiInitialized();
|
||||
if (onUiInitializedAdapter != null) {
|
||||
onUiInitializedAdapter.onUiInitialized();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,8 +215,8 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
|
|||
|
||||
@Override
|
||||
protected void onRightBottomButtonClick() {
|
||||
if (applySelectionListener != null) {
|
||||
applySelectionListener.onSelectionApplied(getSelectedItems());
|
||||
if (onApplySelectionListener != null) {
|
||||
onApplySelectionListener.onSelectionApplied(getSelectedItems());
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ public abstract class SelectionBottomSheet extends MenuBottomSheetDialogFragment
|
|||
}
|
||||
}
|
||||
|
||||
public interface OnUiInitializedListener {
|
||||
public interface OnUiInitializedAdapter {
|
||||
void onUiInitialized();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.download;
|
|||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -59,9 +60,8 @@ public abstract class DownloadItem {
|
|||
@NonNull
|
||||
public abstract List<File> getDownloadedFiles(@NonNull OsmandApplication app);
|
||||
|
||||
public abstract boolean isUseAbbreviation();
|
||||
|
||||
public abstract String getAbbreviationInScopes(Context ctx);
|
||||
@Nullable
|
||||
public abstract String getAdditionalDescription(Context ctx);
|
||||
|
||||
protected abstract double getSizeToDownloadInMb();
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.io.InputStream;
|
|||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
@ -121,7 +122,7 @@ public class DownloadResources extends DownloadResourceGroup {
|
|||
if (group != null) {
|
||||
return group.getIndividualDownloadItems();
|
||||
}
|
||||
return new LinkedList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -132,7 +133,7 @@ public class DownloadResources extends DownloadResourceGroup {
|
|||
return res;
|
||||
}
|
||||
}
|
||||
return new LinkedList<>();
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public void updateLoadedFiles() {
|
||||
|
@ -500,7 +501,7 @@ public class DownloadResources extends DownloadResourceGroup {
|
|||
srtmIndexes.add((IndexItem) item);
|
||||
}
|
||||
}
|
||||
if (srtmIndexes.size() == 2) {
|
||||
if (srtmIndexes.size() > 1) {
|
||||
individualItems.removeAll(srtmIndexes);
|
||||
group.addItem(new SrtmDownloadItem(srtmIndexes, useMetersByDefault));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.download;
|
|||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
|
@ -229,14 +230,10 @@ public class IndexItem extends DownloadItem implements Comparable<IndexItem> {
|
|||
return format.format(new Date(timestamp));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public boolean isUseAbbreviation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAbbreviationInScopes(Context ctx) {
|
||||
return "";
|
||||
public String getAdditionalDescription(Context ctx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class DownloadEntry {
|
||||
|
|
|
@ -144,28 +144,17 @@ public class MultipleDownloadItem extends DownloadItem {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public boolean isUseAbbreviation() {
|
||||
public String getAdditionalDescription(Context ctx) {
|
||||
for (DownloadItem item : items) {
|
||||
if (item.isUseAbbreviation()) {
|
||||
return true;
|
||||
return item.getAdditionalDescription(ctx);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAbbreviationInScopes(Context ctx) {
|
||||
for (DownloadItem item : items) {
|
||||
return item.getAbbreviationInScopes(ctx);
|
||||
}
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDate(@NonNull DateFormat dateFormat, boolean remote) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import net.osmand.plus.base.ModeSelectionBottomSheet;
|
|||
import net.osmand.plus.base.MultipleSelectionWithModeBottomSheet;
|
||||
import net.osmand.plus.base.SelectionBottomSheet;
|
||||
import net.osmand.plus.base.SelectionBottomSheet.OnApplySelectionListener;
|
||||
import net.osmand.plus.base.SelectionBottomSheet.OnUiInitializedListener;
|
||||
import net.osmand.plus.base.SelectionBottomSheet.OnUiInitializedAdapter;
|
||||
import net.osmand.plus.base.SelectionBottomSheet.SelectableItem;
|
||||
import net.osmand.plus.widgets.MultiStateToggleButton.OnRadioItemClickListener;
|
||||
import net.osmand.plus.widgets.MultiStateToggleButton.RadioItem;
|
||||
|
@ -80,7 +80,7 @@ public class SelectIndexesUiHelper {
|
|||
activity, allItems, selectedItems, true);
|
||||
this.dialog = msDialog;
|
||||
|
||||
msDialog.setUiInitializedListener(new OnUiInitializedListener() {
|
||||
msDialog.setOnUiInitializedAdapter(new OnUiInitializedAdapter() {
|
||||
@Override
|
||||
public void onUiInitialized() {
|
||||
dialog.setTitle(app.getString(R.string.welmode_download_maps));
|
||||
|
@ -103,14 +103,14 @@ public class SelectIndexesUiHelper {
|
|||
prepareItems(allItems, selectedItems);
|
||||
|
||||
SrtmDownloadItem srtmItem = (SrtmDownloadItem) ((MultipleDownloadItem)downloadItem).getAllItems().get(0);
|
||||
final int selectedModeOrder = srtmItem.isUseMeters() ? 0 : 1;
|
||||
final int selectedModeOrder = srtmItem.isUseMetric() ? 0 : 1;
|
||||
final List<RadioItem> radioItems = createSrtmRadioItems();
|
||||
|
||||
MultipleSelectionBottomSheet msDialog = MultipleSelectionWithModeBottomSheet.showInstance(
|
||||
activity, allItems, selectedItems, radioItems, true);
|
||||
this.dialog = msDialog;
|
||||
|
||||
msDialog.setUiInitializedListener(new OnUiInitializedListener() {
|
||||
msDialog.setOnUiInitializedAdapter(new OnUiInitializedAdapter() {
|
||||
@Override
|
||||
public void onUiInitialized() {
|
||||
dialog.setTitle(app.getString(R.string.welmode_download_maps));
|
||||
|
@ -131,14 +131,14 @@ public class SelectIndexesUiHelper {
|
|||
|
||||
private void showSrtmModeSelectionDialog() {
|
||||
SrtmDownloadItem srtmItem = (SrtmDownloadItem) downloadItem;
|
||||
final int selectedModeOrder = srtmItem.isUseMeters() ? 0 : 1;
|
||||
final int selectedModeOrder = srtmItem.isUseMetric() ? 0 : 1;
|
||||
|
||||
final List<RadioItem> radioItems = createSrtmRadioItems();
|
||||
SelectableItem preview = createSelectableItem(srtmItem);
|
||||
|
||||
dialog = ModeSelectionBottomSheet.showInstance(activity, preview, radioItems, true);
|
||||
|
||||
dialog.setUiInitializedListener(new OnUiInitializedListener() {
|
||||
dialog.setOnUiInitializedAdapter(new OnUiInitializedAdapter() {
|
||||
@Override
|
||||
public void onUiInitialized() {
|
||||
ModeSelectionBottomSheet dialog = (ModeSelectionBottomSheet) SelectIndexesUiHelper.this.dialog;
|
||||
|
@ -169,7 +169,7 @@ public class SelectIndexesUiHelper {
|
|||
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));
|
||||
radioItems.add(createSrtmRadioBtn(R.string.shared_string_feet, false));
|
||||
return radioItems;
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ public class SelectIndexesUiHelper {
|
|||
for (SelectableItem item : items) {
|
||||
DownloadItem downloadItem = (DownloadItem) item.getObject();
|
||||
if (downloadItem instanceof SrtmDownloadItem) {
|
||||
((SrtmDownloadItem) downloadItem).setUseMeters(useMeters);
|
||||
((SrtmDownloadItem) downloadItem).setUseMetric(useMeters);
|
||||
updateSelectableItem(item, downloadItem);
|
||||
}
|
||||
}
|
||||
|
@ -208,12 +208,12 @@ public class SelectIndexesUiHelper {
|
|||
|
||||
private void updateSelectableItem(SelectableItem selectableItem,
|
||||
DownloadItem downloadItem) {
|
||||
selectableItem.setTitle(
|
||||
downloadItem.getVisibleName(app, app.getRegions(), false));
|
||||
selectableItem.setTitle(downloadItem.getVisibleName(app, app.getRegions(), false));
|
||||
|
||||
String size = downloadItem.getSizeDescription(app);
|
||||
if (downloadItem.isUseAbbreviation()) {
|
||||
size += " " + downloadItem.getAbbreviationInScopes(app);
|
||||
String addDescr = downloadItem.getAdditionalDescription(app);
|
||||
if (addDescr != null) {
|
||||
size += " " + addDescr;
|
||||
}
|
||||
String date = downloadItem.getDate(dateFormat, showRemoteDate);
|
||||
String description = app.getString(R.string.ltr_or_rtl_combine_via_bold_point, size, date);
|
||||
|
|
|
@ -10,6 +10,7 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.LocalIndexInfo;
|
||||
import net.osmand.plus.helpers.enums.MetricsConstants;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
|
@ -24,31 +25,40 @@ import static net.osmand.plus.download.DownloadActivityType.SRTM_COUNTRY_FILE;
|
|||
public class SrtmDownloadItem extends DownloadItem {
|
||||
|
||||
private final List<IndexItem> indexes;
|
||||
private boolean useMeters;
|
||||
private boolean useMetric;
|
||||
|
||||
public SrtmDownloadItem(List<IndexItem> indexes,
|
||||
boolean useMeters) {
|
||||
public SrtmDownloadItem(List<IndexItem> indexes, boolean useMetric) {
|
||||
super(SRTM_COUNTRY_FILE);
|
||||
this.indexes = indexes;
|
||||
this.useMeters = useMeters;
|
||||
this.useMetric = useMetric;
|
||||
}
|
||||
|
||||
public void setUseMeters(boolean useMeters) {
|
||||
this.useMeters = useMeters;
|
||||
public void setUseMetric(boolean useMetric) {
|
||||
this.useMetric = useMetric;
|
||||
}
|
||||
|
||||
public boolean isUseMeters() {
|
||||
return useMeters;
|
||||
public boolean isUseMetric() {
|
||||
for (IndexItem index : indexes) {
|
||||
if (index.isDownloaded()) {
|
||||
return isMetricItem(index);
|
||||
}
|
||||
}
|
||||
return useMetric;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@NonNull
|
||||
public IndexItem getIndexItem() {
|
||||
for (IndexItem index : indexes) {
|
||||
if (useMeters && isMetersItem(index) || !useMeters && !isMetersItem(index)) {
|
||||
if (index.isDownloaded()) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
for (IndexItem index : indexes) {
|
||||
if (useMetric && isMetricItem(index) || !useMetric && !isMetricItem(index)) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return indexes.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,14 +93,13 @@ public class SrtmDownloadItem extends DownloadItem {
|
|||
|
||||
@Override
|
||||
public boolean hasActualDataToDownload() {
|
||||
// may be check only downloaded items if any downloaded
|
||||
for (IndexItem item : indexes) {
|
||||
if (item.hasActualDataToDownload()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!item.hasActualDataToDownload()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDownloading(@NonNull DownloadIndexesThread thread) {
|
||||
|
@ -110,7 +119,6 @@ public class SrtmDownloadItem extends DownloadItem {
|
|||
@NonNull
|
||||
@Override
|
||||
public List<File> getDownloadedFiles(@NonNull OsmandApplication app) {
|
||||
// may be check both indexes files
|
||||
List<File> result = new ArrayList<>();
|
||||
for (IndexItem index : indexes) {
|
||||
result.addAll(index.getDownloadedFiles(app));
|
||||
|
@ -119,17 +127,11 @@ public class SrtmDownloadItem extends DownloadItem {
|
|||
}
|
||||
|
||||
public String getDate(@NonNull DateFormat dateFormat, boolean remote) {
|
||||
// may be check only downloaded items if any downloaded
|
||||
return getIndexItem().getDate(dateFormat, remote);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseAbbreviation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAbbreviationInScopes(Context ctx) {
|
||||
public @Nullable String getAdditionalDescription(Context ctx) {
|
||||
return getAbbreviationInScopes(ctx, this);
|
||||
}
|
||||
|
||||
|
@ -140,27 +142,8 @@ public class SrtmDownloadItem extends DownloadItem {
|
|||
|
||||
@NonNull
|
||||
public static String getAbbreviationInScopes(Context ctx, Object obj) {
|
||||
return "(" + getAbbreviation(ctx, obj) + ")";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static String getAbbreviation(Context context, Object obj) {
|
||||
return context.getString(isMetersItem(obj) ? R.string.m : R.string.foot);
|
||||
}
|
||||
|
||||
public static boolean isMetersItem(Object item) {
|
||||
if (item instanceof IndexItem) {
|
||||
return ((IndexItem) item).getFileName().endsWith(BINARY_SRTM_MAP_INDEX_EXT_ZIP);
|
||||
} else if (item instanceof LocalIndexInfo) {
|
||||
return ((LocalIndexInfo) item).getFileName().endsWith(BINARY_SRTM_MAP_INDEX_EXT);
|
||||
} else if (item instanceof SrtmDownloadItem) {
|
||||
return ((SrtmDownloadItem) item).useMeters;
|
||||
} else if (item instanceof MultipleDownloadItem) {
|
||||
for (DownloadItem downloadItem : ((MultipleDownloadItem) item).getAllItems()) {
|
||||
return isMetersItem(downloadItem);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
String abbreviation = ctx.getString(isMetricItem(obj) ? R.string.m : R.string.foot);
|
||||
return "(" + abbreviation + ")";
|
||||
}
|
||||
|
||||
public static boolean containsSrtmExtension(@NonNull String fileName) {
|
||||
|
@ -175,15 +158,13 @@ public class SrtmDownloadItem extends DownloadItem {
|
|||
|
||||
@NonNull
|
||||
public static String getExtension(IndexItem indexItem) {
|
||||
return isMetersItem(indexItem) ?
|
||||
return isMetricItem(indexItem) ?
|
||||
IndexConstants.BINARY_SRTM_MAP_INDEX_EXT :
|
||||
IndexConstants.BINARY_SRTM_FEET_MAP_INDEX_EXT;
|
||||
}
|
||||
|
||||
public static boolean isSRTMItem(Object item) {
|
||||
if (item instanceof IndexItem) {
|
||||
return ((IndexItem) item).getType() == SRTM_COUNTRY_FILE;
|
||||
} else if (item instanceof DownloadItem) {
|
||||
if (item instanceof DownloadItem) {
|
||||
return ((DownloadItem) item).getType() == SRTM_COUNTRY_FILE;
|
||||
} else if (item instanceof LocalIndexInfo) {
|
||||
return ((LocalIndexInfo) item).getType() == SRTM_DATA;
|
||||
|
@ -191,4 +172,20 @@ public class SrtmDownloadItem extends DownloadItem {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static boolean isMetricItem(Object item) {
|
||||
if (item instanceof IndexItem) {
|
||||
return ((IndexItem) item).getFileName().endsWith(BINARY_SRTM_MAP_INDEX_EXT_ZIP);
|
||||
} else if (item instanceof LocalIndexInfo) {
|
||||
return ((LocalIndexInfo) item).getFileName().endsWith(BINARY_SRTM_MAP_INDEX_EXT);
|
||||
} else if (item instanceof SrtmDownloadItem) {
|
||||
return isMetricItem(((SrtmDownloadItem) item).getIndexItem());
|
||||
} else if (item instanceof MultipleDownloadItem) {
|
||||
List<DownloadItem> items = ((MultipleDownloadItem) item).getAllItems();
|
||||
if (!Algorithms.isEmpty(items)) {
|
||||
return isMetricItem(items.get(0));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -227,8 +227,9 @@ public class ItemViewHolder {
|
|||
count = allRegionsCount;
|
||||
}
|
||||
String fullDescription = context.getString(R.string.ltr_or_rtl_combine_via_colon, header, count);
|
||||
if (item.isUseAbbreviation()) {
|
||||
fullDescription += " " + item.getAbbreviationInScopes(context);
|
||||
String addDescr = item.getAdditionalDescription(context);
|
||||
if (addDescr != null) {
|
||||
fullDescription += " " + addDescr;
|
||||
}
|
||||
if (item.hasActualDataToDownload()) {
|
||||
fullDescription = context.getString(
|
||||
|
@ -240,8 +241,9 @@ public class ItemViewHolder {
|
|||
String pattern = context.getString(R.string.ltr_or_rtl_combine_via_bold_point);
|
||||
String type = downloadItem.getType().getString(context);
|
||||
String size = downloadItem.getSizeDescription(context);
|
||||
if (downloadItem.isUseAbbreviation()) {
|
||||
size += " " + downloadItem.getAbbreviationInScopes(context);
|
||||
String addDescr = downloadItem.getAdditionalDescription(context);
|
||||
if (addDescr != null) {
|
||||
size += " " + addDescr;
|
||||
}
|
||||
String date = downloadItem.getDate(dateFormat, showRemoteDate);
|
||||
String fullDescription = String.format(pattern, size, date);
|
||||
|
|
Loading…
Reference in a new issue