Let user disable plugin
This commit is contained in:
parent
0b86665092
commit
423a2dce6e
2 changed files with 28 additions and 9 deletions
|
@ -64,7 +64,6 @@ public abstract class OsmandPlugin {
|
|||
OsmandRasterMapsPlugin rasterMapsPlugin = new OsmandRasterMapsPlugin(app);
|
||||
installedPlugins.add(rasterMapsPlugin);
|
||||
installedPlugins.add(new OsmandMonitoringPlugin(app));
|
||||
// installedPlugins.add(new OsmandExtraSettings(app));
|
||||
installedPlugins.add(new AccessibilityPlugin(app));
|
||||
if(!installPlugin(SRTM_PLUGIN_COMPONENT_PAID, SRTMPlugin.ID, app,
|
||||
new SRTMPlugin(app, true))) {
|
||||
|
@ -278,12 +277,17 @@ public abstract class OsmandPlugin {
|
|||
} catch ( NameNotFoundException e){
|
||||
}
|
||||
|
||||
|
||||
if(installed) {
|
||||
installedPlugins.add(plugin);
|
||||
app.getSettings().enablePlugin(plugin.getId(), true);
|
||||
if(!app.getSettings().getPlugins().contains("-"+pluginId)) {
|
||||
app.getSettings().enablePlugin(pluginId, true);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
app.getSettings().enablePlugin(pluginId, false);
|
||||
if(app.getSettings().getPlugins().contains(pluginId)) {
|
||||
app.getSettings().enablePlugin(pluginId, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -483,10 +483,23 @@ public class OsmandSettings {
|
|||
///////////// PREFERENCES classes ////////////////
|
||||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
private final OsmandPreference<String> ENABLED_PLUGINS = new StringPreference("enabled_plugins", "").makeGlobal();
|
||||
private final OsmandPreference<String> PLUGINS = new StringPreference("enabled_plugins", "").makeGlobal();
|
||||
|
||||
public Set<String> getEnabledPlugins(){
|
||||
String plugs = ENABLED_PLUGINS.get();
|
||||
String plugs = PLUGINS.get();
|
||||
StringTokenizer toks = new StringTokenizer(plugs, ",");
|
||||
Set<String> res = new LinkedHashSet<String>();
|
||||
while(toks.hasMoreTokens()) {
|
||||
String tok = toks.nextToken();
|
||||
if(!tok.startsWith("-")) {
|
||||
res.add(tok);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public Set<String> getPlugins(){
|
||||
String plugs = PLUGINS.get();
|
||||
StringTokenizer toks = new StringTokenizer(plugs, ",");
|
||||
Set<String> res = new LinkedHashSet<String>();
|
||||
while(toks.hasMoreTokens()) {
|
||||
|
@ -496,11 +509,13 @@ public class OsmandSettings {
|
|||
}
|
||||
|
||||
public void enablePlugin(String pluginId, boolean enable){
|
||||
Set<String> set = getEnabledPlugins();
|
||||
if(enable){
|
||||
Set<String> set = getPlugins();
|
||||
if (enable) {
|
||||
set.remove("-" + pluginId);
|
||||
set.add(pluginId);
|
||||
} else {
|
||||
set.remove(pluginId);
|
||||
set.add("-" + pluginId);
|
||||
}
|
||||
StringBuilder serialization = new StringBuilder();
|
||||
Iterator<String> it = set.iterator();
|
||||
|
@ -510,8 +525,8 @@ public class OsmandSettings {
|
|||
serialization.append(",");
|
||||
}
|
||||
}
|
||||
if(!serialization.toString().equals(ENABLED_PLUGINS.get())) {
|
||||
ENABLED_PLUGINS.set(serialization.toString());
|
||||
if(!serialization.toString().equals(PLUGINS.get())) {
|
||||
PLUGINS.set(serialization.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue