correctly shows names of files with custom routing profiles

This commit is contained in:
madwasp79 2019-05-13 12:51:20 +03:00
parent 0f7f1b6e89
commit bd34a38e7d
4 changed files with 30 additions and 16 deletions

View file

@ -44,7 +44,7 @@ public class GeneralRouter implements VehicleRouter {
private boolean shortestRoute;
private boolean heightObstacles;
private boolean allowPrivate;
private String filename;
private String filename = null;
private Map<RouteRegion, Map<Integer, Integer>> regionConvert = new LinkedHashMap<RouteRegion, Map<Integer,Integer>>();

View file

@ -558,11 +558,12 @@ public class EditProfileFragment extends BaseOsmAndFragment {
}
private ArrayList<RoutingProfile> getRoutingProfiles() {
ArrayList<RoutingProfile> routingProfiles = new ArrayList<>();
Map<String, GeneralRouter> routingProfilesNames = getMyApplication().getDefaultRoutingConfig().getAllRoutes();
for (Entry<String, GeneralRouter> e : routingProfilesNames.entrySet()) {
ArrayList<RoutingProfile> profilesObjects = new ArrayList<>();
Map<String, GeneralRouter> inputProfiles = getMyApplication().getDefaultRoutingConfig().getAllRoutes();
for (Entry<String, GeneralRouter> e : inputProfiles.entrySet()) {
String name;
String description = getResources().getString(R.string.osmand_default_routing);
// String description = getResources().getString(R.string.osmand_default_routing);
String description = "";
int iconRes;
switch (e.getKey()) {
case "car":
@ -596,9 +597,9 @@ public class EditProfileFragment extends BaseOsmAndFragment {
description = "Custom profile"; //todo add filename
break;
}
routingProfiles.add(new RoutingProfile(e.getKey(), name, description, iconRes, false));
profilesObjects.add(new RoutingProfile(e.getKey(), name, description, iconRes, false, e.getValue().getFilename()));
}
return routingProfiles;
return profilesObjects;
}

View file

@ -120,19 +120,13 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
private int previousSelection;
public ProfileTypeAdapter(List<ProfileDataObject> items, boolean isNightMode,
ProfileTypeAdapter(List<ProfileDataObject> items, boolean isNightMode,
ProfileTypeDialogListener listener) {
this.items = items;
this.isNightMode = isNightMode;
this.listener = listener;
}
public void updateData(List<RoutingProfile> newItems) {
items.clear();
items.addAll(newItems);
notifyDataSetChanged();
}
@NonNull
@Override
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@ -168,7 +162,18 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
}
});
holder.descr.setText(item.getDescription());
if(item instanceof RoutingProfile) {
if (((RoutingProfile) item).getFileName() != null) {
holder.descr
.setText(String.format("From %s", ((RoutingProfile) item).getFileName()));
} else {
holder.descr
.setText(getResources().getString(R.string.osmand_default_routing));
}
} else {
holder.descr.setText(item.getDescription());
}
if (item.isSelected()) {
holder.radioButton.setChecked(true);
previousSelection = position;

View file

@ -6,10 +6,12 @@ import android.os.Parcel;
public class RoutingProfile extends ProfileDataObject {
private String stringKey;
private String fileName;
public RoutingProfile(String stringKey, String name, String descr, int iconRes, boolean isSelected) {
public RoutingProfile(String stringKey, String name, String descr, int iconRes, boolean isSelected, String fileName) {
super(name, descr, iconRes, isSelected);
this.stringKey = stringKey;
this.fileName = fileName;
}
public String getStringKey() {
@ -19,6 +21,11 @@ public class RoutingProfile extends ProfileDataObject {
protected RoutingProfile(Parcel in) {
super(in);
stringKey = in.readString();
fileName = in.readString();
}
public String getFileName() {
return fileName;
}
public static final Creator<RoutingProfile> CREATOR = new Creator<RoutingProfile>() {
@ -42,5 +49,6 @@ public class RoutingProfile extends ProfileDataObject {
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeString(stringKey);
dest.writeString(fileName);
}
}