Combine connected app and plugin in UI and add plugin version

This commit is contained in:
Vitaliy 2020-12-06 16:36:11 +02:00
parent e0189c904f
commit 2e5166b887
13 changed files with 159 additions and 34 deletions

View file

@ -77,6 +77,7 @@ import net.osmand.aidlapi.customization.OsmandSettingsInfoParams;
import net.osmand.aidlapi.customization.CustomizationInfoParams; import net.osmand.aidlapi.customization.CustomizationInfoParams;
import net.osmand.aidlapi.customization.ProfileSettingsParams; import net.osmand.aidlapi.customization.ProfileSettingsParams;
import net.osmand.aidlapi.customization.MapMarginsParams; import net.osmand.aidlapi.customization.MapMarginsParams;
import net.osmand.aidlapi.customization.CustomPluginParams;
import net.osmand.aidlapi.gpx.AGpxFile; import net.osmand.aidlapi.gpx.AGpxFile;
import net.osmand.aidlapi.gpx.AGpxFileDetails; import net.osmand.aidlapi.gpx.AGpxFileDetails;
@ -883,4 +884,6 @@ interface IOsmAndAidlInterface {
* Is contect menu open. * Is contect menu open.
*/ */
boolean isMenuOpen(); boolean isMenuOpen();
int getPluginVersion(in CustomPluginParams params);
} }

View file

@ -0,0 +1,3 @@
package net.osmand.aidlapi.customization;
parcelable CustomPluginParams;

View file

@ -0,0 +1,48 @@
package net.osmand.aidlapi.customization;
import android.os.Bundle;
import android.os.Parcel;
import net.osmand.aidlapi.AidlParams;
public class CustomPluginParams extends AidlParams {
public static final String PLUGIN_ID_KEY = "plugin_id";
private String pluginId;
public CustomPluginParams(String pluginId) {
this.pluginId = pluginId;
}
public CustomPluginParams(Parcel in) {
readFromParcel(in);
}
public static final Creator<CustomPluginParams> CREATOR = new Creator<CustomPluginParams>() {
@Override
public CustomPluginParams createFromParcel(Parcel in) {
return new CustomPluginParams(in);
}
@Override
public CustomPluginParams[] newArray(int size) {
return new CustomPluginParams[size];
}
};
public String getPluginId() {
return pluginId;
}
@Override
public void writeToBundle(Bundle bundle) {
bundle.putString(PLUGIN_ID_KEY, pluginId);
}
@Override
protected void readFromBundle(Bundle bundle) {
pluginId = bundle.getString(PLUGIN_ID_KEY);
}
}

View file

@ -50,6 +50,7 @@ import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.AppInitializer.InitEvents; import net.osmand.plus.AppInitializer.InitEvents;
import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.CustomOsmandPlugin;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
@ -125,6 +126,7 @@ import static net.osmand.aidl.ConnectedApp.AIDL_OBJECT_ID;
import static net.osmand.aidl.ConnectedApp.AIDL_PACKAGE_NAME; import static net.osmand.aidl.ConnectedApp.AIDL_PACKAGE_NAME;
import static net.osmand.aidl.ConnectedApp.AIDL_REMOVE_MAP_LAYER; import static net.osmand.aidl.ConnectedApp.AIDL_REMOVE_MAP_LAYER;
import static net.osmand.aidl.ConnectedApp.AIDL_REMOVE_MAP_WIDGET; import static net.osmand.aidl.ConnectedApp.AIDL_REMOVE_MAP_WIDGET;
import static net.osmand.aidlapi.OsmandAidlConstants.CANNOT_ACCESS_API_ERROR;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_IO_ERROR; import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_IO_ERROR;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_MAX_LOCK_TIME_MS; import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_MAX_LOCK_TIME_MS;
import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_PARAMS_ERROR; import static net.osmand.aidlapi.OsmandAidlConstants.COPY_FILE_PARAMS_ERROR;
@ -140,6 +142,7 @@ import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DIRECTION_TURN;
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DISTANCE; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_DISTANCE;
import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_IMMINENT; import static net.osmand.plus.helpers.ExternalApiHelper.PARAM_NT_IMMINENT;
import static net.osmand.plus.settings.backend.backup.SettingsHelper.REPLACE_KEY; import static net.osmand.plus.settings.backend.backup.SettingsHelper.REPLACE_KEY;
import static net.osmand.plus.settings.backend.backup.SettingsHelper.SILENT_IMPORT_KEY;
public class OsmandAidlApi { public class OsmandAidlApi {
@ -2238,6 +2241,7 @@ public class OsmandAidlApi {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putStringArrayList(SettingsHelper.SETTINGS_TYPE_LIST_KEY, settingsTypeKeys); bundle.putStringArrayList(SettingsHelper.SETTINGS_TYPE_LIST_KEY, settingsTypeKeys);
bundle.putBoolean(REPLACE_KEY, replace); bundle.putBoolean(REPLACE_KEY, replace);
bundle.putBoolean(SILENT_IMPORT_KEY, true);
bundle.putString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY, latestChanges); bundle.putString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY, latestChanges);
bundle.putInt(SettingsHelper.SETTINGS_VERSION_KEY, version); bundle.putInt(SettingsHelper.SETTINGS_VERSION_KEY, version);
@ -2324,6 +2328,15 @@ public class OsmandAidlApi {
return mapActivity.getContextMenu().isVisible(); return mapActivity.getContextMenu().isVisible();
} }
public int getPluginVersion(String pluginName) {
OsmandPlugin plugin = OsmandPlugin.getPlugin(pluginName);
if (plugin instanceof CustomOsmandPlugin) {
CustomOsmandPlugin customPlugin = (CustomOsmandPlugin) plugin;
return customPlugin.getVersion();
}
return CANNOT_ACCESS_API_ERROR;
}
private static class FileCopyInfo { private static class FileCopyInfo {
long startTime; long startTime;
long lastAccessTime; long lastAccessTime;

View file

@ -22,9 +22,9 @@ import net.osmand.aidlapi.contextmenu.ContextMenuButtonsParams;
import net.osmand.aidlapi.contextmenu.RemoveContextMenuButtonsParams; import net.osmand.aidlapi.contextmenu.RemoveContextMenuButtonsParams;
import net.osmand.aidlapi.contextmenu.UpdateContextMenuButtonsParams; import net.osmand.aidlapi.contextmenu.UpdateContextMenuButtonsParams;
import net.osmand.aidlapi.copyfile.CopyFileParams; import net.osmand.aidlapi.copyfile.CopyFileParams;
import net.osmand.aidlapi.customization.MapMarginsParams; import net.osmand.aidlapi.customization.CustomPluginParams;
import net.osmand.aidlapi.info.AppInfoParams;
import net.osmand.aidlapi.customization.CustomizationInfoParams; import net.osmand.aidlapi.customization.CustomizationInfoParams;
import net.osmand.aidlapi.customization.MapMarginsParams;
import net.osmand.aidlapi.customization.OsmandSettingsInfoParams; import net.osmand.aidlapi.customization.OsmandSettingsInfoParams;
import net.osmand.aidlapi.customization.OsmandSettingsParams; import net.osmand.aidlapi.customization.OsmandSettingsParams;
import net.osmand.aidlapi.customization.ProfileSettingsParams; import net.osmand.aidlapi.customization.ProfileSettingsParams;
@ -48,6 +48,7 @@ import net.osmand.aidlapi.gpx.RemoveGpxParams;
import net.osmand.aidlapi.gpx.ShowGpxParams; import net.osmand.aidlapi.gpx.ShowGpxParams;
import net.osmand.aidlapi.gpx.StartGpxRecordingParams; import net.osmand.aidlapi.gpx.StartGpxRecordingParams;
import net.osmand.aidlapi.gpx.StopGpxRecordingParams; import net.osmand.aidlapi.gpx.StopGpxRecordingParams;
import net.osmand.aidlapi.info.AppInfoParams;
import net.osmand.aidlapi.lock.SetLockStateParams; import net.osmand.aidlapi.lock.SetLockStateParams;
import net.osmand.aidlapi.map.ALatLon; import net.osmand.aidlapi.map.ALatLon;
import net.osmand.aidlapi.map.SetMapLocationParams; import net.osmand.aidlapi.map.SetMapLocationParams;
@ -1122,6 +1123,7 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
return UNKNOWN_API_ERROR; return UNKNOWN_API_ERROR;
} }
} }
@Override @Override
public long registerForKeyEvents(AKeyEventsParams params, final IOsmAndAidlCallback callback) { public long registerForKeyEvents(AKeyEventsParams params, final IOsmAndAidlCallback callback) {
try { try {
@ -1356,6 +1358,20 @@ public class OsmandAidlServiceV2 extends Service implements AidlCallbackListener
return false; return false;
} }
} }
@Override
public int getPluginVersion(CustomPluginParams params) {
try {
OsmandAidlApi api = getApi("getPluginVersion");
if (api != null) {
return api.getPluginVersion(params.getPluginId());
}
} catch (Exception e) {
handleException(e);
return UNKNOWN_API_ERROR;
}
return CANNOT_ACCESS_API_ERROR;
}
}; };
private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) { private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) {

View file

@ -17,16 +17,6 @@ import net.osmand.PlatformUtil;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.map.WorldRegion; import net.osmand.map.WorldRegion;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.backup.SettingsHelper;
import net.osmand.plus.settings.backend.backup.AvoidRoadsSettingsItem;
import net.osmand.plus.settings.backend.backup.MapSourcesSettingsItem;
import net.osmand.plus.settings.backend.backup.PluginSettingsItem;
import net.osmand.plus.settings.backend.backup.PoiUiFiltersSettingsItem;
import net.osmand.plus.settings.backend.backup.ProfileSettingsItem;
import net.osmand.plus.settings.backend.backup.QuickActionsSettingsItem;
import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsCollectListener;
import net.osmand.plus.settings.backend.backup.SettingsItem;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadResources;
@ -35,6 +25,16 @@ import net.osmand.plus.helpers.AvoidSpecificRoads;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.quickaction.QuickActionRegistry;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.backup.AvoidRoadsSettingsItem;
import net.osmand.plus.settings.backend.backup.MapSourcesSettingsItem;
import net.osmand.plus.settings.backend.backup.PluginSettingsItem;
import net.osmand.plus.settings.backend.backup.PoiUiFiltersSettingsItem;
import net.osmand.plus.settings.backend.backup.ProfileSettingsItem;
import net.osmand.plus.settings.backend.backup.QuickActionsSettingsItem;
import net.osmand.plus.settings.backend.backup.SettingsHelper;
import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsCollectListener;
import net.osmand.plus.settings.backend.backup.SettingsItem;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -73,9 +73,12 @@ public class CustomOsmandPlugin extends OsmandPlugin {
private List<SuggestedDownloadItem> suggestedDownloadItems = new ArrayList<>(); private List<SuggestedDownloadItem> suggestedDownloadItems = new ArrayList<>();
private List<WorldRegion> customRegions = new ArrayList<>(); private List<WorldRegion> customRegions = new ArrayList<>();
private int version;
public CustomOsmandPlugin(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException { public CustomOsmandPlugin(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(app); super(app);
pluginId = json.getString("pluginId"); pluginId = json.getString("pluginId");
version = json.optInt("version", -1);
readAdditionalDataFromJson(json); readAdditionalDataFromJson(json);
readDependentFilesFromJson(json); readDependentFilesFromJson(json);
loadResources(); loadResources();
@ -86,6 +89,11 @@ public class CustomOsmandPlugin extends OsmandPlugin {
return pluginId; return pluginId;
} }
@Override
public int getVersion() {
return version;
}
@Override @Override
public String getName() { public String getName() {
return JsonUtils.getLocalizedResFromMap(app, names, app.getString(R.string.custom_osmand_plugin)); return JsonUtils.getLocalizedResFromMap(app, names, app.getString(R.string.custom_osmand_plugin));

View file

@ -123,8 +123,8 @@ public abstract class OsmandPlugin {
return null; return null;
} }
public String getVersion() { public int getVersion() {
return ""; return -1;
} }
/** /**
@ -340,6 +340,7 @@ public abstract class OsmandPlugin {
try { try {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("pluginId", plugin.getId()); json.put("pluginId", plugin.getId());
json.put("version", plugin.getVersion());
plugin.writeAdditionalDataToJson(json); plugin.writeAdditionalDataToJson(json);
plugin.writeDependentFilesJson(json); plugin.writeDependentFilesJson(json);
itemsJson.put(json); itemsJson.put(json);

View file

@ -42,6 +42,8 @@ import net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenTyp
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class PluginsFragment extends BaseOsmAndFragment implements PluginStateListener { public class PluginsFragment extends BaseOsmAndFragment implements PluginStateListener {
@ -138,6 +140,10 @@ public class PluginsFragment extends BaseOsmAndFragment implements PluginStateLi
private void switchEnabled(@NonNull ConnectedApp connectedApp) { private void switchEnabled(@NonNull ConnectedApp connectedApp) {
app.getAidlApi().switchEnabled(connectedApp); app.getAidlApi().switchEnabled(connectedApp);
OsmandPlugin plugin = OsmandPlugin.getPlugin(connectedApp.getPack());
if (plugin != null) {
OsmandPlugin.enablePlugin(getActivity(), app, plugin, connectedApp.isEnabled());
}
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
} }
@ -150,8 +156,26 @@ public class PluginsFragment extends BaseOsmAndFragment implements PluginStateLi
PluginsListAdapter(Context context) { PluginsListAdapter(Context context) {
super(context, R.layout.plugins_list_item, new ArrayList<>()); super(context, R.layout.plugins_list_item, new ArrayList<>());
addAll(app.getAidlApi().getConnectedApps()); addAll(getFilteredPluginsAndApps());
addAll(OsmandPlugin.getVisiblePlugins()); }
private List<Object> getFilteredPluginsAndApps() {
List<ConnectedApp> connectedApps = app.getAidlApi().getConnectedApps();
List<OsmandPlugin> visiblePlugins = OsmandPlugin.getVisiblePlugins();
for (Iterator<OsmandPlugin> iterator = visiblePlugins.iterator(); iterator.hasNext(); ) {
OsmandPlugin plugin = iterator.next();
for (ConnectedApp app : connectedApps) {
if (plugin.getId().equals(app.getPack())) {
iterator.remove();
}
}
}
List<Object> list = new ArrayList<>();
list.addAll(connectedApps);
list.addAll(visiblePlugins);
return list;
} }
@NonNull @NonNull

View file

@ -70,6 +70,7 @@ import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
import static net.osmand.plus.settings.backend.backup.SettingsHelper.REPLACE_KEY; import static net.osmand.plus.settings.backend.backup.SettingsHelper.REPLACE_KEY;
import static net.osmand.plus.settings.backend.backup.SettingsHelper.SETTINGS_TYPE_LIST_KEY; import static net.osmand.plus.settings.backend.backup.SettingsHelper.SETTINGS_TYPE_LIST_KEY;
import static net.osmand.plus.settings.backend.backup.SettingsHelper.SILENT_IMPORT_KEY;
/** /**
* @author Koen Rabaey * @author Koen Rabaey
@ -267,6 +268,7 @@ public class ImportHelper {
int version = extras.getInt(SettingsHelper.SETTINGS_VERSION_KEY, -1); int version = extras.getInt(SettingsHelper.SETTINGS_VERSION_KEY, -1);
String latestChanges = extras.getString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY); String latestChanges = extras.getString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY);
boolean replace = extras.getBoolean(REPLACE_KEY); boolean replace = extras.getBoolean(REPLACE_KEY);
boolean silentImport = extras.getBoolean(SILENT_IMPORT_KEY);
ArrayList<String> settingsTypeKeys = extras.getStringArrayList(SETTINGS_TYPE_LIST_KEY); ArrayList<String> settingsTypeKeys = extras.getStringArrayList(SETTINGS_TYPE_LIST_KEY);
List<ExportSettingsType> settingsTypes = null; List<ExportSettingsType> settingsTypes = null;
if (settingsTypeKeys != null) { if (settingsTypeKeys != null) {
@ -275,18 +277,18 @@ public class ImportHelper {
settingsTypes.add(ExportSettingsType.valueOf(key)); settingsTypes.add(ExportSettingsType.valueOf(key));
} }
} }
handleOsmAndSettingsImport(intentUri, fileName, settingsTypes, replace, latestChanges, version, callback); handleOsmAndSettingsImport(intentUri, fileName, settingsTypes, replace, silentImport, latestChanges, version, callback);
} else { } else {
handleOsmAndSettingsImport(intentUri, fileName, null, false, null, -1, handleOsmAndSettingsImport(intentUri, fileName, null, false, false, null, -1,
callback); callback);
} }
} }
protected void handleOsmAndSettingsImport(Uri uri, String name, final List<ExportSettingsType> settingsTypes, protected void handleOsmAndSettingsImport(Uri uri, String name, final List<ExportSettingsType> settingsTypes,
final boolean replace, String latestChanges, int version, final boolean replace, boolean silentImport, String latestChanges, int version,
CallbackWithObject<List<SettingsItem>> callback) { CallbackWithObject<List<SettingsItem>> callback) {
executeImportTask(new SettingsImportTask(activity, uri, name, settingsTypes, replace, latestChanges, version, executeImportTask(new SettingsImportTask(activity, uri, name, settingsTypes, replace, silentImport,
callback)); latestChanges, version, callback));
} }
protected void handleXmlFileImport(Uri intentUri, String fileName, CallbackWithObject routingCallback) { protected void handleXmlFileImport(Uri intentUri, String fileName, CallbackWithObject routingCallback) {

View file

@ -17,10 +17,10 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseLoadAsyncTask; import net.osmand.plus.base.BaseLoadAsyncTask;
import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.ExportSettingsType;
import net.osmand.plus.settings.backend.backup.SettingsHelper;
import net.osmand.plus.settings.backend.backup.SettingsHelper.CheckDuplicatesListener;
import net.osmand.plus.settings.backend.backup.PluginSettingsItem; import net.osmand.plus.settings.backend.backup.PluginSettingsItem;
import net.osmand.plus.settings.backend.backup.ProfileSettingsItem; import net.osmand.plus.settings.backend.backup.ProfileSettingsItem;
import net.osmand.plus.settings.backend.backup.SettingsHelper;
import net.osmand.plus.settings.backend.backup.SettingsHelper.CheckDuplicatesListener;
import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsCollectListener; import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsCollectListener;
import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsImportListener; import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsImportListener;
import net.osmand.plus.settings.backend.backup.SettingsItem; import net.osmand.plus.settings.backend.backup.SettingsItem;
@ -42,19 +42,21 @@ class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
private String name; private String name;
private List<ExportSettingsType> settingsTypes; private List<ExportSettingsType> settingsTypes;
private boolean replace; private boolean replace;
private boolean silentImport;
private String latestChanges; private String latestChanges;
private int version; private int version;
private CallbackWithObject<List<SettingsItem>> callback; private CallbackWithObject<List<SettingsItem>> callback;
public SettingsImportTask(@NonNull FragmentActivity activity, @NonNull Uri uri, public SettingsImportTask(@NonNull FragmentActivity activity, @NonNull Uri uri,
@NonNull String name, List<ExportSettingsType> settingsTypes, @NonNull String name, List<ExportSettingsType> settingsTypes,
boolean replace, String latestChanges, int version, boolean replace, boolean silentImport, String latestChanges, int version,
CallbackWithObject<List<SettingsItem>> callback) { CallbackWithObject<List<SettingsItem>> callback) {
super(activity); super(activity);
this.uri = uri; this.uri = uri;
this.name = name; this.name = name;
this.settingsTypes = settingsTypes; this.settingsTypes = settingsTypes;
this.replace = replace; this.replace = replace;
this.silentImport = silentImport;
this.latestChanges = latestChanges; this.latestChanges = latestChanges;
this.version = version; this.version = version;
this.callback = callback; this.callback = callback;
@ -93,7 +95,7 @@ class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
if (!pluginIndependentItems.isEmpty()) { if (!pluginIndependentItems.isEmpty()) {
if (settingsTypes == null) { if (settingsTypes == null) {
FragmentActivity activity = activityRef.get(); FragmentActivity activity = activityRef.get();
if (activity != null) { if (!silentImport && activity != null) {
FragmentManager fragmentManager = activity.getSupportFragmentManager(); FragmentManager fragmentManager = activity.getSupportFragmentManager();
ImportSettingsFragment.showInstance(fragmentManager, pluginIndependentItems, file); ImportSettingsFragment.showInstance(fragmentManager, pluginIndependentItems, file);
} }
@ -141,7 +143,7 @@ class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
((MapActivity) activity).getMapLayers().getMapWidgetRegistry().updateVisibleWidgets(); ((MapActivity) activity).getMapLayers().getMapWidgetRegistry().updateVisibleWidgets();
((MapActivity) activity).updateApplicationModeSettings(); ((MapActivity) activity).updateApplicationModeSettings();
} }
if (file != null && activity != null) { if (!silentImport && file != null && activity != null) {
FragmentManager fm = activity.getSupportFragmentManager(); FragmentManager fm = activity.getSupportFragmentManager();
ImportCompleteFragment.showInstance(fm, items, file.getName()); ImportCompleteFragment.showInstance(fm, items, file.getName());
} }
@ -188,11 +190,14 @@ class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
if (!Algorithms.isEmpty(plugin.getRouterNames())) { if (!Algorithms.isEmpty(plugin.getRouterNames())) {
loadRoutingFiles(app, null); loadRoutingFiles(app, null);
} }
if (activity != null) { if (!silentImport && activity != null) {
plugin.onInstall(app, activity); plugin.onInstall(app, activity);
} }
String pluginId = pluginItem.getPluginId(); String pluginId = pluginItem.getPluginId();
File pluginDir = new File(app.getAppPath(null), IndexConstants.PLUGINS_DIR + pluginId); File pluginDir = app.getAppPath(IndexConstants.PLUGINS_DIR + pluginId);
if (!pluginDir.exists()) {
pluginDir.mkdirs();
}
app.getSettingsHelper().exportSettings(pluginDir, "items", null, items, false); app.getSettingsHelper().exportSettings(pluginDir, "items", null, items, false);
} }
}; };

View file

@ -86,7 +86,7 @@ public class ZipImportTask extends BaseLoadAsyncTask<Void, Void, ImportType> {
} else if (importType == ImportType.SETTINGS) { } else if (importType == ImportType.SETTINGS) {
String name = createUniqueFileName(app, "settings", TEMP_DIR, OSMAND_SETTINGS_FILE_EXT); String name = createUniqueFileName(app, "settings", TEMP_DIR, OSMAND_SETTINGS_FILE_EXT);
importHelper.handleOsmAndSettingsImport(uri, name + OSMAND_SETTINGS_FILE_EXT, importHelper.handleOsmAndSettingsImport(uri, name + OSMAND_SETTINGS_FILE_EXT,
null, false, null, -1, null); null, false, false, null, -1, null);
} }
} }
} }

View file

@ -99,6 +99,7 @@ public class PluginSettingsItem extends SettingsItem {
@Override @Override
void writeToJson(@NonNull JSONObject json) throws JSONException { void writeToJson(@NonNull JSONObject json) throws JSONException {
super.writeToJson(json); super.writeToJson(json);
json.put("version", plugin.getVersion());
plugin.writeAdditionalDataToJson(json); plugin.writeAdditionalDataToJson(json);
} }

View file

@ -95,6 +95,7 @@ public class SettingsHelper {
public static final String SETTINGS_TYPE_LIST_KEY = "settings_type_list_key"; public static final String SETTINGS_TYPE_LIST_KEY = "settings_type_list_key";
public static final String REPLACE_KEY = "replace"; public static final String REPLACE_KEY = "replace";
public static final String SILENT_IMPORT_KEY = "silent_import";
public static final String SETTINGS_LATEST_CHANGES_KEY = "settings_latest_changes"; public static final String SETTINGS_LATEST_CHANGES_KEY = "settings_latest_changes";
public static final String SETTINGS_VERSION_KEY = "settings_version"; public static final String SETTINGS_VERSION_KEY = "settings_version";