From 85e201ab024b71196415a260b2d66b9228bd57f8 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Wed, 3 Oct 2018 11:50:46 +0300 Subject: [PATCH] Add the ability to disable and enable third-party apps from UI --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 5 +++++ .../osmand/plus/activities/PluginsActivity.java | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index a476f9f99c..bece844fcb 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -1611,6 +1611,11 @@ public class OsmandAidlApi { return res; } + public void switchEnabled(@NonNull ConnectedApp app) { + app.enabled = !app.enabled; + saveConnectedApps(); + } + boolean isAppEnabled(@NonNull String pack) { ConnectedApp app = connectedApps.get(pack); if (app == null) { diff --git a/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java b/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java index 2d16f8e31f..4c404be505 100644 --- a/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java @@ -49,6 +49,8 @@ public class PluginsActivity extends OsmandListActivity { Intent intent = new Intent(this, PluginActivity.class); intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, ((OsmandPlugin) tag).getId()); startActivity(intent); + } else if (tag instanceof ConnectedApp) { + switchEnabled((ConnectedApp) tag); } } @@ -69,6 +71,11 @@ public class PluginsActivity extends OsmandListActivity { } } + private void switchEnabled(@NonNull ConnectedApp app) { + getMyApplication().getAidlApi().switchEnabled(app); + getListAdapter().notifyDataSetChanged(); + } + protected class PluginsListAdapter extends ArrayAdapter { PluginsListAdapter() { @@ -104,10 +111,15 @@ public class PluginsActivity extends OsmandListActivity { name = app.getName(); pluginDescription.setText(R.string.third_party_application); pluginLogo.setImageDrawable(app.getIcon()); - pluginLogo.setOnClickListener(null); + pluginLogo.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + switchEnabled(app); + } + }); pluginOptions.setVisibility(View.GONE); pluginOptions.setOnClickListener(null); - view.setTag(null); + view.setTag(app); } else if (item instanceof OsmandPlugin) { final OsmandPlugin plugin = (OsmandPlugin) item; active = plugin.isActive();