Add a display of markers from the history

This commit is contained in:
Alexander Sytnyk 2017-08-31 16:47:18 +03:00
parent 12dc86cc70
commit cd54ad21a6
3 changed files with 64 additions and 5 deletions

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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<MapMarkerItemViewHolder> {
private OsmandApplication app;
private List<MapMarker> 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();
}
}