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));
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"));
DownloadActivityType type = DownloadActivityType.getIndexType(indexType);
@ -157,6 +160,8 @@ public class CustomRegion extends WorldRegion {
.setSubfolder(subfolder)
.setDownloadUrl(downloadUrl)
.setNames(indexNames)
.setFirstSubNames(firstSubNames)
.setSecondSubNames(secondSubNames)
.setDescriptionInfo(descriptionInfo)
.setTimestamp(timestamp)
.setSize(size)

View file

@ -19,6 +19,8 @@ public class CustomIndexItem extends IndexItem {
private String downloadUrl;
private Map<String, String> names;
private Map<String, String> firstSubNames;
private Map<String, String> secondSubNames;
private DownloadDescriptionInfo descriptionInfo;
@ -30,10 +32,14 @@ public class CustomIndexItem extends IndexItem {
long contentSize,
long containerSize,
Map<String, String> names,
Map<String, String> firstSubNames,
Map<String, String> secondSubNames,
@NonNull DownloadActivityType type,
DownloadDescriptionInfo descriptionInfo) {
super(fileName, null, timestamp, size, contentSize, containerSize, type);
this.names = names;
this.firstSubNames = firstSubNames;
this.secondSubNames = secondSubNames;
this.subfolder = subfolder;
this.downloadUrl = downloadUrl;
this.descriptionInfo = descriptionInfo;
@ -68,6 +74,24 @@ public class CustomIndexItem extends IndexItem {
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() {
return descriptionInfo;
}
@ -84,6 +108,8 @@ public class CustomIndexItem extends IndexItem {
private long containerSize;
private Map<String, String> names;
private Map<String, String> firstSubNames;
private Map<String, String> secondSubNames;
private DownloadActivityType type;
private DownloadDescriptionInfo descriptionInfo;
@ -128,6 +154,16 @@ public class CustomIndexItem extends IndexItem {
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) {
this.descriptionInfo = descriptionInfo;
return this;
@ -139,7 +175,18 @@ public class CustomIndexItem extends IndexItem {
}
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) {
banner.updateBannerInProgress();
}
reloadData();
}
@Override

View file

@ -27,6 +27,7 @@ import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType;
import net.osmand.plus.activities.LocalIndexInfo;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
import net.osmand.plus.download.CityItem;
import net.osmand.plus.download.CustomIndexItem;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadResourceGroup;
@ -179,22 +180,24 @@ public class ItemViewHolder {
if (!isDownloading) {
progressBar.setVisibility(View.GONE);
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));
} else if ((indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE
|| indexItem.getType() == DownloadActivityType.HILLSHADE_FILE
|| indexItem.getType() == DownloadActivityType.SLOPE_FILE) && srtmDisabled) {
if(showTypeInName) {
if (showTypeInName) {
descrTextView.setText("");
} else {
descrTextView.setText(indexItem.getType().getString(context));
}
} else if (showTypeInDesc) {
descrTextView.setText(indexItem.getType().getString(context) +
descrTextView.setText(indexItem.getType().getString(context) +
"" + indexItem.getSizeDescription(context) +
"" + (showRemoteDate ? indexItem.getRemoteDate(dateFormat) : indexItem.getLocalDate(dateFormat)));
} else {
descrTextView.setText(indexItem.getSizeDescription(context) + "" +
descrTextView.setText(indexItem.getSizeDescription(context) + "" +
(showRemoteDate ? indexItem.getRemoteDate(dateFormat) : indexItem.getLocalDate(dateFormat)));
}