Fix code review remarks

This commit is contained in:
Dima-1 2020-01-10 14:01:29 +02:00
parent 50192251bb
commit 3d8756459d
7 changed files with 28 additions and 39 deletions

View file

@ -146,7 +146,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
}
public String getCategoryDisplayName(@NonNull Context ctx) {
return FavouritesDbHelper.FavoriteGroup.getDisplayName(category, ctx);
return FavouritesDbHelper.FavoriteGroup.getDisplayName(ctx, category);
}
public void setCategory(String category) {

View file

@ -80,7 +80,11 @@ public class FavouritesDbHelper {
return PERSONAL_CATEGORY.equals(name);
}
public static String getDisplayName(String name, Context ctx) {
public static boolean isPersonalCategoryDisplayName(Context ctx, String name){
return name.equals(ctx.getString(R.string.personal_category_name));
}
public static String getDisplayName(Context ctx, String name) {
if (isPersonal(name)) {
return ctx.getString(R.string.personal_category_name);
} else if (name.isEmpty()) {
@ -107,11 +111,11 @@ public class FavouritesDbHelper {
}
public String getDisplayName(Context ctx) {
return getDisplayName(name, ctx);
return getDisplayName(ctx, name);
}
public static String convertDisplayNameToGroupIdName(Context context, String name) {
if (name.equals(context.getString(R.string.personal_category_name))) {
if (isPersonalCategoryDisplayName(context,name)) {
return PERSONAL_CATEGORY;
}
if (name.equals(context.getString(R.string.shared_string_favorites))) {
@ -121,7 +125,6 @@ public class FavouritesDbHelper {
}
}
public void loadFavorites() {
flatGroups.clear();
favoriteGroups.clear();
@ -435,7 +438,6 @@ public class FavouritesDbHelper {
return true;
}
private void editAddressDescription(@NonNull FavouritePoint p, @Nullable String address) {
p.setAddress(address);
saveCurrentPointsIntoFile();
@ -490,7 +492,6 @@ public class FavouritesDbHelper {
return saveExternalFile(null);
}
private Exception saveExternalFile(Set<String> deleted) {
Map<String, FavouritePoint> all = new LinkedHashMap<String, FavouritePoint>();
loadGPXFile(getExternalFile(), all);
@ -509,7 +510,6 @@ public class FavouritesDbHelper {
return saveFile(favoritePoints, getExternalFile());
}
private String getKey(FavouritePoint p) {
return p.getName() + DELIMETER + p.getCategory();
}
@ -560,7 +560,6 @@ public class FavouritesDbHelper {
return GPXUtilities.writeGpxFile(f, gpx);
}
public GPXFile asGpxFile() {
return asGpxFile(cachedFavoritePoints);
}
@ -573,21 +572,16 @@ public class FavouritesDbHelper {
return gpx;
}
private void addEmptyCategory(String name) {
addEmptyCategory(name, 0, true, false);
addEmptyCategory(name, 0, true);
}
public void addEmptyCategory(String name, int color) {
if (name.equals(context.getString(R.string.personal_category_name)))
if (FavoriteGroup.isPersonalCategoryDisplayName(context,name))
addEmptyCategory(name, color, true);
}
public void addEmptyCategory(String name, int color, boolean visible) {
addEmptyCategory(name, color, visible, false);
}
public void addEmptyCategory(String name, int color, boolean visible, boolean personal) {
FavoriteGroup group = new FavoriteGroup();
group.name = name;
group.color = color;
@ -610,7 +604,6 @@ public class FavouritesDbHelper {
return fp;
}
@Nullable
public FavouritePoint getVisibleFavByLatLon(@NonNull LatLon latLon) {
for (FavouritePoint fav : cachedFavoritePoints) {
@ -621,7 +614,6 @@ public class FavouritesDbHelper {
return null;
}
public List<FavoriteGroup> getFavoriteGroups() {
return favoriteGroups;
}
@ -647,9 +639,6 @@ public class FavouritesDbHelper {
public FavoriteGroup getGroup(String nameId) {
if (flatGroups.containsKey(nameId)) {
return flatGroups.get(nameId);
// TODO HW: double check invocations and use convertDisplayNameToGroupIdName where it is needed?
//// } else if (name.equals(context.getString(R.string.personal_category_name))) {
//// return flatGroups.get(PERSONAL_CATEGORY);
} else {
return null;
}
@ -667,7 +656,6 @@ public class FavouritesDbHelper {
return null;
}
public void recalculateCachedFavPoints() {
List<FavouritePoint> allPoints = new ArrayList<>();
for (FavoriteGroup f : favoriteGroups) {

View file

@ -134,7 +134,7 @@ public class FavouritePointMenuController extends MenuController {
public String getNameStr() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
return fav.getDisplayName(getMapActivity());
return fav.getDisplayName(mapActivity);
} else {
return super.getNameStr();
}

View file

@ -71,7 +71,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment {
View view = super.onCreateView(inflater, container, savedInstanceState);
FavoritePointEditor editor = getFavoritePointEditor();
if (view != null && editor != null && editor.isNew()) {
Button replaceButton = view.findViewById(R.id.replace_button);
Button replaceButton = (Button) view.findViewById(R.id.replace_button);
replaceButton.setTextColor(getResources().getColor(!editor.isLight() ? R.color.osmand_orange : R.color.map_widget_blue));
replaceButton.setVisibility(View.VISIBLE);
replaceButton.setOnClickListener(new View.OnClickListener() {

View file

@ -34,6 +34,7 @@ import net.osmand.plus.widgets.AutoCompleteTextViewEx;
import net.osmand.util.Algorithms;
import static net.osmand.plus.FavouritesDbHelper.FavoriteGroup.PERSONAL_CATEGORY;
import static net.osmand.plus.FavouritesDbHelper.FavoriteGroup.isPersonalCategoryDisplayName;
public abstract class PointEditorFragment extends BaseOsmAndFragment {
@ -356,7 +357,7 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
public String getCategoryTextValue() {
AutoCompleteTextViewEx categoryEdit = (AutoCompleteTextViewEx) view.findViewById(R.id.category_edit);
String name = categoryEdit.getText().toString().trim();
if(name.equals(getString(R.string.personal_category_name))) {
if (isPersonalCategoryDisplayName(requireContext(), name)) {
return PERSONAL_CATEGORY;
}
if(name.equals(getDefaultCategoryName())) {

View file

@ -147,18 +147,19 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag
}
private void selectFavorite(FavouritePoint point) {
TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
FavouritesDbHelper favorites = getMyApplication().getFavorites();
OsmandApplication app = getMyApplication();
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();
FavouritesDbHelper favorites = app.getFavorites();
LatLon ll = new LatLon(point.getLatitude(), point.getLongitude());
switch (pointType) {
case START:
targetPointsHelper.setStartPoint(ll, true, point.getPointDescription(requireActivity()));
targetPointsHelper.setStartPoint(ll, true, point.getPointDescription(app));
break;
case TARGET:
targetPointsHelper.navigateToPoint(ll, true, -1, point.getPointDescription(requireActivity()));
targetPointsHelper.navigateToPoint(ll, true, -1, point.getPointDescription(app));
break;
case INTERMEDIATE:
targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), point.getPointDescription(requireActivity()));
targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), point.getPointDescription(app));
break;
case HOME:
favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.HOME, null);

View file

@ -6,7 +6,6 @@ import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.WorkSource;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager;
@ -161,10 +160,10 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
private void createSearchItem() {
View searchView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_double_item, null);
TextView firstTitle = searchView.findViewById(R.id.first_title);
TextView secondTitle = searchView.findViewById(R.id.second_title);
ImageView firstIcon = searchView.findViewById(R.id.first_icon);
ImageView secondIcon = searchView.findViewById(R.id.second_icon);
TextView firstTitle = (TextView) searchView.findViewById(R.id.first_title);
TextView secondTitle = (TextView) searchView.findViewById(R.id.second_title);
ImageView firstIcon = (ImageView) searchView.findViewById(R.id.first_icon);
ImageView secondIcon = (ImageView) searchView.findViewById(R.id.second_icon);
firstTitle.setText(R.string.shared_string_search);
secondTitle.setText(R.string.shared_string_address);
@ -318,7 +317,7 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
private void createSwitchStartAndEndItem() {
final View switchStartAndEndView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_item_simple_56dp, null);
TextView title = switchStartAndEndView.findViewById(R.id.title);
TextView title = (TextView) switchStartAndEndView.findViewById(R.id.title);
String start = getString(R.string.route_start_point).toLowerCase();
String destination = getString(R.string.route_descr_destination).toLowerCase();
@ -538,9 +537,9 @@ public class AddPointBottomSheetDialog extends MenuBottomSheetDialogFragment {
ItemViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
description = itemView.findViewById(R.id.description);
icon = itemView.findViewById(R.id.icon);
title = (TextView) itemView.findViewById(R.id.title);
description = (TextView) itemView.findViewById(R.id.description);
icon = (ImageView) itemView.findViewById(R.id.icon);
}
}