Fix dashboard/settings srtm plugin get

This commit is contained in:
max-klaus 2019-11-26 16:36:25 +03:00
parent 3519ff0a57
commit f275536131
2 changed files with 34 additions and 3 deletions

View file

@ -8,6 +8,7 @@ import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.util.Log; import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -18,7 +19,9 @@ import android.widget.TextView;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.srtmplugin.SRTMPlugin;
public class PluginActivity extends OsmandActionBarActivity implements DownloadIndexesThread.DownloadEvents { public class PluginActivity extends OsmandActionBarActivity implements DownloadIndexesThread.DownloadEvents {
private static final String TAG = "PluginActivity"; private static final String TAG = "PluginActivity";
@ -94,11 +97,19 @@ public class PluginActivity extends OsmandActionBarActivity implements Download
} }
}); });
Button getButton = (Button)findViewById(R.id.plugin_get); Button getButton = (Button)findViewById(R.id.plugin_get);
getButton.setText(plugin.isPaid() ? R.string.get_plugin : R.string.shared_string_install);
getButton.setOnClickListener(new View.OnClickListener() { getButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
try { try {
if (plugin instanceof SRTMPlugin) {
FragmentManager fragmentManager = getSupportFragmentManager();
if (fragmentManager != null) {
ChoosePlanDialogFragment.showHillshadeSrtmPluginInstance(fragmentManager);
}
} else {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL()))); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL())));
}
} catch (Exception e) { } catch (Exception e) {
//ignored //ignored
} }

View file

@ -5,6 +5,7 @@ import android.content.res.TypedArray;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -17,8 +18,12 @@ import android.widget.TextView;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.PluginActivity; import net.osmand.plus.activities.PluginActivity;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.skimapsplugin.SkiMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -45,7 +50,14 @@ public class DashPluginsFragment extends DashBaseFragment {
return new View.OnClickListener() { return new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (plugin instanceof SRTMPlugin) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
ChoosePlanDialogFragment.showHillshadeSrtmPluginInstance(fragmentManager);
}
} else {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL()))); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(plugin.getInstallURL())));
}
closeDashboard(); closeDashboard();
} }
}; };
@ -82,10 +94,17 @@ public class DashPluginsFragment extends DashBaseFragment {
private void initPlugins() { private void initPlugins() {
List<OsmandPlugin> notActivePlugins = OsmandPlugin.getNotEnabledVisiblePlugins(); List<OsmandPlugin> notActivePlugins = OsmandPlugin.getNotEnabledVisiblePlugins();
notActivePlugins.remove(OsmandPlugin.getPlugin(SkiMapsPlugin.class));
notActivePlugins.remove(OsmandPlugin.getPlugin(NauticalMapsPlugin.class));
Collections.shuffle(notActivePlugins); Collections.shuffle(notActivePlugins);
List<OsmandPlugin> enabledPlugins = OsmandPlugin.getEnabledVisiblePlugins();
enabledPlugins.remove(OsmandPlugin.getPlugin(SkiMapsPlugin.class));
enabledPlugins.remove(OsmandPlugin.getPlugin(NauticalMapsPlugin.class));
plugins = new ArrayList<OsmandPlugin>(); plugins = new ArrayList<OsmandPlugin>();
Iterator<OsmandPlugin> nit = notActivePlugins.iterator(); Iterator<OsmandPlugin> nit = notActivePlugins.iterator();
Iterator<OsmandPlugin> it = OsmandPlugin.getEnabledVisiblePlugins().iterator(); Iterator<OsmandPlugin> it = enabledPlugins.iterator();
addPluginsToLimit(nit, 1); addPluginsToLimit(nit, 1);
addPluginsToLimit(it, 5); addPluginsToLimit(it, 5);
addPluginsToLimit(nit, 5); addPluginsToLimit(nit, 5);
@ -152,6 +171,7 @@ public class DashPluginsFragment extends DashBaseFragment {
CompoundButton enableDisableButton = (CompoundButton) view.findViewById(R.id.plugin_enable_disable); CompoundButton enableDisableButton = (CompoundButton) view.findViewById(R.id.plugin_enable_disable);
Button getButton = (Button) view.findViewById(R.id.get_plugin); Button getButton = (Button) view.findViewById(R.id.get_plugin);
getButton.setText(plugin.isPaid() ? R.string.get_plugin : R.string.shared_string_install);
getButton.setOnClickListener(getListener(plugin)); getButton.setOnClickListener(getListener(plugin));
enableDisableButton.setOnCheckedChangeListener(null); enableDisableButton.setOnCheckedChangeListener(null);
updatePluginState(view, plugin); updatePluginState(view, plugin);