use of net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem in project Osmand by osmandapp.
the class SettingsItemsFactory method createItem.
@Nullable
private SettingsItem createItem(@NonNull JSONObject json) throws IllegalArgumentException, JSONException {
SettingsItem item = null;
SettingsItemType type = SettingsItem.parseItemType(json);
if (type == null) {
return null;
}
OsmandSettings settings = app.getSettings();
switch(type) {
case GLOBAL:
item = new GlobalSettingsItem(settings, json);
break;
case PROFILE:
item = new ProfileSettingsItem(app, json);
break;
case PLUGIN:
item = new PluginSettingsItem(app, json);
break;
case DATA:
item = new DataSettingsItem(app, json);
break;
case FILE:
item = new FileSettingsItem(app, json);
break;
case RESOURCES:
item = new ResourcesSettingsItem(app, json);
break;
case QUICK_ACTIONS:
item = new QuickActionsSettingsItem(app, json);
break;
case POI_UI_FILTERS:
item = new PoiUiFiltersSettingsItem(app, json);
break;
case MAP_SOURCES:
item = new MapSourcesSettingsItem(app, json);
break;
case AVOID_ROADS:
item = new AvoidRoadsSettingsItem(app, json);
break;
case SUGGESTED_DOWNLOADS:
item = new SuggestedDownloadsItem(app, json);
break;
case DOWNLOADS:
item = new DownloadsItem(app, json);
break;
case OSM_NOTES:
item = new OsmNotesSettingsItem(app, json);
break;
case OSM_EDITS:
item = new OsmEditsSettingsItem(app, json);
break;
case FAVOURITES:
item = new FavoritesSettingsItem(app, json);
break;
case ACTIVE_MARKERS:
item = new MarkersSettingsItem(app, json);
break;
case HISTORY_MARKERS:
item = new HistoryMarkersSettingsItem(app, json);
break;
case SEARCH_HISTORY:
item = new SearchHistorySettingsItem(app, json);
break;
case GPX:
item = new GpxSettingsItem(app, json);
break;
case ONLINE_ROUTING_ENGINES:
item = new OnlineRoutingSettingsItem(app, json);
break;
case ITINERARY_GROUPS:
item = new ItinerarySettingsItem(app, json);
break;
}
return item;
}
use of net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem in project Osmand by osmandapp.
the class SettingsHelper method getBaseProfileSettingsItem.
@Nullable
private ProfileSettingsItem getBaseProfileSettingsItem(ApplicationModeBean modeBean, List<SettingsItem> settingsItems) {
for (SettingsItem settingsItem : settingsItems) {
if (settingsItem.getType() == SettingsItemType.PROFILE) {
ProfileSettingsItem profileItem = (ProfileSettingsItem) settingsItem;
ApplicationModeBean bean = profileItem.getModeBean();
if (Algorithms.objectEquals(bean.stringKey, modeBean.stringKey) && Algorithms.objectEquals(bean.userProfileName, modeBean.userProfileName)) {
return profileItem;
}
}
}
return null;
}
use of net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem in project Osmand by osmandapp.
the class OsmandAidlApi method exportProfile.
public boolean exportProfile(String appModeKey, List<String> settingsTypesKeys) {
ApplicationMode appMode = ApplicationMode.valueOfStringKey(appModeKey, null);
if (app != null && appMode != null) {
List<ExportSettingsType> settingsTypes = new ArrayList<>();
for (String key : settingsTypesKeys) {
settingsTypes.add(ExportSettingsType.valueOf(key));
}
settingsTypes.remove(ExportSettingsType.PROFILE);
List<SettingsItem> settingsItems = new ArrayList<>();
settingsItems.add(new ProfileSettingsItem(app, appMode));
File exportDir = app.getSettings().getExternalStorageDirectory();
String fileName = appMode.toHumanString();
FileSettingsHelper settingsHelper = app.getFileSettingsHelper();
settingsItems.addAll(settingsHelper.getFilteredSettingsItems(settingsTypes, true, false));
settingsHelper.exportSettings(exportDir, fileName, null, settingsItems, true);
return true;
}
return false;
}
use of net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem in project Osmand by osmandapp.
the class ItemViewHolder method getItemIcon.
@Nullable
protected Drawable getItemIcon(@NonNull SettingsItem item) {
if (item instanceof ProfileSettingsItem) {
ProfileSettingsItem profileItem = (ProfileSettingsItem) item;
ApplicationMode mode = profileItem.getAppMode();
return getContentIcon(mode.getIconRes());
}
ExportSettingsType type = ExportSettingsType.getExportSettingsTypeForItem(item);
if (type != null) {
return getContentIcon(type.getIconRes());
}
return null;
}
use of net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem in project Osmand by osmandapp.
the class CustomOsmandPlugin method removePluginItemsFromFile.
private void removePluginItemsFromFile(final File file, final PluginItemsListener itemsListener) {
app.getFileSettingsHelper().collectSettings(file, "", 1, new CollectListener() {
@Override
public void onCollectFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items) {
if (succeed && !items.isEmpty()) {
for (SettingsItem item : items) {
if (item instanceof QuickActionsSettingsItem) {
QuickActionsSettingsItem quickActionsSettingsItem = (QuickActionsSettingsItem) item;
List<QuickAction> quickActions = quickActionsSettingsItem.getItems();
QuickActionRegistry actionRegistry = app.getQuickActionRegistry();
for (QuickAction action : quickActions) {
QuickAction savedAction = actionRegistry.getQuickAction(app, action.getType(), action.getName(app), action.getParams());
if (savedAction != null) {
actionRegistry.deleteQuickAction(savedAction);
}
}
} else if (item instanceof MapSourcesSettingsItem) {
MapSourcesSettingsItem mapSourcesSettingsItem = (MapSourcesSettingsItem) item;
List<ITileSource> mapSources = mapSourcesSettingsItem.getItems();
for (ITileSource tileSource : mapSources) {
String tileSourceName = tileSource.getName();
if (tileSource instanceof SQLiteTileSource) {
tileSourceName += SQLITE_EXT;
}
ITileSource savedTileSource = app.getSettings().getTileSourceByName(tileSourceName, false);
if (savedTileSource != null) {
if (savedTileSource instanceof SQLiteTileSource) {
SQLiteTileSource sqLiteTileSource = ((SQLiteTileSource) savedTileSource);
sqLiteTileSource.closeDB();
}
File tPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR);
File dir = new File(tPath, tileSourceName);
Algorithms.removeAllFiles(dir);
}
}
} else if (item instanceof PoiUiFiltersSettingsItem) {
PoiUiFiltersSettingsItem poiUiFiltersSettingsItem = (PoiUiFiltersSettingsItem) item;
List<PoiUIFilter> poiUIFilters = poiUiFiltersSettingsItem.getItems();
for (PoiUIFilter filter : poiUIFilters) {
app.getPoiFilters().removePoiFilter(filter);
}
app.getPoiFilters().reloadAllPoiFilters();
app.getPoiFilters().loadSelectedPoiFilters();
app.getSearchUICore().refreshCustomPoiFilters();
} else if (item instanceof AvoidRoadsSettingsItem) {
AvoidRoadsSettingsItem avoidRoadsSettingsItem = (AvoidRoadsSettingsItem) item;
List<AvoidSpecificRoads.AvoidRoadInfo> avoidRoadInfos = avoidRoadsSettingsItem.getItems();
for (AvoidSpecificRoads.AvoidRoadInfo avoidRoad : avoidRoadInfos) {
app.getAvoidSpecificRoads().removeImpassableRoad(avoidRoad);
}
} else if (item instanceof ProfileSettingsItem) {
ProfileSettingsItem profileSettingsItem = (ProfileSettingsItem) item;
ApplicationMode mode = profileSettingsItem.getAppMode();
ApplicationMode savedMode = ApplicationMode.valueOfStringKey(mode.getStringKey(), null);
if (savedMode != null) {
ApplicationMode.changeProfileAvailability(savedMode, false, app);
}
}
}
}
if (itemsListener != null) {
itemsListener.onItemsRemoved();
}
}
});
}
Aggregations