Create and edit new profiles - in progress, some refactoring

This commit is contained in:
madwasp79 2019-04-18 17:52:15 +03:00
parent 0d5fb3d0dc
commit 885729c6e8
12 changed files with 275 additions and 146 deletions

View file

@ -7,6 +7,7 @@
android:orientation="vertical">
<TextView
android:id="@+id/dialog_title"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -18,6 +19,17 @@
android:textColor="?attr/main_font_color_basic"
android:textSize="@dimen/default_list_text_size"/>
<TextView
android:id="@+id/dialog_description_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/list_content_padding"
android:paddingStart="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:textSize="@dimen/default_list_text_size"
android:visibility="gone"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/menu_list_view"

View file

@ -16,6 +16,7 @@ import java.util.Set;
public class ApplicationMode {
private static Map<String, Set<ApplicationMode>> widgetsVisibilityMap = new LinkedHashMap<>();
private static Map<String, Set<ApplicationMode>> widgetsAvailabilityMap = new LinkedHashMap<>();
private static List<ApplicationMode> defaultValues = new ArrayList<>();
private static List<ApplicationMode> values = new ArrayList<>();
private static List<ApplicationMode> cachedFilteredValues = new ArrayList<>();
/*
@ -42,19 +43,19 @@ public class ApplicationMode {
public static final ApplicationMode AIRCRAFT = create(R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation().
icon(R.drawable.map_action_aircraft, R.drawable.ic_action_aircraft).reg();
//---------------------------------------------------------------------------------------------------------------
public static final ApplicationMode HIKING = create(R.string.app_mode_hiking, "hiking").speed(1.5f, 5).parent(PEDESTRIAN).
icon(R.drawable.map_action_trekking_dark, R.drawable.ic_action_trekking_dark).reg();
public static final ApplicationMode MOTORCYCLE = create(R.string.app_mode_motorcycle, "motorcycle").speed(15.3f, 40).
carLocation().parent(CAR).
icon(R.drawable.map_action_motorcycle_dark, R.drawable.ic_action_motorcycle_dark).reg();
public static final ApplicationMode TRUCK = create(R.string.app_mode_truck, "truck").speed(15.3f, 40).
carLocation().parent(CAR).
icon(R.drawable.map_action_truck_dark, R.drawable.ic_action_truck_dark).reg();
public static final ApplicationMode TRAIN = create(R.string.app_mode_train, "train").speed(25f, 40).
carLocation().icon(R.drawable.map_action_train, R.drawable.ic_action_train).reg();
// public static final ApplicationMode HIKING = create(R.string.app_mode_hiking, "hiking").speed(1.5f, 5).parent(PEDESTRIAN).
// icon(R.drawable.map_action_trekking_dark, R.drawable.ic_action_trekking_dark).reg();
//
// public static final ApplicationMode MOTORCYCLE = create(R.string.app_mode_motorcycle, "motorcycle").speed(15.3f, 40).
// carLocation().parent(CAR).
// icon(R.drawable.map_action_motorcycle_dark, R.drawable.ic_action_motorcycle_dark).reg();
//
// public static final ApplicationMode TRUCK = create(R.string.app_mode_truck, "truck").speed(15.3f, 40).
// carLocation().parent(CAR).
// icon(R.drawable.map_action_truck_dark, R.drawable.ic_action_truck_dark).reg();
//
// public static final ApplicationMode TRAIN = create(R.string.app_mode_train, "train").speed(25f, 40).
// carLocation().icon(R.drawable.map_action_train, R.drawable.ic_action_train).reg();
static {
ApplicationMode[] exceptDefault = new ApplicationMode[]{CAR, PEDESTRIAN, BICYCLE, BOAT, PUBLIC_TRANSPORT};
@ -108,6 +109,12 @@ public class ApplicationMode {
private ApplicationMode applicationMode;
public ApplicationMode reg() {
values.add(applicationMode);
defaultValues.add(applicationMode);
return applicationMode;
}
public ApplicationMode customReg() {
values.add(applicationMode);
return applicationMode;
}
@ -234,9 +241,12 @@ public class ApplicationMode {
}
public static List<ApplicationMode> allPossibleValues() {
return new ArrayList<ApplicationMode>(values);
return new ArrayList<>(values);
}
public static List<ApplicationMode> getDefaultValues() {
return new ArrayList<>(defaultValues);
}
// returns modifiable ! Set<ApplicationMode> to exclude non-wanted derived
public static Set<ApplicationMode> regWidgetVisibility(String widgetId, ApplicationMode... am) {

View file

@ -1,31 +1,23 @@
package net.osmand.plus.profiles;
import android.os.Parcel;
import android.os.Parcelable;
public class BaseProfile implements Parcelable {
public class BaseProfile extends ProfileDataObject {
private String name;
private String description;
private int iconRes;
private String stringKey;
public BaseProfile(String name, int iconRes) {
this.name = name;
this.name = description;
this.iconRes = iconRes;
public BaseProfile(String stringKey, String name, String description, int iconRes) {
super(name, description, iconRes);
this.stringKey = stringKey;
}
public BaseProfile(String name, String description, int iconRes) {
this.name = name;
this.name = description;
this.iconRes = iconRes;
public String getStringKey() {
return stringKey;
}
protected BaseProfile(Parcel in) {
name = in.readString();
description = in.readString();
iconRes = in.readInt();
super(in);
stringKey = in.readString();
}
public static final Creator<BaseProfile> CREATOR = new Creator<BaseProfile>() {
@ -40,19 +32,6 @@ public class BaseProfile implements Parcelable {
}
};
public String getName() {
return name;
}
public int getIconRes() {
return iconRes;
}
public String getDescription() {
return description;
}
@Override
public int describeContents() {
return 0;
@ -60,8 +39,7 @@ public class BaseProfile implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeString(description);
dest.writeInt(iconRes);
super.writeToParcel(dest, flags);
dest.writeString(stringKey);
}
}

View file

@ -1,7 +0,0 @@
package net.osmand.plus.profiles;
public class BaseProfileBottomSheetDialog {
}

View file

@ -13,6 +13,7 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
@ -21,17 +22,22 @@ import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment {
public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment {
private static final Log LOG = PlatformUtil.getLog(NavTypeBottomSheetDialogFragment.class);
private static final Log LOG = PlatformUtil.getLog(ProfileBottomSheetDialogFragment.class);
private List<RoutingProfile> routingProfiles;
private NavTypeDialogListener listener;
private NavTypeDialogListener listListener;
private List<ProfileDataObject> profiles;
private ProfileTypeDialogListener listener;
private ProfileTypeDialogListener listListener;
private RecyclerView recyclerView;
private ProfileTypeAdapter adapter;
public void setNavTypeListener(NavTypeDialogListener listener) {
public final static String TYPE_APP_PROFILE = "base_profiles";
public final static String TYPE_NAV_PROFILE = "routing_profiles";
private String type;
public void setProfileTypeListener(ProfileTypeDialogListener listener) {
this.listener = listener;
}
@ -42,7 +48,17 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
Bundle args = getArguments();
if (args != null) {
routingProfiles = args.getParcelableArrayList("routing_profiles");
if (args.get(TYPE_NAV_PROFILE) != null) {
profiles = args.getParcelableArrayList(TYPE_NAV_PROFILE);
type = TYPE_NAV_PROFILE;
} else if (args.get(TYPE_APP_PROFILE) != null) {
profiles = args.getParcelableArrayList(TYPE_APP_PROFILE);
type = TYPE_APP_PROFILE;
} else {
//todo notify on empty list;
dismiss();
}
}
final int themeRes = getMyApplication().getSettings().isLightContent()
@ -50,13 +66,19 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
: R.style.OsmandDarkTheme;
View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.bottom_sheet_select_type_fragment, null);
if (type.equals(TYPE_APP_PROFILE)) {
TextView fragmentDescription = view.findViewById(R.id.dialog_description_text);
fragmentDescription.setVisibility(View.VISIBLE);
fragmentDescription.setText(
"The new Application Profile should be based on one of the default App Profiles. Selected Profile defines basic settings: setup of Widgets, units of speed and distance. In string below Profile's name, you could learn which Navigation Profiles are suitable for each Application Profile.");
}
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
listListener = new NavTypeDialogListener() {
listListener = new ProfileTypeDialogListener() {
@Override
public void onSelectedType(int pos) {
listener.onSelectedType(pos);
@ -64,7 +86,7 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
}
};
recyclerView = view.findViewById(R.id.menu_list_view);
adapter = new ProfileTypeAdapter(routingProfiles, isNightMode(getMyApplication()),
adapter = new ProfileTypeAdapter(profiles, isNightMode(getMyApplication()),
listListener);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
@ -85,14 +107,15 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
class ProfileTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
private final List<BaseProfile> items;
private final List<ProfileDataObject> items;
private final boolean isNightMode;
private NavTypeDialogListener listener;
private ProfileTypeDialogListener listener;
private int previousSelection;
public NavTypeAdapter(@NonNull List<RoutingProfile> objects,
@NonNull boolean isNightMode, NavTypeDialogListener listener) {
this.items = objects;
public ProfileTypeAdapter(List<ProfileDataObject> items, boolean isNightMode,
ProfileTypeDialogListener listener) {
this.items = items;
this.isNightMode = isNightMode;
this.listener = listener;
}
@ -113,7 +136,7 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
@Override
public void onBindViewHolder(@NonNull final ItemViewHolder holder, int position) {
final int pos = position;
final BaseProfile item = items.get(position);
final ProfileDataObject item = items.get(position);
holder.title.setText(item.getName());
holder.icon.setImageDrawable(getIcon(item.getIconRes(), isNightMode
@ -136,7 +159,7 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
});
if (item instanceof RoutingProfile) {
holder.descr.setText(Algorithms
.capitalizeFirstLetterAndLowercase(((RoutingProfile) item).getParent().getName()));
.capitalizeFirstLetterAndLowercase(((RoutingProfile) item).getParent()));
if (((RoutingProfile) item).isSelected()) {
holder.radioButton.setChecked(true);
previousSelection = position;
@ -168,8 +191,7 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
}
}
interface NavTypeDialogListener {
interface ProfileTypeDialogListener {
void onSelectedType(int pos);
}

View file

@ -0,0 +1,59 @@
package net.osmand.plus.profiles;
import android.os.Parcel;
import android.os.Parcelable;
public class ProfileDataObject implements Parcelable {
private String name;
private String description;
private int iconRes;
public ProfileDataObject(String name, String description, int iconRes) {
this.name = name;
this.iconRes = iconRes;
this.description = description;
}
protected ProfileDataObject(Parcel in) {
name = in.readString();
description = in.readString();
iconRes = in.readInt();
}
public static final Creator<ProfileDataObject> CREATOR = new Creator<ProfileDataObject>() {
@Override
public ProfileDataObject createFromParcel(Parcel in) {
return new ProfileDataObject(in);
}
@Override
public ProfileDataObject[] newArray(int size) {
return new ProfileDataObject[size];
}
};
public String getName() {
return name;
}
public int getIconRes() {
return iconRes;
}
public String getDescription() {
return description;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(name);
dest.writeString(description);
dest.writeInt(iconRes);
}
}

View file

@ -14,9 +14,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileViewHolder;
import net.osmand.util.Algorithms;
import net.sf.junidecode.App;
@ -64,11 +66,15 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
holder.descr.setText(String.format("Type: %s", item.getParent().getStringKey()));
} else {
holder.title.setText(app.getResources().getString(item.getStringResource()));
holder.descr.setText(String.format("Type: %s", item.getStringKey()));
holder.descr.setText(String.format("Type: %s", Algorithms.capitalizeFirstLetterAndLowercase(item.getStringKey().replace("_", " "))));
}
holder.title.setTextColor(app.getResources().getColor(isNightMode(app) ? R.color.main_font_dark : R.color.main_font_light));
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(item.getSmallIconDark(), isNightMode(app) ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light));
holder.title.setTextColor(app.getResources().getColor(isNightMode(app)
? R.color.main_font_dark
: R.color.main_font_light));
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(item.getSmallIconDark(), isNightMode(app)
? R.color.active_buttons_and_links_dark
: R.color.active_buttons_and_links_light));
holder.aSwitch.setChecked(selectedItems.contains(item));
holder.aSwitch.setOnClickListener(new OnClickListener() {
@Override

View file

@ -1,21 +1,19 @@
package net.osmand.plus.profiles;
import android.os.Parcel;
import android.os.Parcelable;
import net.osmand.plus.routing.RoutingHelper;
public class RoutingProfile extends BaseProfile {
public class RoutingProfile extends ProfileDataObject {
private BaseProfile parent;
private String parent;
private boolean isSelected;
public RoutingProfile(String name, BaseProfile parent, int iconRes, boolean isSelected) {
super(name, iconRes);
public RoutingProfile(String name, String parent, int iconRes, boolean isSelected) {
super(name, parent, iconRes);
this.parent = parent;
this.isSelected = isSelected;
}
public BaseProfile getParent() {
public String getParent() {
return parent;
}
@ -29,7 +27,7 @@ public class RoutingProfile extends BaseProfile {
protected RoutingProfile(Parcel in) {
super(in);
parent = in.readParcelable(BaseProfile.class.getClassLoader());
parent = in.readString();
isSelected = in.readByte() != 0;
}
@ -53,7 +51,7 @@ public class RoutingProfile extends BaseProfile {
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeParcelable(parent, flags);
dest.writeString(parent);
dest.writeByte((byte) (isSelected ? 1 : 0));
}
}

View file

@ -8,6 +8,7 @@ import android.view.MenuItem;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.util.Algorithms;
public class SelectedProfileActivity extends OsmandActionBarActivity {
@ -18,8 +19,11 @@ public class SelectedProfileActivity extends OsmandActionBarActivity {
setContentView(R.layout.single_fragment_layout);
Intent intent = getIntent();
if (intent.getExtras() != null) {
String stringKey = intent.getStringExtra("stringKey");
String title = stringKey == null ? "New Profile" : stringKey.toUpperCase(); //todo need normal title
String title = Algorithms.capitalizeFirstLetterAndLowercase(
intent.getStringExtra("stringKey").replace("_", " "));
if (intent.getBooleanExtra("isNew", false)) {
title = String.format("%s (new)", title);
}
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(title);
getSupportActionBar().setElevation(5.0f);

View file

@ -27,7 +27,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.profiles.NavTypeBottomSheetDialogFragment.NavTypeDialogListener;
import net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.ProfileTypeDialogListener;
import net.osmand.plus.profiles.SelectIconBottomSheetDialogFragment.IconIdListener;
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
@ -44,6 +44,8 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
public static final String SCREEN_CONFIG = "openScreenConfigMenu";
public static final String SELECTED_PROFILE = "editedProfile";
ApplicationMode profile = null;
ApplicationMode parent = null;
ArrayList<RoutingProfile> routingProfiles;
@ -51,9 +53,10 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
RoutingProfile selectedRoutingProfile = null;
float defSpeed = 0f;
boolean isDataChanged = false;
private boolean isNew = false;
private boolean isDataChanged = false;
private NavTypeDialogListener navTypeDialogListener = null;
private ProfileTypeDialogListener profileTypeDialogListener = null;
private IconIdListener iconIdListener = null;
@Override
@ -61,9 +64,13 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
super.onCreate(savedInstanceState);
app = getMyApplication();
if (getArguments() != null) {
String modeName = getArguments().getString("stringKey");
profile = ApplicationMode.valueOfStringKey(modeName, ApplicationMode.CAR);
//todo select parent
String modeName = getArguments().getString("stringKey", "car");
if (!getArguments().getBoolean("isNew", true)) {
profile = ApplicationMode.valueOfStringKey(modeName, ApplicationMode.CAR);
} else {
isNew = true;
parent = ApplicationMode.valueOfStringKey(modeName, ApplicationMode.CAR);
}
}
routingProfiles = getRoutingProfiles();
}
@ -92,10 +99,15 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
profileIconBtn.setBackgroundResource(R.drawable.rounded_background_3dp);
GradientDrawable selectIconBtnBackground = (GradientDrawable) profileIconBtn
.getBackground();
profileIcon.setImageDrawable(app.getUIUtilities().getIcon(profile.getSmallIconDark(),
isNightMode ? R.color.active_buttons_and_links_dark
: R.color.active_buttons_and_links_light));
if(isNew) {
profileIcon.setImageDrawable(app.getUIUtilities().getIcon(parent.getSmallIconDark(),
isNightMode ? R.color.active_buttons_and_links_dark
: R.color.active_buttons_and_links_light));
} else {
profileIcon.setImageDrawable(app.getUIUtilities().getIcon(profile.getSmallIconDark(),
isNightMode ? R.color.active_buttons_and_links_dark
: R.color.active_buttons_and_links_light));
}
if (isNightMode) {
profileNameTextBox
@ -109,7 +121,7 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
.setColor(app.getResources().getColor(R.color.text_field_box_light));
}
navTypeDialogListener = new NavTypeDialogListener() {
profileTypeDialogListener = new ProfileTypeDialogListener() {
@Override
public void onSelectedType(int pos) {
selectedRoutingProfile = routingProfiles.get(pos);
@ -153,9 +165,8 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
selectNavTypeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LOG.debug("select icon");
final NavTypeBottomSheetDialogFragment fragment = new NavTypeBottomSheetDialogFragment();
fragment.setNavTypeListener(navTypeDialogListener);
final ProfileBottomSheetDialogFragment fragment = new ProfileBottomSheetDialogFragment();
fragment.setProfileTypeListener(profileTypeDialogListener);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("routing_profiles", routingProfiles);
fragment.setArguments(bundle);
@ -179,7 +190,6 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
profileIconBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LOG.debug("select icon");
final SelectIconBottomSheetDialogFragment iconSelectDialog = new SelectIconBottomSheetDialogFragment();
iconSelectDialog.setIconIdListener(iconIdListener);
Bundle bundle = new Bundle();
@ -319,7 +329,7 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
break;
}
routingProfiles
.add(new RoutingProfile(name, getString(R.string.osmand_default_routing), iconRes, false));
.add(new RoutingProfile(name, getResources().getString(R.string.osmand_default_routing), iconRes, false));
}
return routingProfiles;
}

View file

@ -1,5 +1,7 @@
package net.osmand.plus.profiles;
import static net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.TYPE_APP_PROFILE;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@ -12,6 +14,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@ -19,6 +22,7 @@ import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.ProfileTypeDialogListener;
import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileListener;
import org.apache.commons.logging.Log;
@ -31,59 +35,27 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
private LinearLayout addProfileBtn;
ProfileListener listener = null;
ProfileTypeDialogListener typeListener = null;
private List<ApplicationMode> allAppModes;
private Set<ApplicationMode> availableAppModes;
private ArrayList<BaseProfile> baseProfiles;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Context ctx = getMyApplication().getApplicationContext();
allAppModes = ApplicationMode.allPossibleValues();
allAppModes.remove(ApplicationMode.DEFAULT);
allAppModes.remove(ApplicationMode.AIRCRAFT);
allAppModes.remove(ApplicationMode.HIKING);
allAppModes.remove(ApplicationMode.TRAIN);
availableAppModes = new LinkedHashSet<>(ApplicationMode.values(getMyApplication()));
availableAppModes.remove(ApplicationMode.DEFAULT);
baseProfiles = getBaseProfiles();
}
// private String getNavType(ApplicationMode am, Context ctx) {
// if (am.getParent() != null) {
// return getNavType(am.getParent(), ctx);
// } else {
// switch(am.getStringKey()) {
// case "car":
// return ctx.getResources().getString(R.string.rendering_value_car_name);
// case "bicycle":
// return ctx.getResources().getString(R.string.rendering_value_bicycle_name);
// case "pedestrian":
// return ctx.getResources().getString(R.string.rendering_value_pedestrian_name);
// case "public_transport":
// return ctx.getResources().getString(R.string.app_mode_public_transport);
// case "boat":
// return ctx.getResources().getString(R.string.app_mode_boat);
// }
// }
// return "";
// }
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.profiles_list_fragment, container, false);
recyclerView = view.findViewById(R.id.profiles_list);
addProfileBtn = view.findViewById(R.id.add_profile_btn);
addProfileBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
listener = new ProfileListener() {
@Override
@ -106,26 +78,91 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
for (ApplicationMode sam : availableAppModes) {
vls.append(sam.getStringKey()).append(",");
}
getSettings().AVAILABLE_APP_MODES.set(vls.toString());
if (getSettings() != null) {
getSettings().AVAILABLE_APP_MODES.set(vls.toString());
}
}
@Override
public void editProfile(ApplicationMode item) {
Intent intent = new Intent(getActivity(), SelectedProfileActivity.class);
intent.putExtra("stringKey", item.getStringKey());
intent.putExtra("isNew", false);
startActivity(intent);
}
};
typeListener = new ProfileTypeDialogListener() {
@Override
public void onSelectedType(int pos) {
LOG.debug("Base profile: " + baseProfiles.get(pos).getName());
Intent intent = new Intent(getActivity(), SelectedProfileActivity.class);
intent.putExtra("isNew", true);
intent.putExtra("stringKey", baseProfiles.get(pos).getStringKey());
startActivity(intent);
}
};
View view = inflater.inflate(R.layout.profiles_list_fragment, container, false);
recyclerView = view.findViewById(R.id.profiles_list);
addProfileBtn = view.findViewById(R.id.add_profile_btn);
addProfileBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final ProfileBottomSheetDialogFragment dialog = new ProfileBottomSheetDialogFragment();
dialog.setProfileTypeListener(typeListener);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList(TYPE_APP_PROFILE, baseProfiles);
dialog.setArguments(bundle);
if (getActivity() != null) {
getActivity().getSupportFragmentManager().beginTransaction()
.add(dialog, "select_base_type").commitAllowingStateLoss();
}
}
});
adapter = new ProfileMenuAdapter(allAppModes, availableAppModes, getMyApplication(), listener);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
return view;
}
private ArrayList<BaseProfile> getBaseProfiles() {
ArrayList<BaseProfile> profiles = new ArrayList<>();
for (ApplicationMode mode : ApplicationMode.getDefaultValues()) {
switch (mode.getStringKey()) {
case "car":
profiles.add(new BaseProfile(mode.getStringKey(), getString(R.string.rendering_value_car_name),
"Car, Truck, Motorcycle", R.drawable.ic_action_car_dark));
break;
case "bicycle":
profiles.add(new BaseProfile(mode.getStringKey(), getString(R.string.rendering_value_bicycle_name),
"MBT, Moped, Skiing, Horse", R.drawable.map_action_bicycle_dark));
break;
case "pedestrian":
profiles.add(new BaseProfile(mode.getStringKey(), getString(R.string.rendering_value_pedestrian_name),
"Walking, Hiking, Running", R.drawable.map_action_pedestrian_dark));
break;
case "public_transport":
profiles.add(new BaseProfile(mode.getStringKey(), getString(R.string.app_mode_public_transport),
"All PT types", R.drawable.map_action_bus_dark));
break;
case "boat":
profiles.add(new BaseProfile(mode.getStringKey(), getString(R.string.nautical_renderer),
"Ship, Rowing, Sailing", R.drawable.map_action_sail_boat_dark));
break;
case "aircraft":
profiles.add(new BaseProfile(mode.getStringKey(), getString(R.string.app_mode_aircraft),
"Airplane, Gliding", R.drawable.map_action_aircraft));
break;
}
}
return profiles;
}
}

View file

@ -73,10 +73,10 @@ public class RoutingOptionsHelper {
addRouteMenuAppModes(ApplicationMode.PUBLIC_TRANSPORT, PermanentAppModeOptions.PUBLIC_TRANSPORT.routingParameters);
addRouteMenuAppModes(ApplicationMode.BOAT, PermanentAppModeOptions.BOAT.routingParameters);
addRouteMenuAppModes(ApplicationMode.AIRCRAFT, PermanentAppModeOptions.AIRCAFT.routingParameters);
addRouteMenuAppModes(ApplicationMode.HIKING, PermanentAppModeOptions.HIKING.routingParameters);
addRouteMenuAppModes(ApplicationMode.MOTORCYCLE, PermanentAppModeOptions.MOTORCYCLE.routingParameters);
addRouteMenuAppModes(ApplicationMode.TRUCK, PermanentAppModeOptions.TRUCK.routingParameters);
addRouteMenuAppModes(ApplicationMode.TRAIN, PermanentAppModeOptions.TRAIN.routingParameters);
// addRouteMenuAppModes(ApplicationMode.HIKING, PermanentAppModeOptions.HIKING.routingParameters);
// addRouteMenuAppModes(ApplicationMode.MOTORCYCLE, PermanentAppModeOptions.MOTORCYCLE.routingParameters);
// addRouteMenuAppModes(ApplicationMode.TRUCK, PermanentAppModeOptions.TRUCK.routingParameters);
// addRouteMenuAppModes(ApplicationMode.TRAIN, PermanentAppModeOptions.TRAIN.routingParameters);
}
private void addRouteMenuAppModes(ApplicationMode am, List<String> routingParameters) {