Make show direction menu work

This commit is contained in:
PavelRatushny 2017-09-08 14:13:03 +03:00
parent a86ea5118b
commit 2b264697ad
4 changed files with 59 additions and 27 deletions

View file

@ -19,6 +19,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapmarkers.ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener;
import net.osmand.plus.mapmarkers.MarkerOptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener;
import java.util.Arrays;
@ -65,6 +66,10 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
if (markerOptionsFragment != null) {
((MarkerOptionsBottomSheetDialogFragment) markerOptionsFragment).setListener(createMarkerOptionsFragmentListener());
}
Fragment showDirectionFragment = fragmentManager.findFragmentByTag(ShowDirectionBottomSheetDialogFragment.TAG);
if (showDirectionFragment != null) {
((ShowDirectionBottomSheetDialogFragment) showDirectionFragment).setListener(createShowDirectionFragmentListener());
}
View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container);
@ -137,7 +142,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
@Override
public void showDirectionOnClick() {
openShowDirectionMenu(mapActivity);
ShowDirectionBottomSheetDialogFragment fragment = new ShowDirectionBottomSheetDialogFragment();
fragment.setListener(createShowDirectionFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), ShowDirectionBottomSheetDialogFragment.TAG);
}
@Override
@ -158,9 +165,16 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
};
}
private void openShowDirectionMenu(MapActivity mapActivity) {
ShowDirectionBottomSheetDialogFragment fragment = new ShowDirectionBottomSheetDialogFragment();
fragment.show(mapActivity.getSupportFragmentManager(), ShowDirectionBottomSheetDialogFragment.TAG);
private ShowDirectionFragmentListener createShowDirectionFragmentListener() {
return new ShowDirectionFragmentListener() {
final MapActivity mapActivity = getMapActivity();
@Override
public void onMapMarkersModeChanged() {
mapActivity.getMapLayers().getMapWidgetRegistry().updateMapMarkersMode(mapActivity);
}
};
}
private MapActivity getMapActivity() {

View file

@ -52,7 +52,7 @@ public class MarkerOptionsBottomSheetDialogFragment extends BottomSheetDialogFra
((ImageView) mainView.findViewById(R.id.move_all_to_history_icon))
.setImageDrawable(getIcon(R.drawable.ic_action_history2, R.color.on_map_icon_color));
((TextView) mainView.findViewById(R.id.show_direction_text_view)).setText("Top bar");
((TextView) mainView.findViewById(R.id.show_direction_text_view)).setText(getMyApplication().getSettings().MAP_MARKERS_MODE.get().toHumanString(getActivity()));
mainView.findViewById(R.id.sort_by_row).setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -15,6 +15,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
@ -61,7 +62,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
return false;
}
});
topBarImage.setOnClickListener(topBarOnClickListener);
topBarImage.setOnClickListener(showDirectionOnClickListener);
mainView.findViewById(R.id.widget_text).setOnTouchListener(new View.OnTouchListener() {
@Override
@ -69,7 +70,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
return false;
}
});
widgetImage.setOnClickListener(widgetOnClickListener);
widgetImage.setOnClickListener(showDirectionOnClickListener);
}
if (nightMode) {
@ -87,6 +88,10 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
ImageView noneIcon = (ImageView) mainView.findViewById(R.id.none_icon);
noneIcon.setBackgroundDrawable(getIcon(R.drawable.ic_action_device_top, R.color.on_map_icon_color));
mainView.findViewById(R.id.top_bar_row).setOnClickListener(showDirectionOnClickListener);
mainView.findViewById(R.id.widget_row).setOnClickListener(showDirectionOnClickListener);
mainView.findViewById(R.id.none_row).setOnClickListener(showDirectionOnClickListener);
mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -145,22 +150,31 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra
}
}
private View.OnClickListener topBarOnClickListener = new View.OnClickListener() {
private View.OnClickListener showDirectionOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
}
};
private View.OnClickListener widgetOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.top_bar_image:
case R.id.top_bar_row:
getMyApplication().getSettings().MAP_MARKERS_MODE.set(OsmandSettings.MapMarkersMode.TOOLBAR);
break;
case R.id.widget_image:
case R.id.widget_row:
getMyApplication().getSettings().MAP_MARKERS_MODE.set(OsmandSettings.MapMarkersMode.WIDGETS);
break;
case R.id.none_row:
getMyApplication().getSettings().MAP_MARKERS_MODE.set(OsmandSettings.MapMarkersMode.NONE);
break;
}
if (listener != null) {
listener.onMapMarkersModeChanged();
}
dismiss();
}
};
interface ShowDirectionFragmentListener {
void onMapMarkersModeChanged();
}
}

View file

@ -345,16 +345,7 @@ public class MapWidgetRegistry {
@Override
public void onClick(DialogInterface dialog, int which) {
settings.MAP_MARKERS_MODE.set(MapMarkersMode.values()[which]);
for (MapWidgetRegInfo info : rightWidgetSet) {
if ("map_marker_1st".equals(info.key) || "map_marker_2nd".equals(info.key)) {
setVisibility(info, settings.MAP_MARKERS_MODE.get().isWidgets(), false);
}
}
MapInfoLayer mil = map.getMapLayers().getMapInfoLayer();
if (mil != null) {
mil.recreateControls();
}
map.refreshMap();
updateMapMarkersMode(map);
dialog.dismiss();
cm.getItem(pos).setDescription(settings.MAP_MARKERS_MODE.get().toHumanString(map));
ad.notifyDataSetChanged();
@ -367,6 +358,19 @@ public class MapWidgetRegistry {
}
}
public void updateMapMarkersMode(MapActivity mapActivity) {
for (MapWidgetRegInfo info : rightWidgetSet) {
if ("map_marker_1st".equals(info.key) || "map_marker_2nd".equals(info.key)) {
setVisibility(info, settings.MAP_MARKERS_MODE.get().isWidgets(), false);
}
}
MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
if (mil != null) {
mil.recreateControls();
}
mapActivity.refreshMap();
}
private void addControlId(final MapActivity map, ContextMenuAdapter cm,
@StringRes int stringId, OsmandPreference<Boolean> pref) {
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(stringId, map)