[android] Added guides interface

This commit is contained in:
Dmitry Donskoy 2020-04-24 02:17:51 +03:00 committed by Aleksandr Zatsepin
parent 7d90525420
commit ea7eb3ca48
13 changed files with 145 additions and 10 deletions

View file

@ -19,7 +19,7 @@ static void GuidesStateChanged(GuidesManager::GuidesState state,
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_maplayer_Guides_GuidesManager_nativeAddListener(JNIEnv *env, jclass clazz, jobject listener)
Java_com_mapswithme_maps_maplayer_guides_GuidesManager_nativeAddListener(JNIEnv *env, jclass clazz, jobject listener)
{
CHECK(g_framework, ("Framework isn't created yet!"));
g_framework->SetGuidesListener(std::bind(&GuidesStateChanged,
@ -28,7 +28,7 @@ Java_com_mapswithme_maps_maplayer_Guides_GuidesManager_nativeAddListener(JNIEnv
}
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_maplayer_Guides_GuidesManager_nativeRemoveListener(JNIEnv * env, jclass clazz)
Java_com_mapswithme_maps_maplayer_guides_GuidesManager_nativeRemoveListener(JNIEnv * env, jclass clazz)
{
CHECK(g_framework, ("Framework isn't created yet!"));
g_framework->SetGuidesListener(nullptr);

View file

@ -33,6 +33,15 @@
android:background="?nav_bg_isolines"
android:visibility="invisible"/>
<ImageButton
android:id="@+id/guides"
style="@style/MwmWidget.MapButton.Traffic"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="?nav_bg_isolines"
android:visibility="invisible"/>
<ImageButton
android:id="@+id/nav_zoom_in"
style="@style/MwmWidget.MapButton"

View file

@ -89,6 +89,15 @@
android:visibility="gone"
android:background="?nav_bg_isolines"/>
<ImageView
android:id="@+id/guides"
android:layout_weight="0.2"
android:layout_width="0dp"
android:layout_height="@dimen/nav_icon_size"
android:scaleType="center"
android:visibility="gone"
android:background="?nav_bg_isolines"/>
<ImageView
android:id="@+id/settings"
android:layout_weight="0.2"

View file

@ -35,6 +35,15 @@
android:visibility="invisible"
android:background="?nav_bg_isolines"/>
<ImageButton
android:id="@+id/guides"
style="@style/MwmWidget.MapButton.Traffic"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:visibility="invisible"
android:background="?nav_bg_isolines"/>
<ImageButton
android:id="@+id/my_position"
style="@style/MwmWidget.MapButton"

View file

@ -68,6 +68,7 @@ import com.mapswithme.maps.location.CompassData;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.maplayer.MapLayerCompositeController;
import com.mapswithme.maps.maplayer.Mode;
import com.mapswithme.maps.maplayer.OnGuidesLayerToggleListener;
import com.mapswithme.maps.maplayer.OnIsolinesLayerToggleListener;
import com.mapswithme.maps.maplayer.isolines.IsolinesManager;
import com.mapswithme.maps.maplayer.isolines.IsolinesState;
@ -181,7 +182,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
AppBackgroundTracker.OnTransitionListener,
MaterialTapTargetPrompt.PromptStateChangeListener,
WelcomeDialogFragment.OnboardingStepPassedListener,
OnIsolinesLayerToggleListener
OnIsolinesLayerToggleListener,
OnGuidesLayerToggleListener
{
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
private static final String TAG = MwmActivity.class.getSimpleName();
@ -793,7 +795,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
TrafficButton traffic = new TrafficButton(trafficBtn);
View subway = frame.findViewById(R.id.subway);
View isoLines = frame.findViewById(R.id.isolines);
mToggleMapLayerController = new MapLayerCompositeController(traffic, subway, isoLines,this);
View guides = frame.findViewById(R.id.guides);
mToggleMapLayerController = new MapLayerCompositeController(traffic, subway, isoLines, guides, this);
mToggleMapLayerController.attachCore();
}
@ -1234,6 +1237,12 @@ public class MwmActivity extends BaseMwmFragmentActivity
mToggleMapLayerController.toggleMode(Mode.ISOLINES);
}
@Override
public void onGuidesLayerSelected()
{
mToggleMapLayerController.toggleMode(Mode.GUIDES);
}
private void onIsolinesStateChanged(@NonNull IsolinesState type)
{
if (type != IsolinesState.EXPIREDDATA)
@ -2843,5 +2852,11 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
onIsolinesLayerSelected();
}
@Override
public void onGuidesLayerOptionSelected()
{
onGuidesLayerSelected();
}
}
}

View file

@ -97,4 +97,19 @@ public abstract class BottomSheetItem
return new Isolines(R.drawable.ic_planning_route_isomaps_dark_on, disabled);
}
}
public static class Guides extends BottomSheetItem
{
private Guides(int drawableResId, int disabledStateDrawableResId)
{
super(drawableResId, disabledStateDrawableResId, R.string.button_layer_isolines, Mode.GUIDES);
}
public static BottomSheetItem makeInstance(@NonNull Context mContext)
{
int disabled = ThemeUtils.getResource(mContext, R.attr.isoLinesMenuDisabled);
return new Guides(R.drawable.ic_planning_route_isomaps_dark_on, disabled);
}
}
}

View file

@ -15,7 +15,8 @@ public class LayersUtils
public static List<Pair<BottomSheetItem, OnItemClickListener<BottomSheetItem>>> createItems(
@NonNull Context context, @NonNull OnItemClickListener<BottomSheetItem> subwayListener,
@NonNull OnItemClickListener<BottomSheetItem> trafficListener,
@NonNull OnItemClickListener<BottomSheetItem> isoLinesListener)
@NonNull OnItemClickListener<BottomSheetItem> isoLinesListener,
@NonNull OnItemClickListener<BottomSheetItem> guidesListener)
{
Pair<BottomSheetItem, OnItemClickListener<BottomSheetItem>> subway
= new Pair<>(BottomSheetItem.Subway.makeInstance(context), subwayListener);
@ -26,6 +27,9 @@ public class LayersUtils
Pair<BottomSheetItem, OnItemClickListener<BottomSheetItem>> isoLines
= new Pair<>(BottomSheetItem.Isolines.makeInstance(context), isoLinesListener);
Pair<BottomSheetItem, OnItemClickListener<BottomSheetItem>> guides
= new Pair<>(BottomSheetItem.Guides.makeInstance(context), guidesListener);
return Arrays.asList(traffic, isoLines, subway);
}
}

View file

@ -29,11 +29,12 @@ public class MapLayerCompositeController implements MapLayerController
private final TutorialClickListener mOpenBottomDialogClickListener;
public MapLayerCompositeController(@NonNull TrafficButton traffic, @NonNull View subway,
@NonNull View isoLines, @NonNull AppCompatActivity activity)
@NonNull View isoLines, @NonNull View guides,
@NonNull AppCompatActivity activity)
{
mOpenBottomDialogClickListener = new OpenBottomDialogClickListener(activity);
mActivity = activity;
mLayers = createLayers(traffic, subway, isoLines, activity, mOpenBottomDialogClickListener);
mLayers = createLayers(traffic, subway, isoLines, guides, activity, mOpenBottomDialogClickListener);
mCurrentLayer = getCurrentLayer();
toggleMode(mCurrentLayer.getMode());
}
@ -42,6 +43,7 @@ public class MapLayerCompositeController implements MapLayerController
private static List<ControllerAndMode> createLayers(@NonNull TrafficButton traffic,
@NonNull View subway,
@NonNull View isoLinesView,
@NonNull View guides,
@NonNull AppCompatActivity activity,
@NonNull View.OnClickListener dialogClickListener)
{
@ -54,12 +56,17 @@ public class MapLayerCompositeController implements MapLayerController
isoLinesView.setOnClickListener(dialogClickListener);
DefaultMapLayerController isoLinesController = new DefaultMapLayerController(isoLinesView);
guides.setOnClickListener(dialogClickListener);
DefaultMapLayerController guidesController = new DefaultMapLayerController(guides);
ControllerAndMode subwayEntry = new ControllerAndMode(Mode.SUBWAY, Tutorial.SUBWAY,
subwayMapLayerController);
ControllerAndMode trafficEntry = new ControllerAndMode(Mode.TRAFFIC, null,
trafficButtonController);
ControllerAndMode isoLineEntry = new ControllerAndMode(Mode.ISOLINES, Tutorial.ISOLINES,
isoLinesController);
ControllerAndMode guidesEntry = new ControllerAndMode(Mode.GUIDES, Tutorial.ISOLINES,
guidesController);
List<ControllerAndMode> entries = new ArrayList<>();
entries.add(subwayEntry);

View file

@ -3,6 +3,7 @@ package com.mapswithme.maps.maplayer;
import android.content.Context;
import androidx.annotation.NonNull;
import com.mapswithme.maps.maplayer.guides.GuidesManager;
import com.mapswithme.maps.maplayer.isolines.IsolinesManager;
import com.mapswithme.maps.maplayer.subway.SubwayManager;
import com.mapswithme.maps.maplayer.traffic.TrafficManager;
@ -31,6 +32,7 @@ public enum Mode
TrafficManager.INSTANCE.toggle();
SubwayManager.from(context).setEnabled(false);
IsolinesManager.from(context).setEnabled(false);
GuidesManager.from(context).setEnabled(false);
}
},
SUBWAY
@ -53,6 +55,7 @@ public enum Mode
SubwayManager.from(context).toggle();
TrafficManager.INSTANCE.setEnabled(false);
IsolinesManager.from(context).setEnabled(false);
GuidesManager.from(context).setEnabled(false);
}
},
@ -76,9 +79,34 @@ public enum Mode
IsolinesManager.from(context).toggle();
TrafficManager.INSTANCE.setEnabled(false);
SubwayManager.from(context).setEnabled(false);
GuidesManager.from(context).setEnabled(false);
}
},
GUIDES
{
@Override
public boolean isEnabled(@NonNull Context context)
{
return GuidesManager.from(context).isEnabled();
}
@Override
public void setEnabled(@NonNull Context context, boolean isEnabled)
{
GuidesManager.from(context).setEnabled(isEnabled);
}
@Override
public void toggle(@NonNull Context context)
{
GuidesManager.from(context).toggle();
IsolinesManager.from(context).setEnabled(false);
TrafficManager.INSTANCE.setEnabled(false);
SubwayManager.from(context).setEnabled(false);
}
};
public abstract boolean isEnabled(@NonNull Context context);
public abstract void setEnabled(@NonNull Context context, boolean isEnabled);

View file

@ -0,0 +1,6 @@
package com.mapswithme.maps.maplayer;
public interface OnGuidesLayerToggleListener
{
void onGuidesLayerSelected();
}

View file

@ -69,9 +69,11 @@ public class ToggleMapLayerDialog extends DialogFragment
false);
recycler.setLayoutManager(layoutManager);
mAdapter = new LayersAdapter();
mAdapter.setLayerModes(LayersUtils.createItems(requireContext(), new SubwayItemClickListener(),
mAdapter.setLayerModes(LayersUtils.createItems(requireContext(),
new SubwayItemClickListener(),
new TrafficItemClickListener(),
new IsolinesItemClickListener()));
new IsolinesItemClickListener(),
new GuidesItemClickListener()));
recycler.setAdapter(mAdapter);
}
@ -133,4 +135,19 @@ public class ToggleMapLayerDialog extends DialogFragment
listener.onIsolinesLayerSelected();
}
}
private class GuidesItemClickListener extends DefaultClickListener
{
private GuidesItemClickListener()
{
super(mAdapter);
}
@Override
public void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
{
OnGuidesLayerToggleListener listener = (OnGuidesLayerToggleListener) requireActivity();
listener.onGuidesLayerSelected();
}
}
}

View file

@ -11,4 +11,5 @@ public interface MainMenuOptionListener
void onSubwayLayerOptionSelected();
void onTrafficLayerOptionSelected();
void onIsolinesLayerOptionSelected();
void onGuidesLayerOptionSelected();
}

View file

@ -98,7 +98,8 @@ public class MainMenuRenderer implements MenuRenderer
mLayersAdapter.setLayerModes(LayersUtils.createItems(layersRecycler.getContext(),
new SubwayItemClickListener(),
new TrafficItemClickListener(),
new IsolinesItemClickListener()));
new IsolinesItemClickListener(),
new GuidesItemClickListener()));
layersRecycler.setAdapter(mLayersAdapter);
}
@ -163,4 +164,18 @@ public class MainMenuRenderer implements MenuRenderer
mListener.onIsolinesLayerOptionSelected();
}
}
private class GuidesItemClickListener extends DefaultClickListener
{
GuidesItemClickListener()
{
super(mLayersAdapter);
}
@Override
public void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
{
mListener.onGuidesLayerOptionSelected();
}
}
}