Moved parameters to constants, changed switches to enums
Strings to res Code clean up
This commit is contained in:
parent
d70dfd129b
commit
69590b560b
18 changed files with 280 additions and 381 deletions
|
@ -11,6 +11,27 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="profile_alert_need_save_title">Save Changes</string>
|
||||
<string name="profile_alert_need_save_msg">You need to save changes to Profile before proceed</string>
|
||||
<string name="profile_alert_delete_title">Delete Profile</string>
|
||||
<string name="profile_alert_delete_msg">Are you sure you want to delete %s profile</string>
|
||||
<string name="select_base_profile_dialog_title">Select base profile</string>
|
||||
<string name="select_base_profile_dialog_message">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.</string>
|
||||
<string name="select_nav_profile_dialog_title">Select navigation type</string>
|
||||
<string name="base_profile_descr_car">Car, Truck, Motorcycle</string>
|
||||
<string name="base_profile_descr_bicycle">MBT, Moped, Skiing, Horse</string>
|
||||
<string name="base_profile_descr_pedestrian">Walking, Hiking, Running</string>
|
||||
<string name="base_profile_descr_public_transport">All PT types</string>
|
||||
<string name="base_profile_descr_boat">Ship, Rowing, Sailing</string>
|
||||
<string name="base_profile_descr_aircraft">Airplane, Gliding</string>
|
||||
<string name="routing_profile_geocoding">Geocoding</string>
|
||||
<string name="routing_profile_straightline">Straight Line</string>
|
||||
<string name="routing_profile_broutrer">BRouter (online)</string>
|
||||
<string name="osmand_default_routing">OsmAnd routing</string>
|
||||
<string name="custom_routing">Custom routing profile</string>
|
||||
<string name="special_routing_type">Special routing</string>
|
||||
<string name="online_routing_type">Online routing</string>
|
||||
|
||||
<string name="files_moved">Moved %1$d files (%2$s).</string>
|
||||
<string name="files_copied">Copied %1$d files (%2$s).</string>
|
||||
<string name="files_failed">Failed to copy %1$d files (%2$s).</string>
|
||||
|
@ -24,7 +45,6 @@
|
|||
<string name="public_transport_calc_pedestrian">Calculate pedestrian route</string>
|
||||
<string name="public_transport_type">Transport type</string>
|
||||
<string name="send_log">Send log</string>
|
||||
<string name="osmand_default_routing">OsmAnd routing</string>
|
||||
<string name="application_profiles_descr">Select the profiles to be visible in the app.</string>
|
||||
<string name="application_profiles">Application profiles</string>
|
||||
<string name="routing_attr_avoid_tram_name">Avoid trams</string>
|
||||
|
@ -3120,4 +3140,6 @@
|
|||
<string name="routing_attr_avoid_sett_name">Avoid cobblestone and sett</string>
|
||||
<string name="routing_attr_avoid_sett_description">Avoid cobblestone and sett</string>
|
||||
|
||||
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -460,6 +460,7 @@ public class AppInitializer implements IProgress {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
app.getRoutingConfig();
|
||||
app.applyTheme(app);
|
||||
app.inAppPurchaseHelper = startupInit(new InAppPurchaseHelper(app), InAppPurchaseHelper.class);
|
||||
app.poiTypes = startupInit(MapPoiTypes.getDefaultNoInit(), MapPoiTypes.class);
|
||||
|
@ -562,8 +563,7 @@ public class AppInitializer implements IProgress {
|
|||
for (File f : fl) {
|
||||
if (f.isFile() && f.getName().endsWith(".xml") && f.canRead()) {
|
||||
try {
|
||||
RoutingConfiguration
|
||||
.parseFromInputStream(new FileInputStream(f), f.getName(), config);
|
||||
RoutingConfiguration.parseFromInputStream(new FileInputStream(f), f.getName(), config);
|
||||
} catch (XmlPullParserException | IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
|
|
@ -137,10 +137,10 @@ public class CurrentPositionHelper {
|
|||
for (BinaryMapReaderResource rep : checkReaders) {
|
||||
rs[i++] = rep.getReader(BinaryMapReaderResourceType.STREET_LOOKUP);
|
||||
}
|
||||
RoutingConfiguration cfg = app.getDefaultRoutingConfig().build(p, 10,
|
||||
RoutingConfiguration cfg = app.getRoutingConfig().build(p, 10,
|
||||
new HashMap<String, String>());
|
||||
ctx = new RoutePlannerFrontEnd().buildRoutingContext(cfg, null, rs);
|
||||
RoutingConfiguration defCfg = app.getDefaultRoutingConfig().build("geocoding", 10,
|
||||
RoutingConfiguration defCfg = app.getRoutingConfig().build("geocoding", 10,
|
||||
new HashMap<String, String>());
|
||||
defCtx = new RoutePlannerFrontEnd().buildRoutingContext(defCfg, null, rs);
|
||||
} else {
|
||||
|
|
|
@ -807,7 +807,7 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
return lang;
|
||||
}
|
||||
|
||||
public synchronized RoutingConfiguration.Builder getDefaultRoutingConfig() {
|
||||
public synchronized RoutingConfiguration.Builder getRoutingConfig() {
|
||||
if(defaultRoutingConfig == null) {
|
||||
defaultRoutingConfig = appInitializer.getLazyRoutingConfig();
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
|
@ -30,7 +29,6 @@ import net.osmand.plus.OsmandSettings.CommonPreference;
|
|||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.actions.AppModeDialog;
|
||||
import net.osmand.plus.profiles.BaseProfile;
|
||||
import net.osmand.plus.views.SeekBarPreference;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
@ -52,8 +50,7 @@ public abstract class SettingsBaseActivity extends ActionBarPreferenceActivity
|
|||
protected OsmandSettings settings;
|
||||
protected final boolean profileSettings;
|
||||
protected List<ApplicationMode> modes = new ArrayList<ApplicationMode>();
|
||||
protected final ArrayList<BaseProfile> appModes = new ArrayList<>();
|
||||
private ApplicationMode previousAppMode;
|
||||
private ApplicationMode previousAppMode;
|
||||
|
||||
private Map<String, Preference> screenPreferences = new LinkedHashMap<String, Preference>();
|
||||
private Map<String, OsmandPreference<Boolean>> booleanPreferences = new LinkedHashMap<String, OsmandPreference<Boolean>>();
|
||||
|
|
|
@ -248,7 +248,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
cat.addPreference(fastRoute);
|
||||
} else {
|
||||
ApplicationMode am = settings.getApplicationMode();
|
||||
GeneralRouter router = getRouter(getMyApplication().getDefaultRoutingConfig(), am);
|
||||
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am);
|
||||
clearParameters();
|
||||
if (router != null) {
|
||||
Map<String, RoutingParameter> parameters = router.getParameters();
|
||||
|
|
|
@ -149,7 +149,7 @@ public class AvoidSpecificRoads {
|
|||
app.getSettings().removeImpassableRoad(latLon);
|
||||
RouteDataObject obj = impassableRoads.remove(latLon);
|
||||
if (obj != null) {
|
||||
app.getDefaultRoutingConfig().removeImpassableRoad(obj);
|
||||
app.getRoutingConfig().removeImpassableRoad(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,7 +254,7 @@ public class AvoidSpecificRoads {
|
|||
final LatLon oldLoc = getLocation(currentObject);
|
||||
app.getSettings().moveImpassableRoad(oldLoc, newLoc);
|
||||
impassableRoads.remove(oldLoc);
|
||||
app.getDefaultRoutingConfig().removeImpassableRoad(currentObject);
|
||||
app.getRoutingConfig().removeImpassableRoad(currentObject);
|
||||
addImpassableRoadInternal(object, ll, showDialog, activity, newLoc);
|
||||
|
||||
if (callback != null) {
|
||||
|
@ -276,7 +276,7 @@ public class AvoidSpecificRoads {
|
|||
boolean showDialog,
|
||||
@Nullable MapActivity activity,
|
||||
@NonNull LatLon loc) {
|
||||
if (app.getDefaultRoutingConfig().addImpassableRoad(object, ll)) {
|
||||
if (app.getRoutingConfig().addImpassableRoad(object, ll)) {
|
||||
impassableRoads.put(loc, object);
|
||||
} else {
|
||||
LatLon location = getLocation(object);
|
||||
|
@ -305,7 +305,7 @@ public class AvoidSpecificRoads {
|
|||
}
|
||||
|
||||
public LatLon getLocation(RouteDataObject object) {
|
||||
Location location = app.getDefaultRoutingConfig().getImpassableRoadLocations().get(object.getId());
|
||||
Location location = app.getRoutingConfig().getImpassableRoadLocations().get(object.getId());
|
||||
return location == null ? null : new LatLon(location.getLatitude(), location.getLongitude());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
public class BaseProfile extends ProfileDataObject {
|
||||
|
||||
private String stringKey;
|
||||
|
||||
public BaseProfile(String stringKey, String name, String description, int iconRes, boolean isSelected) {
|
||||
super(name, description, iconRes, isSelected);
|
||||
this.stringKey = stringKey;
|
||||
}
|
||||
|
||||
public String getStringKey() {
|
||||
return stringKey;
|
||||
}
|
||||
|
||||
protected BaseProfile(Parcel in) {
|
||||
super(in);
|
||||
stringKey = in.readString();
|
||||
}
|
||||
|
||||
public static final Creator<BaseProfile> CREATOR = new Creator<BaseProfile>() {
|
||||
@Override
|
||||
public BaseProfile createFromParcel(Parcel in) {
|
||||
return new BaseProfile(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseProfile[] newArray(int size) {
|
||||
return new BaseProfile[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeString(stringKey);
|
||||
}
|
||||
}
|
|
@ -1,7 +1,13 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import static net.osmand.plus.activities.SettingsNavigationActivity.INTENT_SKIP_DIALOG;
|
||||
import static net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.DIALOG_TYPE;
|
||||
import static net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.SELECTED_KEY;
|
||||
import static net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.TYPE_APP_PROFILE;
|
||||
import static net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE;
|
||||
import static net.osmand.plus.profiles.SettingsProfileFragment.IS_NEW_PROFILE;
|
||||
import static net.osmand.plus.profiles.SettingsProfileFragment.IS_USER_PROFILE;
|
||||
import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
|
@ -61,12 +67,14 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
public static final String NAV_CONFIG = "openNavConfigMenu";
|
||||
public static final String SCREEN_CONFIG = "openScreenConfigMenu";
|
||||
public static final String SELECTED_PROFILE = "editedProfile";
|
||||
public static final String SELECTED_ICON = "selectedIcon";
|
||||
|
||||
TempApplicationProfile profile = null;
|
||||
ApplicationMode mode = null;
|
||||
ArrayList<RoutingProfile> routingProfiles;
|
||||
OsmandApplication app;
|
||||
RoutingProfile selectedRoutingProfile = null;
|
||||
|
||||
ApplicationMode mode = null;
|
||||
TempApplicationProfile profile = null;
|
||||
List<RoutingProfileDataObject> routingProfileDataObjects;
|
||||
RoutingProfileDataObject selectedRoutingProfileDataObject = null;
|
||||
|
||||
private boolean isNew = false;
|
||||
private boolean isUserProfile = false;
|
||||
|
@ -105,15 +113,14 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
super.onCreate(savedInstanceState);
|
||||
app = getMyApplication();
|
||||
if (getArguments() != null) {
|
||||
String modeName = getArguments().getString("stringKey", "car");
|
||||
isNew = getArguments().getBoolean("isNew", false);
|
||||
isUserProfile = getArguments().getBoolean("isUserProfile", false);
|
||||
String modeName = getArguments().getString(PROFILE_STRING_KEY, "car");
|
||||
isNew = getArguments().getBoolean(IS_NEW_PROFILE, false);
|
||||
isUserProfile = getArguments().getBoolean(IS_USER_PROFILE, false);
|
||||
mode = ApplicationMode.valueOfStringKey(modeName, ApplicationMode.DEFAULT);
|
||||
profile = new TempApplicationProfile(mode, isNew, isUserProfile);
|
||||
|
||||
}
|
||||
isNightMode = !app.getSettings().isLightContent();
|
||||
routingProfiles = getRoutingProfiles();
|
||||
routingProfileDataObjects = getRoutingProfiles(app);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -161,49 +168,42 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
|
||||
String title = "New Profile";
|
||||
int startIconId = R.drawable.map_world_globe_dark;
|
||||
|
||||
if (isUserProfile && !isNew) {
|
||||
title = profile.getUserProfileTitle();
|
||||
if (isNew) {
|
||||
isDataChanged = true;
|
||||
title = String.format("Custom %s", getResources().getString(profile.parent.getStringResource()));
|
||||
startIconId = profile.parent.getSmallIconDark();
|
||||
profile.iconId = startIconId;
|
||||
} else if (isUserProfile) {
|
||||
title = profile.userProfileTitle;
|
||||
profileNameEt.setText(title);
|
||||
startIconId = profile.iconId;
|
||||
isDataChanged = false;
|
||||
} else if (isNew) {
|
||||
isDataChanged = true;
|
||||
title = String.format("Custom %s", getResources().getString(profile.parent.getStringResource()));
|
||||
startIconId = profile.getParent().getSmallIconDark();
|
||||
profile.setIconId(startIconId);
|
||||
} else if (profile.getKey() != -1) {
|
||||
title = getResources().getString(profile.getKey());
|
||||
profileNameEt.setText(profile.getKey());
|
||||
startIconId = profile.getIconId();
|
||||
} else if (profile.key != -1) {
|
||||
title = getResources().getString(profile.key);
|
||||
profileNameEt.setText(profile.key);
|
||||
startIconId = profile.iconId;
|
||||
clickBlockLayout.setClickable(true);
|
||||
}
|
||||
|
||||
profile.setUserProfileTitle(title);
|
||||
profile.userProfileTitle = title;
|
||||
if (profile.parent != null) {
|
||||
setupBaseProfileView(profile.parent.getStringKey());
|
||||
} else if (profile.getKey() != -1) {
|
||||
baseModeTitle.setText(profile.getKey());
|
||||
} else if (profile.key != -1) {
|
||||
baseModeTitle.setText(profile.key);
|
||||
baseModeIcon.setImageDrawable(
|
||||
app.getUIUtilities().getIcon(profile.getIconId(), R.color.icon_color));
|
||||
app.getUIUtilities().getIcon(profile.iconId, R.color.icon_color));
|
||||
}
|
||||
typeSelectionBtn.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (isUserProfile || isNew) {
|
||||
final ProfileBottomSheetDialogFragment dialog = new ProfileBottomSheetDialogFragment();
|
||||
dialog.setProfileTypeListener(baseTypeListener);
|
||||
Bundle bundle = new Bundle();
|
||||
ArrayList<BaseProfile> lst = SettingsProfileFragment.getBaseProfiles(getMyApplication());
|
||||
for (BaseProfile bp : lst) {
|
||||
LOG.debug("Base");
|
||||
if (bp.getStringKey().equals(profile.getParent().getStringKey())) {
|
||||
bp.setSelected(true);
|
||||
}
|
||||
if (profile.parent != null) {
|
||||
bundle.putString(SELECTED_KEY, profile.parent.getStringKey());
|
||||
}
|
||||
bundle.putParcelableArrayList(TYPE_APP_PROFILE, lst);
|
||||
bundle.putString(DIALOG_TYPE, TYPE_APP_PROFILE);
|
||||
dialog.setArguments(bundle);
|
||||
|
||||
if (getActivity() != null) {
|
||||
getActivity().getSupportFragmentManager().beginTransaction()
|
||||
.add(dialog, "select_base_type").commitAllowingStateLoss();
|
||||
|
@ -211,18 +211,19 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!Algorithms.isEmpty(mode.getRoutingProfile())) {
|
||||
for (RoutingProfile r : routingProfiles) {
|
||||
for (RoutingProfileDataObject r : routingProfileDataObjects) {
|
||||
if (mode.getRoutingProfile().equals(r.getStringKey())) {
|
||||
profile.setRoutingProfile(r);
|
||||
profile.routingProfileDataObject = r;
|
||||
r.setSelected(true);
|
||||
navTypeEt.setText(r.getName());
|
||||
navTypeEt.clearFocus();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (RoutingProfile rp : routingProfiles) {
|
||||
if (profile.getStringKey().equals(rp.getStringKey())) {
|
||||
for (RoutingProfileDataObject rp : routingProfileDataObjects) {
|
||||
if (profile.stringKey.equals(rp.getStringKey())) {
|
||||
switch (rp.getStringKey()) {
|
||||
case "car":
|
||||
navTypeEt.setText(R.string.rendering_value_car_name);
|
||||
|
@ -246,8 +247,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
profileNameEt.clearFocus();
|
||||
|
||||
if (getActivity() != null
|
||||
&& ((EditProfileActivity) getActivity()).getSupportActionBar() != null) {
|
||||
if (getActivity() != null && ((EditProfileActivity) getActivity()).getSupportActionBar() != null) {
|
||||
((EditProfileActivity) getActivity()).getSupportActionBar().setTitle(title);
|
||||
((EditProfileActivity) getActivity()).getSupportActionBar().setElevation(5.0f);
|
||||
}
|
||||
|
@ -265,13 +265,9 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
|
||||
profileNameEt.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (getActivity() instanceof OsmandActionBarActivity) {
|
||||
|
@ -279,7 +275,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
.getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle(s.toString());
|
||||
profile.setUserProfileTitle(s.toString());
|
||||
profile.userProfileTitle = s.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -290,15 +286,16 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
public void onClick(View v) {
|
||||
if (isNew || isUserProfile) {
|
||||
ProfileBottomSheetDialogFragment fragment = new ProfileBottomSheetDialogFragment();
|
||||
fragment.setProfileTypeListener(navTypeListener);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelableArrayList("routing_profiles", routingProfiles);
|
||||
if (profile.routingProfileDataObject != null) {
|
||||
bundle.putString(SELECTED_KEY, profile.routingProfileDataObject.getStringKey());
|
||||
}
|
||||
bundle.putString(DIALOG_TYPE, TYPE_NAV_PROFILE);
|
||||
fragment.setArguments(bundle);
|
||||
if (getActivity() != null) {
|
||||
getActivity().getSupportFragmentManager().beginTransaction()
|
||||
.add(fragment, "select_nav_type").commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
navTypeEt.setCursorVisible(false);
|
||||
navTypeEt.setTextIsSelectable(false);
|
||||
navTypeEt.clearFocus();
|
||||
|
@ -313,7 +310,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
final SelectIconBottomSheetDialogFragment iconSelectDialog = new SelectIconBottomSheetDialogFragment();
|
||||
iconSelectDialog.setIconIdListener(iconIdListener);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("selectedIcon", profile.getIconId());
|
||||
bundle.putInt(SELECTED_ICON, profile.iconId);
|
||||
iconSelectDialog.setArguments(bundle);
|
||||
if (getActivity() != null) {
|
||||
getActivity().getSupportFragmentManager().beginTransaction()
|
||||
|
@ -333,7 +330,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
getSettings().APPLICATION_MODE.set(mode);
|
||||
Intent i = new Intent(getActivity(), MapActivity.class);
|
||||
i.putExtra(OPEN_CONFIG_ON_MAP, MAP_CONFIG);
|
||||
i.putExtra(SELECTED_PROFILE, profile.getStringKey());
|
||||
i.putExtra(SELECTED_PROFILE, profile.stringKey);
|
||||
startActivity(i);
|
||||
}
|
||||
}
|
||||
|
@ -349,7 +346,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
getSettings().APPLICATION_MODE.set(mode);
|
||||
Intent i = new Intent(getActivity(), MapActivity.class);
|
||||
i.putExtra(OPEN_CONFIG_ON_MAP, SCREEN_CONFIG);
|
||||
i.putExtra(SELECTED_PROFILE, profile.getStringKey());
|
||||
i.putExtra(SELECTED_PROFILE, profile.stringKey);
|
||||
startActivity(i);
|
||||
}
|
||||
}
|
||||
|
@ -366,7 +363,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
Intent i = new Intent(getActivity(), SettingsNavigationActivity.class);
|
||||
i.putExtra(INTENT_SKIP_DIALOG, true);
|
||||
i.putExtra(OPEN_CONFIG_ON_MAP, NAV_CONFIG);
|
||||
i.putExtra(SELECTED_PROFILE, profile.getStringKey());
|
||||
i.putExtra(SELECTED_PROFILE, profile.stringKey);
|
||||
startActivity(i);
|
||||
}
|
||||
}
|
||||
|
@ -414,7 +411,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public void onGlobalLayout() {
|
||||
int marginShow = 66;
|
||||
int marginHide = 2;
|
||||
int marginHide = 0;
|
||||
|
||||
float d = getResources().getDisplayMetrics().density;
|
||||
Rect r = new Rect();
|
||||
|
@ -437,16 +434,12 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
|
||||
@Override
|
||||
public void onResume() {
|
||||
LOG.debug("onResume - EditProfileFragment");
|
||||
|
||||
baseTypeListener = new ProfileTypeDialogListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
String key = SettingsProfileFragment.getBaseProfiles(getMyApplication())
|
||||
.get(pos).getStringKey();
|
||||
String key = SettingsProfileFragment.getBaseProfiles(getMyApplication()).get(pos).getStringKey();
|
||||
setupBaseProfileView(key);
|
||||
profile.parent = ApplicationMode
|
||||
.valueOfStringKey(key, ApplicationMode.DEFAULT);
|
||||
profile.parent = ApplicationMode.valueOfStringKey(key, ApplicationMode.DEFAULT);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -461,11 +454,10 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public void selectedIconId(int iconRes) {
|
||||
isDataChanged = true;
|
||||
profile.setIconId(iconRes);
|
||||
profile.iconId = iconRes;
|
||||
profileIcon.setImageDrawable(app.getUIUtilities().getIcon(iconRes,
|
||||
isNightMode ? R.color.active_buttons_and_links_dark
|
||||
: R.color.active_buttons_and_links_light));
|
||||
profile.setIconId(iconRes);
|
||||
}
|
||||
};
|
||||
super.onResume();
|
||||
|
@ -477,15 +469,14 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public void selectedIconId(int iconRes) {
|
||||
isDataChanged = true;
|
||||
profile.setIconId(iconRes);
|
||||
profile.iconId = iconRes;
|
||||
profileIcon.setImageDrawable(app.getUIUtilities().getIcon(iconRes,
|
||||
isNightMode ? R.color.active_buttons_and_links_dark
|
||||
: R.color.active_buttons_and_links_light));
|
||||
profile.setIconId(iconRes);
|
||||
profile.iconId = iconRes;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return iconIdListener;
|
||||
}
|
||||
|
||||
|
@ -497,8 +488,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
String key = SettingsProfileFragment.getBaseProfiles(getMyApplication())
|
||||
.get(pos).getStringKey();
|
||||
setupBaseProfileView(key);
|
||||
profile.parent = ApplicationMode
|
||||
.valueOfStringKey(key, ApplicationMode.DEFAULT);
|
||||
profile.parent = ApplicationMode.valueOfStringKey(key, ApplicationMode.DEFAULT);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -534,16 +524,16 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
|
||||
void updateRoutingProfile(int pos) {
|
||||
isDataChanged = true;
|
||||
for (int i = 0; i < routingProfiles.size(); i++) {
|
||||
for (int i = 0; i < routingProfileDataObjects.size(); i++) {
|
||||
if (i == pos) {
|
||||
routingProfiles.get(i).setSelected(true);
|
||||
routingProfileDataObjects.get(i).setSelected(true);
|
||||
} else {
|
||||
routingProfiles.get(i).setSelected(false);
|
||||
routingProfileDataObjects.get(i).setSelected(false);
|
||||
}
|
||||
}
|
||||
selectedRoutingProfile = routingProfiles.get(pos);
|
||||
navTypeEt.setText(selectedRoutingProfile.getName());
|
||||
profile.setRoutingProfile(selectedRoutingProfile);
|
||||
selectedRoutingProfileDataObject = routingProfileDataObjects.get(pos);
|
||||
navTypeEt.setText(selectedRoutingProfileDataObject.getName());
|
||||
profile.routingProfileDataObject = selectedRoutingProfileDataObject;
|
||||
}
|
||||
|
||||
void activateMode(ApplicationMode mode) {
|
||||
|
@ -580,7 +570,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
|
||||
private boolean saveNewProfile() {
|
||||
if (profile.getRoutingProfile() == null) {
|
||||
if (profile.routingProfileDataObject == null) {
|
||||
showSaveWarningDialog(
|
||||
"Select Routing Type",
|
||||
"You need to select Routing Type to create New Application Profile",
|
||||
|
@ -588,8 +578,8 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (profile.getUserProfileTitle().isEmpty()
|
||||
|| profile.getUserProfileTitle().replace(" ", "").length() < 1) {
|
||||
if (profile.userProfileTitle.isEmpty()
|
||||
|| profile.userProfileTitle.replace(" ", "").length() < 1) {
|
||||
showSaveWarningDialog(
|
||||
"Enter Profile Name",
|
||||
"Profile name shouldn't be empty!",
|
||||
|
@ -600,8 +590,9 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
|
||||
for (ApplicationMode m : ApplicationMode.allPossibleValues()) {
|
||||
if (m.getUserProfileName() != null && getActivity() != null) {
|
||||
if (m.getUserProfileName().equals(profile.getUserProfileTitle())) {
|
||||
if (isNew || !Algorithms.isEmpty(mode.getUserProfileName()) && !mode.getUserProfileName().equals(profile.getUserProfileTitle())) {
|
||||
if (m.getUserProfileName().equals(profile.userProfileTitle)) {
|
||||
if (isNew || !Algorithms.isEmpty(mode.getUserProfileName())
|
||||
&& !mode.getUserProfileName().equals(profile.userProfileTitle)) {
|
||||
AlertDialog.Builder bld = new AlertDialog.Builder(getActivity());
|
||||
bld.setTitle("Duplicate Name");
|
||||
bld.setMessage("There is already profile with such name");
|
||||
|
@ -611,7 +602,6 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
profileNameEt.requestFocus();
|
||||
|
||||
}
|
||||
});
|
||||
return false;
|
||||
|
@ -625,9 +615,9 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
|
||||
String customStringKey = profile.stringKey;
|
||||
if (isNew && profile.getParent() != null) {
|
||||
if (isNew && profile.parent != null) {
|
||||
customStringKey =
|
||||
profile.getParent().getStringKey() + "_" + profile.userProfileTitle.hashCode();
|
||||
profile.parent.getStringKey() + "_" + profile.userProfileTitle.hashCode();
|
||||
}
|
||||
|
||||
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode
|
||||
|
@ -635,8 +625,8 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
.parent(profile.parent)
|
||||
.icon(profile.iconId, profile.iconId);
|
||||
|
||||
if (profile.getRoutingProfile() != null) {
|
||||
builder.setRoutingProfile(profile.getRoutingProfile().getStringKey());
|
||||
if (profile.routingProfileDataObject != null) {
|
||||
builder.setRoutingProfile(profile.routingProfileDataObject.getStringKey());
|
||||
}
|
||||
|
||||
ApplicationMode mode = builder.customReg();
|
||||
|
@ -660,8 +650,8 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
private void needSaveDialog() {
|
||||
if (getActivity() != null) {
|
||||
AlertDialog.Builder bld = new AlertDialog.Builder(getActivity());
|
||||
bld.setTitle("Save Changes");
|
||||
bld.setMessage("You need to save changes to Profile before proceed");
|
||||
bld.setTitle(R.string.profile_alert_need_save_title);
|
||||
bld.setMessage(R.string.profile_alert_need_save_msg);
|
||||
bld.setNegativeButton(R.string.shared_string_ok, null);
|
||||
bld.show();
|
||||
}
|
||||
|
@ -679,17 +669,15 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
if (getActivity() != null) {
|
||||
if (isUserProfile) {
|
||||
AlertDialog.Builder bld = new AlertDialog.Builder(getActivity());
|
||||
bld.setTitle("Delete Profile");
|
||||
bld.setTitle(R.string.profile_alert_delete_title);
|
||||
bld.setMessage(String
|
||||
.format("Are you sure you want to delete %s profile",
|
||||
profile.userProfileTitle));
|
||||
.format(getString(R.string.profile_alert_delete_msg), profile.userProfileTitle));
|
||||
bld.setPositiveButton(R.string.shared_string_delete,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ApplicationMode
|
||||
.deleteCustomMode(profile.getUserProfileTitle(),
|
||||
getMyApplication());
|
||||
.deleteCustomMode(profile.userProfileTitle, getMyApplication());
|
||||
if (getActivity() != null) {
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
|
@ -705,62 +693,78 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private ArrayList<RoutingProfile> getRoutingProfiles() {
|
||||
ArrayList<RoutingProfile> profilesObjects = new ArrayList<>();
|
||||
Map<String, GeneralRouter> inputProfiles = getMyApplication().getDefaultRoutingConfig()
|
||||
.getAllRoutes();
|
||||
static List<RoutingProfileDataObject> getRoutingProfiles(OsmandApplication context) {
|
||||
List<RoutingProfileDataObject> profilesObjects = new ArrayList<>();
|
||||
profilesObjects.add(new RoutingProfileDataObject(
|
||||
RoutingProfilesResources.STRAIGHT_LINE.toString(),
|
||||
context.getString(RoutingProfilesResources.STRAIGHT_LINE.getStringRes()),
|
||||
context.getString(R.string.special_routing_type),
|
||||
RoutingProfilesResources.STRAIGHT_LINE.getIconRes(),
|
||||
false, null));
|
||||
|
||||
profilesObjects.add(new RoutingProfileDataObject(
|
||||
RoutingProfilesResources.BROUTER.toString(),
|
||||
context.getString(RoutingProfilesResources.BROUTER.getStringRes()),
|
||||
context.getString(R.string.online_routing_type),
|
||||
RoutingProfilesResources.BROUTER.getIconRes(),
|
||||
false, null));
|
||||
|
||||
Map<String, GeneralRouter> inputProfiles = context.getRoutingConfig().getAllRoutes();
|
||||
for (Entry<String, GeneralRouter> e : inputProfiles.entrySet()) {
|
||||
int iconRes = R.drawable.ic_action_world_globe;
|
||||
String name = e.getValue().getProfileName();
|
||||
String description = "Custom profile";
|
||||
|
||||
String description;
|
||||
if (e.getValue().getFilename() == null) {
|
||||
switch (e.getValue().getProfileName()) {
|
||||
case "car":
|
||||
iconRes = R.drawable.ic_action_car_dark;
|
||||
name = getString(R.string.rendering_value_car_name);
|
||||
break;
|
||||
case "pedestrian":
|
||||
iconRes = R.drawable.map_action_pedestrian_dark;
|
||||
name = getString(R.string.rendering_value_pedestrian_name);
|
||||
break;
|
||||
case "bicycle":
|
||||
iconRes = R.drawable.map_action_bicycle_dark;
|
||||
name = getString(R.string.rendering_value_bicycle_name);
|
||||
break;
|
||||
case "public_transport":
|
||||
iconRes = R.drawable.map_action_bus_dark;
|
||||
name = getString(R.string.app_mode_public_transport);
|
||||
break;
|
||||
case "boat":
|
||||
iconRes = R.drawable.map_action_sail_boat_dark;
|
||||
name = getString(R.string.app_mode_boat);
|
||||
break;
|
||||
case "geocoding":
|
||||
iconRes = R.drawable.ic_action_world_globe;
|
||||
name = "Geocoding";
|
||||
break;
|
||||
}
|
||||
iconRes = RoutingProfilesResources.valueOf(name.toUpperCase()).getIconRes();
|
||||
name = context.getString(RoutingProfilesResources.valueOf(name.toUpperCase()).getStringRes());
|
||||
description = context.getString(R.string.osmand_default_routing);
|
||||
} else {
|
||||
description = context.getString(R.string.custom_routing);
|
||||
}
|
||||
|
||||
profilesObjects.add(new RoutingProfile(e.getKey(), name, description, iconRes, false,
|
||||
profilesObjects.add(new RoutingProfileDataObject(e.getKey(), name, description, iconRes, false,
|
||||
e.getValue().getFilename()));
|
||||
}
|
||||
return profilesObjects;
|
||||
}
|
||||
|
||||
private class TempApplicationProfile {
|
||||
public enum RoutingProfilesResources {
|
||||
STRAIGHT_LINE(R.string.routing_profile_straightline, R.drawable.ic_action_split_interval),
|
||||
BROUTER(R.string.routing_profile_broutrer, R.drawable.ic_action_split_interval),
|
||||
CAR (R.string.rendering_value_car_name, R.drawable.ic_action_car_dark),
|
||||
PEDESTRIAN (R.string.rendering_value_pedestrian_name, R.drawable.map_action_pedestrian_dark),
|
||||
BICYCLE (R.string.rendering_value_bicycle_name, R.drawable.map_action_bicycle_dark),
|
||||
PUBLIC_TRANSPORT (R.string.app_mode_public_transport, R.drawable.map_action_bus_dark),
|
||||
BOAT (R.string.app_mode_boat, R.drawable.map_action_sail_boat_dark),
|
||||
GEOCODING (R.string.routing_profile_geocoding, R.drawable.ic_action_world_globe);
|
||||
|
||||
int stringRes;
|
||||
int iconRes;
|
||||
|
||||
RoutingProfilesResources(int stringRes, int iconRes) {
|
||||
this.stringRes = stringRes;
|
||||
this.iconRes = iconRes;
|
||||
}
|
||||
|
||||
public int getStringRes() {
|
||||
return stringRes;
|
||||
}
|
||||
|
||||
public int getIconRes() {
|
||||
return iconRes;
|
||||
}
|
||||
}
|
||||
|
||||
private class TempApplicationProfile {
|
||||
int key = -1;
|
||||
String stringKey;
|
||||
String userProfileTitle = "";
|
||||
ApplicationMode parent = null;
|
||||
int iconId = R.drawable.map_world_globe_dark;
|
||||
RoutingProfile routingProfile = null;
|
||||
RoutingProfileDataObject routingProfileDataObject = null;
|
||||
|
||||
TempApplicationProfile(ApplicationMode mode, boolean isNew, boolean isUserProfile) {
|
||||
if (isNew) {
|
||||
stringKey = "new_" + mode.getStringKey();
|
||||
stringKey = mode.getStringKey() + System.currentTimeMillis();
|
||||
parent = mode;
|
||||
} else if (isUserProfile) {
|
||||
stringKey = mode.getStringKey();
|
||||
|
@ -773,46 +777,5 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
iconId = mode.getSmallIconDark();
|
||||
}
|
||||
}
|
||||
|
||||
public RoutingProfile getRoutingProfile() {
|
||||
return routingProfile;
|
||||
}
|
||||
|
||||
public ApplicationMode getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public int getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public int getIconId() {
|
||||
return iconId;
|
||||
}
|
||||
|
||||
public String getStringKey() {
|
||||
return stringKey;
|
||||
}
|
||||
|
||||
public String getUserProfileTitle() {
|
||||
return userProfileTitle;
|
||||
}
|
||||
|
||||
public void setStringKey(String stringKey) {
|
||||
this.stringKey = stringKey;
|
||||
}
|
||||
|
||||
public void setUserProfileTitle(String userProfileTitle) {
|
||||
this.userProfileTitle = userProfileTitle;
|
||||
}
|
||||
|
||||
public void setIconId(int iconId) {
|
||||
this.iconId = iconId;
|
||||
}
|
||||
|
||||
public void setRoutingProfile(RoutingProfile routingProfile) {
|
||||
this.routingProfile = routingProfile;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,12 +13,12 @@ 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;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||
import net.osmand.util.Algorithms;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment {
|
||||
|
@ -33,13 +33,18 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
private TextView titleTV;
|
||||
private TextView fragmentDescriptionTV;
|
||||
|
||||
private String selectedKey = null;
|
||||
|
||||
public final static String DIALOG_TYPE = "dialog_type";
|
||||
public final static String TYPE_APP_PROFILE = "base_profiles";
|
||||
public final static String TYPE_NAV_PROFILE = "routing_profiles";
|
||||
public final static String SELECTED_KEY = "selected_base";
|
||||
private String type;
|
||||
|
||||
public void setProfileTypeListener(ProfileTypeDialogListener listener) {
|
||||
this.listener = listener;
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
profiles = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -49,16 +54,19 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
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;
|
||||
if (args.get(DIALOG_TYPE) != null) {
|
||||
type = args.getString(DIALOG_TYPE);
|
||||
} else {
|
||||
dismiss();
|
||||
}
|
||||
|
||||
selectedKey = args.getString(SELECTED_KEY, "");
|
||||
|
||||
if (type.equals(TYPE_NAV_PROFILE) && getMyApplication() != null) {
|
||||
profiles.addAll(EditProfileFragment.getRoutingProfiles(getMyApplication()));
|
||||
} else if (type.equals(TYPE_APP_PROFILE)) {
|
||||
profiles.addAll(SettingsProfileFragment.getBaseProfiles(getActivity()));
|
||||
}
|
||||
}
|
||||
|
||||
final int themeRes = getMyApplication().getSettings().isLightContent()
|
||||
|
@ -71,12 +79,11 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
fragmentDescriptionTV = view.findViewById(R.id.dialog_description_text);
|
||||
|
||||
if (type.equals(TYPE_APP_PROFILE)) {
|
||||
titleTV.setText("Select base profile");
|
||||
titleTV.setText(R.string.select_base_profile_dialog_title);
|
||||
fragmentDescriptionTV.setVisibility(View.VISIBLE);
|
||||
fragmentDescriptionTV.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.");
|
||||
fragmentDescriptionTV.setText(R.string.select_base_profile_dialog_message);
|
||||
} else if (type.equals(TYPE_NAV_PROFILE)) {
|
||||
titleTV.setText("Select navigation type");
|
||||
titleTV.setText(R.string.select_nav_profile_dialog_title);
|
||||
}
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -88,10 +95,9 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
if (listener == null) {
|
||||
resetListener();
|
||||
getListener();
|
||||
}
|
||||
listener.onSelectedType(pos);
|
||||
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
|
@ -111,12 +117,6 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
LOG.debug("onResume - ProfileBottomSheetDialogFragment");
|
||||
}
|
||||
|
||||
private static boolean isNightMode(OsmandApplication ctx) {
|
||||
return !ctx.getSettings().isLightContent();
|
||||
}
|
||||
|
@ -147,13 +147,7 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
public void onBindViewHolder(@NonNull final ItemViewHolder holder, final int position) {
|
||||
final ProfileDataObject item = items.get(position);
|
||||
holder.title.setText(item.getName());
|
||||
if (item.isSelected()) {
|
||||
holder.icon.setImageDrawable(getIcon(item.getIconRes(), isNightMode
|
||||
? R.color.active_buttons_and_links_dark
|
||||
: R.color.active_buttons_and_links_light));
|
||||
} else {
|
||||
holder.icon.setImageDrawable(getIcon(item.getIconRes(), R.color.icon_color));
|
||||
}
|
||||
|
||||
|
||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -162,7 +156,7 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
|
||||
holder.radioButton.setChecked(true);
|
||||
|
||||
if (item instanceof RoutingProfile) {
|
||||
if (item instanceof RoutingProfileDataObject) {
|
||||
items.get(position).setSelected(true);
|
||||
items.get(previousSelection).setSelected(false);
|
||||
}
|
||||
|
@ -171,25 +165,28 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
}
|
||||
});
|
||||
|
||||
if(item instanceof RoutingProfile) {
|
||||
if (((RoutingProfile) item).getFileName() != null) {
|
||||
if(item instanceof RoutingProfileDataObject) {
|
||||
if (((RoutingProfileDataObject) item).getFileName() != null) {
|
||||
holder.descr
|
||||
.setText(String.format("From %s", ((RoutingProfile) item).getFileName()));
|
||||
.setText(String.format("From %s", ((RoutingProfileDataObject) item).getFileName()));
|
||||
} else {
|
||||
holder.descr
|
||||
.setText(getResources().getString(R.string.osmand_default_routing));
|
||||
.setText(item.getDescription());
|
||||
}
|
||||
} else {
|
||||
holder.descr.setText(item.getDescription());
|
||||
}
|
||||
|
||||
if (item.isSelected()) {
|
||||
if (selectedKey != null && selectedKey.equals(item.getStringKey())) {
|
||||
holder.radioButton.setChecked(true);
|
||||
previousSelection = position;
|
||||
holder.icon.setImageDrawable(getIcon(item.getIconRes(), isNightMode
|
||||
? R.color.active_buttons_and_links_dark
|
||||
: R.color.active_buttons_and_links_light));
|
||||
} else {
|
||||
holder.radioButton.setChecked(false);
|
||||
holder.icon.setImageDrawable(getIcon(item.getIconRes(), R.color.icon_color));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -198,7 +195,7 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
}
|
||||
}
|
||||
|
||||
void resetListener() {
|
||||
void getListener() {
|
||||
if (getActivity() != null && getActivity() instanceof EditProfileActivity) {
|
||||
EditProfileFragment f = (EditProfileFragment) getActivity().getSupportFragmentManager()
|
||||
.findFragmentByTag(EditProfileActivity.EDIT_PROFILE_FRAGMENT_TAG);
|
||||
|
@ -231,6 +228,4 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
|||
interface ProfileTypeDialogListener {
|
||||
void onSelectedType(int pos);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,13 +8,15 @@ public class ProfileDataObject implements Parcelable {
|
|||
private String name;
|
||||
private String description;
|
||||
private int iconRes;
|
||||
private String stringKey;
|
||||
private boolean isSelected;
|
||||
|
||||
public ProfileDataObject(String name, String description, int iconRes, boolean isSelected) {
|
||||
public ProfileDataObject(String name, String description, String stringKey, int iconRes, boolean isSelected) {
|
||||
this.name = name;
|
||||
this.iconRes = iconRes;
|
||||
this.description = description;
|
||||
this.isSelected = isSelected;
|
||||
this.stringKey = stringKey;
|
||||
}
|
||||
|
||||
protected ProfileDataObject(Parcel in) {
|
||||
|
@ -56,6 +58,10 @@ public class ProfileDataObject implements Parcelable {
|
|||
isSelected = selected;
|
||||
}
|
||||
|
||||
public String getStringKey() {
|
||||
return stringKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
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, String fileName) {
|
||||
super(name, descr, iconRes, isSelected);
|
||||
this.stringKey = stringKey;
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getStringKey() {
|
||||
return stringKey;
|
||||
}
|
||||
|
||||
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>() {
|
||||
@Override
|
||||
public RoutingProfile createFromParcel(Parcel in) {
|
||||
return new RoutingProfile(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoutingProfile[] newArray(int size) {
|
||||
return new RoutingProfile[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeString(stringKey);
|
||||
dest.writeString(fileName);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import android.os.Parcel;
|
||||
|
||||
|
||||
public class RoutingProfileDataObject extends ProfileDataObject {
|
||||
|
||||
private String fileName;
|
||||
|
||||
public RoutingProfileDataObject(String stringKey, String name, String descr, int iconRes, boolean isSelected, String fileName) {
|
||||
super(name, descr, stringKey, iconRes, isSelected);
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
}
|
|
@ -45,7 +45,7 @@ public class SelectIconBottomSheetDialogFragment extends BottomSheetDialogFragme
|
|||
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
int selectedIcon = args.getInt("selectedIcon", -1);
|
||||
int selectedIcon = args.getInt(EditProfileFragment.SELECTED_ICON, -1);
|
||||
if(selectedIcon != -1) {
|
||||
for (IconResWithDescr icon : icons) {
|
||||
if (icon.resId == selectedIcon) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import static net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.DIALOG_TYPE;
|
||||
import static net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.TYPE_APP_PROFILE;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -24,12 +25,18 @@ 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 net.osmand.util.Algorithms;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
public class SettingsProfileFragment extends BaseOsmAndFragment {
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(SettingsProfileFragment.class);
|
||||
|
||||
public static final String PROFILE_STRING_KEY = "string_key";
|
||||
public static final String IS_NEW_PROFILE = "new_profile";
|
||||
public static final String IS_USER_PROFILE = "user_profile";
|
||||
|
||||
|
||||
private ProfileMenuAdapter adapter;
|
||||
private RecyclerView recyclerView;
|
||||
private LinearLayout addNewProfileBtn;
|
||||
|
@ -39,8 +46,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
|
||||
private List<ApplicationMode> allAppModes;
|
||||
private Set<ApplicationMode> availableAppModes;
|
||||
private ArrayList<BaseProfile> baseProfiles;
|
||||
|
||||
private List<ProfileDataObject> baseProfiles;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -80,6 +86,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
for (ApplicationMode sam : availableAppModes) {
|
||||
vls.append(sam.getStringKey()).append(",");
|
||||
}
|
||||
|
||||
if (getSettings() != null) {
|
||||
getSettings().AVAILABLE_APP_MODES.set(vls.toString());
|
||||
}
|
||||
|
@ -88,10 +95,9 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public void editProfile(ApplicationMode item) {
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
intent.putExtra("stringKey", item.getStringKey());
|
||||
intent.putExtra("isNew", false);
|
||||
if (item.getUserProfileName() != null && !item.getUserProfileName().isEmpty()) {
|
||||
intent.putExtra("isUserProfile", true);
|
||||
intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
|
||||
if (!Algorithms.isEmpty(item.getUserProfileName())) {
|
||||
intent.putExtra(IS_USER_PROFILE, true);
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
|
@ -100,11 +106,10 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
typeListener = new ProfileTypeDialogListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
LOG.debug("Base profile: " + baseProfiles.get(pos).getName());
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
intent.putExtra("isNew", true);
|
||||
intent.putExtra("isUserProfile", true);
|
||||
intent.putExtra("stringKey", baseProfiles.get(pos).getStringKey());
|
||||
intent.putExtra(IS_NEW_PROFILE, true);
|
||||
intent.putExtra(IS_USER_PROFILE, true);
|
||||
intent.putExtra(PROFILE_STRING_KEY, baseProfiles.get(pos).getStringKey());
|
||||
startActivity(intent);
|
||||
}
|
||||
};
|
||||
|
@ -119,9 +124,8 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
final ProfileBottomSheetDialogFragment dialog = new ProfileBottomSheetDialogFragment();
|
||||
dialog.setProfileTypeListener(typeListener);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelableArrayList(TYPE_APP_PROFILE, baseProfiles);
|
||||
bundle.putString(DIALOG_TYPE, TYPE_APP_PROFILE);
|
||||
dialog.setArguments(bundle);
|
||||
if (getActivity() != null) {
|
||||
getActivity().getSupportFragmentManager().beginTransaction()
|
||||
|
@ -133,7 +137,6 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
adapter = new ProfileMenuAdapter(allAppModes, availableAppModes, getMyApplication(), listener);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -144,18 +147,16 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
typeListener = new ProfileTypeDialogListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
LOG.debug("Base profile: " + baseProfiles.get(pos).getName());
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
intent.putExtra("isNew", true);
|
||||
intent.putExtra("isUserProfile", true);
|
||||
intent.putExtra("stringKey", baseProfiles.get(pos).getStringKey());
|
||||
intent.putExtra(IS_NEW_PROFILE, true);
|
||||
intent.putExtra(IS_USER_PROFILE, true);
|
||||
intent.putExtra(PROFILE_STRING_KEY, baseProfiles.get(pos).getStringKey());
|
||||
startActivity(intent);
|
||||
}
|
||||
};
|
||||
|
||||
allAppModes = ApplicationMode.allPossibleValues();
|
||||
allAppModes.remove(ApplicationMode.DEFAULT);
|
||||
|
||||
adapter.updateItemsList(allAppModes, new LinkedHashSet<>(ApplicationMode.values(getMyApplication())));
|
||||
}
|
||||
|
||||
|
@ -164,11 +165,10 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
typeListener = new ProfileTypeDialogListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
LOG.debug("Base profile: " + baseProfiles.get(pos).getName());
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
intent.putExtra("isNew", true);
|
||||
intent.putExtra("isUserProfile", true);
|
||||
intent.putExtra("stringKey", baseProfiles.get(pos).getStringKey());
|
||||
intent.putExtra(IS_NEW_PROFILE, true);
|
||||
intent.putExtra(IS_USER_PROFILE, true);
|
||||
intent.putExtra(PROFILE_STRING_KEY, baseProfiles.get(pos).getStringKey());
|
||||
startActivity(intent);
|
||||
}
|
||||
};
|
||||
|
@ -176,36 +176,37 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
return typeListener;
|
||||
}
|
||||
|
||||
static ArrayList<BaseProfile> getBaseProfiles(Context ctx) {
|
||||
ArrayList<BaseProfile> profiles = new ArrayList<>();
|
||||
static List<ProfileDataObject> getBaseProfiles(Context ctx) {
|
||||
List<ProfileDataObject> profiles = new ArrayList<>();
|
||||
for (ApplicationMode mode : ApplicationMode.getDefaultValues()) {
|
||||
if (mode != ApplicationMode.DEFAULT) {
|
||||
String descr = "";
|
||||
switch (mode.getStringKey()) {
|
||||
case "car":
|
||||
descr = "Car, Truck, Motorcycle";
|
||||
break;
|
||||
case "bicycle":
|
||||
descr = "MBT, Moped, Skiing, Horse";
|
||||
break;
|
||||
case "pedestrian":
|
||||
descr = "Walking, Hiking, Running";
|
||||
break;
|
||||
case "public_transport":
|
||||
descr = "All PT types";
|
||||
break;
|
||||
case "boat":
|
||||
descr = "Ship, Rowing, Sailing";
|
||||
break;
|
||||
case "aircraft":
|
||||
descr = "Airplane, Gliding";
|
||||
break;
|
||||
}
|
||||
profiles.add(new BaseProfile(mode.getStringKey(), mode.toHumanString(ctx), descr,
|
||||
mode.getSmallIconDark(), false));
|
||||
profiles.add(new ProfileDataObject( mode.toHumanString(ctx),
|
||||
ctx.getString(BaseProfilesDescr.valueOf(mode.getStringKey().toUpperCase()).getDescrRes()),
|
||||
mode.getStringKey(), mode.getSmallIconDark(), false));
|
||||
}
|
||||
}
|
||||
return profiles;
|
||||
}
|
||||
|
||||
public enum BaseProfilesDescr {
|
||||
CAR(R.string.base_profile_descr_car),
|
||||
BICYCLE(R.string.base_profile_descr_bicycle),
|
||||
PEDESTRIAN(R.string.base_profile_descr_pedestrian),
|
||||
PUBLIC_TRANSPORT(R.string.base_profile_descr_public_transport),
|
||||
BOAT(R.string.base_profile_descr_boat),
|
||||
AIRCRAFT(R.string.base_profile_descr_aircraft);
|
||||
|
||||
private int descrRes;
|
||||
|
||||
BaseProfilesDescr(int descrRes) {
|
||||
this.descrRes = descrRes;
|
||||
}
|
||||
|
||||
public int getDescrRes() {
|
||||
return descrRes;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -382,7 +382,7 @@ public class RoutingOptionsHelper {
|
|||
|
||||
public LocalRoutingParameter getRoutingParameterInnerById(ApplicationMode am, String parameterId) {
|
||||
RouteProvider.GPXRouteParamsBuilder rparams = app.getRoutingHelper().getCurrentGPXRoute();
|
||||
GeneralRouter rm = getRouter(app.getDefaultRoutingConfig(), am);
|
||||
GeneralRouter rm = getRouter(app.getRoutingConfig(), am);
|
||||
if (rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute()) && !rparams.getFile().hasRtePt()) {
|
||||
return null;
|
||||
}
|
||||
|
@ -407,7 +407,6 @@ public class RoutingOptionsHelper {
|
|||
}
|
||||
return rpg;
|
||||
}
|
||||
|
||||
return rp;
|
||||
}
|
||||
|
||||
|
@ -457,7 +456,7 @@ public class RoutingOptionsHelper {
|
|||
public List<LocalRoutingParameter> getRoutingParametersInner(ApplicationMode am) {
|
||||
RouteProvider.GPXRouteParamsBuilder rparams = app.getRoutingHelper().getCurrentGPXRoute();
|
||||
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>(getGpxAndOsmandRouterParameters(am));
|
||||
GeneralRouter rm = SettingsNavigationActivity.getRouter(app.getDefaultRoutingConfig(), am);
|
||||
GeneralRouter rm = SettingsNavigationActivity.getRouter(app.getRoutingConfig(), am);
|
||||
if (rm == null || (rparams != null && !rparams.isCalculateOsmAndRoute()) && !rparams.getFile().hasRtePt()) {
|
||||
return list;
|
||||
}
|
||||
|
@ -547,7 +546,7 @@ public class RoutingOptionsHelper {
|
|||
|
||||
public List<GeneralRouter.RoutingParameter> getAvoidRoutingPrefsForAppMode(ApplicationMode applicationMode) {
|
||||
List<GeneralRouter.RoutingParameter> avoidParameters = new ArrayList<GeneralRouter.RoutingParameter>();
|
||||
GeneralRouter router = getRouter(app.getDefaultRoutingConfig(), applicationMode);
|
||||
GeneralRouter router = getRouter(app.getRoutingConfig(), applicationMode);
|
||||
if (router != null) {
|
||||
for (Map.Entry<String, GeneralRouter.RoutingParameter> e : router.getParameters().entrySet()) {
|
||||
String param = e.getKey();
|
||||
|
@ -561,7 +560,7 @@ public class RoutingOptionsHelper {
|
|||
}
|
||||
|
||||
public GeneralRouter.RoutingParameter getRoutingPrefsForAppModeById(ApplicationMode applicationMode, String parameterId) {
|
||||
GeneralRouter router = getRouter(app.getDefaultRoutingConfig(), applicationMode);
|
||||
GeneralRouter router = getRouter(app.getRoutingConfig(), applicationMode);
|
||||
GeneralRouter.RoutingParameter parameter = null;
|
||||
|
||||
if (router != null) {
|
||||
|
@ -972,10 +971,6 @@ public class RoutingOptionsHelper {
|
|||
PUBLIC_TRANSPORT(MuteSoundRoutingParameter.KEY, AvoidPTTypesRoutingParameter.KEY),
|
||||
BOAT(MuteSoundRoutingParameter.KEY),
|
||||
AIRCRAFT(MuteSoundRoutingParameter.KEY);
|
||||
// HIKING(MuteSoundRoutingParameter.KEY),
|
||||
// MOTORCYCLE(MuteSoundRoutingParameter.KEY),
|
||||
// TRUCK(MuteSoundRoutingParameter.KEY),
|
||||
// TRAIN(MuteSoundRoutingParameter.KEY);
|
||||
|
||||
List<String> routingParameters;
|
||||
|
||||
|
|
|
@ -595,7 +595,7 @@ public class RouteProvider {
|
|||
OsmandSettings settings = params.ctx.getSettings();
|
||||
router.setUseFastRecalculation(settings.USE_FAST_RECALCULATION.get());
|
||||
|
||||
RoutingConfiguration.Builder config = params.ctx.getDefaultRoutingConfig();
|
||||
RoutingConfiguration.Builder config = params.ctx.getRoutingConfig();
|
||||
GeneralRouter generalRouter = SettingsNavigationActivity.getRouter(config, params.mode);
|
||||
if(generalRouter == null) {
|
||||
return applicationModeNotSupported(params);
|
||||
|
|
|
@ -443,7 +443,7 @@ public class TransportRoutingHelper {
|
|||
}
|
||||
|
||||
private List<TransportRouteResult> calculateRouteImpl(TransportRouteCalculationParams params) throws IOException, InterruptedException {
|
||||
RoutingConfiguration.Builder config = params.ctx.getDefaultRoutingConfig();
|
||||
RoutingConfiguration.Builder config = params.ctx.getRoutingConfig();
|
||||
BinaryMapIndexReader[] files = params.ctx.getResourceManager().getTransportRoutingMapFiles();
|
||||
params.params.clear();
|
||||
OsmandSettings settings = params.ctx.getSettings();
|
||||
|
|
Loading…
Reference in a new issue