Merge branch 'sasha_pasha_branch' of ssh://github.com/osmandapp/Osmand into sasha_pasha_branch

This commit is contained in:
PavelRatushny 2017-10-11 18:17:59 +03:00
commit 4820b3181a
7 changed files with 125 additions and 48 deletions

View file

@ -149,17 +149,23 @@
tools:background="@drawable/marker_circle_background_dark_with_inset" tools:background="@drawable/marker_circle_background_dark_with_inset"
tools:src="@drawable/ic_action_marker_passed"/> tools:src="@drawable/ic_action_marker_passed"/>
<CheckBox <FrameLayout
android:id="@+id/map_marker_check_box" android:id="@+id/check_box_container"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp" <CheckBox
android:layout_marginRight="16dp" android:id="@+id/map_marker_check_box"
android:layout_marginTop="16dp" android:layout_width="wrap_content"
android:background="@null" android:layout_height="wrap_content"
android:visibility="gone" android:layout_marginBottom="16dp"
tools:visibility="visible"/> android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:visibility="gone"
tools:visibility="visible"/>
</FrameLayout>
</LinearLayout> </LinearLayout>
<View <View

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="route_calculated_toast">Route is calculated: Show map</string>
<string name="plan_route_no_markers_toast">You must add at least one marker to use this function.</string>
<string name="osn_modify_dialog_error">Exception occurred: note was not modified</string> <string name="osn_modify_dialog_error">Exception occurred: note was not modified</string>
<string name="osn_modify_dialog_title">Modify note</string> <string name="osn_modify_dialog_title">Modify note</string>
<string name="context_menu_item_modify_note">Modify OSM note</string> <string name="context_menu_item_modify_note">Modify OSM note</string>

View file

@ -16,6 +16,7 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import net.osmand.plus.LockableViewPager; import net.osmand.plus.LockableViewPager;
import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper;
@ -193,54 +194,70 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
@Override @Override
public void sortByOnClick() { public void sortByOnClick() {
OrderByBottomSheetDialogFragment fragment = new OrderByBottomSheetDialogFragment(); if (mapActivity != null) {
fragment.setListener(createOrderByFragmentListener()); OrderByBottomSheetDialogFragment fragment = new OrderByBottomSheetDialogFragment();
fragment.show(mapActivity.getSupportFragmentManager(), OrderByBottomSheetDialogFragment.TAG); fragment.setListener(createOrderByFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), OrderByBottomSheetDialogFragment.TAG);
}
} }
@Override @Override
public void showDirectionOnClick() { public void showDirectionOnClick() {
ShowDirectionBottomSheetDialogFragment fragment = new ShowDirectionBottomSheetDialogFragment(); if (mapActivity != null) {
fragment.setListener(createShowDirectionFragmentListener()); ShowDirectionBottomSheetDialogFragment fragment = new ShowDirectionBottomSheetDialogFragment();
fragment.show(mapActivity.getSupportFragmentManager(), ShowDirectionBottomSheetDialogFragment.TAG); fragment.setListener(createShowDirectionFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), ShowDirectionBottomSheetDialogFragment.TAG);
}
} }
@Override @Override
public void coordinateInputOnClick() { public void coordinateInputOnClick() {
CoordinateInputDialogFragment.showInstance(mapActivity); if (mapActivity != null) {
CoordinateInputDialogFragment.showInstance(mapActivity);
}
} }
@Override @Override
public void buildRouteOnClick() { public void buildRouteOnClick() {
PlanRouteFragment.showInstance(mapActivity); if (mapActivity != null) {
dismiss(); if (mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers().isEmpty()) {
Toast.makeText(mapActivity, getString(R.string.plan_route_no_markers_toast), Toast.LENGTH_SHORT).show();
} else {
PlanRouteFragment.showInstance(mapActivity);
dismiss();
}
}
} }
@Override @Override
public void saveAsNewTrackOnClick() { public void saveAsNewTrackOnClick() {
SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment(); if (mapActivity != null) {
fragment.setListener(createSaveAsTrackFragmentListener()); SaveAsTrackBottomSheetDialogFragment fragment = new SaveAsTrackBottomSheetDialogFragment();
fragment.show(mapActivity.getSupportFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG); fragment.setListener(createSaveAsTrackFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), SaveAsTrackBottomSheetDialogFragment.TAG);
}
} }
@Override @Override
public void moveAllToHistoryOnClick() { public void moveAllToHistoryOnClick() {
final MapMarkersHelper helper = mapActivity.getMyApplication().getMapMarkersHelper(); if (mapActivity != null) {
final List<MapMarkersHelper.MapMarker> markers = new ArrayList<>(helper.getMapMarkers()); final MapMarkersHelper helper = mapActivity.getMyApplication().getMapMarkersHelper();
helper.moveAllActiveMarkersToHistory(); final List<MapMarkersHelper.MapMarker> markers = new ArrayList<>(helper.getMapMarkers());
activeFragment.updateAdapter(); helper.moveAllActiveMarkersToHistory();
snackbar = Snackbar.make(viewPager, R.string.all_markers_moved_to_history, Snackbar.LENGTH_LONG) activeFragment.updateAdapter();
.setAction(R.string.shared_string_undo, new View.OnClickListener() { snackbar = Snackbar.make(viewPager, R.string.all_markers_moved_to_history, Snackbar.LENGTH_LONG)
@Override .setAction(R.string.shared_string_undo, new View.OnClickListener() {
public void onClick(View view) { @Override
helper.restoreMarkersFromHistory(markers); public void onClick(View view) {
activeFragment.updateAdapter(); helper.restoreMarkersFromHistory(markers);
} activeFragment.updateAdapter();
}); }
View snackBarView = snackbar.getView(); });
TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action); View snackBarView = snackbar.getView();
tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark)); TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action);
snackbar.show(); tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark));
snackbar.show();
}
} }
}; };
} }

View file

@ -41,6 +41,7 @@ public class MarkersPlanRouteContext {
private boolean progressBarVisible; private boolean progressBarVisible;
private boolean fragmentVisible; private boolean fragmentVisible;
private boolean markersListOpened; private boolean markersListOpened;
private boolean adjustMapOnStart = true;
Map<Pair<WptPt, WptPt>, List<WptPt>> getSnappedToRoadPoints() { Map<Pair<WptPt, WptPt>, List<WptPt>> getSnappedToRoadPoints() {
return snappedToRoadPoints; return snappedToRoadPoints;
@ -90,12 +91,20 @@ public class MarkersPlanRouteContext {
this.markersListOpened = markersListOpened; this.markersListOpened = markersListOpened;
} }
public boolean isAdjustMapOnStart() {
return adjustMapOnStart;
}
public void setAdjustMapOnStart(boolean adjustMapOnStart) {
this.adjustMapOnStart = adjustMapOnStart;
}
public MarkersPlanRouteContext(OsmandApplication app) { public MarkersPlanRouteContext(OsmandApplication app) {
this.app = app; this.app = app;
} }
void cancelSnapToRoad() { void cancelSnapToRoad() {
listener.hideProgressBar(); listener.hideProgressBar(true);
snapToRoadPairsToCalculate.clear(); snapToRoadPairsToCalculate.clear();
if (calculationProgress != null) { if (calculationProgress != null) {
calculationProgress.isCancelled = true; calculationProgress.isCancelled = true;
@ -245,7 +254,7 @@ public class MarkersPlanRouteContext {
app.runInUIThread(new Runnable() { app.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
listener.hideProgressBar(); listener.hideProgressBar(false);
} }
}); });
} }
@ -261,7 +270,7 @@ public class MarkersPlanRouteContext {
void updateProgress(int progress); void updateProgress(int progress);
void hideProgressBar(); void hideProgressBar(boolean canceled);
void refresh(); void refresh();

View file

@ -24,6 +24,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.Location; import net.osmand.Location;
@ -62,6 +63,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT; import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT;
import static net.osmand.plus.OsmandSettings.MIDDLE_TOP_CONSTANT;
public class PlanRouteFragment extends Fragment implements OsmAndLocationListener { public class PlanRouteFragment extends Fragment implements OsmAndLocationListener {
@ -108,9 +110,13 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
} }
@Override @Override
public void hideProgressBar() { public void hideProgressBar(boolean canceled) {
mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE); mainView.findViewById(R.id.snap_to_road_progress_bar).setVisibility(View.GONE);
planRouteContext.setProgressBarVisible(false); planRouteContext.setProgressBarVisible(false);
if (!canceled && portrait && planRouteContext.isMarkersListOpened()) {
Toast.makeText(mapActivity, getString(R.string.route_calculated_toast), Toast.LENGTH_SHORT).show();
showHideMarkersList();
}
} }
@Override @Override
@ -268,7 +274,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
private int toPosition; private int toPosition;
@Override @Override
public void onItemClick(View view) { public void onCheckBoxClick(View view) {
int pos = markersRv.getChildAdapterPosition(view); int pos = markersRv.getChildAdapterPosition(view);
if (pos == RecyclerView.NO_POSITION) { if (pos == RecyclerView.NO_POSITION) {
return; return;
@ -288,6 +294,22 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
planRouteContext.recreateSnapTrkSegment(false); planRouteContext.recreateSnapTrkSegment(false);
} }
@Override
public void onItemClick(View v) {
int pos = markersRv.getChildAdapterPosition(v);
if (pos == RecyclerView.NO_POSITION) {
return;
}
Object item = adapter.getItem(pos);
if (item instanceof Location) {
Location loc = (Location) item;
moveMapToPosition(loc.getLatitude(), loc.getLongitude());
} else if (item instanceof MapMarker) {
MapMarker marker = (MapMarker) item;
moveMapToPosition(marker.getLatitude(), marker.getLongitude());
}
}
@Override @Override
public void onDragStarted(RecyclerView.ViewHolder holder) { public void onDragStarted(RecyclerView.ViewHolder holder) {
fromPosition = holder.getAdapterPosition(); fromPosition = holder.getAdapterPosition();
@ -398,6 +420,18 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
return iconsCache.getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance); return iconsCache.getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance);
} }
private void moveMapToPosition(double lat, double lon) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
OsmandMapTileView view = mapActivity.getMapView();
view.getAnimatedDraggingThread().startMoving(lat, lon, view.getZoom(), true);
if (planRouteContext.isMarkersListOpened()) {
planRouteContext.setAdjustMapOnStart(false);
showHideMarkersList();
}
}
}
private SnapToRoadFragmentListener createSnapToRoadFragmentListener() { private SnapToRoadFragmentListener createSnapToRoadFragmentListener() {
return new SnapToRoadFragmentListener() { return new SnapToRoadFragmentListener() {
@Override @Override
@ -581,12 +615,11 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
OsmandMapTileView tileView = mapActivity.getMapView(); OsmandMapTileView tileView = mapActivity.getMapView();
previousMapPosition = tileView.getMapPosition(); previousMapPosition = tileView.getMapPosition();
if (!portrait) { tileView.setMapPosition(portrait ? MIDDLE_TOP_CONSTANT : LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
tileView.setMapPosition(LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
}
selectedCount = mapActivity.getMyApplication().getMapMarkersHelper().getSelectedMarkersCount(); selectedCount = mapActivity.getMyApplication().getMapMarkersHelper().getSelectedMarkersCount();
planRouteContext.recreateSnapTrkSegment(true); planRouteContext.recreateSnapTrkSegment(planRouteContext.isAdjustMapOnStart());
planRouteContext.setAdjustMapOnStart(true);
mapActivity.refreshMap(); mapActivity.refreshMap();
updateSelectButton(); updateSelectButton();
} }

View file

@ -25,6 +25,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
final View rightPointSpace; final View rightPointSpace;
final TextView description; final TextView description;
public final ImageButton optionsBtn; public final ImageButton optionsBtn;
final View checkBoxContainer;
final CheckBox checkBox; final CheckBox checkBox;
final View divider; final View divider;
final View bottomShadow; final View bottomShadow;
@ -45,6 +46,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
rightPointSpace = view.findViewById(R.id.map_marker_right_point_space); rightPointSpace = view.findViewById(R.id.map_marker_right_point_space);
description = (TextView) view.findViewById(R.id.map_marker_description); description = (TextView) view.findViewById(R.id.map_marker_description);
optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button); optionsBtn = (ImageButton) view.findViewById(R.id.map_marker_options_button);
checkBoxContainer = view.findViewById(R.id.check_box_container);
checkBox = (CheckBox) view.findViewById(R.id.map_marker_check_box); checkBox = (CheckBox) view.findViewById(R.id.map_marker_check_box);
divider = view.findViewById(R.id.divider); divider = view.findViewById(R.id.divider);
bottomShadow = view.findViewById(R.id.bottom_shadow); bottomShadow = view.findViewById(R.id.bottom_shadow);

View file

@ -106,7 +106,13 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
holder.checkBox.setOnClickListener(new View.OnClickListener() { holder.checkBox.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
listener.onItemClick(holder.itemView); listener.onCheckBoxClick(holder.itemView);
}
});
holder.checkBoxContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
holder.checkBox.performClick();
} }
}); });
holder.bottomShadow.setVisibility(lastMarkerItem ? View.VISIBLE : View.GONE); holder.bottomShadow.setVisibility(lastMarkerItem ? View.VISIBLE : View.GONE);
@ -339,6 +345,8 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
public interface MapMarkersListAdapterListener { public interface MapMarkersListAdapterListener {
void onCheckBoxClick(View view);
void onItemClick(View view); void onItemClick(View view);
void onDragStarted(RecyclerView.ViewHolder holder); void onDragStarted(RecyclerView.ViewHolder holder);