Fix review
This commit is contained in:
parent
67952bdc63
commit
ad31b0842a
11 changed files with 39 additions and 59 deletions
|
@ -106,8 +106,6 @@ import net.osmand.aidlapi.events.AKeyEventsParams;
|
||||||
import net.osmand.aidlapi.info.AppInfoParams;
|
import net.osmand.aidlapi.info.AppInfoParams;
|
||||||
|
|
||||||
import net.osmand.aidlapi.profile.ExportProfileParams;
|
import net.osmand.aidlapi.profile.ExportProfileParams;
|
||||||
import net.osmand.aidlapi.profile.ExportSettingsType;
|
|
||||||
|
|
||||||
|
|
||||||
// NOTE: Add new methods at the end of file!!!
|
// NOTE: Add new methods at the end of file!!!
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import android.os.Bundle;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
|
|
||||||
import net.osmand.aidlapi.AidlParams;
|
import net.osmand.aidlapi.AidlParams;
|
||||||
import net.osmand.aidlapi.profile.ExportSettingsType;
|
import net.osmand.aidlapi.profile.AExportSettingsType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -20,13 +20,13 @@ public class ProfileSettingsParams extends AidlParams {
|
||||||
private Uri profileSettingsUri;
|
private Uri profileSettingsUri;
|
||||||
private String latestChanges;
|
private String latestChanges;
|
||||||
private int version;
|
private int version;
|
||||||
ArrayList<String> settingsTypeKeyList = new ArrayList<>();
|
private ArrayList<String> settingsTypeKeyList = new ArrayList<>();
|
||||||
boolean replace;
|
boolean replace;
|
||||||
|
|
||||||
public ProfileSettingsParams(Uri profileSettingsUri, ArrayList<ExportSettingsType> settingsTypeList, boolean replace,
|
public ProfileSettingsParams(Uri profileSettingsUri, ArrayList<AExportSettingsType> settingsTypeList, boolean replace,
|
||||||
String latestChanges, int version) {
|
String latestChanges, int version) {
|
||||||
this.profileSettingsUri = profileSettingsUri;
|
this.profileSettingsUri = profileSettingsUri;
|
||||||
for (ExportSettingsType settingsType : settingsTypeList) {
|
for (AExportSettingsType settingsType : settingsTypeList) {
|
||||||
settingsTypeKeyList.add(settingsType.name());
|
settingsTypeKeyList.add(settingsType.name());
|
||||||
}
|
}
|
||||||
this.replace = replace;
|
this.replace = replace;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.osmand.aidlapi.profile;
|
package net.osmand.aidlapi.profile;
|
||||||
|
|
||||||
public enum ExportSettingsType {
|
public enum AExportSettingsType {
|
||||||
PROFILE,
|
PROFILE,
|
||||||
QUICK_ACTIONS,
|
QUICK_ACTIONS,
|
||||||
POI_TYPES,
|
POI_TYPES,
|
|
@ -13,12 +13,12 @@ public class ExportProfileParams extends AidlParams {
|
||||||
public static final String PROFILE_KEY = "profile";
|
public static final String PROFILE_KEY = "profile";
|
||||||
public static final String SETTINGS_TYPE_KEY = "settings_type";
|
public static final String SETTINGS_TYPE_KEY = "settings_type";
|
||||||
private String profile;
|
private String profile;
|
||||||
ArrayList<String> settingsTypeKeyList = new ArrayList<>();
|
private ArrayList<String> settingsTypeKeyList = new ArrayList<>();
|
||||||
|
|
||||||
public ExportProfileParams(String profile, ArrayList<ExportSettingsType> settingsTypeList) {
|
public ExportProfileParams(String profile, ArrayList<AExportSettingsType> settingsTypeList) {
|
||||||
|
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
for (ExportSettingsType settingsType : settingsTypeList) {
|
for (AExportSettingsType settingsType : settingsTypeList) {
|
||||||
settingsTypeKeyList.add(settingsType.name());
|
settingsTypeKeyList.add(settingsType.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2253,7 +2253,19 @@ public class OsmandAidlApi {
|
||||||
|
|
||||||
private Map<String, FileCopyInfo> copyFilesCache = new ConcurrentHashMap<>();
|
private Map<String, FileCopyInfo> copyFilesCache = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public boolean importProfile(final Uri profileUri, ArrayList<String> settingsTypeKeys, boolean replace,
|
public boolean importProfile(final Uri profileUri, String latestChanges, int version) {
|
||||||
|
if (profileUri != null) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY, latestChanges);
|
||||||
|
bundle.putInt(SettingsHelper.SETTINGS_VERSION_KEY, version);
|
||||||
|
|
||||||
|
MapActivity.launchMapActivityMoveToTop(app, null, profileUri, bundle);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean importProfileV2(final Uri profileUri, ArrayList<String> settingsTypeKeys, boolean replace,
|
||||||
String latestChanges, int version) {
|
String latestChanges, int version) {
|
||||||
if (profileUri != null) {
|
if (profileUri != null) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
|
@ -2362,7 +2374,7 @@ public class OsmandAidlApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int copyFileOld(String fileName, byte[] filePartData, long startTime, boolean done) {
|
int copyFile(String fileName, byte[] filePartData, long startTime, boolean done) {
|
||||||
if (Algorithms.isEmpty(fileName) || filePartData == null) {
|
if (Algorithms.isEmpty(fileName) || filePartData == null) {
|
||||||
return COPY_FILE_PARAMS_ERROR;
|
return COPY_FILE_PARAMS_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -2376,7 +2388,7 @@ public class OsmandAidlApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int copyFile(String destinationDir, String fileName, byte[] filePartData, long startTime, boolean done) {
|
int copyFileV2(String destinationDir, String fileName, byte[] filePartData, long startTime, boolean done) {
|
||||||
if (Algorithms.isEmpty(fileName) || filePartData == null) {
|
if (Algorithms.isEmpty(fileName) || filePartData == null) {
|
||||||
return COPY_FILE_PARAMS_ERROR;
|
return COPY_FILE_PARAMS_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -2391,7 +2403,7 @@ public class OsmandAidlApi {
|
||||||
} else if (fileName.endsWith(IndexConstants.GPX_FILE_EXT)) {
|
} else if (fileName.endsWith(IndexConstants.GPX_FILE_EXT)) {
|
||||||
if (destinationDir.startsWith(IndexConstants.GPX_INDEX_DIR)
|
if (destinationDir.startsWith(IndexConstants.GPX_INDEX_DIR)
|
||||||
&& !FILE_TO_SAVE.equals(fileName)) {
|
&& !FILE_TO_SAVE.equals(fileName)) {
|
||||||
GPXUtilities.loadGPXFile(new File(destinationDir, fileName));
|
showGpx(new File(destinationDir, fileName).getName());
|
||||||
} else if (destinationDir.isEmpty() && FILE_TO_SAVE.equals(fileName)) {
|
} else if (destinationDir.isEmpty() && FILE_TO_SAVE.equals(fileName)) {
|
||||||
GPXUtilities.loadGPXFile(new File(destinationDir, fileName));
|
GPXUtilities.loadGPXFile(new File(destinationDir, fileName));
|
||||||
app.getFavorites().loadFavorites();
|
app.getFavorites().loadFavorites();
|
||||||
|
@ -2404,7 +2416,7 @@ public class OsmandAidlApi {
|
||||||
private int copyFileImpl(String fileName, byte[] filePartData, long startTime, boolean done, String destinationDir) {
|
private int copyFileImpl(String fileName, byte[] filePartData, long startTime, boolean done, String destinationDir) {
|
||||||
File tempDir = FileUtils.getTempDir(app);
|
File tempDir = FileUtils.getTempDir(app);
|
||||||
File file = new File(tempDir, fileName);
|
File file = new File(tempDir, fileName);
|
||||||
File destFile = app.getAppPath(destinationDir + fileName);
|
File destFile = app.getAppPath(new File(destinationDir, fileName).getPath());
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
FileCopyInfo info = copyFilesCache.get(fileName);
|
FileCopyInfo info = copyFilesCache.get(fileName);
|
||||||
|
|
|
@ -1138,7 +1138,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
|
||||||
if (api == null) {
|
if (api == null) {
|
||||||
return CANNOT_ACCESS_API_ERROR;
|
return CANNOT_ACCESS_API_ERROR;
|
||||||
}
|
}
|
||||||
return api.copyFileOld(params.getFileName(), params.getFilePartData(), params.getStartTime(), params.isDone());
|
return api.copyFile(params.getFileName(), params.getFilePartData(), params.getStartTime(), params.isDone());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e);
|
||||||
return UNKNOWN_API_ERROR;
|
return UNKNOWN_API_ERROR;
|
||||||
|
@ -1299,8 +1299,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
|
||||||
public boolean importProfile(ProfileSettingsParams params) {
|
public boolean importProfile(ProfileSettingsParams params) {
|
||||||
try {
|
try {
|
||||||
OsmandAidlApi api = getApi("importProfile");
|
OsmandAidlApi api = getApi("importProfile");
|
||||||
return api != null && api.importProfile(params.getProfileSettingsUri(), params.getSettingsTypeKeys(),
|
return api != null && api.importProfile(params.getProfileSettingsUri(), params.getLatestChanges(),
|
||||||
params.isReplace(), params.getLatestChanges(), params.getVersion());
|
params.getVersion());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1092,7 +1092,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
|
||||||
if (api == null) {
|
if (api == null) {
|
||||||
return CANNOT_ACCESS_API_ERROR;
|
return CANNOT_ACCESS_API_ERROR;
|
||||||
}
|
}
|
||||||
return api.copyFile(params.getDestinationDir(), params.getFileName(), params.getFilePartData(),
|
return api.copyFileV2(params.getDestinationDir(), params.getFileName(), params.getFilePartData(),
|
||||||
params.getStartTime(), params.isDone());
|
params.getStartTime(), params.isDone());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e);
|
||||||
|
@ -1260,7 +1260,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
|
||||||
public boolean importProfile(ProfileSettingsParams params) {
|
public boolean importProfile(ProfileSettingsParams params) {
|
||||||
try {
|
try {
|
||||||
OsmandAidlApi api = getApi("importProfile");
|
OsmandAidlApi api = getApi("importProfile");
|
||||||
return api != null && api.importProfile(params.getProfileSettingsUri(), params.getSettingsTypeKeys(),
|
return api != null && api.importProfileV2(params.getProfileSettingsUri(), params.getSettingsTypeKeys(),
|
||||||
params.isReplace(), params.getLatestChanges(), params.getVersion());
|
params.isReplace(), params.getLatestChanges(), params.getVersion());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
handleException(e);
|
handleException(e);
|
||||||
|
|
|
@ -4,20 +4,13 @@ import android.net.Uri;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import net.osmand.aidlapi.profile.ExportSettingsType;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class ProfileSettingsParams implements Parcelable {
|
public class ProfileSettingsParams implements Parcelable {
|
||||||
|
|
||||||
private Uri profileSettingsUri;
|
private Uri profileSettingsUri;
|
||||||
private String latestChanges;
|
private String latestChanges;
|
||||||
private int version;
|
private int version;
|
||||||
ArrayList<String> settingsTypeKeyList = new ArrayList<>();
|
|
||||||
boolean replace;
|
|
||||||
|
|
||||||
public ProfileSettingsParams(Uri profileSettingsUri, ArrayList<ExportSettingsType> settingsTypeList,
|
public ProfileSettingsParams(Uri profileSettingsUri, String latestChanges, int version) {
|
||||||
boolean replace, String latestChanges, int version) {
|
|
||||||
this.profileSettingsUri = profileSettingsUri;
|
this.profileSettingsUri = profileSettingsUri;
|
||||||
this.latestChanges = latestChanges;
|
this.latestChanges = latestChanges;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
|
@ -51,29 +44,17 @@ public class ProfileSettingsParams implements Parcelable {
|
||||||
return profileSettingsUri;
|
return profileSettingsUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getSettingsTypeKeys() {
|
|
||||||
return settingsTypeKeyList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isReplace() {
|
|
||||||
return replace;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel out, int flags) {
|
public void writeToParcel(Parcel out, int flags) {
|
||||||
out.writeInt(version);
|
out.writeInt(version);
|
||||||
out.writeString(latestChanges);
|
out.writeString(latestChanges);
|
||||||
out.writeParcelable(profileSettingsUri, flags);
|
out.writeParcelable(profileSettingsUri, flags);
|
||||||
out.writeStringList(settingsTypeKeyList);
|
|
||||||
out.writeInt(replace ? 1 : 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readFromParcel(Parcel in) {
|
private void readFromParcel(Parcel in) {
|
||||||
version = in.readInt();
|
version = in.readInt();
|
||||||
latestChanges = in.readString();
|
latestChanges = in.readString();
|
||||||
profileSettingsUri = in.readParcelable(Uri.class.getClassLoader());
|
profileSettingsUri = in.readParcelable(Uri.class.getClassLoader());
|
||||||
in.readStringList(settingsTypeKeyList);
|
|
||||||
replace = in.readInt() == 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -701,9 +701,7 @@ public class ImportHelper {
|
||||||
|
|
||||||
private void handleOsmAndSettingsImport(Uri intentUri, String fileName, Bundle extras, CallbackWithObject<List<SettingsItem>> callback) {
|
private void handleOsmAndSettingsImport(Uri intentUri, String fileName, Bundle extras, CallbackWithObject<List<SettingsItem>> callback) {
|
||||||
if (extras != null && extras.containsKey(SETTINGS_VERSION_KEY)
|
if (extras != null && extras.containsKey(SETTINGS_VERSION_KEY)
|
||||||
&& extras.containsKey(REPLACE_KEY)
|
&& extras.containsKey(SETTINGS_LATEST_CHANGES_KEY)) {
|
||||||
&& extras.containsKey(SETTINGS_LATEST_CHANGES_KEY)
|
|
||||||
&& extras.containsKey(SETTINGS_TYPE_LIST_KEY)) {
|
|
||||||
int version = extras.getInt(SETTINGS_VERSION_KEY, -1);
|
int version = extras.getInt(SETTINGS_VERSION_KEY, -1);
|
||||||
String latestChanges = extras.getString(SETTINGS_LATEST_CHANGES_KEY);
|
String latestChanges = extras.getString(SETTINGS_LATEST_CHANGES_KEY);
|
||||||
boolean replace = extras.getBoolean(REPLACE_KEY);
|
boolean replace = extras.getBoolean(REPLACE_KEY);
|
||||||
|
@ -817,11 +815,7 @@ public class ImportHelper {
|
||||||
if (mapActivity != null && succeed) {
|
if (mapActivity != null && succeed) {
|
||||||
FragmentManager fm = mapActivity.getSupportFragmentManager();
|
FragmentManager fm = mapActivity.getSupportFragmentManager();
|
||||||
app.getRendererRegistry().updateExternalRenderers();
|
app.getRendererRegistry().updateExternalRenderers();
|
||||||
AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
|
AppInitializer.loadRoutingFiles(app, null);
|
||||||
@Override
|
|
||||||
public void onRoutingFilesLoaded() {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2931,14 +2931,13 @@ public class SettingsHelper {
|
||||||
IMPORT
|
IMPORT
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SettingsHelper.SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> additionalData,
|
public List<SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> additionalData,
|
||||||
List<ExportSettingsType> settingsTypes) {
|
List<ExportSettingsType> settingsTypes) {
|
||||||
List<SettingsHelper.SettingsItem> settingsItems = new ArrayList<>();
|
List<SettingsItem> settingsItems = new ArrayList<>();
|
||||||
for (ExportSettingsType settingsType : settingsTypes) {
|
for (ExportSettingsType settingsType : settingsTypes) {
|
||||||
List<?> settingsDataObjects = additionalData.get(settingsType);
|
List<?> settingsDataObjects = additionalData.get(settingsType);
|
||||||
if (settingsDataObjects != null) {
|
if (settingsDataObjects != null) {
|
||||||
settingsItems.addAll(app.getSettingsHelper().prepareAdditionalSettingsItems(
|
settingsItems.addAll(prepareAdditionalSettingsItems(new ArrayList<>(settingsDataObjects)));
|
||||||
new ArrayList<>(settingsDataObjects)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return settingsItems;
|
return settingsItems;
|
||||||
|
|
|
@ -267,11 +267,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
||||||
FragmentManager fm = getFragmentManager();
|
FragmentManager fm = getFragmentManager();
|
||||||
if (succeed) {
|
if (succeed) {
|
||||||
app.getRendererRegistry().updateExternalRenderers();
|
app.getRendererRegistry().updateExternalRenderers();
|
||||||
AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
|
AppInitializer.loadRoutingFiles(app, null);
|
||||||
@Override
|
|
||||||
public void onRoutingFilesLoaded() {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (fm != null && file != null) {
|
if (fm != null && file != null) {
|
||||||
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue