From b3ba0d6a1cd97579b96d387be841966f0ec3807a Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Mon, 14 Mar 2022 13:41:34 +0100 Subject: [PATCH] [android] Simplify layers management Signed-off-by: Arnaud Vergnet --- .../layout-land/map_navigation_buttons.xml | 23 +-- ..._bottomsheet_dialog.xml => item_layer.xml} | 37 ++-- android/res/layout/map_navigation_buttons.xml | 17 -- .../src/com/mapswithme/maps/MwmActivity.java | 31 ++- .../AbstractIsoLinesClickListener.java | 29 --- .../maps/maplayer/BottomSheetItem.java | 102 ---------- .../maps/maplayer/DefaultClickListener.java | 31 --- .../maps/maplayer/LayerBottomSheetItem.java | 96 +++++++++ .../mapswithme/maps/maplayer/LayerHolder.java | 23 +-- .../maps/maplayer/LayersAdapter.java | 30 +-- .../mapswithme/maps/maplayer/LayersUtils.java | 31 +-- .../maplayer/MapLayerCompositeController.java | 190 ------------------ .../maps/maplayer/MapLayerController.java | 14 -- .../maps/maplayer/MapLayersController.java | 107 ++++++++++ .../com/mapswithme/maps/maplayer/Mode.java | 26 --- .../maps/maplayer/ToggleMapLayerFragment.java | 93 ++++----- .../widget/TrafficButtonController.java | 13 +- .../mapswithme/maps/widget/menu/MainMenu.java | 35 ---- .../mapswithme/maps/widget/menu/NavMenu.java | 12 +- 19 files changed, 306 insertions(+), 634 deletions(-) rename android/res/layout/{item_bottomsheet_dialog.xml => item_layer.xml} (74%) delete mode 100644 android/src/com/mapswithme/maps/maplayer/AbstractIsoLinesClickListener.java delete mode 100644 android/src/com/mapswithme/maps/maplayer/BottomSheetItem.java delete mode 100644 android/src/com/mapswithme/maps/maplayer/DefaultClickListener.java create mode 100644 android/src/com/mapswithme/maps/maplayer/LayerBottomSheetItem.java delete mode 100644 android/src/com/mapswithme/maps/maplayer/MapLayerCompositeController.java delete mode 100644 android/src/com/mapswithme/maps/maplayer/MapLayerController.java create mode 100644 android/src/com/mapswithme/maps/maplayer/MapLayersController.java diff --git a/android/res/layout-land/map_navigation_buttons.xml b/android/res/layout-land/map_navigation_buttons.xml index 4f46effed7..cf4ceb9588 100644 --- a/android/res/layout-land/map_navigation_buttons.xml +++ b/android/res/layout-land/map_navigation_buttons.xml @@ -1,6 +1,7 @@ - - - - + android:background="?toggleMapLayerBtnBg" + android:visibility="invisible" + tools:visibility="visible" /> - + android:layout_height="match_parent" + android:layout_marginTop="@dimen/margin_direction_big" + android:orientation="vertical"> + + android:layout_height="wrap_content" + android:layout_gravity="center"> + + android:minHeight="@dimen/margin_double_plus" + tools:background="?attr/subwayMenuDisabled" /> + + + tools:text="Layer Name" /> diff --git a/android/res/layout/map_navigation_buttons.xml b/android/res/layout/map_navigation_buttons.xml index 3b57dbc3e4..fe7d29d1cc 100644 --- a/android/res/layout/map_navigation_buttons.xml +++ b/android/res/layout/map_navigation_buttons.xml @@ -17,23 +17,6 @@ android:visibility="invisible" tools:visibility="visible" /> - - - - -{ - @NonNull - private final LayersAdapter mAdapter; - - public DefaultClickListener(@NonNull LayersAdapter adapter) - { - mAdapter = adapter; - } - - @Override - public void onItemClick(@NonNull View v, @NonNull BottomSheetItem item) - { - Mode mode = item.getMode(); - SharedPropertiesUtils.setLayerMarkerShownForLayerMode(v.getContext(), mode); - mode.toggle(v.getContext()); - onItemClickInternal(v, item); - mAdapter.notifyDataSetChanged(); - } - - public abstract void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item); -} diff --git a/android/src/com/mapswithme/maps/maplayer/LayerBottomSheetItem.java b/android/src/com/mapswithme/maps/maplayer/LayerBottomSheetItem.java new file mode 100644 index 0000000000..d55bb47855 --- /dev/null +++ b/android/src/com/mapswithme/maps/maplayer/LayerBottomSheetItem.java @@ -0,0 +1,96 @@ +package com.mapswithme.maps.maplayer; + +import android.content.Context; +import android.view.View; + +import androidx.annotation.DrawableRes; +import androidx.annotation.NonNull; +import androidx.annotation.StringRes; + +import com.mapswithme.maps.R; +import com.mapswithme.maps.adapter.OnItemClickListener; +import com.mapswithme.util.ThemeUtils; + +public class LayerBottomSheetItem +{ + @DrawableRes + private final int mEnabledStateDrawableResId; + @DrawableRes + private final int mDisabledStateDrawableResId; + @StringRes + private final int mTitleResId; + @NonNull + private final Mode mMode; + @NonNull + private final OnItemClickListener mItemClickListener; + + LayerBottomSheetItem(@DrawableRes int enabledStateDrawableResId, + @DrawableRes int disabledStateDrawableResId, + @StringRes int titleResId, + @NonNull Mode mode, + @NonNull OnItemClickListener itemClickListener) + { + mEnabledStateDrawableResId = enabledStateDrawableResId; + mDisabledStateDrawableResId = disabledStateDrawableResId; + mTitleResId = titleResId; + mMode = mode; + mItemClickListener = itemClickListener; + } + + public static LayerBottomSheetItem create(@NonNull Context mContext, Mode mode, @NonNull OnItemClickListener layerItemClickListener) + { + int disabledResource = R.attr.toggleMapLayerBtnBg; + int enabledResource = R.attr.toggleMapLayerBtnBg; + int buttonTextResource = R.string.layers_title; + switch (mode) + { + case SUBWAY: + disabledResource = R.attr.subwayMenuDisabled; + enabledResource = R.attr.subwayMenuEnabled; + buttonTextResource = R.string.button_layer_subway; + break; + case ISOLINES: + disabledResource = R.attr.isoLinesMenuDisabled; + enabledResource = R.attr.isoLinesMenuEnabled; + buttonTextResource = R.string.button_layer_isolines; + break; + case TRAFFIC: + disabledResource = R.attr.trafficMenuDisabled; + enabledResource = R.attr.trafficMenuEnabled; + buttonTextResource = R.string.button_layer_traffic; + break; + } + int disabled = ThemeUtils.getResource(mContext, disabledResource); + int enabled = ThemeUtils.getResource(mContext, enabledResource); + return new LayerBottomSheetItem(enabled, disabled, buttonTextResource, mode, layerItemClickListener); + } + + @NonNull + public Mode getMode() + { + return mMode; + } + + @DrawableRes + public int getEnabledStateDrawable() + { + return mEnabledStateDrawableResId; + } + + @DrawableRes + public int getDisabledStateDrawable() + { + return mDisabledStateDrawableResId; + } + + @StringRes + public int getTitle() + { + return mTitleResId; + } + + public void onClick(@NonNull View v, @NonNull LayerBottomSheetItem item) + { + mItemClickListener.onItemClick(v, item); + } +} diff --git a/android/src/com/mapswithme/maps/maplayer/LayerHolder.java b/android/src/com/mapswithme/maps/maplayer/LayerHolder.java index 99618b5c6b..20227079f7 100644 --- a/android/src/com/mapswithme/maps/maplayer/LayerHolder.java +++ b/android/src/com/mapswithme/maps/maplayer/LayerHolder.java @@ -11,8 +11,6 @@ import androidx.recyclerview.widget.RecyclerView; import com.mapswithme.maps.R; import com.mapswithme.maps.adapter.OnItemClickListener; -import java.util.Objects; - class LayerHolder extends RecyclerView.ViewHolder { @NonNull @@ -22,9 +20,9 @@ class LayerHolder extends RecyclerView.ViewHolder @NonNull final View mNewMarker; @Nullable - BottomSheetItem mItem; + LayerBottomSheetItem mItem; @Nullable - OnItemClickListener mListener; + OnItemClickListener mListener; LayerHolder(@NonNull View root) { @@ -35,20 +33,9 @@ class LayerHolder extends RecyclerView.ViewHolder mButton.setOnClickListener(this::onItemClicked); } - @NonNull - public BottomSheetItem getItem() + public void onItemClicked(@NonNull View v) { - return Objects.requireNonNull(mItem); - } - - @NonNull - public OnItemClickListener getListener() - { - return Objects.requireNonNull(mListener); - } - - private void onItemClicked(@NonNull View v) - { - getListener().onItemClick(v, getItem()); + if (mListener != null && mItem != null) + mListener.onItemClick(v, mItem); } } diff --git a/android/src/com/mapswithme/maps/maplayer/LayersAdapter.java b/android/src/com/mapswithme/maps/maplayer/LayersAdapter.java index f209e17324..428670c3a1 100644 --- a/android/src/com/mapswithme/maps/maplayer/LayersAdapter.java +++ b/android/src/com/mapswithme/maps/maplayer/LayersAdapter.java @@ -1,52 +1,43 @@ package com.mapswithme.maps.maplayer; import android.content.Context; -import android.util.Pair; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; import com.mapswithme.maps.R; -import com.mapswithme.maps.adapter.OnItemClickListener; import com.mapswithme.util.SharedPropertiesUtils; import com.mapswithme.util.UiUtils; import java.util.List; -import java.util.Objects; public class LayersAdapter extends RecyclerView.Adapter { - @Nullable - private List>> mItems; + @NonNull + private final List mItems; - public LayersAdapter() + public LayersAdapter(@NonNull List items) { + mItems = items; } - public void setLayerModes(@NonNull List>> modes) - { - mItems = modes; - } - + @NonNull @Override public LayerHolder onCreateViewHolder(ViewGroup parent, int viewType) { LayoutInflater inflater = LayoutInflater.from(parent.getContext()); - View root = inflater.inflate(R.layout.item_bottomsheet_dialog, parent, false); + View root = inflater.inflate(R.layout.item_layer, parent, false); return new LayerHolder(root); } @Override public void onBindViewHolder(LayerHolder holder, int position) { - Objects.requireNonNull(mItems); Context context = holder.itemView.getContext(); - Pair> pair = mItems.get(position); - BottomSheetItem item = pair.first; + LayerBottomSheetItem item = mItems.get(position); holder.mItem = item; boolean isEnabled = item.getMode().isEnabled(context); @@ -55,17 +46,16 @@ public class LayersAdapter extends RecyclerView.Adapter holder.mTitle.setSelected(isEnabled); holder.mTitle.setText(item.getTitle()); boolean isNewLayer = SharedPropertiesUtils.shouldShowNewMarkerForLayerMode(context, - item.getMode()); + item.getMode()); UiUtils.showIf(isNewLayer, holder.mNewMarker); holder.mButton.setImageResource(isEnabled ? item.getEnabledStateDrawable() - : item.getDisabledStateDrawable()); - holder.mListener = pair.second; + : item.getDisabledStateDrawable()); + holder.mListener = item::onClick; } @Override public int getItemCount() { - Objects.requireNonNull(mItems); return mItems.size(); } } diff --git a/android/src/com/mapswithme/maps/maplayer/LayersUtils.java b/android/src/com/mapswithme/maps/maplayer/LayersUtils.java index 5e057d5866..f75fb1d155 100644 --- a/android/src/com/mapswithme/maps/maplayer/LayersUtils.java +++ b/android/src/com/mapswithme/maps/maplayer/LayersUtils.java @@ -1,34 +1,15 @@ package com.mapswithme.maps.maplayer; -import android.content.Context; -import android.util.Pair; - -import androidx.annotation.NonNull; - -import com.mapswithme.maps.adapter.OnItemClickListener; - -import java.util.Arrays; +import java.util.ArrayList; import java.util.List; public class LayersUtils { - @NonNull - public static List>> createItems( - @NonNull Context context, @NonNull OnItemClickListener subwayListener, - @NonNull OnItemClickListener trafficListener, - @NonNull OnItemClickListener isoLinesListener) + public static List getAvailableLayers() { - Pair> subway - = new Pair<>(BottomSheetItem.Subway.makeInstance(context), subwayListener); - - /* - Pair> traffic - = new Pair<>(BottomSheetItem.Traffic.makeInstance(context), trafficListener); - */ - - Pair> isoLines - = new Pair<>(BottomSheetItem.Isolines.makeInstance(context), isoLinesListener); - - return Arrays.asList(/*traffic,*/ isoLines, subway); + List availableLayers = new ArrayList<>(); + availableLayers.add(Mode.ISOLINES); + availableLayers.add(Mode.SUBWAY); + return availableLayers; } } diff --git a/android/src/com/mapswithme/maps/maplayer/MapLayerCompositeController.java b/android/src/com/mapswithme/maps/maplayer/MapLayerCompositeController.java deleted file mode 100644 index b96020ce77..0000000000 --- a/android/src/com/mapswithme/maps/maplayer/MapLayerCompositeController.java +++ /dev/null @@ -1,190 +0,0 @@ -package com.mapswithme.maps.maplayer; - -import android.view.View; -import android.view.ViewGroup; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; - -import com.mapswithme.util.InputUtils; -import com.mapswithme.util.UiUtils; - -import java.util.ArrayList; -import java.util.List; - -public class MapLayerCompositeController implements MapLayerController -{ - @NonNull - private final AppCompatActivity mActivity; - @NonNull - private final List mLayers; - @NonNull - private Mode mCurrentLayer; - @NonNull - private final View mLayersButton; - @NonNull - OnShowMenuListener mOnshowMenuListener; - - public MapLayerCompositeController(@NonNull View layersButton, @NonNull OnShowMenuListener onshowMenuListener, @NonNull AppCompatActivity activity) - { - mActivity = activity; - mLayersButton = layersButton; - mLayersButton.setOnClickListener(view -> onLayersButtonClick()); - mOnshowMenuListener = onshowMenuListener; - mLayers = new ArrayList<>(); - mLayers.add(Mode.SUBWAY); - mLayers.add(Mode.ISOLINES); - mCurrentLayer = getCurrentLayer(); - toggleMode(mCurrentLayer); - } - - public void toggleMode(@NonNull Mode mode) - { - toggleMode(mode, false); - } - - private void toggleMode(@NonNull Mode mode, boolean animate) - { - setMasterController(mode); - showMasterController(animate); - - boolean enabled = mode.isEnabled(mActivity); - if (enabled) - { - turnOn(); - } - else - { - turnOff(); - turnInitialMode(); - } - } - - private void turnInitialMode() - { - UiUtils.hide(mLayersButton); - mCurrentLayer = mLayers.iterator().next(); - UiUtils.show(mLayersButton); - } - - public void applyLastActiveMode() - { - toggleMode(mCurrentLayer, true); - } - - @Override - public void attachCore() - { - // Do nothing - } - - @Override - public void detachCore() - { - // Do nothing - } - - private void setMasterController(@NonNull Mode mode) - { - for (Mode each : mLayers) - { - if (each == mode) - { - mCurrentLayer = each; - } - else - { - UiUtils.hide(mLayersButton); - each.setEnabled(mActivity, false); - } - } - } - - private void showMasterController(boolean animate) - { - UiUtils.show(mLayersButton); - } - - @NonNull - private Mode getCurrentLayer() - { - for (Mode each : mLayers) - { - if (each.isEnabled(mActivity)) - return each; - } - return mLayers.iterator().next(); - } - - @Override - public void turnOn() - { - mLayersButton.setSelected(true); - mCurrentLayer.setEnabled(mActivity, true); - } - - @Override - public void turnOff() - { - mLayersButton.setSelected(false); - mCurrentLayer.setEnabled(mActivity, false); - } - - @Override - public void show() - { - UiUtils.show(mLayersButton); - } - - @Override - public void showImmediately() - { - UiUtils.show(mLayersButton); - } - - @Override - public void hide() - { - UiUtils.hide(mLayersButton); - } - - @Override - public void hideImmediately() - { - UiUtils.hide(mLayersButton); - } - - @Override - public void adjust(int offsetX, int offsetY) - { - ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mLayersButton.getLayoutParams(); - params.setMargins(offsetX, offsetY, 0, 0); - mLayersButton.setLayoutParams(params); - } - - public void turnOnView(@NonNull Mode mode) - { - setMasterController(mode); - UiUtils.show(mLayersButton); - mLayersButton.setSelected(true); - } - - private void onLayersButtonClick() - { - if (mCurrentLayer.isEnabled(mActivity)) - { - Mode mode = getCurrentLayer(); - turnOff(); - toggleMode(mode); - } else - { - InputUtils.hideKeyboard(mActivity.getWindow().getDecorView()); - mOnshowMenuListener.onShow(); - } - } - - public interface OnShowMenuListener - { - void onShow(); - } -} diff --git a/android/src/com/mapswithme/maps/maplayer/MapLayerController.java b/android/src/com/mapswithme/maps/maplayer/MapLayerController.java deleted file mode 100644 index 07fe30b4dd..0000000000 --- a/android/src/com/mapswithme/maps/maplayer/MapLayerController.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.mapswithme.maps.maplayer; - -import com.mapswithme.maps.content.CoreDetachable; - -public interface MapLayerController extends CoreDetachable -{ - void turnOn(); - void turnOff(); - void show(); - void showImmediately(); - void hide(); - void hideImmediately(); - void adjust(int offsetX, int offsetY); -} diff --git a/android/src/com/mapswithme/maps/maplayer/MapLayersController.java b/android/src/com/mapswithme/maps/maplayer/MapLayersController.java new file mode 100644 index 0000000000..5ef9b44c29 --- /dev/null +++ b/android/src/com/mapswithme/maps/maplayer/MapLayersController.java @@ -0,0 +1,107 @@ +package com.mapswithme.maps.maplayer; + +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import com.mapswithme.util.UiUtils; + +import java.util.List; + +public class MapLayersController +{ + @NonNull + private final AppCompatActivity mActivity; + @NonNull + private final List mLayers; + @NonNull + private final View mLayersButton; + @NonNull + OnShowMenuListener mOnShowMenuListener; + @NonNull + private Mode mCurrentLayer; + + public MapLayersController(@NonNull View layersButton, @NonNull OnShowMenuListener onShowMenuListener, @NonNull AppCompatActivity activity) + { + mActivity = activity; + mLayersButton = layersButton; + mLayersButton.setOnClickListener(view -> onLayersButtonClick()); + mOnShowMenuListener = onShowMenuListener; + mLayers = LayersUtils.getAvailableLayers(); + mCurrentLayer = getCurrentLayer(); + initMode(); + } + + private void initMode() + { + setEnabled(mCurrentLayer.isEnabled(mActivity)); + showButton(); + } + + @NonNull + private Mode getCurrentLayer() + { + for (Mode each : mLayers) + { + if (each.isEnabled(mActivity)) + return each; + } + return mLayers.iterator().next(); + } + + private void setCurrentLayer(@NonNull Mode mode) + { + for (Mode each : mLayers) + { + if (each == mode) + mCurrentLayer = each; + else + each.setEnabled(mActivity, false); + } + } + + private void setEnabled(boolean enabled) + { + mLayersButton.setSelected(enabled); + mCurrentLayer.setEnabled(mActivity, enabled); + } + + private void onLayersButtonClick() + { + if (mCurrentLayer.isEnabled(mActivity)) + setEnabled(false); + else + mOnShowMenuListener.onShow(); + } + + public void toggleMode(@NonNull Mode mode) + { + setCurrentLayer(mode); + showButton(); + setEnabled(!mode.isEnabled(mActivity)); + } + + public void showButton() + { + UiUtils.show(mLayersButton); + } + + public void hideButton() + { + UiUtils.hide(mLayersButton); + } + + public void adjust(int offsetX, int offsetY) + { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mLayersButton.getLayoutParams(); + params.setMargins(offsetX, offsetY, 0, 0); + mLayersButton.setLayoutParams(params); + } + + public interface OnShowMenuListener + { + void onShow(); + } +} diff --git a/android/src/com/mapswithme/maps/maplayer/Mode.java b/android/src/com/mapswithme/maps/maplayer/Mode.java index a08bc0bfb0..9f536ba28d 100644 --- a/android/src/com/mapswithme/maps/maplayer/Mode.java +++ b/android/src/com/mapswithme/maps/maplayer/Mode.java @@ -25,14 +25,6 @@ public enum Mode { TrafficManager.INSTANCE.setEnabled(isEnabled); } - - @Override - public void toggle(@NonNull Context context) - { - TrafficManager.INSTANCE.toggle(); - SubwayManager.from(context).setEnabled(false); - IsolinesManager.from(context).setEnabled(false); - } }, SUBWAY { @@ -47,14 +39,6 @@ public enum Mode { SubwayManager.from(context).setEnabled(isEnabled); } - - @Override - public void toggle(@NonNull Context context) - { - SubwayManager.from(context).toggle(); - TrafficManager.INSTANCE.setEnabled(false); - IsolinesManager.from(context).setEnabled(false); - } }, ISOLINES @@ -70,22 +54,12 @@ public enum Mode { IsolinesManager.from(context).setEnabled(isEnabled); } - - @Override - public void toggle(@NonNull Context context) - { - IsolinesManager.from(context).toggle(); - 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); - public abstract void toggle(@NonNull Context context); - public boolean isNew(@NonNull Context context) { return SharedPropertiesUtils.shouldShowNewMarkerForLayerMode(context, this); diff --git a/android/src/com/mapswithme/maps/maplayer/ToggleMapLayerFragment.java b/android/src/com/mapswithme/maps/maplayer/ToggleMapLayerFragment.java index 4819a3ba4a..a02c1a3631 100644 --- a/android/src/com/mapswithme/maps/maplayer/ToggleMapLayerFragment.java +++ b/android/src/com/mapswithme/maps/maplayer/ToggleMapLayerFragment.java @@ -1,5 +1,6 @@ package com.mapswithme.maps.maplayer; +import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -12,21 +13,24 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.mapswithme.maps.R; +import com.mapswithme.maps.maplayer.isolines.IsolinesManager; import com.mapswithme.maps.widget.recycler.SpanningLinearLayoutManager; +import com.mapswithme.util.SharedPropertiesUtils; +import com.mapswithme.util.Utils; + +import java.util.ArrayList; +import java.util.List; public class ToggleMapLayerFragment extends Fragment { @NonNull - private final LayerItemClickListener mIsolinesListener; - @NonNull - private final LayerItemClickListener mSubwayListener; - @NonNull + private final LayerItemClickListener mLayerItemClickListener; + @Nullable private LayersAdapter mAdapter; - public ToggleMapLayerFragment(@NonNull LayerItemClickListener isolinesListener, @NonNull LayerItemClickListener subwayListener) + public ToggleMapLayerFragment(@NonNull LayerItemClickListener layerItemClickListener) { - this.mIsolinesListener = isolinesListener; - this.mSubwayListener = subwayListener; + mLayerItemClickListener = layerItemClickListener; } @Nullable @@ -42,61 +46,38 @@ public class ToggleMapLayerFragment extends Fragment { RecyclerView recycler = root.findViewById(R.id.recycler); RecyclerView.LayoutManager layoutManager = new SpanningLinearLayoutManager(requireContext(), - LinearLayoutManager.HORIZONTAL, - false); + LinearLayoutManager.HORIZONTAL, + false); recycler.setLayoutManager(layoutManager); - mAdapter = new LayersAdapter(); - mAdapter.setLayerModes(LayersUtils.createItems(requireContext(), - new SubwayItemClickListener(), - new TrafficItemClickListener(), - new IsolinesItemClickListener())); + mAdapter = new LayersAdapter(getLayersItems()); recycler.setAdapter(mAdapter); recycler.setNestedScrollingEnabled(false); } + private List getLayersItems() + { + List availableLayers = LayersUtils.getAvailableLayers(); + List items = new ArrayList<>(); + for (Mode layer : availableLayers) + { + items.add(LayerBottomSheetItem.create(requireContext(), layer, this::onItemClick)); + } + return items; + } + + private void onItemClick(@NonNull View v, @NonNull LayerBottomSheetItem item) + { + Mode mode = item.getMode(); + Context context = v.getContext(); + SharedPropertiesUtils.setLayerMarkerShownForLayerMode(context, mode); + mAdapter.notifyDataSetChanged(); + if (IsolinesManager.from(context).shouldShowNotification()) + Utils.showSnackbar(context, v.getRootView(), R.string.isolines_toast_zooms_1_10); + mLayerItemClickListener.onClick(mode); + } + public interface LayerItemClickListener { - void onClick(); - } - - private class SubwayItemClickListener extends DefaultClickListener - { - private SubwayItemClickListener() - { - super(mAdapter); - } - - @Override - public void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item) - { - mSubwayListener.onClick(); - } - } - - private class TrafficItemClickListener extends DefaultClickListener - { - private TrafficItemClickListener() - { - super(mAdapter); - } - - @Override - public void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item) - {} - } - - private class IsolinesItemClickListener extends AbstractIsoLinesClickListener - { - private IsolinesItemClickListener() - { - super(mAdapter); - } - - @Override - public void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item) - { - super.onItemClickInternal(v, item); - mIsolinesListener.onClick(); - } + void onClick(@NonNull Mode mode); } } diff --git a/android/src/com/mapswithme/maps/maplayer/traffic/widget/TrafficButtonController.java b/android/src/com/mapswithme/maps/maplayer/traffic/widget/TrafficButtonController.java index 5f98c65153..b22d4ae4ed 100644 --- a/android/src/com/mapswithme/maps/maplayer/traffic/widget/TrafficButtonController.java +++ b/android/src/com/mapswithme/maps/maplayer/traffic/widget/TrafficButtonController.java @@ -9,11 +9,10 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import com.mapswithme.maps.R; -import com.mapswithme.maps.maplayer.MapLayerController; import com.mapswithme.maps.maplayer.traffic.TrafficManager; import com.mapswithme.util.Utils; -public class TrafficButtonController implements TrafficManager.TrafficCallback, MapLayerController +public class TrafficButtonController implements TrafficManager.TrafficCallback { @NonNull private final TrafficButton mButton; @@ -35,61 +34,51 @@ public class TrafficButtonController implements TrafficManager.TrafficCallback, turnOn(); } - @Override public void turnOn() { mButton.turnOn(); } - @Override public void hideImmediately() { mButton.hideImmediately(); } - @Override public void adjust(int offsetX, int offsetY) { mButton.setOffset(offsetX, offsetY); } - @Override public void attachCore() { TrafficManager.INSTANCE.attach(this); } - @Override public void detachCore() { destroy(); } - @Override public void onDisabled() { turnOff(); } - @Override public void turnOff() { mButton.turnOff(); } - @Override public void show() { mButton.show(); } - @Override public void showImmediately() { mButton.showImmediately(); } - @Override public void hide() { mButton.hide(); diff --git a/android/src/com/mapswithme/maps/widget/menu/MainMenu.java b/android/src/com/mapswithme/maps/widget/menu/MainMenu.java index 94949512b1..41b0277bd4 100644 --- a/android/src/com/mapswithme/maps/widget/menu/MainMenu.java +++ b/android/src/com/mapswithme/maps/widget/menu/MainMenu.java @@ -58,16 +58,6 @@ public class MainMenu extends BaseMenu return new MwmActivity.MenuClickDelegate(activity, item); } }, - ADD_PLACE(R.id.add_place) - { - @NonNull - @Override - public ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity, - @NonNull Item item) - { - throw new UnsupportedOperationException("Main menu option doesn't support it!"); - } - }, SEARCH(R.id.search) { @NonNull @@ -98,26 +88,6 @@ public class MainMenu extends BaseMenu return new MwmActivity.BookmarksDelegate(activity, item); } }, - SHARE_MY_LOCATION(R.id.share) - { - @NonNull - @Override - public ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity, - @NonNull Item item) - { - throw new UnsupportedOperationException("Main menu option doesn't support it!"); - } - }, - DOWNLOAD_MAPS(R.id.download_maps) - { - @NonNull - @Override - public ClickMenuDelegate createClickDelegate(@NonNull MwmActivity activity, - @NonNull Item item) - { - throw new UnsupportedOperationException("Main menu option doesn't support it!"); - } - }, SETTINGS(R.id.settings) { @NonNull @@ -233,12 +203,9 @@ public class MainMenu extends BaseMenu private void init() { - mapItem(Item.ADD_PLACE); mapItem(Item.SEARCH); mapItem(Item.HELP); mapItem(Item.BOOKMARKS); - mapItem(Item.SHARE_MY_LOCATION); - mapItem(Item.DOWNLOAD_MAPS); mapItem(Item.SETTINGS); setState(State.MENU, false); @@ -283,8 +250,6 @@ public class MainMenu extends BaseMenu if (isRouting) mToggle.hide(); } - - setVisible(Item.ADD_PLACE, !isRouting); } show(state != State.NAVIGATION && !isFullScreen); diff --git a/android/src/com/mapswithme/maps/widget/menu/NavMenu.java b/android/src/com/mapswithme/maps/widget/menu/NavMenu.java index 56c7fa2eb7..6b09f7c4b3 100644 --- a/android/src/com/mapswithme/maps/widget/menu/NavMenu.java +++ b/android/src/com/mapswithme/maps/widget/menu/NavMenu.java @@ -24,8 +24,8 @@ public class NavMenu extends BaseMenu private final int mAnimationDuration; @NonNull private final ImageView mTts; - @NonNull - private final ImageView mTraffic; +// @NonNull +// private final ImageView mTraffic; ImageView mToggle; @@ -44,8 +44,8 @@ public class NavMenu extends BaseMenu TOGGLE(R.id.toggle), TTS_VOLUME(R.id.tts_volume), STOP(R.id.stop), - SETTINGS(R.id.settings), - TRAFFIC(R.id.traffic); + SETTINGS(R.id.settings); +// TRAFFIC(R.id.traffic); private final int mViewId; @@ -94,7 +94,7 @@ public class NavMenu extends BaseMenu mapItem(Item.SETTINGS, mFrame); mTts = (ImageView) mapItem(Item.TTS_VOLUME, mFrame); - mTraffic = (ImageView) mapItem(Item.TRAFFIC, mFrame); +// mTraffic = (ImageView) mapItem(Item.TRAFFIC, mFrame); } @Override @@ -235,7 +235,7 @@ public class NavMenu extends BaseMenu Drawable onIcon = Graphics.tint(mFrame.getContext(), R.drawable.ic_setting_traffic_on, R.attr.colorAccent); Drawable offIcon = Graphics.tint(mFrame.getContext(), R.drawable.ic_setting_traffic_off); - mTraffic.setImageDrawable(TrafficManager.INSTANCE.isEnabled() ? onIcon : offIcon); +// mTraffic.setImageDrawable(TrafficManager.INSTANCE.isEnabled() ? onIcon : offIcon); } @Override