This commit is contained in:
max-klaus 2019-12-11 16:07:55 +03:00
parent 6e4b7d5464
commit 88b3eb5686
14 changed files with 247 additions and 197 deletions

View file

@ -11,7 +11,8 @@
Thx - Hardy
-->
<string name="distance_and_address">%1$s• %2$s</string>
<string name="distance_and_address">%1$s • %2$s</string>
<string name="street_city">%1$s, %2$s</string>
<string name="personal_category_name">Personal</string>
<string name="add_new_profile_q">Add new profile \'%1$s\'?</string>
<string name="save_heading">Include heading</string>

View file

@ -25,13 +25,13 @@ public class PersonalFavouritePoint extends FavouritePoint {
private int resId;
private int order;
@DrawableRes
private int iconID;
private int iconId;
PointType(@NonNull String typeName, @StringRes int resId, int order, @DrawableRes int iconID) {
PointType(@NonNull String typeName, @StringRes int resId, int order, @DrawableRes int iconId) {
this.typeName = typeName;
this.resId = resId;
this.order = order;
this.iconID = iconID;
this.iconId = iconId;
}
public String getName() {
@ -43,16 +43,16 @@ public class PersonalFavouritePoint extends FavouritePoint {
}
public static PointType valueOfTypeName(@NonNull String typeName) {
for (PointType pt:values()) {
if (pt.typeName.equals(typeName))
for (PointType pt : values()) {
if (pt.typeName.equals(typeName)) {
return pt;
}
}
throw new IllegalArgumentException("Illegal PointType typeName");
}
public int getIconID() {
return iconID;
public int getIconId() {
return iconId;
}
public String getHumanString(@NonNull Context ctx) {

View file

@ -3,15 +3,17 @@ package net.osmand.plus;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.PlatformUtil;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.PersonalFavouritePoint;
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
@ -31,6 +33,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import static net.osmand.data.PersonalFavouritePoint.PointType.HOME;
import static net.osmand.data.PersonalFavouritePoint.PointType.PARKING;
@ -38,12 +41,9 @@ import static net.osmand.data.PersonalFavouritePoint.PointType.WORK;
public class FavouritesDbHelper {
private GeocodingLookupService.AddressLookupRequest workPointRequest;
private GeocodingLookupService.AddressLookupRequest homePointRequest;
private GeocodingLookupService.AddressLookupRequest parkingPointRequest;
public interface FavoritesListener {
void onFavoritesLoaded();
void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint);
}
private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(FavouritesDbHelper.class);
@ -63,6 +63,8 @@ public class FavouritesDbHelper {
private Set<FavoritesListener> listeners = new HashSet<>();
private boolean favoritesLoaded;
private Map<FavouritePoint, AddressLookupRequest> addressRequestMap = new ConcurrentHashMap<>();
public FavouritesDbHelper(OsmandApplication context) {
this.context = context;
}
@ -237,46 +239,46 @@ public class FavouritesDbHelper {
return true;
}
public void setHomePoint(@NonNull LatLon latLon) {
public void setHomePoint(@NonNull LatLon latLon, @Nullable String description) {
FavouritePoint homePoint = getHomePoint();
if (homePoint != null) {
editFavourite(homePoint, latLon.getLatitude(), latLon.getLongitude());
editFavourite(homePoint, latLon.getLatitude(), latLon.getLongitude(), description);
} else {
FavouritePoint cachedHomePoint = new PersonalFavouritePoint(context, HOME,
latLon.getLatitude(), latLon.getLongitude());
addFavourite(cachedHomePoint);
homePoint = new PersonalFavouritePoint(context, HOME, latLon.getLatitude(), latLon.getLongitude());
homePoint.setDescription(description);
addFavourite(homePoint);
}
if (description == null) {
lookupAddress(homePoint);
}
lookupAddressAllPersonalPoints();
}
public void setWorkPoint(@NonNull LatLon latLon) {
public void setWorkPoint(@NonNull LatLon latLon, @Nullable String description) {
FavouritePoint workPoint = getWorkPoint();
if (workPoint != null) {
editFavourite(workPoint, latLon.getLatitude(), latLon.getLongitude());
editFavourite(workPoint, latLon.getLatitude(), latLon.getLongitude(), description);
} else {
FavouritePoint cachedWorkPoint = new PersonalFavouritePoint(context, WORK,
latLon.getLatitude(), latLon.getLongitude());
addFavourite(cachedWorkPoint);
workPoint = new PersonalFavouritePoint(context, WORK, latLon.getLatitude(), latLon.getLongitude());
workPoint.setDescription(description);
addFavourite(workPoint);
}
if (description == null) {
lookupAddress(workPoint);
}
lookupAddressAllPersonalPoints();
}
public void setParkingPoint(@NonNull LatLon latLon) {
FavouritePoint parkingPoint = getParkingPoint();
if (parkingPoint != null) {
editFavourite(parkingPoint, latLon.getLatitude(), latLon.getLongitude());
editFavourite(parkingPoint, latLon.getLatitude(), latLon.getLongitude(), null);
} else {
FavouritePoint cachedParkingPoint = new PersonalFavouritePoint(context, PARKING,
latLon.getLatitude(), latLon.getLongitude());
addFavourite(cachedParkingPoint);
parkingPoint = new PersonalFavouritePoint(context, PARKING, latLon.getLatitude(), latLon.getLongitude());
addFavourite(parkingPoint);
}
lookupAddressAllPersonalPoints();
lookupAddress(parkingPoint);
}
public boolean addFavourite(FavouritePoint p) {
if (p instanceof PersonalFavouritePoint) {
cachedPersonalFavoritePoints.add(p);
}
return addFavourite(p, true);
}
@ -293,6 +295,9 @@ public class FavouritesDbHelper {
group.points.add(p);
cachedFavoritePoints.add(p);
}
if (p.isPersonal()) {
cachedPersonalFavoritePoints.add(p);
}
if (saveImmediately) {
sortAll();
saveCurrentPointsIntoFile();
@ -304,87 +309,54 @@ public class FavouritesDbHelper {
public void lookupAddressAllPersonalPoints() {
if (!context.isApplicationInitializing()) {
lookupAddressForHomePoint();
lookupAddressForWorkPoint();
lookupAddressForParkingPoint();
FavouritePoint workPoint = getWorkPoint();
if (workPoint != null) {
lookupAddress(workPoint);
}
FavouritePoint homePoint = getHomePoint();
if (homePoint != null) {
lookupAddress(homePoint);
}
FavouritePoint parkingPoint = getParkingPoint();
if (parkingPoint != null) {
lookupAddress(parkingPoint);
}
}
}
private void lookupAddressForWorkPoint() {
final TargetPointsHelper targetPointsHelper = context.getTargetPointsHelper();
final FavouritePoint workPoint = getWorkPoint();
if (workPoint != null && (workPointRequest == null ||
!workPointRequest.getLatLon().equals(new LatLon(workPoint.getLatitude(), workPoint.getLongitude())))) {
cancelWorkPointAddressRequest();
workPointRequest = new GeocodingLookupService.AddressLookupRequest(
new LatLon(workPoint.getLatitude(), workPoint.getLongitude()), new GeocodingLookupService.OnAddressLookupResult() {
private void lookupAddress(@NonNull final FavouritePoint p) {
AddressLookupRequest request = addressRequestMap.get(p);
double latitude = p.getLatitude();
double longitude = p.getLongitude();
if (request == null || !request.getLatLon().equals(new LatLon(latitude, longitude))) {
cancelAddressRequest(p);
request = new AddressLookupRequest(new LatLon(latitude, longitude),
new GeocodingLookupService.OnAddressLookupResult() {
@Override
public void geocodingDone(String address) {
workPointRequest = null;
workPoint.setDescription(address);
targetPointsHelper.updateRouteAndRefresh(false);
}
}, null);
context.getGeocodingLookupService().lookupAddress(workPointRequest);
}
}
private void lookupAddressForHomePoint() {
final TargetPointsHelper targetPointsHelper = context.getTargetPointsHelper();
final FavouritePoint homePoint = getHomePoint();
if (homePoint != null && (homePointRequest == null ||
!homePointRequest.getLatLon().equals(new LatLon(homePoint.getLatitude(), homePoint.getLongitude())))) {
cancelHomePointAddressRequest();
homePointRequest = new GeocodingLookupService.AddressLookupRequest(
new LatLon(homePoint.getLatitude(), homePoint.getLongitude()), new GeocodingLookupService.OnAddressLookupResult() {
addressRequestMap.remove(p);
editFavouriteDescription(p, address);
context.runInUIThread(new Runnable() {
@Override
public void geocodingDone(String address) {
homePointRequest = null;
homePoint.setDescription(address);
targetPointsHelper.updateRouteAndRefresh(false);
public void run() {
for (FavoritesListener listener : listeners) {
listener.onFavoriteAddressResolved(p);
}
}
});
}
}, null);
context.getGeocodingLookupService().lookupAddress(homePointRequest);
addressRequestMap.put(p, request);
context.getGeocodingLookupService().lookupAddress(request);
}
}
private void lookupAddressForParkingPoint() {
final TargetPointsHelper targetPointsHelper = context.getTargetPointsHelper();
final FavouritePoint parkingPoint = getParkingPoint();
if (parkingPoint != null && (parkingPointRequest == null ||
!parkingPointRequest.getLatLon().equals(new LatLon(parkingPoint.getLatitude(), parkingPoint.getLongitude())))) {
cancelParkingPointAddressRequest();
parkingPointRequest = new GeocodingLookupService.AddressLookupRequest(
new LatLon(parkingPoint.getLatitude(), parkingPoint.getLongitude()), new GeocodingLookupService.OnAddressLookupResult() {
@Override
public void geocodingDone(String address) {
parkingPointRequest = null;
parkingPoint.setDescription(address);
targetPointsHelper.updateRouteAndRefresh(false);
}
}, null);
context.getGeocodingLookupService().lookupAddress(parkingPointRequest);
}
}
private void cancelHomePointAddressRequest() {
if (homePointRequest != null) {
context.getGeocodingLookupService().cancel(homePointRequest);
homePointRequest = null;
}
}
private void cancelParkingPointAddressRequest() {
if (parkingPointRequest != null) {
context.getGeocodingLookupService().cancel(parkingPointRequest);
parkingPointRequest = null;
}
}
private void cancelWorkPointAddressRequest() {
if (workPointRequest != null) {
context.getGeocodingLookupService().cancel(workPointRequest);
workPointRequest = null;
private void cancelAddressRequest(@NonNull FavouritePoint p) {
AddressLookupRequest request = addressRequestMap.get(p);
if (request != null) {
context.getGeocodingLookupService().cancel(request);
addressRequestMap.remove(p);
}
}
@ -482,7 +454,15 @@ public class FavouritesDbHelper {
return true;
}
public boolean editFavouriteDescription(FavouritePoint p, String description) {
p.setDescription(description);
saveCurrentPointsIntoFile();
runSyncWithMarkers(getOrCreateGroup(p, 0));
return true;
}
public boolean editFavourite(FavouritePoint p, double lat, double lon) {
cancelAddressRequest(p);
p.setLatitude(lat);
p.setLongitude(lon);
saveCurrentPointsIntoFile();
@ -490,6 +470,16 @@ public class FavouritesDbHelper {
return true;
}
public boolean editFavourite(FavouritePoint p, double lat, double lon, String description) {
cancelAddressRequest(p);
p.setLatitude(lat);
p.setLongitude(lon);
p.setDescription(description);
saveCurrentPointsIntoFile();
runSyncWithMarkers(getOrCreateGroup(p, 0));
return true;
}
public void saveCurrentPointsIntoFile() {
try {
Map<String, FavouritePoint> deletedInMemory = new LinkedHashMap<String, FavouritePoint>();

View file

@ -261,11 +261,24 @@ public class OsmandSettings {
void migrateHomeWorkParkingToFavorites() {
FavouritesDbHelper favorites = ctx.getFavorites();
if (getHomePoint() != null) {
favorites.setHomePoint(getHomePoint());
LatLon homePoint = null;
float lat = settingsAPI.getFloat(globalPreferences, "home_point_lat", 0);
float lon = settingsAPI.getFloat(globalPreferences, "home_point_lon", 0);
if (lat != 0 || lon != 0) {
homePoint = new LatLon(lat, lon);
}
if (getWorkPoint() != null) {
favorites.setWorkPoint(getWorkPoint());
LatLon workPoint = null;
lat = settingsAPI.getFloat(globalPreferences, "work_point_lat", 0);
lon = settingsAPI.getFloat(globalPreferences, "work_point_lon", 0);
if (lat != 0 || lon != 0) {
workPoint = new LatLon(lat, lon);
}
if (homePoint != null) {
favorites.setHomePoint(homePoint, null);
}
if (workPoint != null) {
favorites.setWorkPoint(workPoint, null);
}
}
@ -2428,13 +2441,6 @@ public class OsmandSettings {
public final static String MY_LOC_POINT_LON = "my_loc_point_lon";
public final static String MY_LOC_POINT_DESCRIPTION = "my_loc_point_description";
public final static String HOME_POINT_LAT = "home_point_lat";
public final static String HOME_POINT_LON = "home_point_lon";
public final static String HOME_POINT_DESCRIPTION = "home_point_description";
public final static String WORK_POINT_LAT = "work_point_lat";
public final static String WORK_POINT_LON = "work_point_lon";
public final static String WORK_POINT_DESCRIPTION = "work_point_description";
private static final String IMPASSABLE_ROAD_POINTS = "impassable_road_points";
private static final String IMPASSABLE_ROADS_DESCRIPTIONS = "impassable_roads_descriptions";
private ImpassableRoadsStorage mImpassableRoadsStorage = new ImpassableRoadsStorage();
@ -2549,34 +2555,6 @@ public class OsmandSettings {
settingsAPI.getString(globalPreferences, POINT_NAVIGATE_DESCRIPTION_BACKUP, ""), getPointToNavigate());
}
public LatLon getHomePoint() {
float lat = settingsAPI.getFloat(globalPreferences, HOME_POINT_LAT, 0);
float lon = settingsAPI.getFloat(globalPreferences, HOME_POINT_LON, 0);
if (lat == 0 && lon == 0) {
return null;
}
return new LatLon(lat, lon);
}
public PointDescription getHomePointDescription() {
return PointDescription.deserializeFromString(
settingsAPI.getString(globalPreferences, HOME_POINT_DESCRIPTION, ""), getHomePoint());
}
public LatLon getWorkPoint() {
float lat = settingsAPI.getFloat(globalPreferences, WORK_POINT_LAT, 0);
float lon = settingsAPI.getFloat(globalPreferences, WORK_POINT_LON, 0);
if (lat == 0 && lon == 0) {
return null;
}
return new LatLon(lat, lon);
}
public PointDescription getWorkPointDescription() {
return PointDescription.deserializeFromString(
settingsAPI.getString(globalPreferences, WORK_POINT_DESCRIPTION, ""), getWorkPoint());
}
public LatLon getMyLocationToStart() {
float lat = settingsAPI.getFloat(globalPreferences, MY_LOC_POINT_LAT, 0);
float lon = settingsAPI.getFloat(globalPreferences, MY_LOC_POINT_LON, 0);

View file

@ -116,6 +116,10 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
public void onFavoritesLoaded() {
favouritesAdapter.synchronizeGroups();
}
@Override
public void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint) {
}
});
}
setAdapter(favouritesAdapter);
@ -947,7 +951,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
name.setTextColor(getResources().getColor(visible ? enabledColor : disabledColor));
distanceText.setText(distance);
if (model instanceof PersonalFavouritePoint) {
String distanceWithAddress = String.format(getString(R.string.distance_and_address), distance, model.getDescription() != null ? model.getDescription() : "");
String distanceWithAddress = String.format(getString(R.string.distance_and_address), distance.trim(), model.getDescription() != null ? model.getDescription() : "");
distanceText.setText(distanceWithAddress);
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(),
visible ? model.getColor() : getResources().getColor(disabledIconColor), false,

View file

@ -42,14 +42,14 @@ public class FavoriteImageDrawable extends Drawable {
private Paint paintInnerCircle = new Paint();
private ColorFilter colorFilter;
private ColorFilter grayFilter;
private Drawable personalPointBitmaps;
private Drawable personalPointBitmap;
public FavoriteImageDrawable(Context ctx, int color, boolean withShadow, boolean synced, PointType pointType) {
this.withShadow = withShadow;
this.synced = synced;
Resources res = ctx.getResources();
if (pointType != null) {
personalPointBitmaps = UiUtilities.tintDrawable(ResourcesCompat.getDrawable(res, pointType.getIconID(), null),
personalPointBitmap = UiUtilities.tintDrawable(ResourcesCompat.getDrawable(res, pointType.getIconId(), null),
ContextCompat.getColor(ctx, R.color.icon_color_default_light));
}
int col = color == 0 || color == Color.BLACK ? res.getColor(R.color.color_favorite) : color;
@ -80,8 +80,8 @@ public class FavoriteImageDrawable extends Drawable {
//bs.inset((int) (4 * density), (int) (4 * density));
bs.inset(bs.width() / 4, bs.height() / 4);
listDrawable.setBounds(bs);
if (personalPointBitmaps != null) {
personalPointBitmaps.setBounds(bounds);
if (personalPointBitmap != null) {
personalPointBitmap.setBounds(bounds);
}
}
}
@ -108,8 +108,8 @@ public class FavoriteImageDrawable extends Drawable {
} else if (withShadow) {
canvas.drawBitmap(favBackground, bs.exactCenterX() - favBackground.getWidth() / 2f, bs.exactCenterY() - favBackground.getHeight() / 2f, paintBackground);
canvas.drawBitmap(favIcon, bs.exactCenterX() - favIcon.getWidth() / 2f, bs.exactCenterY() - favIcon.getHeight() / 2f, paintIcon);
} else if (personalPointBitmaps != null) {
personalPointBitmaps.draw(canvas);
} else if (personalPointBitmap != null) {
personalPointBitmap.draw(canvas);
} else {
int min = Math.min(bs.width(), bs.height());
int r = (min * 4 / 10);
@ -131,7 +131,7 @@ public class FavoriteImageDrawable extends Drawable {
@Override
public int getOpacity() {
return PixelFormat.UNKNOWN;
return 0;
}
@Override
@ -147,11 +147,11 @@ public class FavoriteImageDrawable extends Drawable {
private static TreeMap<Integer, FavoriteImageDrawable> cache = new TreeMap<>();
public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow, boolean synced, PointType pointType) {
int order = 0;
int pointTypeId = 0;
if (pointType != null)
order = pointType.getOrder();
pointTypeId = pointType.ordinal();
color = color | 0xff000000;
int hash = (color << 4) + (withShadow ? 0b0100 : 0) + (synced ? 0b1100 : 0) + order;
int hash = (color << 4) + ((withShadow ? 1 : 0) << 2) + ((synced ? 3 : 0) << 2) + pointTypeId;
FavoriteImageDrawable drawable = cache.get(hash);
if (drawable == null) {
drawable = new FavoriteImageDrawable(a, color, withShadow, synced, pointType);

View file

@ -2,6 +2,7 @@ package net.osmand.plus.dashboard;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
@ -74,6 +75,10 @@ public class DashFavoritesFragment extends DashLocationFragment {
public void onFavoritesLoaded() {
setupFavorites();
}
@Override
public void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint) {
}
});
}
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu.other;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -73,6 +74,10 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
loadFavorites();
adapter.notifyDataSetChanged();
}
@Override
public void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint) {
}
});
}
recyclerView = new RecyclerView(getContext());
@ -155,10 +160,10 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), point.getPointDescription());
break;
case HOME:
favorites.setHomePoint(ll);
favorites.setHomePoint(ll, null);
break;
case WORK:
favorites.setWorkPoint(ll);
favorites.setWorkPoint(ll, null);
break;
}
MapRouteInfoMenu routeMenu = getMapRouteInfoMenu();

View file

@ -1,7 +1,9 @@
package net.osmand.plus.mapmarkers;
import android.os.Bundle;
import android.support.annotation.NonNull;
import net.osmand.data.FavouritePoint;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
@ -38,6 +40,10 @@ public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomS
adapter.notifyDataSetChanged();
}
}
@Override
public void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint) {
}
});
}
return new FavouritesGroupsAdapter(getContext(), favouritesDbHelper.getFavoriteGroups());

View file

@ -5,6 +5,7 @@ import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
@ -250,12 +251,12 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size());
break;
case HOME:
app.showShortToastMessage(R.string.add_intermediate_point);
app.getFavorites().setHomePoint(ll);
app.showShortToastMessage(R.string.add_home);
app.getFavorites().setHomePoint(ll, null);
break;
case WORK:
app.showShortToastMessage(R.string.add_intermediate_point);
app.getFavorites().setWorkPoint(ll);
app.showShortToastMessage(R.string.add_work);
app.getFavorites().setWorkPoint(ll, null);
break;
}
} else if (pointType == PointType.START) {
@ -392,14 +393,24 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
} else {
addMainScrollItems(items, helper);
helper.addListener(new FavouritesDbHelper.FavoritesListener() {
@Override
public void onFavoritesLoaded() {
private void reloadFavoritesItems() {
MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {
loadFavoritesItems(adapter.getItems(), helper);
adapter.notifyDataSetChanged();
}
}
@Override
public void onFavoritesLoaded() {
reloadFavoritesItems();
}
@Override
public void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint) {
reloadFavoritesItems();
}
});
}
BaseBottomSheetItem scrollItem = new HorizontalRecyclerBottomSheetItem.Builder()
@ -443,6 +454,7 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
dismiss();
}
} else {
FavouritesDbHelper favorites = requiredMyApplication().getFavorites();
switch (pointType) {
case START:
helper.setStartPoint(ll, true, name);
@ -453,6 +465,15 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
case INTERMEDIATE:
helper.navigateToPoint(ll, true, helper.getIntermediatePoints().size(), name);
break;
case HOME:
favorites.setHomePoint(ll, null);
break;
case WORK:
favorites.setWorkPoint(ll, null);
break;
case PARKING:
favorites.setParkingPoint(ll);
break;
}
dismiss();
}
@ -598,8 +619,11 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
private class FavoritesItemsAdapter extends ScrollItemsAdapter {
private FavouritesDbHelper favorites;
FavoritesItemsAdapter(OsmandApplication app, List<Object> items) {
super(app, items);
favorites = app.getFavorites();
}
@NonNull
@ -634,11 +658,9 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
favoriteViewHolder.description.setVisibility(View.GONE);
} else {
if (item instanceof PointType) {
PersonalFavouritePoint.PointType pointType = PersonalFavouritePoint.PointType.valueOf(((PointType) item).name());
final FavouritesDbHelper favorites = app.getFavorites();
FavouritePoint point = null;
boolean light = app.getSettings().isLightContent();
int disabledIconColor = light ? R.color.icon_color_default_light : R.color.icon_color_default_dark;
int iconColor = light ? R.color.icon_color_default_light : R.color.icon_color_default_dark;
if (item == PointType.HOME) {
point = favorites.getHomePoint();
} else if (item == PointType.WORK) {
@ -646,12 +668,18 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
} else if (item == PointType.PARKING) {
point = favorites.getParkingPoint();
}
favoriteViewHolder.icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(),
getResources().getColor(disabledIconColor), false, pointType));
favoriteViewHolder.title.setText(point.getName());
favoriteViewHolder.description.setText(point != null
? point.getPointDescription().getSimpleName(app, false)
: getString(R.string.shared_string_add));
Drawable icon = null;
String title = "";
String description = "";
if (point != null) {
PersonalFavouritePoint personalPoint = (PersonalFavouritePoint) point;
icon = app.getUIUtilities().getIcon(personalPoint.getType().getIconId(), iconColor);
title = point.getName();
description = point.getDescription();
}
favoriteViewHolder.icon.setImageDrawable(icon);
favoriteViewHolder.title.setText(title);
favoriteViewHolder.description.setText(description);
} else if (item instanceof FavouritePoint) {
FavouritePoint point = (FavouritePoint) getItem(position);
favoriteViewHolder.title.setText(point.getName());

View file

@ -19,6 +19,7 @@ import android.support.transition.Transition;
import android.support.transition.TransitionListenerAdapter;
import android.support.transition.TransitionManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
import android.view.View;
@ -39,11 +40,13 @@ import net.osmand.PlatformUtil;
import net.osmand.StateChangedListener;
import net.osmand.ValueHolder;
import net.osmand.binary.RouteDataObject;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
import net.osmand.plus.GeocodingLookupService;
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
@ -116,7 +119,7 @@ import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
public class MapRouteInfoMenu implements IRouteInformationListener, CardListener {
public class MapRouteInfoMenu implements IRouteInformationListener, CardListener, FavoritesListener {
private static final Log LOG = PlatformUtil.getLog(MapRouteInfoMenu.class);
@ -211,7 +214,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
app = mapActivity.getMyApplication();
portraitMode = AndroidUiHelper.isOrientationPortrait(mapActivity);
animationsHandler = new Handler();
mapActivity.getMyApplication().getRoutingHelper().addListener(this);
}
}
@ -275,10 +277,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
targets.navigateToPoint(latlon, true, targets.getIntermediatePoints().size());
break;
case HOME:
favorites.setHomePoint(latlon);
favorites.setHomePoint(latlon, null);
break;
case WORK:
favorites.setWorkPoint(latlon);
favorites.setWorkPoint(latlon, null);
break;
}
if (selectFromMapWaypoints) {
@ -1785,7 +1787,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
hide();
}
public void selectAddress(String name, LatLon l, PointType pointType) {
public void selectAddress(@Nullable String name, @NonNull LatLon l, PointType pointType) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, name);
@ -1802,10 +1804,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
targets.navigateToPoint(l, true, targets.getIntermediatePoints().size(), pd);
break;
case HOME:
favorites.setHomePoint(l);
favorites.setHomePoint(l, name);
break;
case WORK:
favorites.setWorkPoint(l);
favorites.setWorkPoint(l, name);
break;
}
updateMenu();
@ -1862,10 +1864,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
targets.navigateToPoint(point, true, targets.getIntermediatePoints().size(), m.getPointDescription(mapActivity));
break;
case HOME:
favorites.setHomePoint(point);
favorites.setHomePoint(point, null);
break;
case WORK:
favorites.setWorkPoint(point);
favorites.setWorkPoint(point, null);
break;
}
updateMenu();
@ -2103,6 +2105,25 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
public void routeWasFinished() {
}
public void onResume(Fragment fragment) {
OsmandApplication app = getApp();
if (app != null) {
app.getRoutingHelper().addListener(this);
app.getFavorites().addListener(this);
}
addTargetPointListener();
}
public void onPause(Fragment fragment) {
OsmandApplication app = getApp();
if (app != null) {
app.getRoutingHelper().removeListener(this);
app.getFavorites().removeListener(this);
}
removeTargetPointListener();
menuCards = new ArrayList<>();
}
public void onDismiss(Fragment fragment, int currentMenuState, Bundle arguments, boolean backPressed) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
@ -2127,7 +2148,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (onDismissListener != null) {
onDismissListener.onDismiss(null);
}
removeTargetPointListener();
} else if (fragment instanceof ChooseRouteFragment) {
routeSelected = true;
MapRouteMenuStateHolder holder = new MapRouteMenuStateHolder(MapRouteMenuType.ROUTE_DETAILS, currentMenuState, fragment.getArguments());
@ -2206,12 +2226,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
if (fragmentRef != null) {
fragmentRef.get().dismiss();
}
OsmandApplication app = getApp();
if (app != null) {
app.getRoutingHelper().removeListener(this);
}
removeTargetPointListener();
menuCards = new ArrayList<>();
}
public boolean needShowMenu() {
@ -2228,6 +2242,15 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
return menuBackStack.empty() ? 0 : menuBackStack.peek().getButtonImage();
}
@Override
public void onFavoritesLoaded() {
}
@Override
public void onFavoriteAddressResolved(@NonNull FavouritePoint favouritePoint) {
updateMenu();
}
public enum MapRouteMenuType {
ROUTE_INFO,
ROUTE_DETAILS

View file

@ -159,13 +159,16 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
updateRouteCalculationProgress(0);
}
}
menu.addTargetPointListener();
menu.onResume(this);
}
}
@Override
public void onPause() {
super.onPause();
if (menu != null) {
menu.onPause(this);
}
}
@Override

View file

@ -270,9 +270,16 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
OsmandApplication app = mapActivity.getMyApplication();
QuickSearchType searchType = dialogFragment.getSearchType();
if (searchType.isTargetPoint()) {
mapActivity.getMapLayers().getMapControlsLayer().selectAddress(
pointDescription != null ? pointDescription.getName() : null,
latitude, longitude, searchType);
String name = null;
if (pointDescription != null) {
String typeName = pointDescription.getTypeName();
if (!Algorithms.isEmpty(typeName)) {
name = mapActivity.getString(R.string.street_city, pointDescription.getName(), typeName);
} else {
name = pointDescription.getName();
}
}
mapActivity.getMapLayers().getMapControlsLayer().selectAddress(name, latitude, longitude, searchType);
dialogFragment.dismiss();
mapActivity.getMapLayers().getMapControlsLayer().showRouteInfoMenu();

View file

@ -1286,7 +1286,7 @@ public class MapControlsLayer extends OsmandMapLayer {
break;
}
if (pointType != null) {
mapRouteInfoMenu.selectAddress(name != null ? name : "", new LatLon(latitude, longitude), pointType);
mapRouteInfoMenu.selectAddress(name, new LatLon(latitude, longitude), pointType);
}
}