forked from organicmaps/organicmaps
[android] Implemented new marker displaying on a map layer button
This commit is contained in:
parent
30c8edf998
commit
87074d17b1
8 changed files with 150 additions and 49 deletions
|
@ -0,0 +1,30 @@
|
|||
package com.mapswithme.maps.maplayer;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.mapswithme.maps.adapter.OnItemClickListener;
|
||||
import com.mapswithme.util.SharedPropertiesUtils;
|
||||
|
||||
public abstract class DefaultClickListener implements OnItemClickListener<BottomSheetItem>
|
||||
{
|
||||
@NonNull
|
||||
private final LayersAdapter mAdapter;
|
||||
|
||||
public DefaultClickListener(@NonNull LayersAdapter adapter)
|
||||
{
|
||||
mAdapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final 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);
|
||||
}
|
|
@ -18,6 +18,8 @@ class LayerHolder extends RecyclerView.ViewHolder
|
|||
final ImageView mButton;
|
||||
@NonNull
|
||||
final TextView mTitle;
|
||||
@NonNull
|
||||
final View mNewMarker;
|
||||
@Nullable
|
||||
BottomSheetItem mItem;
|
||||
@Nullable
|
||||
|
@ -26,8 +28,9 @@ class LayerHolder extends RecyclerView.ViewHolder
|
|||
LayerHolder(@NonNull View root)
|
||||
{
|
||||
super(root);
|
||||
mButton = root.findViewById(R.id.btn);
|
||||
mTitle = root.findViewById(R.id.name);
|
||||
mNewMarker = root.findViewById(R.id.marker);
|
||||
mButton = root.findViewById(R.id.btn);
|
||||
mButton.setOnClickListener(this::onItemClicked);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,18 +7,26 @@ 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<LayerHolder>
|
||||
{
|
||||
@NonNull
|
||||
private final List<Pair<BottomSheetItem, OnItemClickListener<BottomSheetItem>>> mItems;
|
||||
@Nullable
|
||||
private List<Pair<BottomSheetItem, OnItemClickListener<BottomSheetItem>>> mItems;
|
||||
|
||||
public LayersAdapter(@NonNull List<Pair<BottomSheetItem, OnItemClickListener<BottomSheetItem>>> modes)
|
||||
public LayersAdapter()
|
||||
{
|
||||
}
|
||||
|
||||
public void setLayerModes(@NonNull List<Pair<BottomSheetItem, OnItemClickListener<BottomSheetItem>>> modes)
|
||||
{
|
||||
mItems = modes;
|
||||
}
|
||||
|
@ -34,6 +42,7 @@ public class LayersAdapter extends RecyclerView.Adapter<LayerHolder>
|
|||
@Override
|
||||
public void onBindViewHolder(LayerHolder holder, int position)
|
||||
{
|
||||
Objects.requireNonNull(mItems);
|
||||
Context context = holder.itemView.getContext();
|
||||
Pair<BottomSheetItem, OnItemClickListener<BottomSheetItem>> pair = mItems.get(position);
|
||||
BottomSheetItem item = pair.first;
|
||||
|
@ -44,6 +53,9 @@ public class LayersAdapter extends RecyclerView.Adapter<LayerHolder>
|
|||
holder.mButton.setSelected(isEnabled);
|
||||
holder.mTitle.setSelected(isEnabled);
|
||||
holder.mTitle.setText(item.getTitle());
|
||||
boolean isNewLayer = SharedPropertiesUtils.shouldShowNewMarkerForLayerMode(context,
|
||||
item.getMode());
|
||||
UiUtils.showIf(isNewLayer, holder.mNewMarker);
|
||||
holder.mButton.setImageResource(isEnabled ? item.getEnabledStateDrawable()
|
||||
: item.getDisabledStateDrawable());
|
||||
holder.mListener = pair.second;
|
||||
|
@ -52,6 +64,7 @@ public class LayersAdapter extends RecyclerView.Adapter<LayerHolder>
|
|||
@Override
|
||||
public int getItemCount()
|
||||
{
|
||||
Objects.requireNonNull(mItems);
|
||||
return mItems.size();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@ package com.mapswithme.maps.maplayer;
|
|||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.maps.maplayer.isolines.IsolinesManager;
|
||||
import com.mapswithme.maps.maplayer.subway.SubwayManager;
|
||||
import com.mapswithme.maps.maplayer.traffic.TrafficManager;
|
||||
import com.mapswithme.util.SharedPropertiesUtils;
|
||||
|
||||
public enum Mode
|
||||
{
|
||||
|
@ -84,4 +84,9 @@ public enum Mode
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.adapter.OnItemClickListener;
|
||||
import com.mapswithme.maps.maplayer.subway.OnSubwayLayerToggleListener;
|
||||
import com.mapswithme.maps.maplayer.traffic.OnTrafficLayerToggleListener;
|
||||
import com.mapswithme.maps.widget.recycler.SpanningLinearLayoutManager;
|
||||
|
@ -69,9 +68,10 @@ public class ToggleMapLayerDialog extends DialogFragment
|
|||
LinearLayoutManager.HORIZONTAL,
|
||||
false);
|
||||
recycler.setLayoutManager(layoutManager);
|
||||
mAdapter = new LayersAdapter(LayersUtils.createItems(requireContext(), new SubwayItemClickListener(),
|
||||
new TrafficItemClickListener(),
|
||||
new IsolinesItemClickListener()));
|
||||
mAdapter = new LayersAdapter();
|
||||
mAdapter.setLayerModes(LayersUtils.createItems(requireContext(), new SubwayItemClickListener(),
|
||||
new TrafficItemClickListener(),
|
||||
new IsolinesItemClickListener()));
|
||||
recycler.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
|
@ -89,23 +89,15 @@ public class ToggleMapLayerDialog extends DialogFragment
|
|||
fm.executePendingTransactions();
|
||||
}
|
||||
|
||||
private abstract class DefaultClickListener implements OnItemClickListener<BottomSheetItem>
|
||||
{
|
||||
@Override
|
||||
public final void onItemClick(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
{
|
||||
item.getMode().toggle(requireContext());
|
||||
onItemClickInternal(v, item);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
abstract void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item);
|
||||
}
|
||||
|
||||
private class SubwayItemClickListener extends DefaultClickListener
|
||||
{
|
||||
private SubwayItemClickListener()
|
||||
{
|
||||
super(mAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
public void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
{
|
||||
OnSubwayLayerToggleListener listener = (OnSubwayLayerToggleListener) requireActivity();
|
||||
listener.onSubwayLayerSelected();
|
||||
|
@ -114,8 +106,13 @@ public class ToggleMapLayerDialog extends DialogFragment
|
|||
|
||||
private class TrafficItemClickListener extends DefaultClickListener
|
||||
{
|
||||
private TrafficItemClickListener()
|
||||
{
|
||||
super(mAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
public void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
{
|
||||
OnTrafficLayerToggleListener listener = (OnTrafficLayerToggleListener) requireActivity();
|
||||
listener.onTrafficLayerSelected();
|
||||
|
@ -124,8 +121,13 @@ public class ToggleMapLayerDialog extends DialogFragment
|
|||
|
||||
private class IsolinesItemClickListener extends DefaultClickListener
|
||||
{
|
||||
private IsolinesItemClickListener()
|
||||
{
|
||||
super(mAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
public void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
{
|
||||
OnIsolinesLayerToggleListener listener = (OnIsolinesLayerToggleListener) requireActivity();
|
||||
listener.onIsolinesLayerSelected();
|
||||
|
|
|
@ -9,8 +9,10 @@ import com.mapswithme.maps.MwmActivity;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.downloader.MapManager;
|
||||
import com.mapswithme.maps.downloader.UpdateInfo;
|
||||
import com.mapswithme.maps.maplayer.Mode;
|
||||
import com.mapswithme.maps.routing.RoutingController;
|
||||
import com.mapswithme.util.Animations;
|
||||
import com.mapswithme.util.SharedPropertiesUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.statistics.StatisticValueConverter;
|
||||
|
||||
|
@ -257,7 +259,19 @@ public class MainMenu extends BaseMenu
|
|||
UpdateInfo info = MapManager.nativeGetUpdateInfo(null);
|
||||
int count = (info == null ? 0 : info.filesCount);
|
||||
|
||||
boolean show = count > 0 && !isOpen();
|
||||
boolean show = (count > 0 && !isOpen());
|
||||
|
||||
UiUtils.showIf(show, mNewsMarker);
|
||||
|
||||
if (show)
|
||||
return;
|
||||
|
||||
for (Mode mode : Mode.values())
|
||||
{
|
||||
show = SharedPropertiesUtils.shouldShowNewMarkerForLayerMode(mFrame.getContext(), mode);
|
||||
if (show)
|
||||
break;
|
||||
}
|
||||
|
||||
UiUtils.showIf(show, mNewsMarker);
|
||||
}
|
||||
|
|
|
@ -9,10 +9,10 @@ import androidx.core.widget.NestedScrollView;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.adapter.OnItemClickListener;
|
||||
import com.mapswithme.maps.downloader.MapManager;
|
||||
import com.mapswithme.maps.downloader.UpdateInfo;
|
||||
import com.mapswithme.maps.maplayer.BottomSheetItem;
|
||||
import com.mapswithme.maps.maplayer.DefaultClickListener;
|
||||
import com.mapswithme.maps.maplayer.LayersAdapter;
|
||||
import com.mapswithme.maps.maplayer.LayersUtils;
|
||||
import com.mapswithme.maps.widget.recycler.SpanningLinearLayoutManager;
|
||||
|
@ -90,10 +90,11 @@ public class MainMenuRenderer implements MenuRenderer
|
|||
LinearLayoutManager.HORIZONTAL,
|
||||
false);
|
||||
layersRecycler.setLayoutManager(layoutManager);
|
||||
mLayersAdapter = new LayersAdapter(LayersUtils.createItems(layersRecycler.getContext(),
|
||||
new SubwayItemClickListener(),
|
||||
new TrafficItemClickListener(),
|
||||
new IsolinesItemClickListener()));
|
||||
mLayersAdapter = new LayersAdapter();
|
||||
mLayersAdapter.setLayerModes(LayersUtils.createItems(layersRecycler.getContext(),
|
||||
new SubwayItemClickListener(),
|
||||
new TrafficItemClickListener(),
|
||||
new IsolinesItemClickListener()));
|
||||
layersRecycler.setAdapter(mLayersAdapter);
|
||||
}
|
||||
|
||||
|
@ -109,23 +110,15 @@ public class MainMenuRenderer implements MenuRenderer
|
|||
mScrollView.scrollTo(0, 0);
|
||||
}
|
||||
|
||||
private abstract class DefaultClickListener implements OnItemClickListener<BottomSheetItem>
|
||||
{
|
||||
@Override
|
||||
public final void onItemClick(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
{
|
||||
item.getMode().toggle(v.getContext());
|
||||
onItemClickInternal(v, item);
|
||||
mLayersAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
abstract void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item);
|
||||
}
|
||||
|
||||
private class SubwayItemClickListener extends DefaultClickListener
|
||||
{
|
||||
SubwayItemClickListener()
|
||||
{
|
||||
super(mLayersAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
public void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
{
|
||||
mListener.onSubwayLayerOptionSelected();
|
||||
}
|
||||
|
@ -133,8 +126,13 @@ public class MainMenuRenderer implements MenuRenderer
|
|||
|
||||
private class TrafficItemClickListener extends DefaultClickListener
|
||||
{
|
||||
TrafficItemClickListener()
|
||||
{
|
||||
super(mLayersAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
public void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
{
|
||||
mListener.onTrafficLayerOptionSelected();
|
||||
}
|
||||
|
@ -142,8 +140,13 @@ public class MainMenuRenderer implements MenuRenderer
|
|||
|
||||
private class IsolinesItemClickListener extends DefaultClickListener
|
||||
{
|
||||
IsolinesItemClickListener()
|
||||
{
|
||||
super(mLayersAdapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
public void onItemClickInternal(@NonNull View v, @NonNull BottomSheetItem item)
|
||||
{
|
||||
mListener.onIsolinesLayerOptionSelected();
|
||||
}
|
||||
|
|
|
@ -3,12 +3,15 @@ package com.mapswithme.util;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.BookmarksPageFactory;
|
||||
import com.mapswithme.maps.maplayer.Mode;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.mapswithme.util.Config.KEY_PREF_STATISTICS;
|
||||
|
||||
|
@ -21,6 +24,7 @@ public final class SharedPropertiesUtils
|
|||
private static final String PREFS_WHATS_NEW_TITLE_CONCATENATION = "WhatsNewTitleConcatenation";
|
||||
private static final String PREFS_CATALOG_CATEGORIES_HEADER_CLOSED = "CatalogCategoriesHeaderClosed";
|
||||
private static final String PREFS_BOOKMARK_CATEGORIES_LAST_VISIBLE_PAGE = "BookmarkCategoriesLastVisiblePage";
|
||||
private static final String PREFS_SHOULD_SHOW_LAYER_MARKER_FOR = "ShouldShowGuidesLayerMarkerFor";
|
||||
private static final SharedPreferences PREFS
|
||||
= PreferenceManager.getDefaultSharedPreferences(MwmApplication.get());
|
||||
|
||||
|
@ -126,9 +130,36 @@ public final class SharedPropertiesUtils
|
|||
putBoolean(context, USER_AGREEMENT_TERM_OF_USE, isChecked);
|
||||
}
|
||||
|
||||
public static boolean shouldShowNewMarkerForLayerMode(@NonNull Context context,
|
||||
@NonNull Mode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case SUBWAY:
|
||||
case TRAFFIC:
|
||||
case ISOLINES:
|
||||
return false;
|
||||
default:
|
||||
return getBoolean(context, PREFS_SHOULD_SHOW_LAYER_MARKER_FOR + mode.name()
|
||||
.toLowerCase(Locale.ENGLISH),
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setLayerMarkerShownForLayerMode(@NonNull Context context, @NonNull Mode mode)
|
||||
{
|
||||
putBoolean(context, PREFS_SHOULD_SHOW_LAYER_MARKER_FOR + mode.name()
|
||||
.toLowerCase(Locale.ENGLISH), false);
|
||||
}
|
||||
|
||||
private static boolean getBoolean(@NonNull Context context, @NonNull String key)
|
||||
{
|
||||
return MwmApplication.prefs(context).getBoolean(key, false);
|
||||
return getBoolean(context, key, false);
|
||||
}
|
||||
|
||||
private static boolean getBoolean(@NonNull Context context, @NonNull String key, boolean defValue)
|
||||
{
|
||||
return MwmApplication.prefs(context).getBoolean(key, defValue);
|
||||
}
|
||||
|
||||
private static void putBoolean(@NonNull Context context, @NonNull String key, boolean value)
|
||||
|
|
Loading…
Add table
Reference in a new issue