Fix "Download all button" request after code review
This commit is contained in:
parent
357ab00ed6
commit
454831591b
9 changed files with 36 additions and 56 deletions
|
@ -10,7 +10,6 @@ import net.osmand.binary.BinaryMapIndexReader.TagValuePair;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.QuadRect;
|
import net.osmand.data.QuadRect;
|
||||||
import net.osmand.data.QuadTree;
|
import net.osmand.data.QuadTree;
|
||||||
import net.osmand.map.WorldRegion.RegionBoundingBox;
|
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
import net.osmand.util.MapAlgorithms;
|
import net.osmand.util.MapAlgorithms;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
@ -463,9 +462,9 @@ public class OsmandRegions {
|
||||||
return rd;
|
return rd;
|
||||||
}
|
}
|
||||||
|
|
||||||
private RegionBoundingBox findBoundingBox(BinaryMapDataObject object) {
|
private QuadRect findBoundingBox(BinaryMapDataObject object) {
|
||||||
if (object.getPointsLength() == 0) {
|
if (object.getPointsLength() == 0) {
|
||||||
return new RegionBoundingBox(0, 0, 0, 0);
|
return new QuadRect(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
double currentX = object.getPoint31XTile(0);
|
double currentX = object.getPoint31XTile(0);
|
||||||
|
@ -497,7 +496,7 @@ public class OsmandRegions {
|
||||||
double revertedMinY = MapUtils.get31LatitudeY((int) maxY);
|
double revertedMinY = MapUtils.get31LatitudeY((int) maxY);
|
||||||
double revertedMaxY = MapUtils.get31LatitudeY((int) minY);
|
double revertedMaxY = MapUtils.get31LatitudeY((int) minY);
|
||||||
|
|
||||||
return new RegionBoundingBox(minX, maxX, revertedMinY, revertedMaxY);
|
return new QuadRect(minX, revertedMinY, maxX, revertedMaxY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSearchIndex(BinaryMapDataObject object) {
|
private String getSearchIndex(BinaryMapDataObject object) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.osmand.map;
|
package net.osmand.map;
|
||||||
|
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
import net.osmand.data.QuadRect;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -40,7 +41,7 @@ public class WorldRegion implements Serializable {
|
||||||
protected String regionDownloadName;
|
protected String regionDownloadName;
|
||||||
protected boolean regionMapDownload;
|
protected boolean regionMapDownload;
|
||||||
protected LatLon regionCenter;
|
protected LatLon regionCenter;
|
||||||
protected RegionBoundingBox boundingBox;
|
protected QuadRect boundingBox;
|
||||||
|
|
||||||
public static class RegionParams {
|
public static class RegionParams {
|
||||||
protected String regionLeftHandDriving;
|
protected String regionLeftHandDriving;
|
||||||
|
@ -184,31 +185,10 @@ public class WorldRegion implements Serializable {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFirstRegionInsideTheSecond(WorldRegion first,
|
public boolean containsRegion(WorldRegion region) {
|
||||||
WorldRegion second) {
|
if (this.boundingBox != null && region.boundingBox != null) {
|
||||||
RegionBoundingBox bbox1 = first.boundingBox;
|
return this.boundingBox.contains(region.boundingBox);
|
||||||
RegionBoundingBox bbox2 = second.boundingBox;
|
|
||||||
if ((bbox1.minX > bbox2.minX) && (bbox1.maxX < bbox2.maxX)) {
|
|
||||||
if ((bbox1.minY > bbox2.minY) && (bbox1.maxY < bbox2.maxY)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RegionBoundingBox {
|
|
||||||
|
|
||||||
double minX;
|
|
||||||
double maxX;
|
|
||||||
double minY;
|
|
||||||
double maxY;
|
|
||||||
|
|
||||||
public RegionBoundingBox(double minX, double maxX, double minY, double maxY) {
|
|
||||||
this.minX = minX;
|
|
||||||
this.maxX = maxX;
|
|
||||||
this.minY = minY;
|
|
||||||
this.maxY = maxY;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -127,6 +127,17 @@ public class Algorithms {
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double parseDoubleSilently(String input, double def) {
|
||||||
|
if (input != null && input.length() > 0) {
|
||||||
|
try {
|
||||||
|
return Double.parseDouble(input);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
public static String getFileNameWithoutExtension(File f) {
|
public static String getFileNameWithoutExtension(File f) {
|
||||||
return getFileNameWithoutExtension(f.getName());
|
return getFileNameWithoutExtension(f.getName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,8 @@ public abstract class DownloadItem {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getSizeDescription(Context ctx) {
|
public String getSizeDescription(Context ctx) {
|
||||||
String pattern = ctx.getString(R.string.ltr_or_rtl_combine_via_space);
|
|
||||||
String size = String.format(Locale.US, "%.2f", getSizeToDownloadInMb());
|
String size = String.format(Locale.US, "%.2f", getSizeToDownloadInMb());
|
||||||
return String.format(pattern, size, "MB");
|
return ctx.getString(R.string.ltr_or_rtl_combine_via_space, size, "MB");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVisibleName(Context ctx, OsmandRegions osmandRegions) {
|
public String getVisibleName(Context ctx, OsmandRegions osmandRegions) {
|
||||||
|
@ -48,8 +47,8 @@ public abstract class DownloadItem {
|
||||||
return type.getVisibleName(this, ctx, osmandRegions, includingParent);
|
return type.getVisibleName(this, ctx, osmandRegions, includingParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVisibleDescription(OsmandApplication clctx) {
|
public String getVisibleDescription(OsmandApplication ctx) {
|
||||||
return type.getVisibleDescription(this, clctx);
|
return type.getVisibleDescription(this, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBasename() {
|
public String getBasename() {
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class DownloadResourceGroup {
|
||||||
|
|
||||||
private final DownloadResourceGroupType type;
|
private final DownloadResourceGroupType type;
|
||||||
private final DownloadResourceGroup parentGroup;
|
private final DownloadResourceGroup parentGroup;
|
||||||
// ASSERT: individualDisplayItems are not empty if and only if groups are empty
|
// ASSERT: individualDownloadItems are not empty if and only if groups are empty
|
||||||
private final List<DownloadItem> individualDownloadItems;
|
private final List<DownloadItem> individualDownloadItems;
|
||||||
private final List<DownloadResourceGroup> groups;
|
private final List<DownloadResourceGroup> groups;
|
||||||
protected final String id;
|
protected final String id;
|
||||||
|
|
|
@ -533,13 +533,13 @@ public class DownloadResources extends DownloadResourceGroup {
|
||||||
// collect duplicates
|
// collect duplicates
|
||||||
Set<WorldRegion> duplicates = new HashSet<>();
|
Set<WorldRegion> duplicates = new HashSet<>();
|
||||||
for (int i = 0; i < regions.size() - 1; i++) {
|
for (int i = 0; i < regions.size() - 1; i++) {
|
||||||
WorldRegion firstRegion = regions.get(i);
|
WorldRegion r1 = regions.get(i);
|
||||||
for (int j = i + 1; j < regions.size(); j++) {
|
for (int j = i + 1; j < regions.size(); j++) {
|
||||||
WorldRegion secondRegion = regions.get(j);
|
WorldRegion r2 = regions.get(j);
|
||||||
if (WorldRegion.isFirstRegionInsideTheSecond(firstRegion, secondRegion)) {
|
if (r1.containsRegion(r2)) {
|
||||||
duplicates.add(firstRegion);
|
duplicates.add(r1);
|
||||||
} else if (WorldRegion.isFirstRegionInsideTheSecond(secondRegion, firstRegion)) {
|
} else if (r2.containsRegion(r1)) {
|
||||||
duplicates.add(secondRegion);
|
duplicates.add(r2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,14 @@ import net.osmand.PlatformUtil;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -58,11 +59,10 @@ public class IndexItem extends DownloadItem implements Comparable<IndexItem> {
|
||||||
@Override
|
@Override
|
||||||
public List<File> getDownloadedFiles(OsmandApplication app) {
|
public List<File> getDownloadedFiles(OsmandApplication app) {
|
||||||
File targetFile = getTargetFile(app);
|
File targetFile = getTargetFile(app);
|
||||||
List<File> result = new ArrayList<>();
|
|
||||||
if (targetFile.exists()) {
|
if (targetFile.exists()) {
|
||||||
result.add(targetFile);
|
return Collections.singletonList(targetFile);
|
||||||
}
|
}
|
||||||
return result;
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
|
@ -91,11 +91,7 @@ public class IndexItem extends DownloadItem implements Comparable<IndexItem> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double getSizeToDownloadInMb() {
|
protected double getSizeToDownloadInMb() {
|
||||||
try {
|
return Algorithms.parseDoubleSilently(size, 0.0);
|
||||||
return Double.parseDouble(size);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DownloadEntry createDownloadEntry(OsmandApplication ctx) {
|
public DownloadEntry createDownloadEntry(OsmandApplication ctx) {
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class MultipleIndexItem extends DownloadItem {
|
||||||
double totalSizeMb = 0.0d;
|
double totalSizeMb = 0.0d;
|
||||||
for (IndexItem item : items) {
|
for (IndexItem item : items) {
|
||||||
if (item.hasActualDataToDownload()) {
|
if (item.hasActualDataToDownload()) {
|
||||||
totalSizeMb += Double.parseDouble(item.size);
|
totalSizeMb += item.getSizeToDownloadInMb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return totalSizeMb;
|
return totalSizeMb;
|
||||||
|
|
|
@ -48,7 +48,6 @@ 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;
|
||||||
|
|
||||||
public class ItemViewHolder {
|
public class ItemViewHolder {
|
||||||
|
@ -412,7 +411,7 @@ public class ItemViewHolder {
|
||||||
final List<File> downloadedFiles = downloadItem.getDownloadedFiles(app);
|
final List<File> downloadedFiles = downloadItem.getDownloadedFiles(app);
|
||||||
if (!Algorithms.isEmpty(downloadedFiles)) {
|
if (!Algorithms.isEmpty(downloadedFiles)) {
|
||||||
item = optionsMenu.getMenu().add(R.string.shared_string_remove)
|
item = optionsMenu.getMenu().add(R.string.shared_string_remove)
|
||||||
.setIcon(getThemedIcon(context, R.drawable.ic_action_remove_dark));
|
.setIcon(getContentIcon(context, R.drawable.ic_action_remove_dark));
|
||||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
@ -560,10 +559,6 @@ public class ItemViewHolder {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable getThemedIcon(DownloadActivity context, int resourceId) {
|
|
||||||
return context.getMyApplication().getUIUtilities().getThemedIcon(resourceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Drawable getContentIcon(DownloadActivity context, int resourceId) {
|
private Drawable getContentIcon(DownloadActivity context, int resourceId) {
|
||||||
return context.getMyApplication().getUIUtilities().getThemedIcon(resourceId);
|
return context.getMyApplication().getUIUtilities().getThemedIcon(resourceId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue