Fix Mapillary layer show/hide
This commit is contained in:
parent
da452a5804
commit
8d58d772b8
3 changed files with 33 additions and 21 deletions
|
@ -5,10 +5,13 @@ import android.support.annotation.NonNull;
|
|||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.mapillary.MapillaryImageDialog;
|
||||
import net.osmand.plus.mapillary.MapillaryPlugin;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
||||
public abstract class ContextMenuCardDialog {
|
||||
|
@ -79,7 +82,7 @@ public abstract class ContextMenuCardDialog {
|
|||
this.description = bundle.getString(KEY_CARD_DIALOG_TITLE);
|
||||
}
|
||||
|
||||
public static ContextMenuCardDialog restoreMenu(@NonNull Bundle bundle, @NonNull MapActivity mapActivity) {
|
||||
static ContextMenuCardDialog restoreMenu(@NonNull Bundle bundle, @NonNull MapActivity mapActivity) {
|
||||
|
||||
try {
|
||||
CardDialogType type = CardDialogType.valueOf(bundle.getString(KEY_CARD_DIALOG_TYPE));
|
||||
|
@ -88,6 +91,8 @@ public abstract class ContextMenuCardDialog {
|
|||
case MAPILLARY:
|
||||
dialog = new MapillaryImageDialog(mapActivity, bundle);
|
||||
break;
|
||||
case REGULAR:
|
||||
break;
|
||||
}
|
||||
return dialog;
|
||||
} catch (Exception e) {
|
||||
|
@ -97,10 +102,12 @@ public abstract class ContextMenuCardDialog {
|
|||
|
||||
public void onResume() {
|
||||
shiftMapPosition();
|
||||
updateLayers(true);
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
restoreMapPosition();
|
||||
updateLayers(false);
|
||||
}
|
||||
|
||||
private void shiftMapPosition() {
|
||||
|
@ -124,4 +131,23 @@ public abstract class ContextMenuCardDialog {
|
|||
}
|
||||
|
||||
public abstract View getContentView();
|
||||
|
||||
private void updateLayers(boolean activate) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
switch (type) {
|
||||
case MAPILLARY: {
|
||||
boolean showMapillary = app.getSettings().SHOW_MAPILLARY.get();
|
||||
if (!showMapillary) {
|
||||
MapillaryPlugin mapillaryPlugin = OsmandPlugin.getPlugin(MapillaryPlugin.class);
|
||||
if (mapillaryPlugin != null) {
|
||||
mapillaryPlugin.updateLayers(mapActivity.getMapView(), mapActivity, activate);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case REGULAR:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu.builders.cards.dialogs;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.AppCompatImageView;
|
||||
|
@ -15,12 +16,10 @@ import android.widget.LinearLayout;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.mapillary.MapillaryPlugin;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
public class ContextMenuCardDialogFragment extends BaseOsmAndFragment {
|
||||
|
@ -42,10 +41,11 @@ public class ContextMenuCardDialogFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.context_menu_card_dialog, container, false);
|
||||
AndroidUtils.addStatusBarPadding21v(getActivity(), view);
|
||||
FragmentActivity activity = requireActivity();
|
||||
AndroidUtils.addStatusBarPadding21v(activity, view);
|
||||
if (dialog.getType() == ContextMenuCardDialog.CardDialogType.MAPILLARY) {
|
||||
view.findViewById(R.id.dialog_layout)
|
||||
.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.mapillary_action_bar));
|
||||
.setBackgroundColor(ContextCompat.getColor(activity, R.color.mapillary_action_bar));
|
||||
}
|
||||
contentLayout = (LinearLayout) view.findViewById(R.id.content);
|
||||
contentView = dialog.getContentView();
|
||||
|
@ -70,7 +70,7 @@ public class ContextMenuCardDialogFragment extends BaseOsmAndFragment {
|
|||
moreButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final PopupMenu optionsMenu = new PopupMenu(getContext(), v);
|
||||
final PopupMenu optionsMenu = new PopupMenu(v.getContext(), v);
|
||||
DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
|
||||
dialog.createMenuItems(optionsMenu.getMenu());
|
||||
optionsMenu.show();
|
||||
|
@ -110,7 +110,7 @@ public class ContextMenuCardDialogFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
dialog.saveMenu(outState);
|
||||
}
|
||||
|
||||
|
@ -133,14 +133,6 @@ public class ContextMenuCardDialogFragment extends BaseOsmAndFragment {
|
|||
public void dismiss() {
|
||||
MapActivity activity = dialog.getMapActivity();
|
||||
if (activity != null) {
|
||||
if (dialog.getType() == ContextMenuCardDialog.CardDialogType.MAPILLARY) {
|
||||
if (!activity.getMyApplication().getSettings().SHOW_MAPILLARY.get()) {
|
||||
MapillaryPlugin mapillaryPlugin = OsmandPlugin.getPlugin(MapillaryPlugin.class);
|
||||
if (mapillaryPlugin != null) {
|
||||
mapillaryPlugin.updateLayers(activity.getMapView(), activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
activity.getSupportFragmentManager().popBackStack(TAG,
|
||||
FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||
|
|
|
@ -21,12 +21,6 @@ public class MapillaryImageCard extends ImageCard {
|
|||
OnClickListener onClickListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!getMyApplication().getSettings().SHOW_MAPILLARY.get()) {
|
||||
MapillaryPlugin mapillaryPlugin = OsmandPlugin.getPlugin(MapillaryPlugin.class);
|
||||
if (mapillaryPlugin != null) {
|
||||
mapillaryPlugin.updateLayers(getMapActivity().getMapView(), getMapActivity(), true);
|
||||
}
|
||||
}
|
||||
getMapActivity().getContextMenu().close();
|
||||
MapillaryImageDialog.show(getMapActivity(), getKey(), getImageHiresUrl(), getUrl(), getLocation(),
|
||||
getCa(), getMyApplication().getString(R.string.mapillary), null, true);
|
||||
|
|
Loading…
Reference in a new issue