diff --git a/android/res/drawable/bg_subway_light.xml b/android/res/drawable/bg_subway_light.xml new file mode 100644 index 0000000000..850c414abc --- /dev/null +++ b/android/res/drawable/bg_subway_light.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/android/res/drawable/subway_bg_night_selected.xml b/android/res/drawable/bg_subway_light_default.xml similarity index 76% rename from android/res/drawable/subway_bg_night_selected.xml rename to android/res/drawable/bg_subway_light_default.xml index 762777b730..47077bcee5 100644 --- a/android/res/drawable/subway_bg_night_selected.xml +++ b/android/res/drawable/bg_subway_light_default.xml @@ -1,11 +1,11 @@ + - diff --git a/android/res/drawable/bg_subway_light_pressed.xml b/android/res/drawable/bg_subway_light_pressed.xml new file mode 100644 index 0000000000..83d11f1a6e --- /dev/null +++ b/android/res/drawable/bg_subway_light_pressed.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/android/res/drawable/bg_subway_light_selected.xml b/android/res/drawable/bg_subway_light_selected.xml new file mode 100644 index 0000000000..8e283b5307 --- /dev/null +++ b/android/res/drawable/bg_subway_light_selected.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/android/res/drawable/bg_subway_night.xml b/android/res/drawable/bg_subway_night.xml new file mode 100644 index 0000000000..91ddbee2d5 --- /dev/null +++ b/android/res/drawable/bg_subway_night.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/android/res/drawable/subway_bg_night_default.xml b/android/res/drawable/bg_subway_night_default.xml similarity index 100% rename from android/res/drawable/subway_bg_night_default.xml rename to android/res/drawable/bg_subway_night_default.xml diff --git a/android/res/drawable/subway_bg_night_pressed.xml b/android/res/drawable/bg_subway_night_pressed.xml similarity index 100% rename from android/res/drawable/subway_bg_night_pressed.xml rename to android/res/drawable/bg_subway_night_pressed.xml diff --git a/android/res/drawable/bg_subway_night_selected.xml b/android/res/drawable/bg_subway_night_selected.xml new file mode 100644 index 0000000000..fe5466a1a2 --- /dev/null +++ b/android/res/drawable/bg_subway_night_selected.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/android/res/drawable/bg_toggle_map_layer_btn.xml b/android/res/drawable/bg_toggle_map_layer_btn.xml new file mode 100644 index 0000000000..7d28ef4fae --- /dev/null +++ b/android/res/drawable/bg_toggle_map_layer_btn.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/android/res/drawable/traffic_subway_bg_default.xml b/android/res/drawable/bg_toggle_map_layer_btn_default.xml similarity index 77% rename from android/res/drawable/traffic_subway_bg_default.xml rename to android/res/drawable/bg_toggle_map_layer_btn_default.xml index c72e72eca6..aff70729be 100644 --- a/android/res/drawable/traffic_subway_bg_default.xml +++ b/android/res/drawable/bg_toggle_map_layer_btn_default.xml @@ -4,5 +4,5 @@ android:shape="oval" android:height="@dimen/margin_double_plus" android:width="@dimen/margin_double_plus"> - + diff --git a/android/res/drawable/traffic_subway_btn_bg_selected.xml b/android/res/drawable/bg_toggle_map_layer_btn_selected.xml similarity index 100% rename from android/res/drawable/traffic_subway_btn_bg_selected.xml rename to android/res/drawable/bg_toggle_map_layer_btn_selected.xml diff --git a/android/res/drawable/subway_bg_light.xml b/android/res/drawable/subway_bg_light.xml deleted file mode 100644 index b7f3286cee..0000000000 --- a/android/res/drawable/subway_bg_light.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/android/res/drawable/subway_bg_light_default.xml b/android/res/drawable/subway_bg_light_default.xml deleted file mode 100644 index 00aea5f0d8..0000000000 --- a/android/res/drawable/subway_bg_light_default.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - diff --git a/android/res/drawable/subway_bg_light_pressed.xml b/android/res/drawable/subway_bg_light_pressed.xml deleted file mode 100644 index b924ff266a..0000000000 --- a/android/res/drawable/subway_bg_light_pressed.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/android/res/drawable/subway_bg_light_selected.xml b/android/res/drawable/subway_bg_light_selected.xml deleted file mode 100644 index a327d62494..0000000000 --- a/android/res/drawable/subway_bg_light_selected.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - diff --git a/android/res/drawable/subway_bg_night.xml b/android/res/drawable/subway_bg_night.xml deleted file mode 100644 index cc313fd8fd..0000000000 --- a/android/res/drawable/subway_bg_night.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/android/res/drawable/traffic_subway_btn_bg.xml b/android/res/drawable/traffic_subway_btn_bg.xml deleted file mode 100644 index 3bae4d725b..0000000000 --- a/android/res/drawable/traffic_subway_btn_bg.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/android/res/layout/fragment_toggle_map_layer.xml b/android/res/layout/fragment_toggle_map_layer.xml index 726e3362a7..a954438e83 100644 --- a/android/res/layout/fragment_toggle_map_layer.xml +++ b/android/res/layout/fragment_toggle_map_layer.xml @@ -1,11 +1,11 @@ diff --git a/android/res/layout/bootsheet_dialog_item.xml b/android/res/layout/item_bottomsheet_dialog.xml similarity index 83% rename from android/res/layout/bootsheet_dialog_item.xml rename to android/res/layout/item_bottomsheet_dialog.xml index 10e028c714..3091824aee 100644 --- a/android/res/layout/bootsheet_dialog_item.xml +++ b/android/res/layout/item_bottomsheet_dialog.xml @@ -6,15 +6,16 @@ android:gravity="center" android:layout_height="match_parent"> diff --git a/android/res/layout/item_category_title.xml b/android/res/layout/item_category_title.xml index b747583bfa..5840b67322 100644 --- a/android/res/layout/item_category_title.xml +++ b/android/res/layout/item_category_title.xml @@ -11,7 +11,7 @@ android:fontFamily="@string/robotoMedium" android:text="@string/bookmarks" tools:targetApi="jelly_bean" - android:background="@color/bookmarks_list_item_bg" + android:background="@color/black_12" android:paddingEnd="@dimen/margin_base" android:paddingRight="@dimen/margin_base" android:paddingStart="@dimen/margin_base" diff --git a/android/res/values/colors.xml b/android/res/values/colors.xml index e2915e2743..202c9c8bcb 100644 --- a/android/res/values/colors.xml +++ b/android/res/values/colors.xml @@ -225,7 +225,4 @@ #E53935 #FF888A82 #FF1E96F0 - #1E000000 - #f5f5f5 - diff --git a/android/res/values/dimens.xml b/android/res/values/dimens.xml index 10482ac40e..c75dc5c274 100644 --- a/android/res/values/dimens.xml +++ b/android/res/values/dimens.xml @@ -248,5 +248,5 @@ 22dp 80dp 0dp - 98dp + 98dp diff --git a/android/res/values/themes-base.xml b/android/res/values/themes-base.xml index 8e991155e8..29899248af 100644 --- a/android/res/values/themes-base.xml +++ b/android/res/values/themes-base.xml @@ -126,7 +126,7 @@ @drawable/button_with_border @drawable/ic_ad_light @drawable/ic_deal_light - @drawable/subway_bg_light + @drawable/bg_subway_light @@ -256,6 +256,6 @@ @drawable/button_with_border_night @drawable/ic_ad_dark @drawable/ic_deal_dark - @drawable/subway_bg_night + @drawable/bg_subway_night diff --git a/android/src/com/mapswithme/maps/adapter/BottomSheetItem.java b/android/src/com/mapswithme/maps/adapter/BottomSheetItem.java index 8327199832..36429d3f36 100644 --- a/android/src/com/mapswithme/maps/adapter/BottomSheetItem.java +++ b/android/src/com/mapswithme/maps/adapter/BottomSheetItem.java @@ -1,21 +1,100 @@ package com.mapswithme.maps.adapter; -import android.content.Context; import android.support.annotation.DrawableRes; import android.support.annotation.NonNull; import android.support.annotation.StringRes; -import com.mapswithme.maps.MwmActivity; +import com.mapswithme.maps.R; +import com.mapswithme.maps.subway.Mode; +import com.mapswithme.util.ThemeUtils; -public interface BottomSheetItem +public abstract class BottomSheetItem { + private final int mEnabledStateDrawableResId; + private final int mDisabledStateDrawableResId; + private final int mTitleResId; + @NonNull + private final Mode mMode; + + protected BottomSheetItem(int enabledStateDrawableResId, + int disabledStateDrawableResId, + int titleResId, + @NonNull Mode mode) + { + mEnabledStateDrawableResId = enabledStateDrawableResId; + mDisabledStateDrawableResId = disabledStateDrawableResId; + mTitleResId = titleResId; + mMode = mode; + } + + @NonNull + public Mode getMode() + { + return mMode; + } +/* + boolean isSelected(@NonNull Context context); void onSelected(@NonNull MwmActivity activity); +*/ @DrawableRes - int getDrawableResId(@NonNull Context context); + public int getEnabledStateDrawable() + { + return mEnabledStateDrawableResId; + } + + @DrawableRes + public int getDisabledStateDrawable() + { + return mDisabledStateDrawableResId; + } @StringRes - int getTitleResId(); + public int getTitle() + { + return mTitleResId; + } + + public static class Subway extends BottomSheetItem + { + private Subway(int drawableResId, int disabledStateDrawableResId) + { + super(drawableResId, disabledStateDrawableResId, R.string.button_layer_subway, Mode.SUBWAY); + } + + public static BottomSheetItem makeInstance() + { + int disabled = getDisabledStateFromTheme(R.drawable.ic_subway_menu_dark_off, + R.drawable.ic_subway_menu_light_off); + + return new Subway(R.drawable.ic_subway_menu_on, disabled); + } + } + + private static int getDisabledStateFromTheme(int light, int dark) + { + return ThemeUtils.isNightTheme() + ? light + : dark; + } + + public static class Traffic extends BottomSheetItem + { + private Traffic(int drawableResId, int disabledStateDrawableResId) + { + super(drawableResId, disabledStateDrawableResId, R.string.button_layer_traffic, Mode.TRAFFIC); + } + + public static BottomSheetItem makeInstance() + { + int disabled = getDisabledStateFromTheme(R.drawable.ic_traffic_menu_dark_off, + R.drawable.ic_traffic_menu_light_off); + + return new Traffic(R.drawable.ic_traffic_menu_on, disabled); + } + } + + } diff --git a/android/src/com/mapswithme/maps/subway/Mode.java b/android/src/com/mapswithme/maps/subway/Mode.java index 0f60ae3ec4..4ed4ecf4e2 100644 --- a/android/src/com/mapswithme/maps/subway/Mode.java +++ b/android/src/com/mapswithme/maps/subway/Mode.java @@ -1,27 +1,28 @@ package com.mapswithme.maps.subway; +import android.content.Context; import android.support.annotation.NonNull; -import android.support.v7.app.AppCompatActivity; -import com.mapswithme.maps.adapter.BottomSheetItem; -import com.mapswithme.maps.traffic.TrafficItem; +import com.mapswithme.maps.traffic.TrafficManager; public enum Mode { - TRAFFIC(new TrafficItem()), - SUBWAY(new SubwayItem()); + TRAFFIC + { + @Override + public boolean isEnabled(@NonNull Context context) + { + return TrafficManager.INSTANCE.isEnabled(); + } + }, + SUBWAY + { + @Override + public boolean isEnabled(@NonNull Context context) + { + return SubwayManager.from(context).isEnabled(); + } + }; - @NonNull - private final BottomSheetItem mItem; - - Mode(@NonNull BottomSheetItem item) - { - mItem = item; - } - - @NonNull - public BottomSheetItem getItem() - { - return mItem; - } + public abstract boolean isEnabled(@NonNull Context context); } diff --git a/android/src/com/mapswithme/maps/subway/SubwayItem.java b/android/src/com/mapswithme/maps/subway/SubwayItem.java deleted file mode 100644 index aeb52e27ea..0000000000 --- a/android/src/com/mapswithme/maps/subway/SubwayItem.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.mapswithme.maps.subway; - -import android.content.Context; -import android.support.annotation.NonNull; - -import com.mapswithme.maps.MwmActivity; -import com.mapswithme.maps.R; -import com.mapswithme.maps.adapter.BottomSheetItem; -import com.mapswithme.maps.traffic.TrafficManager; - -class SubwayItem implements BottomSheetItem -{ - @Override - public void onSelected(@NonNull MwmActivity activity) - { - SubwayManager.from(activity).toggle(); - TrafficManager.INSTANCE.setEnabled(false); - activity.onSubwayModeSelected(); - } - - @Override - public int getDrawableResId(@NonNull Context context) - { - return SubwayManager.from(context).getIconRes(); - } - - @Override - public int getTitleResId() - { - return R.string.button_layer_subway; - } - - @Override - public boolean isSelected(@NonNull Context context) - { - return SubwayManager.from(context).isEnabled(); - } -} diff --git a/android/src/com/mapswithme/maps/subway/SubwayManager.java b/android/src/com/mapswithme/maps/subway/SubwayManager.java index fc1ba8112a..fc5efc7c7a 100644 --- a/android/src/com/mapswithme/maps/subway/SubwayManager.java +++ b/android/src/com/mapswithme/maps/subway/SubwayManager.java @@ -52,24 +52,6 @@ public class SubwayManager nativeRemoveListener(listener); } - @DrawableRes - public int getIconRes() - { - return isEnabled() ? getEnabledStateIcon() : getDisabledStateIcon(); - } - - private int getEnabledStateIcon() - { - return R.drawable.ic_subway_menu_on; - } - - private int getDisabledStateIcon() - { - return ThemeUtils.isNightTheme() - ? R.drawable.ic_subway_menu_dark_off - : R.drawable.ic_subway_menu_light_off; - } - @NonNull public static SubwayManager from(@NonNull Context context) { diff --git a/android/src/com/mapswithme/maps/subway/ToggleMapLayerDialog.java b/android/src/com/mapswithme/maps/subway/ToggleMapLayerDialog.java index 9e0bc0bd3f..08e006e701 100644 --- a/android/src/com/mapswithme/maps/subway/ToggleMapLayerDialog.java +++ b/android/src/com/mapswithme/maps/subway/ToggleMapLayerDialog.java @@ -12,22 +12,24 @@ import android.support.v4.app.FragmentManager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.util.Pair; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.TextView; -import com.mapswithme.maps.MwmActivity; import com.mapswithme.maps.R; +import com.mapswithme.maps.adapter.BottomSheetItem; import com.mapswithme.maps.adapter.SpanningLinearLayoutManager; import com.mapswithme.maps.bookmarks.OnItemClickListener; +import com.mapswithme.maps.traffic.widget.OnTrafficModeSelectListener; import java.util.Arrays; import java.util.List; import java.util.Objects; -public class ToggleMapLayerDialog extends DialogFragment implements OnItemClickListener +public class ToggleMapLayerDialog extends DialogFragment { @NonNull @SuppressWarnings("NullableProblems") @@ -68,16 +70,22 @@ public class ToggleMapLayerDialog extends DialogFragment implements OnItemClickL LinearLayoutManager.HORIZONTAL, false); recycler.setLayoutManager(layoutManager); - mAdapter = new ModeAdapter(Arrays.asList(Mode.values()), this); + mAdapter = new ModeAdapter(createItems()); recycler.setAdapter(mAdapter); } - @Override - public void onItemClick(@NonNull View v, @NonNull Mode item) + @NonNull + private List>> createItems() { - MwmActivity activity = (MwmActivity) getActivity(); - item.getItem().onSelected(activity); - mAdapter.notifyDataSetChanged(); + SubwayItemClickListener subwayListener = new SubwayItemClickListener(); + Pair> subway + = new Pair<>(BottomSheetItem.Subway.makeInstance(), subwayListener); + + TrafficItemClickListener trafficListener = new TrafficItemClickListener(); + Pair> traffic + = new Pair<>(BottomSheetItem.Traffic.makeInstance(), trafficListener); + + return Arrays.asList(subway, traffic); } public static void show(@NonNull AppCompatActivity activity) @@ -97,40 +105,42 @@ public class ToggleMapLayerDialog extends DialogFragment implements OnItemClickL private static class ModeAdapter extends RecyclerView.Adapter { @NonNull - private final List mModes; - @NonNull - private final OnItemClickListener mListener; + private final List>> mItems; - private ModeAdapter(@NonNull List modes, - @NonNull OnItemClickListener listener) + private ModeAdapter(@NonNull List>> modes) { - mModes = modes; - mListener = listener; + mItems = modes; } @Override public ModeHolder onCreateViewHolder(ViewGroup parent, int viewType) { LayoutInflater inflater = LayoutInflater.from(parent.getContext()); - View root = inflater.inflate(R.layout.bootsheet_dialog_item, parent, false); - return new ModeHolder(root, mListener); + View root = inflater.inflate(R.layout.item_bottomsheet_dialog, parent, false); + return new ModeHolder(root); } @Override public void onBindViewHolder(ModeHolder holder, int position) { Context context = holder.itemView.getContext(); - Mode mode = mModes.get(position); - holder.mItem = mode; - holder.mButton.setSelected(mode.getItem().isSelected(context)); - holder.mButton.setImageResource(mode.getItem().getDrawableResId(context)); - holder.mTitle.setText(mode.getItem().getTitleResId()); + Pair> pair = mItems.get(position); + BottomSheetItem item = pair.first; + holder.mItem = item; + + boolean isEnabled = item.getMode().isEnabled(context); + + holder.mButton.setSelected(isEnabled); + holder.mTitle.setText(item.getTitle()); + holder.mButton.setImageResource(isEnabled ? item.getEnabledStateDrawable() + : item.getDisabledStateDrawable()); + holder.mListener = pair.second; } @Override public int getItemCount() { - return mModes.size(); + return mItems.size(); } } private static class ModeHolder extends RecyclerView.ViewHolder @@ -138,30 +148,67 @@ public class ToggleMapLayerDialog extends DialogFragment implements OnItemClickL @NonNull private final ImageButton mButton; @NonNull - private final OnItemClickListener mListener; - @NonNull private final TextView mTitle; @Nullable - private Mode mItem; + private BottomSheetItem mItem; + @Nullable + private OnItemClickListener mListener; - ModeHolder(@NonNull View root, @NonNull OnItemClickListener listener) + ModeHolder(@NonNull View root) { super(root); - mButton = root.findViewById(R.id.item_btn); + mButton = root.findViewById(R.id.btn); mTitle = root.findViewById(R.id.name); - mListener = listener; mButton.setOnClickListener(this::onItemClicked); } @NonNull - public Mode getItem() + public BottomSheetItem getItem() { return Objects.requireNonNull(mItem); } + @NonNull + public OnItemClickListener getListener() + { + return Objects.requireNonNull(mListener); + } + private void onItemClicked(@NonNull View v) { - mListener.onItemClick(v, getItem()); + getListener().onItemClick(v, getItem()); + } + } + + private abstract class DefaultClickListener implements OnItemClickListener + { + @Override + public final void onItemClick(@NonNull View v, @NonNull BottomSheetItem item) + { + onItemClickInternal(v, item); + mAdapter.notifyDataSetChanged(); + } + + abstract void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item); + } + + private class SubwayItemClickListener extends DefaultClickListener + { + @Override + void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item) + { + OnSubwayModeSelectListener listener = (OnSubwayModeSelectListener) getActivity(); + listener.onSubwayModeSelected(); + } + } + + private class TrafficItemClickListener extends DefaultClickListener + { + @Override + void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item) + { + OnTrafficModeSelectListener listener = (OnTrafficModeSelectListener) getActivity(); + listener.onTrafficModeSelected(); } } } diff --git a/android/src/com/mapswithme/maps/traffic/TrafficItem.java b/android/src/com/mapswithme/maps/traffic/TrafficItem.java deleted file mode 100644 index ff7dbd06c2..0000000000 --- a/android/src/com/mapswithme/maps/traffic/TrafficItem.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.mapswithme.maps.traffic; - -import android.content.Context; -import android.support.annotation.NonNull; - -import com.mapswithme.maps.MwmActivity; -import com.mapswithme.maps.R; -import com.mapswithme.maps.adapter.BottomSheetItem; -import com.mapswithme.maps.subway.SubwayManager; - -public class TrafficItem implements BottomSheetItem -{ - @Override - public boolean isSelected(@NonNull Context context) { - return !SubwayManager.from(context).isEnabled() - && TrafficManager.INSTANCE.isEnabled(); - } - - @Override - public void onSelected(@NonNull MwmActivity activity) - { - TrafficManager.INSTANCE.toggle(); - SubwayManager.from(activity).setEnabled(false); - activity.onTrafficModeSelected(); - } - - @Override - public int getDrawableResId(@NonNull Context context) - { - return TrafficManager.INSTANCE.getIconRes(); - } - - @Override - public int getTitleResId() - { - return R.string.button_layer_traffic; - } -} diff --git a/android/src/com/mapswithme/maps/traffic/TrafficManager.java b/android/src/com/mapswithme/maps/traffic/TrafficManager.java index fdec85f4c5..c69318f2e1 100644 --- a/android/src/com/mapswithme/maps/traffic/TrafficManager.java +++ b/android/src/com/mapswithme/maps/traffic/TrafficManager.java @@ -1,11 +1,8 @@ package com.mapswithme.maps.traffic; -import android.support.annotation.DrawableRes; import android.support.annotation.MainThread; import android.support.annotation.NonNull; -import com.mapswithme.maps.R; -import com.mapswithme.util.ThemeUtils; import com.mapswithme.util.Utils; import com.mapswithme.util.log.Logger; import com.mapswithme.util.log.LoggerFactory; @@ -108,24 +105,6 @@ public enum TrafficManager throw new AssertionError("Traffic manager is not initialized!"); } - @DrawableRes - public int getIconRes() - { - return isEnabled() ? getEnabledStateIcon() : getDisabledStateIcon(); - } - - private int getEnabledStateIcon() - { - return R.drawable.ic_traffic_menu_on; - } - - private int getDisabledStateIcon() - { - return ThemeUtils.isNightTheme() - ? R.drawable.ic_traffic_menu_dark_off - : R.drawable.ic_traffic_menu_light_off; - } - public void setEnabled(boolean enabled) { if (isEnabled() == enabled)