Fix check for render and router plugin items

This commit is contained in:
Vitaliy 2020-03-25 22:02:05 +02:00
parent 3c61faa8c3
commit 0c52eeef18
5 changed files with 35 additions and 15 deletions

View file

@ -104,6 +104,14 @@ public class Algorithms {
return name.substring(i + 1);
}
public static String getFileWithoutDirs(String name) {
int i = name.lastIndexOf(File.separator);
if (i != -1) {
return name.substring(i + 1);
}
return name;
}
public static File[] getSortedFilesVersions(File dir) {
File[] listFiles = dir.listFiles();
if (listFiles != null) {

View file

@ -22,6 +22,7 @@ import net.osmand.plus.helpers.AvoidSpecificRoads;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionRegistry;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -135,8 +136,11 @@ public class CustomOsmandPlugin extends OsmandPlugin {
PoiUiFilterSettingsItem poiUiFilterSettingsItem = (PoiUiFilterSettingsItem) item;
List<PoiUIFilter> poiUIFilters = poiUiFilterSettingsItem.getItems();
for (PoiUIFilter filter : poiUIFilters) {
app.getPoiFilters().removePoiFilter(filter);
PoiUIFilter savedFilter = app.getPoiFilters().getFilterById(filter.getFilterId());
app.getPoiFilters().removePoiFilter(savedFilter);
}
app.getPoiFilters().reloadAllPoiFilters();
app.getPoiFilters().loadSelectedPoiFilters();
app.getSearchUICore().refreshCustomPoiFilters();
} else if (item instanceof AvoidRoadsSettingsItem) {
AvoidRoadsSettingsItem avoidRoadsSettingsItem = (AvoidRoadsSettingsItem) item;
@ -280,4 +284,9 @@ public class CustomOsmandPlugin extends OsmandPlugin {
public List<String> getRouterNames() {
return routerNames;
}
public void addRenderer(String fileName) {
String renderer = RendererRegistry.formatRenderFileName(fileName);
rendererNames.add(renderer.replace('_', ' ').replace('-', ' '));
}
}

View file

@ -372,9 +372,9 @@ public class SettingsHelper {
if (item instanceof SettingsHelper.FileSettingsItem) {
FileSettingsItem fileItem = (FileSettingsItem) item;
if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.RENDERING_STYLE) {
plugin.rendererNames.add(fileItem.getFileName());
plugin.addRenderer(fileItem.getName());
} else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.ROUTING_CONFIG) {
plugin.routerNames.add(fileItem.getFileName());
plugin.getRouterNames().add(fileItem.getName());
}
}
}
@ -1005,7 +1005,10 @@ public class SettingsHelper {
}
public static FileSubtype getSubtypeByFileName(@NonNull String fileName) {
String name = fileName.substring(1);
String name = fileName;
if (fileName.startsWith(File.separator)) {
name = fileName.substring(1);
}
for (FileSubtype subtype : FileSubtype.values()) {
if (subtype == ROUTING_CONFIG || subtype == RENDERING_STYLE) {
if (name.startsWith(subtype.subtypeFolder) || name.startsWith(subtype.subtypeName)) {
@ -1080,12 +1083,7 @@ public class SettingsHelper {
if (subtype == FileSubtype.OTHER) {
name = fileName;
} else if (subtype != null && subtype != FileSubtype.UNKNOWN) {
int index = fileName.lastIndexOf(File.separator);
if (index != -1) {
name = fileName.substring(index);
} else {
name = fileName;
}
name = Algorithms.getFileWithoutDirs(fileName);
}
}
}

View file

@ -261,8 +261,8 @@ public class RendererRegistry {
for (File f : lf) {
if (f != null && f.getName().endsWith(IndexConstants.ROUTING_AND_RENDERING_FILE_EXT)) {
if (!internalRenderers.containsValue(f.getName())) {
String name = f.getName().substring(0, f.getName().length() - IndexConstants.ROUTING_AND_RENDERING_FILE_EXT.length());
externalRenderers.put(name.replace('_', ' ').replace('-', ' '), f);
String name = formatRenderFileName(f.getName());
externalRenderers.put(name, f);
}
}
}
@ -271,6 +271,11 @@ public class RendererRegistry {
this.externalRenderers = externalRenderers;
}
public static String formatRenderFileName(String fileName) {
String name = fileName.substring(0, fileName.length() - IndexConstants.ROUTING_AND_RENDERING_FILE_EXT.length());
return name.replace('_', ' ').replace('-', ' ');
}
public Collection<String> getRendererNames(){
LinkedHashSet<String> names = new LinkedHashSet<String>();
names.add(DEFAULT_RENDER);

View file

@ -238,7 +238,7 @@ public class NavigationFragment extends BaseSettingsFragment {
for (Map.Entry<String, GeneralRouter> entry : builder.getAllRouters().entrySet()) {
String routerKey = entry.getKey();
GeneralRouter router = entry.getValue();
if (!routerKey.equals("geocoding") && !disabledRouterNames.contains(routerKey)) {
if (!routerKey.equals("geocoding") && !disabledRouterNames.contains(router.getFilename())) {
int iconRes = R.drawable.ic_action_gdirections_dark;
String name = router.getProfileName();
String description = app.getString(R.string.osmand_default_routing);