From cd54ad21a61dbceace1ffa773ed3e5a000c35993 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 31 Aug 2017 16:47:18 +0300 Subject: [PATCH] Add a display of markers from the history --- .../mapmarkers/MapMarkersDialogFragment.java | 5 +- .../mapmarkers/MapMarkersHistoryFragment.java | 16 +++++-- .../adapters/MapMarkersHistoryAdapter.java | 48 +++++++++++++++++++ 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 4b689e261b..7f60d31240 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -49,7 +49,8 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm dismiss(); } }); - mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() { + final View optionsButton = mainView.findViewById(R.id.options_button); + optionsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(getContext(), "Options", Toast.LENGTH_SHORT).show(); @@ -69,10 +70,12 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm case R.id.action_active: ((MapMarkersActiveFragment) adapter.getItem(0)).startLocationUpdate(); viewPager.setCurrentItem(0); + optionsButton.setVisibility(View.VISIBLE); return true; case R.id.action_history: ((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate(); viewPager.setCurrentItem(1); + optionsButton.setVisibility(View.GONE); return true; } return false; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index 1667047172..b84d42ba86 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -3,18 +3,26 @@ package net.osmand.plus.mapmarkers; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; + +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter; public class MapMarkersHistoryFragment extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - TextView textView = new TextView(getContext()); - textView.setText("history fragment"); - return textView; + final RecyclerView recyclerView = new RecyclerView(getContext()); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + final MapActivity mapActivity = (MapActivity) getActivity(); + + recyclerView.setAdapter(new MapMarkersHistoryAdapter(mapActivity.getMyApplication())); + + return recyclerView; } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java new file mode 100644 index 0000000000..ee9b3bdd86 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -0,0 +1,48 @@ +package net.osmand.plus.mapmarkers.adapters; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import net.osmand.plus.IconsCache; +import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; + +import java.util.List; + +public class MapMarkersHistoryAdapter extends RecyclerView.Adapter { + + private OsmandApplication app; + private List markers; + + public MapMarkersHistoryAdapter(OsmandApplication app) { + this.app = app; + markers = app.getMapMarkersHelper().getMapMarkersHistory(); + } + + @Override + public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { + View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false); + return new MapMarkerItemViewHolder(view); + } + + @Override + public void onBindViewHolder(MapMarkerItemViewHolder holder, int pos) { + IconsCache iconsCache = app.getIconsCache(); + MapMarker marker = markers.get(pos); + + holder.iconReorder.setVisibility(View.GONE); + + int color = MapMarker.getColorId(marker.colorIndex); + holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color)); + + holder.title.setText(marker.getName(app)); + } + + @Override + public int getItemCount() { + return markers.size(); + } +}