Add possibility to move marker to history; add small changes

This commit is contained in:
Alex 2017-09-01 17:07:52 +03:00
parent 7bca3f2850
commit 0dcb35b8d3
7 changed files with 40 additions and 9 deletions

View file

@ -102,12 +102,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layout_marginBottom="16dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginTop="16dp"
android:background="?attr/selectableItemBackground"
android:focusableInTouchMode="true"
android:paddingBottom="16dp"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:paddingTop="16dp"
tools:src="@drawable/ic_overflow_menu_white"/>
</LinearLayout>

View file

@ -121,6 +121,12 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
return null;
}
void updateAdapter() {
if (adapter != null) {
adapter.notifyDataSetChanged();
}
}
private void updateLocationUi() {
final MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {

View file

@ -78,11 +78,17 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
switch (menuItem.getItemId()) {
case R.id.action_active:
((MapMarkersActiveFragment) adapter.getItem(0)).startLocationUpdate();
if (viewPager.getCurrentItem() != 0) {
((MapMarkersActiveFragment) adapter.getItem(0)).updateAdapter();
}
viewPager.setCurrentItem(0);
optionsButton.setVisibility(View.VISIBLE);
return true;
case R.id.action_history:
((MapMarkersActiveFragment) adapter.getItem(0)).stopLocationUpdate();
if (viewPager.getCurrentItem() != 1) {
((MapMarkersHistoryFragment) adapter.getItem(1)).updateAdapter();
}
viewPager.setCurrentItem(1);
optionsButton.setVisibility(View.GONE);
return true;

View file

@ -14,6 +14,8 @@ import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter;
public class MapMarkersHistoryFragment extends Fragment {
MapMarkersHistoryAdapter adapter;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -21,8 +23,15 @@ public class MapMarkersHistoryFragment extends Fragment {
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
final MapActivity mapActivity = (MapActivity) getActivity();
recyclerView.setAdapter(new MapMarkersHistoryAdapter(mapActivity.getMyApplication()));
adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication());
recyclerView.setAdapter(adapter);
return recyclerView;
}
void updateAdapter() {
if (adapter != null) {
adapter.notifyDataSetChanged();
}
}
}

View file

@ -17,7 +17,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
final TextView distance;
final TextView point;
final TextView description;
final ImageButton options;
final ImageButton optionsBtn;
public MapMarkerItemViewHolder(View view) {
super(view);
@ -28,6 +28,6 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
distance = (TextView) view.findViewById(R.id.map_marker_distance);
point = (TextView) view.findViewById(R.id.map_marker_point_text_view);
description = (TextView) view.findViewById(R.id.map_marker_description);
options = (ImageButton) view.findViewById(R.id.map_marker_options_button);
optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button);
}
}

View file

@ -89,6 +89,18 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
holder.description.setText(marker.creationDate + "");
holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark));
holder.optionsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int position = holder.getAdapterPosition();
MapMarker marker = markers.get(position);
mapActivity.getMyApplication().getMapMarkersHelper().removeMapMarker(marker.index);
mapActivity.getMyApplication().getMapMarkersHelper().addMapMarkerHistory(marker);
notifyItemRemoved(position);
}
});
DashLocationFragment.updateLocationView(useCenter, location,
heading, holder.iconDirection, holder.distance,
marker.getLatitude(), marker.getLongitude(),

View file

@ -39,8 +39,6 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<MapMarkerItem
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color));
holder.title.setText(marker.getName(app));
holder.description.setText(marker.creationDate + "");
}
@Override