From 11eb486144dd3f61eb877755ea3969f84eb8f614 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Thu, 14 Sep 2017 09:58:35 +0300 Subject: [PATCH] Add groups tab --- .../menu/map_markers_bottom_navigation.xml | 5 ++ OsmAnd/res/values/strings.xml | 1 + .../mapmarkers/MapMarkersDialogFragment.java | 22 ++++++-- .../mapmarkers/MapMarkersGroupsFragment.java | 37 ++++++++++++++ .../adapters/MapMarkersGroupsAdapter.java | 51 +++++++++++++++++++ 5 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java diff --git a/OsmAnd/res/menu/map_markers_bottom_navigation.xml b/OsmAnd/res/menu/map_markers_bottom_navigation.xml index 5751b155b0..23cd570d73 100644 --- a/OsmAnd/res/menu/map_markers_bottom_navigation.xml +++ b/OsmAnd/res/menu/map_markers_bottom_navigation.xml @@ -5,6 +5,11 @@ android:icon="@drawable/ic_map" android:title="@string/osm_live_active"/> + + + Groups Passed: %1$s Make active Today diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 06028476be..ccc2005fa0 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -31,6 +31,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm public static final String TAG = "MapMarkersDialogFragment"; private MapMarkersActiveFragment activeFragment; + private MapMarkersGroupsFragment groupsFragment; private MapMarkersHistoryFragment historyFragment; @Override @@ -50,6 +51,8 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm for (Fragment fragment : fragments) { if (fragment instanceof MapMarkersActiveFragment) { activeFragment = (MapMarkersActiveFragment) fragment; + } else if (fragment instanceof MapMarkersGroupsFragment) { + groupsFragment = (MapMarkersGroupsFragment) fragment; } else if (fragment instanceof MapMarkersHistoryFragment) { historyFragment = (MapMarkersHistoryFragment) fragment; } @@ -58,6 +61,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm if (activeFragment == null) { activeFragment = new MapMarkersActiveFragment(); } + if (groupsFragment == null) { + groupsFragment = new MapMarkersGroupsFragment(); + } if (historyFragment == null) { historyFragment = new MapMarkersHistoryFragment(); } @@ -111,13 +117,23 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm viewPager.setCurrentItem(0); optionsButton.setVisibility(View.VISIBLE); return true; - case R.id.action_history: + case R.id.action_groups: activeFragment.stopLocationUpdate(); if (viewPager.getCurrentItem() != 1) { + groupsFragment.updateAdapter(); + activeFragment.hideSnackbar(); + historyFragment.hideSnackbar(); + } + viewPager.setCurrentItem(1); + optionsButton.setVisibility(View.GONE); + return true; + case R.id.action_history: + activeFragment.stopLocationUpdate(); + if (viewPager.getCurrentItem() != 2) { historyFragment.updateAdapter(); activeFragment.hideSnackbar(); } - viewPager.setCurrentItem(1); + viewPager.setCurrentItem(2); optionsButton.setVisibility(View.GONE); return true; } @@ -203,7 +219,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm MapMarkersViewPagerAdapter(FragmentManager fm) { super(fm); - fragments = Arrays.asList(activeFragment, historyFragment); + fragments = Arrays.asList(activeFragment, groupsFragment, historyFragment); } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java new file mode 100644 index 0000000000..328575d030 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java @@ -0,0 +1,37 @@ +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 net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapmarkers.adapters.MapMarkersGroupsAdapter; + +public class MapMarkersGroupsFragment extends Fragment { + + public static final String TAG = "MapMarkersGroupsFragment"; + + private MapMarkersGroupsAdapter adapter; + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + final RecyclerView recyclerView = new RecyclerView(getContext()); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + final MapActivity mapActivity = (MapActivity) getActivity(); + + adapter = new MapMarkersGroupsAdapter(mapActivity); + return recyclerView; + } + + void updateAdapter() { + if (adapter != null) { + adapter.notifyDataSetChanged(); + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java new file mode 100644 index 0000000000..1aebc80531 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -0,0 +1,51 @@ +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; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; + +import java.util.List; + +public class MapMarkersGroupsAdapter extends RecyclerView.Adapter { + + private MapActivity mapActivity; + private List markers; + private boolean night; + + public MapMarkersGroupsAdapter(MapActivity mapActivity) { + this.mapActivity = mapActivity; + markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers(); + night = !mapActivity.getMyApplication().getSettings().isLightContent(); + } + + @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 mapMarkerItemViewHolder, int i) { + IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache(); + MapMarkersHelper.MapMarker marker = markers.get(i); + } + + @Override + public int getItemCount() { + return markers.size(); + } + + public MapMarkersHelper.MapMarker getItem(int position) { + return markers.get(position); + } + + public List getItems() { + return markers; + } +}