Search in sources :

Example 1 with DashFragmentData

use of net.osmand.plus.dashboard.tools.DashFragmentData in project Osmand by osmandapp.

the class OsmandPlugin method enablePlugin.

public static boolean enablePlugin(@Nullable Activity activity, @NonNull OsmandApplication app, @NonNull OsmandPlugin plugin, boolean enable) {
    if (enable) {
        if (!plugin.init(app, activity)) {
            plugin.setEnabled(false);
            return false;
        } else {
            plugin.setEnabled(true);
        }
    } else {
        plugin.disable(app);
        plugin.setEnabled(false);
    }
    app.getSettings().enablePlugin(plugin.getId(), enable);
    app.getQuickActionRegistry().updateActionTypes();
    if (activity != null) {
        if (activity instanceof MapActivity) {
            final MapActivity mapActivity = (MapActivity) activity;
            plugin.updateLayers(mapActivity, mapActivity);
            mapActivity.getDashboard().refreshDashboardFragments();
            DashFragmentData fragmentData = plugin.getCardFragment();
            if (!enable && fragmentData != null) {
                FragmentManager fm = mapActivity.getSupportFragmentManager();
                Fragment fragment = fm.findFragmentByTag(fragmentData.tag);
                if (fragment != null) {
                    fm.beginTransaction().remove(fragment).commitAllowingStateLoss();
                }
            }
        }
        if (plugin.isMarketPlugin() || plugin.isPaid()) {
            if (plugin.isActive()) {
                plugin.showInstallDialog(activity);
            } else if (OsmandPlugin.checkPluginPackage(app, plugin)) {
                plugin.showDisableDialog(activity);
            }
        }
    }
    return true;
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) Fragment(androidx.fragment.app.Fragment) QuickSearchDialogFragment(net.osmand.plus.search.QuickSearchDialogFragment) MapActivity(net.osmand.plus.activities.MapActivity) DashFragmentData(net.osmand.plus.dashboard.tools.DashFragmentData)

Aggregations

Fragment (androidx.fragment.app.Fragment)1 FragmentManager (androidx.fragment.app.FragmentManager)1 MapActivity (net.osmand.plus.activities.MapActivity)1 DashFragmentData (net.osmand.plus.dashboard.tools.DashFragmentData)1 QuickSearchDialogFragment (net.osmand.plus.search.QuickSearchDialogFragment)1