Add subName to custom download item

This commit is contained in:
Vitaliy 2020-04-23 21:33:27 +03:00
parent a16b85850b
commit e517b425dc
4 changed files with 61 additions and 5 deletions

View file

@ -148,6 +148,9 @@ public class CustomRegion extends WorldRegion {
String size = new DecimalFormat("#.#").format(containerSize / (1024f * 1024f)); String size = new DecimalFormat("#.#").format(containerSize / (1024f * 1024f));
Map<String, String> indexNames = JsonUtils.getLocalizedMapFromJson("name", itemJson); Map<String, String> indexNames = JsonUtils.getLocalizedMapFromJson("name", itemJson);
Map<String, String> firstSubNames = JsonUtils.getLocalizedMapFromJson("firstsubname", itemJson);
Map<String, String> secondSubNames = JsonUtils.getLocalizedMapFromJson("secondsubname", itemJson);
DownloadDescriptionInfo descriptionInfo = DownloadDescriptionInfo.fromJson(itemJson.optJSONObject("description")); DownloadDescriptionInfo descriptionInfo = DownloadDescriptionInfo.fromJson(itemJson.optJSONObject("description"));
DownloadActivityType type = DownloadActivityType.getIndexType(indexType); DownloadActivityType type = DownloadActivityType.getIndexType(indexType);
@ -157,6 +160,8 @@ public class CustomRegion extends WorldRegion {
.setSubfolder(subfolder) .setSubfolder(subfolder)
.setDownloadUrl(downloadUrl) .setDownloadUrl(downloadUrl)
.setNames(indexNames) .setNames(indexNames)
.setFirstSubNames(firstSubNames)
.setSecondSubNames(secondSubNames)
.setDescriptionInfo(descriptionInfo) .setDescriptionInfo(descriptionInfo)
.setTimestamp(timestamp) .setTimestamp(timestamp)
.setSize(size) .setSize(size)

View file

@ -19,6 +19,8 @@ public class CustomIndexItem extends IndexItem {
private String downloadUrl; private String downloadUrl;
private Map<String, String> names; private Map<String, String> names;
private Map<String, String> firstSubNames;
private Map<String, String> secondSubNames;
private DownloadDescriptionInfo descriptionInfo; private DownloadDescriptionInfo descriptionInfo;
@ -30,10 +32,14 @@ public class CustomIndexItem extends IndexItem {
long contentSize, long contentSize,
long containerSize, long containerSize,
Map<String, String> names, Map<String, String> names,
Map<String, String> firstSubNames,
Map<String, String> secondSubNames,
@NonNull DownloadActivityType type, @NonNull DownloadActivityType type,
DownloadDescriptionInfo descriptionInfo) { DownloadDescriptionInfo descriptionInfo) {
super(fileName, null, timestamp, size, contentSize, containerSize, type); super(fileName, null, timestamp, size, contentSize, containerSize, type);
this.names = names; this.names = names;
this.firstSubNames = firstSubNames;
this.secondSubNames = secondSubNames;
this.subfolder = subfolder; this.subfolder = subfolder;
this.downloadUrl = downloadUrl; this.downloadUrl = downloadUrl;
this.descriptionInfo = descriptionInfo; this.descriptionInfo = descriptionInfo;
@ -68,6 +74,24 @@ public class CustomIndexItem extends IndexItem {
return JsonUtils.getLocalizedResFromMap(ctx, names, name); return JsonUtils.getLocalizedResFromMap(ctx, names, name);
} }
public String getSubName(Context ctx) {
String subName = getFirstSubName(ctx);
String secondSubName = getSecondSubName(ctx);
if (secondSubName != null) {
subName = subName == null ? secondSubName : subName + "" + secondSubName;
}
return subName;
}
public String getFirstSubName(Context ctx) {
return JsonUtils.getLocalizedResFromMap(ctx, firstSubNames, null);
}
public String getSecondSubName(Context ctx) {
return JsonUtils.getLocalizedResFromMap(ctx, secondSubNames, null);
}
public DownloadDescriptionInfo getDescriptionInfo() { public DownloadDescriptionInfo getDescriptionInfo() {
return descriptionInfo; return descriptionInfo;
} }
@ -84,6 +108,8 @@ public class CustomIndexItem extends IndexItem {
private long containerSize; private long containerSize;
private Map<String, String> names; private Map<String, String> names;
private Map<String, String> firstSubNames;
private Map<String, String> secondSubNames;
private DownloadActivityType type; private DownloadActivityType type;
private DownloadDescriptionInfo descriptionInfo; private DownloadDescriptionInfo descriptionInfo;
@ -128,6 +154,16 @@ public class CustomIndexItem extends IndexItem {
return this; return this;
} }
public CustomIndexItemBuilder setFirstSubNames(Map<String, String> firstSubNames) {
this.firstSubNames = firstSubNames;
return this;
}
public CustomIndexItemBuilder setSecondSubNames(Map<String, String> secondSubNames) {
this.secondSubNames = secondSubNames;
return this;
}
public CustomIndexItemBuilder setDescriptionInfo(DownloadDescriptionInfo descriptionInfo) { public CustomIndexItemBuilder setDescriptionInfo(DownloadDescriptionInfo descriptionInfo) {
this.descriptionInfo = descriptionInfo; this.descriptionInfo = descriptionInfo;
return this; return this;
@ -139,7 +175,18 @@ public class CustomIndexItem extends IndexItem {
} }
public CustomIndexItem create() { public CustomIndexItem create() {
return new CustomIndexItem(fileName, subfolder, downloadUrl, size, timestamp, contentSize, containerSize, names, type, descriptionInfo); return new CustomIndexItem(fileName,
subfolder,
downloadUrl,
size,
timestamp,
contentSize,
containerSize,
names,
firstSubNames,
secondSubNames,
type,
descriptionInfo);
} }
} }
} }

View file

@ -135,6 +135,7 @@ public class DownloadItemFragment extends DialogFragment implements DownloadEven
if (banner != null) { if (banner != null) {
banner.updateBannerInProgress(); banner.updateBannerInProgress();
} }
reloadData();
} }
@Override @Override

View file

@ -27,6 +27,7 @@ import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment; import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
import net.osmand.plus.download.CityItem; import net.osmand.plus.download.CityItem;
import net.osmand.plus.download.CustomIndexItem;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadResourceGroup; import net.osmand.plus.download.DownloadResourceGroup;
@ -179,12 +180,14 @@ public class ItemViewHolder {
if (!isDownloading) { if (!isDownloading) {
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
descrTextView.setVisibility(View.VISIBLE); descrTextView.setVisibility(View.VISIBLE);
if (indexItem.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE && !depthContoursPurchased) { if (indexItem instanceof CustomIndexItem && (((CustomIndexItem) indexItem).getSubName(context) != null)) {
descrTextView.setText(((CustomIndexItem) indexItem).getSubName(context));
} else if (indexItem.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE && !depthContoursPurchased) {
descrTextView.setText(context.getString(R.string.depth_contour_descr)); descrTextView.setText(context.getString(R.string.depth_contour_descr));
} else if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE } else if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE
|| indexItem.getType() == DownloadActivityType.HILLSHADE_FILE || indexItem.getType() == DownloadActivityType.HILLSHADE_FILE
|| indexItem.getType() == DownloadActivityType.SLOPE_FILE) && srtmDisabled) { || indexItem.getType() == DownloadActivityType.SLOPE_FILE) && srtmDisabled) {
if(showTypeInName) { if (showTypeInName) {
descrTextView.setText(""); descrTextView.setText("");
} else { } else {
descrTextView.setText(indexItem.getType().getString(context)); descrTextView.setText(indexItem.getType().getString(context));