Add subfolder to target file

This commit is contained in:
Vitaliy 2020-04-15 13:59:50 +03:00
parent ac60edda8d
commit 946c22adfc
3 changed files with 29 additions and 12 deletions

View file

@ -815,7 +815,7 @@ public class SettingsHelper {
@NonNull DownloadActivityType tp = DownloadActivityType.getIndexType(indexType);
if (tp != null) {
IndexItem indexItem = new CustomIndexItem(fileName, description, downloadurl, timestamp, size, contentSize, containerSize, tp);
IndexItem indexItem = new CustomIndexItem(fileName, subfolder, description, downloadurl, timestamp, size, contentSize, containerSize, tp);
region.downloadItems.add(indexItem);
}
}

View file

@ -1,15 +1,20 @@
package net.osmand.plus.download;
import net.osmand.plus.OsmandApplication;
import net.osmand.util.Algorithms;
import java.io.File;
public class CustomIndexItem extends IndexItem {
private final String downloadurl;
private String downloadurl;
private String subfolder;
public CustomIndexItem(String fileName, String description, String downloadurl,
public CustomIndexItem(String fileName, String subfolder, String description, String downloadurl,
long dateModified, String size, long contentSize,
long containerSize, DownloadActivityType type) {
super(fileName, description, dateModified, size, contentSize, containerSize, type);
this.subfolder = subfolder;
this.downloadurl = downloadurl;
}
@ -22,4 +27,13 @@ public class CustomIndexItem extends IndexItem {
return entry;
}
@Override
public File getTargetFile(OsmandApplication ctx) {
String basename = getTranslatedBasename();
if (!Algorithms.isEmpty(subfolder)) {
basename = subfolder + "/" + basename;
}
return new File(type.getDownloadFolder(ctx, this), basename + type.getUnzipExtension(ctx, this));
}
}

View file

@ -135,19 +135,22 @@ public class IndexItem implements Comparable<IndexItem> {
public String getBasename() {
return type.getBasename(this);
}
public File getTargetFile(OsmandApplication ctx) {
String basename;
if (type == DownloadActivityType.HILLSHADE_FILE) {
basename = (FileNameTranslationHelper.HILL_SHADE + getBasename()).replace("_", " ");
} else if (type == DownloadActivityType.SLOPE_FILE) {
basename = (FileNameTranslationHelper.SLOPE + getBasename()).replace('_', ' ');
} else {
basename = getBasename();
}
String basename = getTranslatedBasename();
return new File(type.getDownloadFolder(ctx, this), basename + type.getUnzipExtension(ctx, this));
}
public String getTranslatedBasename() {
if (type == DownloadActivityType.HILLSHADE_FILE) {
return (FileNameTranslationHelper.HILL_SHADE + getBasename()).replace("_", " ");
} else if (type == DownloadActivityType.SLOPE_FILE) {
return (FileNameTranslationHelper.SLOPE + getBasename()).replace('_', ' ');
} else {
return getBasename();
}
}
public File getBackupFile(OsmandApplication ctx) {
File backup = new File(ctx.getAppPath(IndexConstants.BACKUP_INDEX_DIR), getTargetFile(ctx).getName());
return backup;