Fix review

This commit is contained in:
Dima-1 2020-10-06 14:04:48 +03:00
parent 67952bdc63
commit ad31b0842a
11 changed files with 39 additions and 59 deletions

View file

@ -106,8 +106,6 @@ import net.osmand.aidlapi.events.AKeyEventsParams;
import net.osmand.aidlapi.info.AppInfoParams;
import net.osmand.aidlapi.profile.ExportProfileParams;
import net.osmand.aidlapi.profile.ExportSettingsType;
// NOTE: Add new methods at the end of file!!!

View file

@ -5,7 +5,7 @@ import android.os.Bundle;
import android.os.Parcel;
import net.osmand.aidlapi.AidlParams;
import net.osmand.aidlapi.profile.ExportSettingsType;
import net.osmand.aidlapi.profile.AExportSettingsType;
import java.util.ArrayList;
@ -20,13 +20,13 @@ public class ProfileSettingsParams extends AidlParams {
private Uri profileSettingsUri;
private String latestChanges;
private int version;
ArrayList<String> settingsTypeKeyList = new ArrayList<>();
private ArrayList<String> settingsTypeKeyList = new ArrayList<>();
boolean replace;
public ProfileSettingsParams(Uri profileSettingsUri, ArrayList<ExportSettingsType> settingsTypeList, boolean replace,
public ProfileSettingsParams(Uri profileSettingsUri, ArrayList<AExportSettingsType> settingsTypeList, boolean replace,
String latestChanges, int version) {
this.profileSettingsUri = profileSettingsUri;
for (ExportSettingsType settingsType : settingsTypeList) {
for (AExportSettingsType settingsType : settingsTypeList) {
settingsTypeKeyList.add(settingsType.name());
}
this.replace = replace;

View file

@ -1,6 +1,6 @@
package net.osmand.aidlapi.profile;
public enum ExportSettingsType {
public enum AExportSettingsType {
PROFILE,
QUICK_ACTIONS,
POI_TYPES,

View file

@ -13,12 +13,12 @@ public class ExportProfileParams extends AidlParams {
public static final String PROFILE_KEY = "profile";
public static final String SETTINGS_TYPE_KEY = "settings_type";
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;
for (ExportSettingsType settingsType : settingsTypeList) {
for (AExportSettingsType settingsType : settingsTypeList) {
settingsTypeKeyList.add(settingsType.name());
}
}

View file

@ -2253,7 +2253,19 @@ public class OsmandAidlApi {
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) {
if (profileUri != null) {
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) {
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) {
return COPY_FILE_PARAMS_ERROR;
}
@ -2391,7 +2403,7 @@ public class OsmandAidlApi {
} else if (fileName.endsWith(IndexConstants.GPX_FILE_EXT)) {
if (destinationDir.startsWith(IndexConstants.GPX_INDEX_DIR)
&& !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)) {
GPXUtilities.loadGPXFile(new File(destinationDir, fileName));
app.getFavorites().loadFavorites();
@ -2404,7 +2416,7 @@ public class OsmandAidlApi {
private int copyFileImpl(String fileName, byte[] filePartData, long startTime, boolean done, String destinationDir) {
File tempDir = FileUtils.getTempDir(app);
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();
try {
FileCopyInfo info = copyFilesCache.get(fileName);

View file

@ -1138,7 +1138,7 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
if (api == null) {
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) {
handleException(e);
return UNKNOWN_API_ERROR;
@ -1299,8 +1299,8 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
public boolean importProfile(ProfileSettingsParams params) {
try {
OsmandAidlApi api = getApi("importProfile");
return api != null && api.importProfile(params.getProfileSettingsUri(), params.getSettingsTypeKeys(),
params.isReplace(), params.getLatestChanges(), params.getVersion());
return api != null && api.importProfile(params.getProfileSettingsUri(), params.getLatestChanges(),
params.getVersion());
} catch (Exception e) {
handleException(e);
return false;

View file

@ -1092,7 +1092,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
if (api == null) {
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());
} catch (Exception e) {
handleException(e);
@ -1260,7 +1260,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
public boolean importProfile(ProfileSettingsParams params) {
try {
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());
} catch (Exception e) {
handleException(e);

View file

@ -4,20 +4,13 @@ import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import net.osmand.aidlapi.profile.ExportSettingsType;
import java.util.ArrayList;
public class ProfileSettingsParams implements Parcelable {
private Uri profileSettingsUri;
private String latestChanges;
private int version;
ArrayList<String> settingsTypeKeyList = new ArrayList<>();
boolean replace;
public ProfileSettingsParams(Uri profileSettingsUri, ArrayList<ExportSettingsType> settingsTypeList,
boolean replace, String latestChanges, int version) {
public ProfileSettingsParams(Uri profileSettingsUri, String latestChanges, int version) {
this.profileSettingsUri = profileSettingsUri;
this.latestChanges = latestChanges;
this.version = version;
@ -51,29 +44,17 @@ public class ProfileSettingsParams implements Parcelable {
return profileSettingsUri;
}
public ArrayList<String> getSettingsTypeKeys() {
return settingsTypeKeyList;
}
public boolean isReplace() {
return replace;
}
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(version);
out.writeString(latestChanges);
out.writeParcelable(profileSettingsUri, flags);
out.writeStringList(settingsTypeKeyList);
out.writeInt(replace ? 1 : 0);
}
private void readFromParcel(Parcel in) {
version = in.readInt();
latestChanges = in.readString();
profileSettingsUri = in.readParcelable(Uri.class.getClassLoader());
in.readStringList(settingsTypeKeyList);
replace = in.readInt() == 1;
}
@Override

View file

@ -701,9 +701,7 @@ public class ImportHelper {
private void handleOsmAndSettingsImport(Uri intentUri, String fileName, Bundle extras, CallbackWithObject<List<SettingsItem>> callback) {
if (extras != null && extras.containsKey(SETTINGS_VERSION_KEY)
&& extras.containsKey(REPLACE_KEY)
&& extras.containsKey(SETTINGS_LATEST_CHANGES_KEY)
&& extras.containsKey(SETTINGS_TYPE_LIST_KEY)) {
&& extras.containsKey(SETTINGS_LATEST_CHANGES_KEY)) {
int version = extras.getInt(SETTINGS_VERSION_KEY, -1);
String latestChanges = extras.getString(SETTINGS_LATEST_CHANGES_KEY);
boolean replace = extras.getBoolean(REPLACE_KEY);
@ -817,11 +815,7 @@ public class ImportHelper {
if (mapActivity != null && succeed) {
FragmentManager fm = mapActivity.getSupportFragmentManager();
app.getRendererRegistry().updateExternalRenderers();
AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
@Override
public void onRoutingFilesLoaded() {
}
});
AppInitializer.loadRoutingFiles(app, null);
if (file != null) {
ImportCompleteFragment.showInstance(fm, items, file.getName());
}

View file

@ -2931,14 +2931,13 @@ public class SettingsHelper {
IMPORT
}
public List<SettingsHelper.SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> additionalData,
public List<SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> additionalData,
List<ExportSettingsType> settingsTypes) {
List<SettingsHelper.SettingsItem> settingsItems = new ArrayList<>();
List<SettingsItem> settingsItems = new ArrayList<>();
for (ExportSettingsType settingsType : settingsTypes) {
List<?> settingsDataObjects = additionalData.get(settingsType);
if (settingsDataObjects != null) {
settingsItems.addAll(app.getSettingsHelper().prepareAdditionalSettingsItems(
new ArrayList<>(settingsDataObjects)));
settingsItems.addAll(prepareAdditionalSettingsItems(new ArrayList<>(settingsDataObjects)));
}
}
return settingsItems;

View file

@ -267,11 +267,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
FragmentManager fm = getFragmentManager();
if (succeed) {
app.getRendererRegistry().updateExternalRenderers();
AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
@Override
public void onRoutingFilesLoaded() {
}
});
AppInitializer.loadRoutingFiles(app, null);
if (fm != null && file != null) {
ImportCompleteFragment.showInstance(fm, items, file.getName());
}