Skip to content

Commit

Permalink
Merge branch 'r4.9' of https://github.com/osmandapp/OsmAnd into r4.9
Browse files Browse the repository at this point in the history
  • Loading branch information
dmpr0 committed Nov 25, 2024
2 parents 9c15788 + d8d59f6 commit 133d0a0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
49 changes: 24 additions & 25 deletions OsmAnd/src/net/osmand/plus/backup/BackupImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static net.osmand.plus.backup.BackupHelper.INFO_EXT;
import static net.osmand.plus.backup.BackupUtils.getRemoteFilesSettingsItems;
import static net.osmand.plus.backup.ExportBackupTask.APPROXIMATE_FILE_SIZE_BYTES;
import static net.osmand.plus.settings.backend.backup.SettingsItemType.QUICK_ACTIONS;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -24,6 +25,7 @@
import net.osmand.plus.settings.backend.backup.items.SettingsItem;
import net.osmand.plus.utils.FileUtils;
import net.osmand.util.Algorithms;
import net.osmand.util.CollectionUtils;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
Expand All @@ -35,17 +37,8 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicInteger;

class BackupImporter {
Expand Down Expand Up @@ -275,11 +268,13 @@ private List<SettingsItem> getRemoteItems(@NonNull List<RemoteFile> remoteFiles,
collectNoInfoRemoteItemFiles(noInfoRemoteItemFiles, remoteItemFilesMap, remoteInfoNames);
operationLog.log("build noInfoRemoteItemFiles");

if (readItems) {
generateItemsJson(itemsJson, remoteInfoFilesMap, noInfoRemoteItemFiles);
} else {
generateItemsJson(itemsJson, remoteInfoFiles, noInfoRemoteItemFiles);
if (readItems || !Algorithms.isEmpty(remoteInfoFilesMap)) {
generateItemsJson(itemsJson, remoteInfoFilesMap, remoteInfoFiles);
}
if (!readItems) {
generateItemsJson(itemsJson, remoteInfoFiles);
}
addRemoteFilesToJson(itemsJson, noInfoRemoteItemFiles);
operationLog.log("generateItemsJson");

SettingsItemsFactory itemsFactory = new SettingsItemsFactory(backupHelper.getApp(), json);
Expand Down Expand Up @@ -335,7 +330,8 @@ private void processUniqueRemoteFiles(@NonNull List<RemoteFile> uniqueRemoteFile
}
UploadedFileInfo fileInfo = infoMap.get(remoteFile.getType() + "___" + origFileName);
long uploadTime = fileInfo != null ? fileInfo.getUploadTime() : 0;
if (readItems && (uploadTime != remoteFile.getUpdatetimems() || delete)) {
if (shouldDownloadOnCollecting(remoteFile, readItems)
&& (uploadTime != remoteFile.getUpdatetimems() || delete)) {
remoteInfoFilesMap.put(new File(tempDir, fileName), remoteFile);
}
String itemFileName = fileName.substring(0, fileName.length() - INFO_EXT.length());
Expand Down Expand Up @@ -402,9 +398,7 @@ private List<RemoteFile> getItemRemoteFiles(@NonNull SettingsItem item, @NonNull
return res;
}

private void generateItemsJson(@NonNull JSONArray itemsJson,
@NonNull List<RemoteFile> remoteInfoFiles,
@NonNull List<RemoteFile> noInfoRemoteItemFiles) throws JSONException {
private void generateItemsJson(@NonNull JSONArray itemsJson, @NonNull List<RemoteFile> remoteInfoFiles) throws JSONException {
for (RemoteFile remoteFile : remoteInfoFiles) {
String fileName = remoteFile.getName();
fileName = fileName.substring(0, fileName.length() - INFO_EXT.length());
Expand All @@ -426,22 +420,23 @@ private void generateItemsJson(@NonNull JSONArray itemsJson,
itemJson.put("file", fileName);
itemsJson.put(itemJson);
}
addRemoteFilesToJson(itemsJson, noInfoRemoteItemFiles);
}

private void generateItemsJson(@NonNull JSONArray itemsJson,
@NonNull Map<File, RemoteFile> remoteInfoFiles,
@NonNull List<RemoteFile> noInfoRemoteItemFiles) throws JSONException, IOException {
@NonNull Map<File, RemoteFile> remoteInfoFilesMap,
@NonNull List<RemoteFile> remoteInfoFiles) throws JSONException, IOException {
List<FileDownloadTask> tasks = new ArrayList<>();
for (Entry<File, RemoteFile> fileEntry : remoteInfoFiles.entrySet()) {
tasks.add(new FileDownloadTask(fileEntry.getKey(), fileEntry.getValue()));
for (Entry<File, RemoteFile> fileEntry : remoteInfoFilesMap.entrySet()) {
RemoteFile remoteFile = fileEntry.getValue();
tasks.add(new FileDownloadTask(fileEntry.getKey(), remoteFile));
remoteInfoFiles.remove(remoteFile);
}
ThreadPoolTaskExecutor<FileDownloadTask> executor = createExecutor();
executor.run(tasks);

boolean hasDownloadErrors = hasDownloadErrors(tasks);
if (!hasDownloadErrors) {
for (File file : remoteInfoFiles.keySet()) {
for (File file : remoteInfoFilesMap.keySet()) {
String jsonStr = Algorithms.getFileAsString(file);
if (!Algorithms.isEmpty(jsonStr)) {
itemsJson.put(new JSONObject(jsonStr));
Expand All @@ -452,7 +447,11 @@ private void generateItemsJson(@NonNull JSONArray itemsJson,
} else {
throw new IOException("Error downloading items info");
}
addRemoteFilesToJson(itemsJson, noInfoRemoteItemFiles);
}

private boolean shouldDownloadOnCollecting(@NonNull RemoteFile remoteFile, boolean defValue) {
String type = remoteFile.getType();
return defValue || CollectionUtils.equalsToAny(type, QUICK_ACTIONS.name());
}

private void addRemoteFilesToJson(@NonNull JSONArray itemsJson, @NonNull List<RemoteFile> noInfoRemoteItemFiles) throws JSONException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2872,7 +2872,7 @@ public boolean moveImpassableRoad(@NonNull LatLon latLonEx, @NonNull LatLon latL
}

public final CommonPreference<Boolean> IS_QUICK_ACTION_TUTORIAL_SHOWN = new BooleanPreference(this, "quick_action_tutorial", false).makeGlobal().makeShared();
public final ListStringPreference QUICK_ACTION_BUTTONS = (ListStringPreference) new ListStringPreference(this, "quick_action_buttons", DEFAULT_BUTTON_ID + ";", ";").makeGlobal().makeShared().storeLastModifiedTime();
public final ListStringPreference QUICK_ACTION_BUTTONS = (ListStringPreference) new ListStringPreference(this, "quick_action_buttons", DEFAULT_BUTTON_ID + ";", ";").makeGlobal();


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public boolean set(T obj) {
}
cachedValue = obj;
cachedPreference = prefs;
if (changed && isShared()) {
if (changed && (isShared() || !global)) {
settings.updateLastPreferencesEditTime(prefs);
}
fireEvent(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class QuickActionButtonState extends MapButtonState {
public QuickActionButtonState(@NonNull OsmandApplication app, @NonNull String id) {
super(app, id);
this.visibilityPref = addPreference(settings.registerBooleanPreference(id + "_state", false)).makeProfile();
this.namePref = addPreference(settings.registerStringPreference(id + "_name", null)).makeGlobal();
this.namePref = addPreference(settings.registerStringPreference(id + "_name", null)).makeGlobal().storeLastModifiedTime();
this.quickActionsPref = addPreference(settings.registerStringPreference(id + "_list", null)).makeGlobal().storeLastModifiedTime();
this.quickActionLayer = app.getOsmandMap().getMapLayers().getMapQuickActionLayer();
}
Expand Down Expand Up @@ -130,10 +130,11 @@ public CommonPreference<String> getQuickActionsPref() {
}

public long getLastModifiedTime() {
return quickActionsPref.getLastModifiedTime();
return Math.max(namePref.getLastModifiedTime(), quickActionsPref.getLastModifiedTime());
}

public void setLastModifiedTime(long lastModifiedTime) {
namePref.setLastModifiedTime(lastModifiedTime);
quickActionsPref.setLastModifiedTime(lastModifiedTime);
}

Expand Down

0 comments on commit 133d0a0

Please sign in to comment.