Add gpx menu

This commit is contained in:
PavelRatushny 2017-11-10 14:25:38 +02:00
parent ee96bcb5c2
commit 97c248dc98
10 changed files with 391 additions and 153 deletions

View file

@ -6,12 +6,20 @@
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/favourites_group_recycler_view"
android:id="@+id/groups_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/bottom_sheet_content_padding_small"
android:clipToPadding="false"/>
<ProgressBar
android:id="@+id/progress_bar"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:layout_gravity="center"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"

View file

@ -1,84 +1,31 @@
package net.osmand.plus.mapmarkers;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.adapters.FavouritesGroupsAdapter;
import java.util.List;
public class AddFavouritesGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public final static String TAG = "AddFavouritesGroupBottomSheetDialogFragment";
private AddFavouriteGroupListener listener;
public class AddFavouritesGroupBottomSheetDialogFragment extends AddMarkersGroupBottomSheetDialogFragment {
private List<FavoriteGroup> favoriteGroups;
private MapMarkersHelper mapMarkersHelper;
public void setListener(AddFavouriteGroupListener listener) {
this.listener = listener;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
favoriteGroups = getMyApplication().getFavorites().getFavoriteGroups();
mapMarkersHelper = getMyApplication().getMapMarkersHelper();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_favourites_group_bottom_sheet_dialog, container);
final RecyclerView recyclerView = mainView.findViewById(R.id.favourites_group_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
final FavouritesGroupsAdapter adapter = new FavouritesGroupsAdapter(getContext(), favoriteGroups);
adapter.setAdapterListener(new FavouritesGroupsAdapter.FavouritesGroupsAdapterListener() {
@Override
public void onItemClick(View view) {
int position = recyclerView.getChildAdapterPosition(view);
if (position == RecyclerView.NO_POSITION) {
return;
}
public MarkersSyncGroup createMapMarkersSyncGroup(int position) {
FavoriteGroup group = favoriteGroups.get(position - 1);
MarkersSyncGroup markersSyncGroup = new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
mapMarkersHelper.addMarkersSyncGroup(markersSyncGroup);
mapMarkersHelper.syncGroup(markersSyncGroup);
if (listener != null) {
listener.onFavouriteGroupAdded();
return new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
}
dismiss();
}
});
recyclerView.setAdapter(adapter);
mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
setupHeightAndBackground(mainView, R.id.favourites_group_recycler_view);
return mainView;
}
public interface AddFavouriteGroupListener {
void onFavouriteGroupAdded();
public void createAdapter() {
adapter = new FavouritesGroupsAdapter(getContext(), favoriteGroups);
}
}

View file

@ -2,57 +2,64 @@ package net.osmand.plus.mapmarkers;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.adapters.GroupsAdapter;
public class AddMarkersGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public abstract class AddMarkersGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public final static String TAG = "AddMarkersGroupBottomSheetDialogFragment";
public static final String TAG = "AddMarkersGroupBottomSheetDialogFragment";
private AddMarkersGroupFragmentListener listener;
private AddGroupListener listener;
protected View mainView;
protected GroupsAdapter adapter;
protected MapMarkersHelper mapMarkersHelper;
public void setListener(AddMarkersGroupFragmentListener listener) {
public void setListener(AddGroupListener listener) {
this.listener = listener;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapMarkersHelper = getMyApplication().getMapMarkersHelper();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_markers_group_bottom_sheet_dialog, container);
mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_group_bottom_sheet_dialog, container);
if (nightMode) {
((TextView) mainView.findViewById(R.id.add_group_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark));
}
((ImageView) mainView.findViewById(R.id.favourites_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_fav_dark));
((ImageView) mainView.findViewById(R.id.waypoints_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark));
mainView.findViewById(R.id.favourites_row).setOnClickListener(new View.OnClickListener() {
final RecyclerView recyclerView = mainView.findViewById(R.id.groups_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
createAdapter();
adapter.setAdapterListener(new GroupsAdapter.GroupsAdapterListener() {
@Override
public void onClick(View view) {
public void onItemClick(View view) {
int position = recyclerView.getChildAdapterPosition(view);
if (position == RecyclerView.NO_POSITION) {
return;
}
MarkersSyncGroup group = createMapMarkersSyncGroup(position);
mapMarkersHelper.addMarkersSyncGroup(group);
mapMarkersHelper.syncGroup(group);
if (listener != null) {
listener.favouritesOnClick();
}
dismiss();
}
});
mainView.findViewById(R.id.waypoints_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.waypointsOnClick();
listener.onGroupAdded();
}
dismiss();
}
});
recyclerView.setAdapter(adapter);
mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() {
@Override
@ -61,15 +68,16 @@ public class AddMarkersGroupBottomSheetDialogFragment extends MenuBottomSheetDia
}
});
setupHeightAndBackground(mainView, R.id.add_markers_group_scroll_view);
setupHeightAndBackground(mainView, R.id.groups_recycler_view);
return mainView;
}
interface AddMarkersGroupFragmentListener {
protected abstract void createAdapter();
void favouritesOnClick();
protected abstract MarkersSyncGroup createMapMarkersSyncGroup(int position);
void waypointsOnClick();
public interface AddGroupListener {
void onGroupAdded();
}
}

View file

@ -0,0 +1,138 @@
package net.osmand.plus.mapmarkers;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ProgressBar;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.plus.GPXDatabase;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.mapmarkers.adapters.TracksGroupsAdapter;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AddTracksGroupBottomSheetDialogFragment extends AddMarkersGroupBottomSheetDialogFragment {
private ProcessGpxTask asyncProcessor;
private List<GpxDataItem> gpxList = new ArrayList<>();
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
asyncProcessor = new ProcessGpxTask();
asyncProcessor.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public void createAdapter() {
adapter = new TracksGroupsAdapter(getContext(), gpxList);
}
@Override
public MarkersSyncGroup createMapMarkersSyncGroup(int position) {
GpxDataItem gpxDataItem = gpxList.get(position - 1);
File gpx = gpxDataItem.getFile();
return new MarkersSyncGroup(gpx.getAbsolutePath(), AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
}
@Override
public void onDestroyView() {
super.onDestroyView();
if (asyncProcessor != null) {
asyncProcessor.cancel(false);
asyncProcessor = null;
}
}
public class ProcessGpxTask extends AsyncTask<Void, GpxDataItem, Void> {
private OsmandApplication app = getMyApplication();
private Map<File, GpxDataItem> processedDataFiles = new HashMap<>();
private GPXDatabase db = app.getGpxDatabase();
private ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);;
private RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.groups_recycler_view);
ProcessGpxTask() {
List<GpxDataItem> dataItems = db.getItems();
for (GpxDataItem item : dataItems) {
processedDataFiles.put(item.getFile(), item);
}
}
@Override
protected void onPreExecute() {
recyclerView.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
}
@Override
protected Void doInBackground(Void... params) {
File gpxPath = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
if (gpxPath.canRead()) {
processGPXFolder(gpxPath, "");
}
return null;
}
private File[] listFilesSorted(File dir) {
File[] listFiles = dir.listFiles();
if (listFiles == null) {
return new File[0];
}
Arrays.sort(listFiles);
return listFiles;
}
private void processGPXFolder(File gpxPath, String gpxSubfolder) {
for (File gpxFile : listFilesSorted(gpxPath)) {
if (gpxFile.isDirectory()) {
String sub = gpxSubfolder.length() == 0 ?
gpxFile.getName() : gpxSubfolder + "/" + gpxFile.getName();
processGPXFolder(gpxFile, sub);
} else if (gpxFile.isFile() && gpxFile.getName().toLowerCase().endsWith(".gpx")) {
GpxDataItem item = processedDataFiles.get(gpxFile);
if (item == null || item.getFileLastModifiedTime() != gpxFile.lastModified()) {
GPXFile f = GPXUtilities.loadGPXFile(app, gpxFile);
GPXTrackAnalysis analysis = f.getAnalysis(gpxFile.lastModified());
if (item == null) {
item = new GpxDataItem(gpxFile, analysis);
db.add(item);
} else {
db.updateAnalysis(item, analysis);
}
}
processedDataFiles.put(gpxFile, item);
if (item.getAnalysis().wptPoints > 0) {
gpxList.add(item);
}
}
if (isCancelled()) {
break;
}
}
}
@Override
protected void onPostExecute(Void aVoid) {
asyncProcessor = null;
adapter.notifyDataSetChanged();
progressBar.setVisibility(View.GONE);
recyclerView.setVisibility(View.VISIBLE);
}
}
}

View file

@ -35,8 +35,7 @@ import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder;
import net.osmand.plus.mapmarkers.adapters.MapMarkersGroupsAdapter;
import net.osmand.plus.mapmarkers.AddMarkersGroupBottomSheetDialogFragment.AddMarkersGroupFragmentListener;
import net.osmand.plus.mapmarkers.AddFavouritesGroupBottomSheetDialogFragment.AddFavouriteGroupListener;
import net.osmand.plus.mapmarkers.SelectionMarkersGroupBottomSheetDialogFragment.AddMarkersGroupFragmentListener;
import net.osmand.plus.widgets.EmptyStateRecyclerView;
import net.osmand.util.MapUtils;
@ -62,13 +61,13 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
final boolean night = !mapActivity.getMyApplication().getSettings().isLightContent();
mainView = inflater.inflate(R.layout.fragment_map_markers_groups, container, false);
Fragment addMarkersGroupFragment = getChildFragmentManager().findFragmentByTag(AddMarkersGroupBottomSheetDialogFragment.TAG);
if (addMarkersGroupFragment != null) {
((AddMarkersGroupBottomSheetDialogFragment) addMarkersGroupFragment).setListener(createAddMarkersGroupFragmentListener());
Fragment selectionMarkersGroupFragment = getChildFragmentManager().findFragmentByTag(SelectionMarkersGroupBottomSheetDialogFragment.TAG);
if (selectionMarkersGroupFragment != null) {
((SelectionMarkersGroupBottomSheetDialogFragment) selectionMarkersGroupFragment).setListener(createAddMarkersGroupFragmentListener());
}
Fragment addFavouritesGroupFragment = getChildFragmentManager().findFragmentByTag(AddFavouritesGroupBottomSheetDialogFragment.TAG);
if (addFavouritesGroupFragment != null) {
((AddFavouritesGroupBottomSheetDialogFragment) addFavouritesGroupFragment).setListener(createAddFavouritesGroupListener());
Fragment addGroupFragment = getChildFragmentManager().findFragmentByTag(AddMarkersGroupBottomSheetDialogFragment.TAG);
if (addGroupFragment != null) {
((AddMarkersGroupBottomSheetDialogFragment) addGroupFragment).setListener(createAddGroupListener());
}
final EmptyStateRecyclerView recyclerView = (EmptyStateRecyclerView) mainView.findViewById(R.id.list);
@ -279,23 +278,22 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
}
private void openAddGroupMenu() {
AddMarkersGroupBottomSheetDialogFragment fragment = new AddMarkersGroupBottomSheetDialogFragment();
SelectionMarkersGroupBottomSheetDialogFragment fragment = new SelectionMarkersGroupBottomSheetDialogFragment();
fragment.setListener(createAddMarkersGroupFragmentListener());
fragment.setUsedOnMap(false);
fragment.show(getChildFragmentManager(), SelectionMarkersGroupBottomSheetDialogFragment.TAG);
}
private void openAddGroupMenu(AddMarkersGroupBottomSheetDialogFragment fragment) {
fragment.setListener(createAddGroupListener());
fragment.setUsedOnMap(false);
fragment.show(getChildFragmentManager(), AddMarkersGroupBottomSheetDialogFragment.TAG);
}
private void openAddFavouritesGroupMenu() {
AddFavouritesGroupBottomSheetDialogFragment fragment = new AddFavouritesGroupBottomSheetDialogFragment();
fragment.setListener(createAddFavouritesGroupListener());
fragment.setUsedOnMap(false);
fragment.show(getChildFragmentManager(), AddFavouritesGroupBottomSheetDialogFragment.TAG);
}
private AddFavouriteGroupListener createAddFavouritesGroupListener() {
return new AddFavouriteGroupListener() {
private AddMarkersGroupBottomSheetDialogFragment.AddGroupListener createAddGroupListener() {
return new AddMarkersGroupBottomSheetDialogFragment.AddGroupListener() {
@Override
public void onFavouriteGroupAdded() {
public void onGroupAdded() {
updateAdapter();
}
};
@ -305,12 +303,14 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
return new AddMarkersGroupFragmentListener() {
@Override
public void favouritesOnClick() {
openAddFavouritesGroupMenu();
AddFavouritesGroupBottomSheetDialogFragment fragment = new AddFavouritesGroupBottomSheetDialogFragment();
openAddGroupMenu(fragment);
}
@Override
public void waypointsOnClick() {
AddTracksGroupBottomSheetDialogFragment fragment = new AddTracksGroupBottomSheetDialogFragment();
openAddGroupMenu(fragment);
}
};
}

View file

@ -0,0 +1,75 @@
package net.osmand.plus.mapmarkers;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
public class SelectionMarkersGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
public final static String TAG = "SelectionMarkersGroupBottomSheetDialogFragment";
private AddMarkersGroupFragmentListener listener;
public void setListener(AddMarkersGroupFragmentListener listener) {
this.listener = listener;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_markers_group_bottom_sheet_dialog, container);
if (nightMode) {
((TextView) mainView.findViewById(R.id.add_group_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark));
}
((ImageView) mainView.findViewById(R.id.favourites_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_fav_dark));
((ImageView) mainView.findViewById(R.id.waypoints_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark));
mainView.findViewById(R.id.favourites_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.favouritesOnClick();
}
dismiss();
}
});
mainView.findViewById(R.id.waypoints_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.waypointsOnClick();
}
dismiss();
}
});
mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
setupHeightAndBackground(mainView, R.id.add_markers_group_scroll_view);
return mainView;
}
interface AddMarkersGroupFragmentListener {
void favouritesOnClick();
void waypointsOnClick();
}
}

View file

@ -14,43 +14,13 @@ import net.osmand.plus.R;
import java.util.List;
public class FavouritesGroupsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public class FavouritesGroupsAdapter extends GroupsAdapter {
private static final int TYPE_HEADER = 12;
private static final int TYPE_ITEM = 13;
private FavouritesGroupsAdapterListener listener;
private OsmandApplication app;
private List<FavoriteGroup> favoriteGroups;
private IconsCache iconsCache;
public FavouritesGroupsAdapter(Context context, List<FavoriteGroup> favoriteGroups) {
this.app = (OsmandApplication) context.getApplicationContext();
super(context);
this.favoriteGroups = favoriteGroups;
this.iconsCache = app.getIconsCache();
}
public void setAdapterListener(FavouritesGroupsAdapterListener listener) {
this.listener = listener;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_HEADER) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.add_favourites_group_header, parent, false);
return new MapMarkersGroupHeaderViewHolder(view);
} else {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.markers_group_view_holder, parent, false);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onItemClick(view);
}
}
});
return new MapMarkersGroupViewHolder(view);
}
}
@Override
@ -69,11 +39,6 @@ public class FavouritesGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
}
}
@Override
public int getItemViewType(int position) {
return position == 0 ? TYPE_HEADER : TYPE_ITEM;
}
@Override
public int getItemCount() {
return favoriteGroups.size() + 1;
@ -82,8 +47,4 @@ public class FavouritesGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
private FavoriteGroup getItem(int position) {
return favoriteGroups.get(position - 1);
}
public interface FavouritesGroupsAdapterListener {
void onItemClick(View view);
}
}

View file

@ -0,0 +1,58 @@
package net.osmand.plus.mapmarkers.adapters;
import android.content.Context;
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.OsmandApplication;
import net.osmand.plus.R;
public abstract class GroupsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int TYPE_HEADER = 12;
private static final int TYPE_ITEM = 13;
private GroupsAdapterListener listener;
protected OsmandApplication app;
protected IconsCache iconsCache;
public GroupsAdapter(Context context) {
this.app = (OsmandApplication) context.getApplicationContext();
this.iconsCache = app.getIconsCache();
}
public void setAdapterListener(GroupsAdapterListener listener) {
this.listener = listener;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_HEADER) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.add_markers_group_header, parent, false);
return new MapMarkersGroupHeaderViewHolder(view);
} else {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.markers_group_view_holder, parent, false);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onItemClick(view);
}
}
});
return new MapMarkersGroupViewHolder(view);
}
}
@Override
public int getItemViewType(int position) {
return position == 0 ? TYPE_HEADER : TYPE_ITEM;
}
public interface GroupsAdapterListener {
void onItemClick(View view);
}
}

View file

@ -0,0 +1,43 @@
package net.osmand.plus.mapmarkers.adapters;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.R;
import java.util.List;
public class TracksGroupsAdapter extends GroupsAdapter {
private List<GpxDataItem> gpxFiles;
public TracksGroupsAdapter(Context context, List<GpxDataItem> gpxFiles) {
super(context);
this.gpxFiles = gpxFiles;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof MapMarkersGroupHeaderViewHolder) {
MapMarkersGroupHeaderViewHolder markersGroupHeaderViewHolder = (MapMarkersGroupHeaderViewHolder) holder;
markersGroupHeaderViewHolder.title.setText(app.getText(R.string.shared_string_tracks));
markersGroupHeaderViewHolder.description.setText(app.getText(R.string.add_track_to_markers_descr));
} else if (holder instanceof MapMarkersGroupViewHolder) {
GpxDataItem gpx = getItem(position);
MapMarkersGroupViewHolder markersGroupViewHolder = (MapMarkersGroupViewHolder) holder;
markersGroupViewHolder.icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_polygom_dark));
markersGroupViewHolder.name.setText(gpx.getFile().getName().replace(".gpx", "").replace("/", " ").replace("_", " "));
markersGroupViewHolder.numberCount.setText(String.valueOf(gpx.getAnalysis().wptPoints));
}
}
@Override
public int getItemCount() {
return gpxFiles.size() + 1;
}
private GpxDataItem getItem(int position) {
return gpxFiles.get(position - 1);
}
}