Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-10-03 21:48:33 +02:00
commit 2f4ff0557e
9 changed files with 143 additions and 100 deletions

View file

@ -486,7 +486,7 @@
<style name="TextAppearance.ContextMenuTitle" parent="TextAppearance.AppCompat">
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:textSize">@dimen/default_list_text_size_large</item>
<item name="android:maxLines">6</item>
<item name="android:maxLines">3</item>
<item name="android:ellipsize">end</item>
</style>

View file

@ -26,6 +26,7 @@ public class AudioVideoNoteMenuController extends MenuController {
this.mRecording = recording;
mPlugin = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class);
mIsFileAvailable = mRecording.getFile().exists();
builder.setShowTitleIfTruncated(false);
if (mIsFileAvailable) {
leftTitleButtonController = new TitleButtonController() {

View file

@ -59,8 +59,10 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
public class MenuBuilder {
public static final float SHADOW_HEIGHT_TOP_DP = 17f;
public static final int TITLE_LIMIT = 60;
protected MapActivity mapActivity;
protected MapContextMenu mapContextMenu;
protected OsmandApplication app;
protected LinkedList<PlainMenuItem> plainMenuItems;
private boolean firstRow;
@ -68,6 +70,7 @@ public class MenuBuilder {
private long objectId;
private LatLon latLon;
private boolean hidden;
private boolean showTitleIfTruncated = true;
private boolean showNearestWiki = false;
private boolean showOnlinePhotos = true;
protected List<Amenity> nearestWiki = new ArrayList<>();
@ -200,6 +203,10 @@ public class MenuBuilder {
this.latLon = objectLocation;
}
public void setMapContextMenu(MapContextMenu mapContextMenu) {
this.mapContextMenu = mapContextMenu;
}
public boolean isShowNearestWiki() {
return showNearestWiki;
}
@ -208,6 +215,10 @@ public class MenuBuilder {
this.showNearestWiki = showNearestWiki;
}
public void setShowTitleIfTruncated(boolean showTitleIfTruncated) {
this.showTitleIfTruncated = showTitleIfTruncated;
}
public boolean isShowOnlinePhotos() {
return showOnlinePhotos;
}
@ -232,6 +243,9 @@ public class MenuBuilder {
public void build(View view) {
firstRow = true;
hidden = false;
if (showTitleIfTruncated) {
buildTitleRow(view);
}
buildNearestWikiRow(view);
if (needBuildPlainMenuItems()) {
buildPlainMenuItems(view);
@ -281,6 +295,15 @@ public class MenuBuilder {
}
}
public void buildTitleRow(View view) {
if (mapContextMenu != null) {
String title = mapContextMenu.getTitleStr();
if (title.length() > TITLE_LIMIT) {
buildRow(view, R.drawable.ic_action_note_dark, title, 0, false, null, false, 0, false, null);
}
}
}
protected void buildNearestWikiRow(View view) {
if (processNearstWiki() && nearestWiki.size() > 0) {
buildRow(view, R.drawable.ic_action_wikipedia, app.getString(R.string.wiki_around) + " (" + nearestWiki.size()+")", 0,

View file

@ -121,6 +121,7 @@ public abstract class MenuController extends BaseMenuController {
public void setMapContextMenu(MapContextMenu mapContextMenu) {
this.mapContextMenu = mapContextMenu;
builder.setMapContextMenu(mapContextMenu);
}
public void build(View rootView) {

View file

@ -9,6 +9,7 @@ import net.osmand.data.FavouritePoint;
import net.osmand.data.QuadRect;
import net.osmand.data.TransportStop;
import net.osmand.osm.PoiCategory;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.mapillary.MapillaryPlugin;

View file

@ -33,12 +33,10 @@ import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapmarkers.PlanRouteSortByBottomSheetDialogFragment.PlanRouteSortByFragmentListener;
import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback;
@ -57,7 +55,7 @@ import java.util.List;
import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT;
public class PlanRouteFragment extends Fragment implements OsmAndLocationListener {
public class PlanRouteFragment extends Fragment {
public static final String TAG = "PlanRouteFragment";
@ -71,9 +69,6 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
private int toolbarHeight;
private Location location;
private boolean locationUpdateStarted;
private boolean nightMode;
private boolean portrait;
private boolean markersListOpened;
@ -161,6 +156,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
markersHelper.setStartFromMyLocation(true);
selectedCount = activeMarkersCount;
}
adapter.calculateStartAndFinishPos();
adapter.notifyDataSetChanged();
updateText();
updateSelectButton();
@ -205,6 +201,8 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
}
adapter = new MapMarkersListAdapter(mapActivity);
adapter.setHasStableIds(true);
adapter.calculateStartAndFinishPos();
final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(adapter));
touchHelper.attachToRecyclerView(markersRv);
adapter.setAdapterListener(new MapMarkersListAdapter.MapMarkersListAdapterListener() {
@ -226,7 +224,8 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
marker.selected = !marker.selected;
markersHelper.updateMapMarker(marker, false);
}
adapter.notifyItemChanged(pos);
adapter.calculateStartAndFinishPos();
adapter.notifyDataSetChanged();
updateSelectButton();
updateText();
showMarkersRouteOnMap();
@ -245,12 +244,15 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
mapActivity.getMyApplication().getMapMarkersHelper().reorderActiveMarkersIfNeeded();
mapActivity.getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM);
mapActivity.refreshMap();
adapter.calculateStartAndFinishPos();
try {
adapter.notifyDataSetChanged();
} catch (Exception e) {
// to avoid crash because of:
// java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
}
updateText();
showMarkersRouteOnMap();
}
}
});
@ -259,6 +261,12 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
markersRv.setClipToPadding(false);
markersRv.setLayoutManager(new LinearLayoutManager(getContext()));
markersRv.setAdapter(adapter);
markersRv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
});
final int screenH = AndroidUtils.getScreenHeight(mapActivity);
final int statusBarH = AndroidUtils.getStatusBarHeight(mapActivity);
@ -291,18 +299,6 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
return view;
}
@Override
public void onResume() {
super.onResume();
startLocationUpdate();
}
@Override
public void onPause() {
super.onPause();
stopLocationUpdate();
}
@Override
public void onDestroyView() {
super.onDestroyView();
@ -312,18 +308,6 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
}
}
@Override
public void updateLocation(Location location) {
boolean newLocation = this.location == null && location != null;
boolean locationChanged = this.location != null && location != null
&& this.location.getLatitude() != location.getLatitude()
&& this.location.getLongitude() != location.getLongitude();
if (newLocation || locationChanged) {
this.location = location;
updateLocationUi();
}
}
private MapActivity getMapActivity() {
return (MapActivity) getActivity();
}
@ -381,6 +365,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
public void reverseOrderOnClick() {
if (mapActivity != null) {
markersHelper.reverseActiveMarkersOrder();
adapter.calculateStartAndFinishPos();
adapter.notifyDataSetChanged();
}
}
@ -519,26 +504,6 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
}
}
private void updateLocationUi() {
final MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null && adapter != null) {
mapActivity.getMyApplication().runInUIThread(new Runnable() {
@Override
public void run() {
if (location == null) {
location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
}
MapViewTrackingUtilities utilities = mapActivity.getMapViewTrackingUtilities();
boolean useCenter = !(utilities.isMapLinkedToLocation() && location != null);
adapter.setUseCenter(useCenter);
adapter.setLocation(useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude()));
adapter.notifyDataSetChanged();
}
});
}
}
private void mark(int status, int... widgets) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
@ -619,23 +584,6 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
}
}
private void startLocationUpdate() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null && !locationUpdateStarted) {
locationUpdateStarted = true;
mapActivity.getMyApplication().getLocationProvider().addLocationListener(this);
updateLocationUi();
}
}
private void stopLocationUpdate() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null && locationUpdateStarted) {
locationUpdateStarted = false;
mapActivity.getMyApplication().getLocationProvider().removeLocationListener(this);
}
}
private void showMarkersRouteOnMap() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
@ -747,8 +695,8 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
if (i == 0 && startFromLoc) {
continue;
}
int index = sequence[startFromLoc ? i - 1 : i];
res.add(selectedMarkers.get(index));
int index = sequence[i];
res.add(selectedMarkers.get(startFromLoc ? index - 1 : index));
}
return res;
@ -771,8 +719,10 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene
}
mapActivity.getMyApplication().getMapMarkersHelper().addSelectedMarkersToTop(res);
adapter.calculateStartAndFinishPos();
adapter.notifyDataSetChanged();
updateText();
showMarkersRouteOnMap();
}
}.execute();
}

View file

@ -8,10 +8,12 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.util.MapUtils;
@ -25,25 +27,20 @@ import java.util.Locale;
public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder>
implements MapMarkersItemTouchHelperCallback.ItemTouchHelperAdapter {
private static final int LOCATION_ITEM_ID = 0;
private MapActivity mapActivity;
private List<MapMarker> markers;
private MapMarkersListAdapterListener listener;
private LatLon location;
private boolean useCenter;
private int startPos = -1;
private int finishPos = -1;
private int firstSelectedMarkerPos = -1;
public void setAdapterListener(MapMarkersListAdapterListener listener) {
this.listener = listener;
}
public void setLocation(LatLon location) {
this.location = location;
}
public void setUseCenter(boolean useCenter) {
this.useCenter = useCenter;
}
public MapMarkersListAdapter(MapActivity mapActivity) {
this.mapActivity = mapActivity;
markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers();
@ -63,12 +60,19 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
@Override
public void onBindViewHolder(final MapMarkerItemViewHolder holder, int pos) {
boolean night = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
OsmandApplication app = mapActivity.getMyApplication();
boolean night = app.getDaynightHelper().isNightModeForMapControls();
IconsCache iconsCache = app.getIconsCache();
boolean locationItem = pos == 0;
boolean firstMarkerItem = pos == 1;
boolean lastMarkerItem = pos == getItemCount() - 1;
boolean start = pos == startPos;
boolean finish = pos == finishPos && startPos != finishPos;
boolean firstSelectedMarker = pos == firstSelectedMarkerPos;
Location myLoc = app.getLocationProvider().getLastStaleKnownLocation();
boolean useLocation = app.getMapMarkersHelper().isStartFromMyLocation() && myLoc != null;
MapMarker marker = locationItem ? null : getItem(pos);
@ -88,10 +92,10 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
});
holder.bottomShadow.setVisibility(lastMarkerItem ? View.VISIBLE : View.GONE);
holder.firstDescription.setVisibility((firstMarkerItem || lastMarkerItem) ? View.VISIBLE : View.GONE);
if (firstMarkerItem) {
holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_control_start) + "");
} else if (lastMarkerItem) {
holder.firstDescription.setVisibility((start || finish) ? View.VISIBLE : View.GONE);
if (start) {
holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_control_start) + (locationItem && !useLocation ? "" : ""));
} else if (finish) {
holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_finish) + "");
}
@ -100,7 +104,7 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
holder.flagIconLeftSpace.setVisibility(View.VISIBLE);
holder.icon.setImageDrawable(ContextCompat.getDrawable(mapActivity, R.drawable.map_pedestrian_location));
holder.point.setVisibility(View.GONE);
holder.checkBox.setChecked(mapActivity.getMyApplication().getMapMarkersHelper().isStartFromMyLocation());
holder.checkBox.setChecked(app.getMapMarkersHelper().isStartFromMyLocation());
holder.iconReorder.setVisibility(View.GONE);
holder.description.setVisibility(View.GONE);
holder.distance.setVisibility(View.GONE);
@ -140,16 +144,28 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
descr = month + " " + day;
}
holder.description.setText(descr);
if (location != null) {
holder.distance.setVisibility(View.VISIBLE);
holder.distance.setTextColor(ContextCompat.getColor(mapActivity, useCenter
? R.color.color_distance : R.color.color_myloc_distance));
float dist = (float) MapUtils.getDistance(location.getLatitude(), location.getLongitude(),
marker.getLatitude(), marker.getLongitude());
holder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
}
}
boolean showDistance = locationItem ? useLocation : marker.selected;
boolean showPoint = showDistance && !locationItem;
holder.distance.setVisibility(showDistance ? View.VISIBLE : View.GONE);
holder.point.setVisibility(showPoint ? View.VISIBLE : View.GONE);
if (showDistance) {
holder.distance.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_distance : R.color.color_myloc_distance));
LatLon first = firstSelectedMarker && useLocation
? new LatLon(myLoc.getLatitude(), myLoc.getLongitude())
: getPreviousSelectedMarkerLatLon(pos - 1);
float dist = 0;
if (first != null && marker != null) {
dist = (float) MapUtils.getDistance(first, marker.point);
}
holder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app));
}
}
@Override
public long getItemId(int position) {
return position == 0 ? LOCATION_ITEM_ID : getItem(position).hashCode();
}
@Override
@ -186,6 +202,54 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter<MapMarkerItemVie
listener.onDragEnded(holder);
}
private LatLon getPreviousSelectedMarkerLatLon(int currentMarkerPos) {
for (int i = currentMarkerPos - 1; i >= 0; i--) {
MapMarker m = markers.get(i);
if (m.selected) {
return m.point;
}
}
return null;
}
public void calculateStartAndFinishPos() {
OsmandApplication app = mapActivity.getMyApplication();
boolean startCalculated = false;
boolean finishCalculated = false;
boolean firstSelectedMarkerCalculated = false;
if (app.getMapMarkersHelper().isStartFromMyLocation() && app.getLocationProvider().getLastStaleKnownLocation() != null) {
startPos = 0;
startCalculated = true;
}
for (int i = 0; i < markers.size(); i++) {
if (markers.get(i).selected) {
if (!startCalculated) {
startPos = i + 1;
startCalculated = true;
}
firstSelectedMarkerPos = i + 1;
firstSelectedMarkerCalculated = true;
break;
}
}
for (int i = markers.size() - 1; i >= 0; i--) {
if (markers.get(i).selected) {
finishPos = i + 1;
finishCalculated = true;
break;
}
}
if (!startCalculated) {
startPos = -1;
}
if (!finishCalculated) {
finishPos = -1;
}
if (!firstSelectedMarkerCalculated) {
firstSelectedMarkerPos = -1;
}
}
public interface MapMarkersListAdapterListener {
void onItemClick(View view);

View file

@ -23,6 +23,9 @@ public class EditPOIMenuController extends MenuController {
super(new EditPOIMenuBuilder(mapActivity, osmPoint), pointDescription, mapActivity);
this.osmPoint = osmPoint;
plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (osmPoint instanceof OsmNotesPoint) {
builder.setShowTitleIfTruncated(false);
}
leftTitleButtonController = new TitleButtonController() {
@Override

View file

@ -220,9 +220,9 @@ public class SendPoiDialogFragment extends DialogFragment {
modifiedItemsOutOfLimit += quantity;
} else {
if (pos == 0) {
comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ").concat(quantity == 1 ? "" : quantity + "").concat(type);
comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
} else {
comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + "").concat(type);
comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
}
}
pos++;