Save edited files time to osf
This commit is contained in:
parent
4a1934e09c
commit
f267393887
5 changed files with 46 additions and 19 deletions
|
@ -19,6 +19,7 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class FileSettingsItem extends StreamSettingsItem {
|
||||
|
@ -131,6 +132,7 @@ public class FileSettingsItem extends StreamSettingsItem {
|
|||
private final File appPath;
|
||||
protected FileSubtype subtype;
|
||||
private long size;
|
||||
private long lastModified;
|
||||
|
||||
public FileSettingsItem(@NonNull OsmandApplication app, @NonNull File file) throws IllegalArgumentException {
|
||||
super(app, file.getPath().replace(app.getAppPath(null).getPath(), ""));
|
||||
|
@ -222,6 +224,14 @@ public class FileSettingsItem extends StreamSettingsItem {
|
|||
this.size = size;
|
||||
}
|
||||
|
||||
public long getLastModified() {
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
public void setLastModified(long lastModified) {
|
||||
this.lastModified = lastModified;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public File getFile() {
|
||||
return file;
|
||||
|
@ -292,6 +302,9 @@ public class FileSettingsItem extends StreamSettingsItem {
|
|||
} finally {
|
||||
Algorithms.closeStream(output);
|
||||
}
|
||||
if (lastModified != -1) {
|
||||
dest.setLastModified(lastModified);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -306,7 +319,14 @@ public class FileSettingsItem extends StreamSettingsItem {
|
|||
warnings.add(app.getString(R.string.settings_item_read_error, file.getName()));
|
||||
SettingsHelper.LOG.error("Failed to set input stream from file: " + file.getName(), e);
|
||||
}
|
||||
return super.getWriter();
|
||||
return new StreamSettingsItemWriter(this) {
|
||||
@Override
|
||||
public ZipEntry createNewEntry(String fileName) {
|
||||
ZipEntry entry = super.createNewEntry(fileName);
|
||||
entry.setTime(file.lastModified());
|
||||
return entry;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return new StreamSettingsItemWriter(this) {
|
||||
|
||||
|
|
|
@ -829,10 +829,10 @@ public class SettingsHelper {
|
|||
List<File> routingFilesList = new ArrayList<>();
|
||||
List<File> renderFilesList = new ArrayList<>();
|
||||
List<File> multimediaFilesList = new ArrayList<>();
|
||||
List<File> tracksFilesList = new ArrayList<>();
|
||||
List<File> ttsVoiceFilesList = new ArrayList<>();
|
||||
List<File> voiceFilesList = new ArrayList<>();
|
||||
List<FileSettingsItem> mapFilesList = new ArrayList<>();
|
||||
List<FileSettingsItem> tracksFilesList = new ArrayList<>();
|
||||
List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
|
||||
List<GlobalSettingsItem> globalSettingsItems = new ArrayList<>();
|
||||
List<OsmNotesPoint> notesPointList = new ArrayList<>();
|
||||
|
@ -856,7 +856,7 @@ public class SettingsHelper {
|
|||
} else if (fileItem.getSubtype() == FileSubtype.MULTIMEDIA_NOTES) {
|
||||
multimediaFilesList.add(fileItem.getFile());
|
||||
} else if (fileItem.getSubtype() == FileSubtype.GPX) {
|
||||
tracksFilesList.add(fileItem.getFile());
|
||||
tracksFilesList.add(fileItem);
|
||||
} else if (fileItem.getSubtype().isMap()) {
|
||||
mapFilesList.add(fileItem);
|
||||
} else if (fileItem.getSubtype() == FileSubtype.TTS_VOICE) {
|
||||
|
|
|
@ -60,7 +60,7 @@ class SettingsImporter {
|
|||
try {
|
||||
SettingsItemsFactory itemsFactory = new SettingsItemsFactory(app, itemsJson);
|
||||
List<SettingsItem> settingsItemList = itemsFactory.getItems();
|
||||
getFilesSize(file, settingsItemList);
|
||||
updateFilesInfo(file, settingsItemList);
|
||||
items.addAll(settingsItemList);
|
||||
} catch (IllegalArgumentException e) {
|
||||
SettingsHelper.LOG.error("Error parsing items: " + itemsJson, e);
|
||||
|
@ -81,7 +81,7 @@ class SettingsImporter {
|
|||
return items;
|
||||
}
|
||||
|
||||
private void getFilesSize(@NonNull File file, List<SettingsItem> settingsItemList) throws IOException {
|
||||
private void updateFilesInfo(@NonNull File file, List<SettingsItem> settingsItemList) throws IOException {
|
||||
ZipFile zipfile = new ZipFile(file.getPath());
|
||||
Enumeration<? extends ZipEntry> zipEnum = zipfile.entries();
|
||||
while (zipEnum.hasMoreElements()) {
|
||||
|
@ -90,7 +90,9 @@ class SettingsImporter {
|
|||
for (SettingsItem settingsItem : settingsItemList) {
|
||||
if (settingsItem instanceof FileSettingsItem
|
||||
&& zipEntry.getName().equals(settingsItem.getFileName())) {
|
||||
((FileSettingsItem) settingsItem).setSize(size);
|
||||
FileSettingsItem fileSettingsItem = (FileSettingsItem) settingsItem;
|
||||
fileSettingsItem.setSize(size);
|
||||
fileSettingsItem.setLastModified(zipEntry.getTime());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,13 @@ public abstract class SettingsItemWriter<T extends SettingsItem> {
|
|||
public abstract boolean writeToStream(@NonNull OutputStream outputStream) throws IOException;
|
||||
|
||||
public void writeEntry(String fileName, @NonNull ZipOutputStream zos) throws IOException {
|
||||
ZipEntry entry = new ZipEntry(fileName);
|
||||
ZipEntry entry = createNewEntry(fileName);
|
||||
zos.putNextEntry(entry);
|
||||
writeToStream(zos);
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
||||
public ZipEntry createNewEntry(String fileName) {
|
||||
return new ZipEntry(fileName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -313,10 +313,11 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
builder.setTitle(tileSource.getName());
|
||||
builder.setIcon(uiUtilities.getIcon(R.drawable.ic_map, activeColorRes));
|
||||
} else if (object instanceof File) {
|
||||
setupBottomSheetItemForFile(builder, (File) object);
|
||||
File file = (File) object;
|
||||
setupBottomSheetItemForFile(builder, file, file.lastModified(), file.length());
|
||||
} else if (object instanceof FileSettingsItem) {
|
||||
FileSettingsItem fileSettingsItem = (FileSettingsItem) object;
|
||||
setupBottomSheetItemForFile(builder, fileSettingsItem.getFile());
|
||||
FileSettingsItem item = (FileSettingsItem) object;
|
||||
setupBottomSheetItemForFile(builder, item.getFile(), item.getLastModified(), item.getSize());
|
||||
} else if (object instanceof AvoidRoadInfo) {
|
||||
AvoidRoadInfo avoidRoadInfo = (AvoidRoadInfo) object;
|
||||
builder.setTitle(avoidRoadInfo.name);
|
||||
|
@ -360,7 +361,7 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private void setupBottomSheetItemForFile(Builder builder, File file) {
|
||||
private void setupBottomSheetItemForFile(Builder builder, File file, long lastModified, long size) {
|
||||
FileSubtype fileSubtype = FileSubtype.getSubtypeByPath(app, file.getPath());
|
||||
builder.setTitle(file.getName());
|
||||
if (file.getAbsolutePath().contains(IndexConstants.RENDERERS_DIR)) {
|
||||
|
@ -370,7 +371,7 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
} else if (file.getAbsolutePath().contains(IndexConstants.GPX_INDEX_DIR)) {
|
||||
builder.setTitle(GpxUiHelper.getGpxTitle(file.getName()));
|
||||
builder.setTag(file);
|
||||
builder.setDescription(getTrackDescr(file));
|
||||
builder.setDescription(getTrackDescr(file, lastModified, size));
|
||||
builder.setIcon(uiUtilities.getIcon(R.drawable.ic_action_route_distance, activeColorRes));
|
||||
} else if (file.getAbsolutePath().contains(IndexConstants.AV_INDEX_DIR)) {
|
||||
int iconId = AudioVideoNotesPlugin.getIconIdForRecordingFile(file);
|
||||
|
@ -386,11 +387,11 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
|
||||
if (fileSubtype.isMap()) {
|
||||
String mapDescription = getMapDescription(file);
|
||||
String size = AndroidUtils.formatSize(app, file.length());
|
||||
String formattedSize = AndroidUtils.formatSize(app, size);
|
||||
if (mapDescription != null) {
|
||||
builder.setDescription(getString(R.string.ltr_or_rtl_combine_via_star, mapDescription, size));
|
||||
builder.setDescription(getString(R.string.ltr_or_rtl_combine_via_star, mapDescription, formattedSize));
|
||||
} else {
|
||||
builder.setDescription(size);
|
||||
builder.setDescription(formattedSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -413,7 +414,7 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
}
|
||||
};
|
||||
|
||||
private String getTrackDescr(@NonNull File file) {
|
||||
private String getTrackDescr(@NonNull File file, long lastModified, long size) {
|
||||
String folder = "";
|
||||
File parent = file.getParentFile();
|
||||
if (parent != null) {
|
||||
|
@ -425,10 +426,10 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
return getTrackDescrForDataItem(dataItem);
|
||||
}
|
||||
} else {
|
||||
String date = OsmAndFormatter.getFormattedDate(app, file.lastModified());
|
||||
String size = AndroidUtils.formatSize(app, file.length());
|
||||
String date = OsmAndFormatter.getFormattedDate(app, lastModified);
|
||||
String formattedSize = AndroidUtils.formatSize(app, size);
|
||||
String descr = getString(R.string.ltr_or_rtl_combine_via_bold_point, folder, date);
|
||||
return getString(R.string.ltr_or_rtl_combine_via_comma, descr, size);
|
||||
return getString(R.string.ltr_or_rtl_combine_via_comma, descr, formattedSize);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue