Fix check for market plugins
This commit is contained in:
parent
8b038fc5ed
commit
687607698d
7 changed files with 134 additions and 70 deletions
|
@ -56,8 +56,6 @@ public abstract class OsmandPlugin {
|
|||
private static List<OsmandPlugin> allPlugins = new ArrayList<OsmandPlugin>();
|
||||
private static final Log LOG = PlatformUtil.getLog(OsmandPlugin.class);
|
||||
|
||||
private static final String SRTM_PLUGIN_COMPONENT_PAID = "net.osmand.srtmPlugin.paid"; //$NON-NLS-1$
|
||||
private static final String SRTM_PLUGIN_COMPONENT = "net.osmand.srtmPlugin";
|
||||
private boolean active;
|
||||
private String installURL = null;
|
||||
|
||||
|
@ -99,6 +97,14 @@ public abstract class OsmandPlugin {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean isMarketPlugin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPaid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean needsInstallation() {
|
||||
return installURL != null;
|
||||
}
|
||||
|
@ -111,6 +117,14 @@ public abstract class OsmandPlugin {
|
|||
return installURL;
|
||||
}
|
||||
|
||||
public String getComponentId1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getComponentId2() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ApplicationMode> getAddedAppModes() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -167,15 +181,15 @@ public abstract class OsmandPlugin {
|
|||
|
||||
allPlugins.add(new OsmandRasterMapsPlugin(app));
|
||||
allPlugins.add(new OsmandMonitoringPlugin(app));
|
||||
checkMarketPlugin(app, new SRTMPlugin(app), true, SRTM_PLUGIN_COMPONENT_PAID, SRTM_PLUGIN_COMPONENT);
|
||||
checkMarketPlugin(app, new SRTMPlugin(app));
|
||||
|
||||
// ? questionable - definitely not market plugin
|
||||
// checkMarketPlugin(app, enabledPlugins, new TouringViewPlugin(app), false, TouringViewPlugin.COMPONENT, null);
|
||||
checkMarketPlugin(app, new NauticalMapsPlugin(app), false, NauticalMapsPlugin.COMPONENT, null);
|
||||
checkMarketPlugin(app, new SkiMapsPlugin(app), false, SkiMapsPlugin.COMPONENT, null);
|
||||
checkMarketPlugin(app, new NauticalMapsPlugin(app));
|
||||
checkMarketPlugin(app, new SkiMapsPlugin(app));
|
||||
|
||||
allPlugins.add(new AudioVideoNotesPlugin(app));
|
||||
checkMarketPlugin(app, new ParkingPositionPlugin(app), false, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null);
|
||||
checkMarketPlugin(app, new ParkingPositionPlugin(app));
|
||||
allPlugins.add(new AccessibilityPlugin(app));
|
||||
allPlugins.add(new OsmEditingPlugin(app));
|
||||
allPlugins.add(new OsmandDevelopmentPlugin(app));
|
||||
|
@ -193,7 +207,9 @@ public abstract class OsmandPlugin {
|
|||
}
|
||||
|
||||
public static void updateActivatedPlugins(OsmandApplication app) {
|
||||
checkMarketPlugins(app);
|
||||
for (OsmandPlugin plugin : OsmandPlugin.getMarketPlugins()) {
|
||||
updateMarketPlugin(app, plugin);
|
||||
}
|
||||
Set<String> enabledPlugins = app.getSettings().getEnabledPlugins();
|
||||
for (OsmandPlugin plugin : allPlugins) {
|
||||
if (enabledPlugins.contains(plugin.getId())) {
|
||||
|
@ -215,17 +231,16 @@ public abstract class OsmandPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
private static void checkMarketPlugin(@NonNull OsmandApplication app, @NonNull OsmandPlugin plugin,
|
||||
boolean paid, String id, String id2) {
|
||||
if (updateMarketPlugin(app, plugin, paid, id, id2)) {
|
||||
private static void checkMarketPlugin(@NonNull OsmandApplication app, @NonNull OsmandPlugin plugin) {
|
||||
if (updateMarketPlugin(app, plugin)) {
|
||||
allPlugins.add(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean updateMarketPlugin(@NonNull OsmandApplication app, @NonNull OsmandPlugin plugin,
|
||||
boolean paid, String id, String id2) {
|
||||
private static boolean updateMarketPlugin(@NonNull OsmandApplication app, @NonNull OsmandPlugin plugin) {
|
||||
boolean marketEnabled = Version.isMarketEnabled(app);
|
||||
boolean pckg = checkPackage(app, id, id2);
|
||||
boolean pckg = checkPluginPackage(app, plugin);
|
||||
boolean paid = plugin.isPaid();
|
||||
if ((Version.isDeveloperVersion(app) || !Version.isProductionVersion(app)) && !paid) {
|
||||
// for test reasons
|
||||
marketEnabled = false;
|
||||
|
@ -243,66 +258,41 @@ public abstract class OsmandPlugin {
|
|||
if (!app.getSettings().getPlugins().contains("-" + plugin.getId())) {
|
||||
app.getSettings().enablePlugin(plugin.getId(), false);
|
||||
}
|
||||
plugin.setInstallURL(Version.getUrlWithUtmRef(app, id));
|
||||
plugin.setInstallURL(Version.getUrlWithUtmRef(app, plugin.getComponentId1()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void checkMarketPlugins(@NonNull OsmandApplication app) {
|
||||
SRTMPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
|
||||
if (srtmPlugin != null) {
|
||||
updateMarketPlugin(app, srtmPlugin, true, SRTM_PLUGIN_COMPONENT_PAID, SRTM_PLUGIN_COMPONENT);
|
||||
}
|
||||
NauticalMapsPlugin nauticalMapsPlugin = OsmandPlugin.getPlugin(NauticalMapsPlugin.class);
|
||||
if (nauticalMapsPlugin != null) {
|
||||
updateMarketPlugin(app, nauticalMapsPlugin, false, NauticalMapsPlugin.COMPONENT, null);
|
||||
}
|
||||
SkiMapsPlugin skiMapsPlugin = OsmandPlugin.getPlugin(SkiMapsPlugin.class);
|
||||
if (skiMapsPlugin != null) {
|
||||
updateMarketPlugin(app, skiMapsPlugin, false, SkiMapsPlugin.COMPONENT, null);
|
||||
}
|
||||
ParkingPositionPlugin parkingPlugin = OsmandPlugin.getPlugin(ParkingPositionPlugin.class);
|
||||
if (parkingPlugin != null) {
|
||||
updateMarketPlugin(app, parkingPlugin, false, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null);
|
||||
public static boolean isPluginEnabledForMode(@NonNull OsmandApplication app, @NonNull OsmandPlugin plugin, @NonNull ApplicationMode mode) {
|
||||
if (plugin.isMarketPlugin()) {
|
||||
boolean marketEnabled = Version.isMarketEnabled(app);
|
||||
boolean pckg = checkPluginPackage(app, plugin);
|
||||
if ((Version.isDeveloperVersion(app) || !Version.isProductionVersion(app)) && !plugin.isPaid()) {
|
||||
// for test reasons
|
||||
marketEnabled = false;
|
||||
}
|
||||
if (pckg || (!marketEnabled && !plugin.isPaid())) {
|
||||
return pckg && !app.getSettings().getPluginsForMode(mode).contains("-" + plugin.getId());
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return app.getSettings().getEnabledPluginsForMode(mode).contains(plugin.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkInstalledMarketPlugins(@NonNull OsmandApplication app, @Nullable Activity activity) {
|
||||
for (OsmandPlugin plugin : OsmandPlugin.getAvailablePlugins()) {
|
||||
if (plugin.getInstallURL() != null) {
|
||||
if (plugin instanceof SRTMPlugin) {
|
||||
if (checkPackage(app, SRTM_PLUGIN_COMPONENT_PAID, SRTM_PLUGIN_COMPONENT)
|
||||
&& updateMarketPlugin(app, plugin, true, SRTM_PLUGIN_COMPONENT_PAID, SRTM_PLUGIN_COMPONENT)) {
|
||||
plugin.onInstall(app, activity);
|
||||
initPlugin(app, plugin);
|
||||
}
|
||||
} else if (plugin instanceof NauticalMapsPlugin) {
|
||||
if (checkPackage(app, NauticalMapsPlugin.COMPONENT, null)
|
||||
&& updateMarketPlugin(app, plugin, false, NauticalMapsPlugin.COMPONENT, null)) {
|
||||
plugin.onInstall(app, activity);
|
||||
initPlugin(app, plugin);
|
||||
}
|
||||
} else if (plugin instanceof SkiMapsPlugin) {
|
||||
if (checkPackage(app, SkiMapsPlugin.COMPONENT, null)
|
||||
&& updateMarketPlugin(app, plugin, false, SkiMapsPlugin.COMPONENT, null)) {
|
||||
plugin.onInstall(app, activity);
|
||||
initPlugin(app, plugin);
|
||||
}
|
||||
} else if (plugin instanceof ParkingPositionPlugin) {
|
||||
if (checkPackage(app, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null)
|
||||
&& updateMarketPlugin(app, plugin, false, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null)) {
|
||||
plugin.onInstall(app, activity);
|
||||
initPlugin(app, plugin);
|
||||
}
|
||||
}
|
||||
for (OsmandPlugin plugin : OsmandPlugin.getMarketPlugins()) {
|
||||
if (plugin.getInstallURL() != null && checkPluginPackage(app, plugin) && updateMarketPlugin(app, plugin)) {
|
||||
plugin.onInstall(app, activity);
|
||||
initPlugin(app, plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkPackage(OsmandApplication app, String id, String id2) {
|
||||
return isPackageInstalled(id, app) || isPackageInstalled(id2, app)
|
||||
private static boolean checkPluginPackage(OsmandApplication app, OsmandPlugin plugin) {
|
||||
return isPackageInstalled(plugin.getComponentId1(), app) || isPackageInstalled(plugin.getComponentId2(), app)
|
||||
|| InAppPurchaseHelper.isSubscribedToLiveUpdates(app);
|
||||
}
|
||||
|
||||
|
@ -477,6 +467,16 @@ public abstract class OsmandPlugin {
|
|||
return lst;
|
||||
}
|
||||
|
||||
public static List<OsmandPlugin> getMarketPlugins() {
|
||||
ArrayList<OsmandPlugin> lst = new ArrayList<OsmandPlugin>(allPlugins.size());
|
||||
for (OsmandPlugin p : allPlugins) {
|
||||
if (p.isMarketPlugin()) {
|
||||
lst.add(p);
|
||||
}
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends OsmandPlugin> T getEnabledPlugin(Class<T> clz) {
|
||||
for (OsmandPlugin lr : getEnabledPlugins()) {
|
||||
|
|
|
@ -1013,7 +1013,11 @@ public class OsmandSettings {
|
|||
}.makeProfile();
|
||||
|
||||
public Set<String> getEnabledPlugins() {
|
||||
String plugs = PLUGINS.get();
|
||||
return getEnabledPluginsForMode(APPLICATION_MODE.get());
|
||||
}
|
||||
|
||||
public Set<String> getEnabledPluginsForMode(ApplicationMode mode) {
|
||||
String plugs = PLUGINS.getModeValue(mode);
|
||||
StringTokenizer toks = new StringTokenizer(plugs, ",");
|
||||
Set<String> res = new LinkedHashSet<String>();
|
||||
while (toks.hasMoreTokens()) {
|
||||
|
@ -1039,11 +1043,11 @@ public class OsmandSettings {
|
|||
return res;
|
||||
}
|
||||
|
||||
public void enablePlugin(String pluginId, boolean enable) {
|
||||
enablePluginForMode(pluginId, enable, APPLICATION_MODE.get());
|
||||
public boolean enablePlugin(String pluginId, boolean enable) {
|
||||
return enablePluginForMode(pluginId, enable, APPLICATION_MODE.get());
|
||||
}
|
||||
|
||||
public void enablePluginForMode(String pluginId, boolean enable, ApplicationMode mode) {
|
||||
public boolean enablePluginForMode(String pluginId, boolean enable, ApplicationMode mode) {
|
||||
Set<String> set = getPluginsForMode(mode);
|
||||
if (enable) {
|
||||
set.remove("-" + pluginId);
|
||||
|
@ -1061,8 +1065,9 @@ public class OsmandSettings {
|
|||
}
|
||||
}
|
||||
if (!serialization.toString().equals(PLUGINS.getModeValue(mode))) {
|
||||
PLUGINS.setModeValue(mode, serialization.toString());
|
||||
return PLUGINS.setModeValue(mode, serialization.toString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -43,6 +43,16 @@ public class NauticalMapsPlugin extends OsmandPlugin {
|
|||
return R.drawable.nautical_map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMarketPlugin() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentId1() {
|
||||
return COMPONENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return app.getString(net.osmand.plus.R.string.plugin_nautical_descr);
|
||||
|
|
|
@ -174,6 +174,15 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
|||
return "feature_articles/parking-plugin.html";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMarketPlugin() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentId1() {
|
||||
return PARKING_PLUGIN_COMPONENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerLayers(MapActivity activity) {
|
||||
|
|
|
@ -262,12 +262,13 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
if (plugin instanceof SkiMapsPlugin || plugin instanceof NauticalMapsPlugin) {
|
||||
continue;
|
||||
}
|
||||
boolean pluginEnabled = OsmandPlugin.isPluginEnabledForMode(app, plugin, getSelectedAppMode());
|
||||
SwitchPreferenceEx preference = new SwitchPreferenceEx(ctx);
|
||||
preference.setPersistent(false);
|
||||
preference.setKey(plugin.getId());
|
||||
preference.setTitle(plugin.getName());
|
||||
preference.setChecked(plugin.isActive());
|
||||
preference.setIcon(getPluginIcon(plugin));
|
||||
preference.setChecked(pluginEnabled);
|
||||
preference.setIcon(getPluginIcon(plugin, pluginEnabled));
|
||||
preference.setIntent(getPluginIntent(plugin));
|
||||
preference.setLayoutResource(R.layout.preference_dialog_and_switch);
|
||||
|
||||
|
@ -275,9 +276,9 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private Drawable getPluginIcon(OsmandPlugin plugin) {
|
||||
private Drawable getPluginIcon(OsmandPlugin plugin, boolean pluginEnabled) {
|
||||
int iconResId = plugin.getLogoResourceId();
|
||||
return plugin.isActive() ? getActiveIcon(iconResId) : getIcon(iconResId, isNightMode() ? R.color.icon_color_secondary_dark : R.color.icon_color_secondary_light);
|
||||
return pluginEnabled ? getActiveIcon(iconResId) : getIcon(iconResId, isNightMode() ? R.color.icon_color_secondary_dark : R.color.icon_color_secondary_light);
|
||||
}
|
||||
|
||||
private Intent getPluginIntent(OsmandPlugin plugin) {
|
||||
|
@ -343,8 +344,15 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
if (plugin != null) {
|
||||
if (newValue instanceof Boolean) {
|
||||
if ((plugin.isActive() || !plugin.needsInstallation())) {
|
||||
if (OsmandPlugin.enablePlugin(getActivity(), app, plugin, (Boolean) newValue)) {
|
||||
preference.setIcon(getPluginIcon(plugin));
|
||||
ApplicationMode selectedMode = getSelectedAppMode();
|
||||
boolean pluginChanged;
|
||||
if (selectedMode.equals(settings.APPLICATION_MODE.get())) {
|
||||
pluginChanged = OsmandPlugin.enablePlugin(getActivity(), app, plugin, (Boolean) newValue);
|
||||
} else {
|
||||
pluginChanged = settings.enablePluginForMode(plugin.getId(), (Boolean) newValue, selectedMode);
|
||||
}
|
||||
if (pluginChanged) {
|
||||
preference.setIcon(getPluginIcon(plugin, (Boolean) newValue));
|
||||
return true;
|
||||
}
|
||||
} else if (plugin.needsInstallation() && preference.getIntent() != null) {
|
||||
|
|
|
@ -43,6 +43,15 @@ public class SkiMapsPlugin extends OsmandPlugin {
|
|||
return R.drawable.ski_map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMarketPlugin() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentId1() {
|
||||
return COMPONENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpFileName() {
|
||||
|
|
|
@ -44,6 +44,9 @@ public class SRTMPlugin extends OsmandPlugin {
|
|||
public static final String ID = "osmand.srtm";
|
||||
public static final String FREE_ID = "osmand.srtm.paid";
|
||||
|
||||
private static final String SRTM_PLUGIN_COMPONENT_PAID = "net.osmand.srtmPlugin.paid";
|
||||
private static final String SRTM_PLUGIN_COMPONENT = "net.osmand.srtmPlugin";
|
||||
|
||||
public static final String CONTOUR_LINES_ATTR = "contourLines";
|
||||
public static final String CONTOUR_LINES_SCHEME_ATTR = "contourColorScheme";
|
||||
public static final String CONTOUR_LINES_DISABLED_VALUE = "disabled";
|
||||
|
@ -81,6 +84,26 @@ public class SRTMPlugin extends OsmandPlugin {
|
|||
return super.needsInstallation() && !InAppPurchaseHelper.isSubscribedToLiveUpdates(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMarketPlugin() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPaid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentId1() {
|
||||
return SRTM_PLUGIN_COMPONENT_PAID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComponentId2() {
|
||||
return SRTM_PLUGIN_COMPONENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return app.getString(R.string.srtm_plugin_description);
|
||||
|
|
Loading…
Reference in a new issue