add save and read profiles from settings, deleting profiles - w.i.p.
This commit is contained in:
parent
3c81d0a147
commit
7b60c15a49
8 changed files with 155 additions and 80 deletions
|
@ -190,7 +190,9 @@ public class AppInitializer implements IProgress {
|
||||||
}
|
}
|
||||||
app.getSettings().SHOW_TRAVEL_UPDATE_CARD.set(true);
|
app.getSettings().SHOW_TRAVEL_UPDATE_CARD.set(true);
|
||||||
app.getSettings().SHOW_TRAVEL_NEEDED_MAPS_CARD.set(true);
|
app.getSettings().SHOW_TRAVEL_NEEDED_MAPS_CARD.set(true);
|
||||||
|
ApplicationMode.initCustomProfiles(app.getSettings());
|
||||||
initSettings = true;
|
initSettings = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumberOfStarts() {
|
public int getNumberOfStarts() {
|
||||||
|
|
|
@ -2,6 +2,13 @@ package net.osmand.plus;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.StateChangedListener;
|
import net.osmand.StateChangedListener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -11,9 +18,14 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
import net.sf.junidecode.App;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
|
||||||
public class ApplicationMode {
|
public class ApplicationMode {
|
||||||
|
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(ApplicationMode.class);
|
||||||
private static Map<String, Set<ApplicationMode>> widgetsVisibilityMap = new LinkedHashMap<>();
|
private static Map<String, Set<ApplicationMode>> widgetsVisibilityMap = new LinkedHashMap<>();
|
||||||
private static Map<String, Set<ApplicationMode>> widgetsAvailabilityMap = new LinkedHashMap<>();
|
private static Map<String, Set<ApplicationMode>> widgetsAvailabilityMap = new LinkedHashMap<>();
|
||||||
private static List<ApplicationMode> defaultValues = new ArrayList<>();
|
private static List<ApplicationMode> defaultValues = new ArrayList<>();
|
||||||
|
@ -42,6 +54,8 @@ public class ApplicationMode {
|
||||||
|
|
||||||
public static final ApplicationMode AIRCRAFT = create(R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation().
|
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();
|
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).
|
// 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();
|
// icon(R.drawable.map_action_trekking_dark, R.drawable.ic_action_trekking_dark).reg();
|
||||||
|
@ -134,6 +148,7 @@ public class ApplicationMode {
|
||||||
* 1 - car, 2 - bicicle, 3 - nautical, any other - default
|
* 1 - car, 2 - bicicle, 3 - nautical, any other - default
|
||||||
*/
|
*/
|
||||||
public ApplicationModeBuilder setLocationAndBearingIcons(int type) {
|
public ApplicationModeBuilder setLocationAndBearingIcons(int type) {
|
||||||
|
applicationMode.mapIconsSetId = type;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 1:
|
case 1:
|
||||||
return this.carLocation();
|
return this.carLocation();
|
||||||
|
@ -209,7 +224,7 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationModeBuilder userProfileTitle(String userProfileTitle) {
|
public ApplicationModeBuilder userProfileTitle(String userProfileTitle) {
|
||||||
applicationMode.userProfileTitle = userProfileTitle;
|
applicationMode.userProfileName = userProfileTitle;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -401,11 +416,20 @@ public class ApplicationMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toHumanString(Context ctx) {
|
public String toHumanString(Context ctx) {
|
||||||
|
if (Algorithms.isEmpty(userProfileName)) {
|
||||||
return ctx.getString(key);
|
return ctx.getString(key);
|
||||||
|
} else {
|
||||||
|
return userProfileName;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toHumanStringCtx(Context ctx) {
|
public String toHumanStringCtx(Context ctx) {
|
||||||
|
if (Algorithms.isEmpty(userProfileName)) {
|
||||||
return ctx.getString(key);
|
return ctx.getString(key);
|
||||||
|
} else {
|
||||||
|
return userProfileName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ApplicationMode valueOfStringKey(String key, ApplicationMode def) {
|
public static ApplicationMode valueOfStringKey(String key, ApplicationMode def) {
|
||||||
|
@ -437,28 +461,73 @@ public class ApplicationMode {
|
||||||
return this == mode || getParent() == mode;
|
return this == mode || getParent() == mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserProfileTitle() {
|
public int getMapIconsSetId() {
|
||||||
return userProfileTitle;
|
return mapIconsSetId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int key;
|
public String getUserProfileName() {
|
||||||
private final String stringKey;
|
return userProfileName;
|
||||||
private String userProfileTitle = "";
|
}
|
||||||
private ApplicationMode parent;
|
|
||||||
private int mapIconId = R.drawable.map_world_globe_dark;
|
@Expose private final int key;
|
||||||
private int smallIconDark = R.drawable.ic_world_globe_dark;
|
@Expose private final String stringKey;
|
||||||
private float defaultSpeed = 10f;
|
@Expose private String userProfileName = "";
|
||||||
private int minDistanceForTurn = 50;
|
@Expose private int mapIconsSetId = 0;
|
||||||
private int arrivalDistance = 90;
|
@Expose private ApplicationMode parent;
|
||||||
private int offRouteDistance = 350;
|
@Expose private int mapIconId = R.drawable.map_world_globe_dark;
|
||||||
private int bearingIconDay = R.drawable.map_pedestrian_bearing;
|
@Expose private int smallIconDark = R.drawable.ic_world_globe_dark;
|
||||||
private int bearingIconNight = R.drawable.map_pedestrian_bearing_night;
|
@Expose private float defaultSpeed = 10f;
|
||||||
private int headingIconDay = R.drawable.map_pedestrian_location_view_angle;
|
@Expose private int minDistanceForTurn = 50;
|
||||||
private int headingIconNight = R.drawable.map_pedestrian_location_view_angle_night;
|
@Expose private int arrivalDistance = 90;
|
||||||
private int locationIconDay = R.drawable.map_pedestrian_location;
|
@Expose private int offRouteDistance = 350;
|
||||||
private int locationIconNight = R.drawable.map_pedestrian_location_night;
|
@Expose private int bearingIconDay = R.drawable.map_pedestrian_bearing;
|
||||||
private int locationIconDayLost = R.drawable.map_pedestrian_location_lost;
|
@Expose private int bearingIconNight = R.drawable.map_pedestrian_bearing_night;
|
||||||
private int locationIconNightLost = R.drawable.map_pedestrian_location_lost_night;
|
@Expose private int headingIconDay = R.drawable.map_pedestrian_location_view_angle;
|
||||||
|
@Expose private int headingIconNight = R.drawable.map_pedestrian_location_view_angle_night;
|
||||||
|
@Expose private int locationIconDay = R.drawable.map_pedestrian_location;
|
||||||
|
@Expose private int locationIconNight = R.drawable.map_pedestrian_location_night;
|
||||||
|
@Expose private int locationIconDayLost = R.drawable.map_pedestrian_location_lost;
|
||||||
|
@Expose private int locationIconNightLost = R.drawable.map_pedestrian_location_lost_night;
|
||||||
private static StateChangedListener<String> listener;
|
private static StateChangedListener<String> listener;
|
||||||
private static OsmAndAppCustomization.OsmAndAppCustomizationListener customizationListener;
|
private static OsmAndAppCustomization.OsmAndAppCustomizationListener customizationListener;
|
||||||
|
|
||||||
|
|
||||||
|
public void saveCustomProfileToSettings(OsmandSettings settings){
|
||||||
|
List<ApplicationMode> customModes = new ArrayList<>();
|
||||||
|
for (ApplicationMode mode : values) {
|
||||||
|
if (mode.parent != null) {
|
||||||
|
customModes.add(mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||||
|
String profiles = gson.toJson(customModes);
|
||||||
|
settings.CUSTOM_APP_PROFILES.set(profiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean initCustomProfiles(OsmandSettings settings){
|
||||||
|
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
||||||
|
Type t = new TypeToken<ArrayList<ApplicationMode>>() {}.getType();
|
||||||
|
List<ApplicationMode> customProfiles = gson.fromJson(settings.CUSTOM_APP_PROFILES.get(), t);
|
||||||
|
|
||||||
|
if (!Algorithms.isEmpty(customProfiles)) {
|
||||||
|
for (ApplicationMode m : customProfiles) {
|
||||||
|
if (!values.contains(m)) {
|
||||||
|
values.add(m);
|
||||||
|
if (m.getParent() != null) {
|
||||||
|
LOG.debug("parent: " + m.getParent().getStringKey());
|
||||||
|
} else {
|
||||||
|
LOG.debug("parent: propal!!!!!111 " );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -2745,6 +2745,9 @@ public class OsmandSettings {
|
||||||
RateUsBottomSheetDialog.RateUsState.INITIAL_STATE, RateUsBottomSheetDialog.RateUsState.values())
|
RateUsBottomSheetDialog.RateUsState.INITIAL_STATE, RateUsBottomSheetDialog.RateUsState.values())
|
||||||
.makeGlobal();
|
.makeGlobal();
|
||||||
|
|
||||||
|
public final CommonPreference<String> CUSTOM_APP_PROFILES = new StringPreference(
|
||||||
|
"custom_profiles", "").makeGlobal().cache();
|
||||||
|
|
||||||
|
|
||||||
public enum DayNightMode {
|
public enum DayNightMode {
|
||||||
AUTO(R.string.daynight_mode_auto, R.drawable.ic_action_map_sunst),
|
AUTO(R.string.daynight_mode_auto, R.drawable.ic_action_map_sunst),
|
||||||
|
|
|
@ -4,6 +4,9 @@ import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import android.support.v4.view.MenuItemCompat;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -17,34 +20,34 @@ public class EditProfileActivity extends OsmandActionBarActivity {
|
||||||
getMyApplication().applyTheme(this);
|
getMyApplication().applyTheme(this);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.single_fragment_layout);
|
setContentView(R.layout.single_fragment_layout);
|
||||||
// Intent intent = getIntent();
|
|
||||||
// if (intent.getExtras() != null) {
|
|
||||||
// String title = "";
|
|
||||||
// if (intent.getBooleanExtra("isUserProfile", false)) {
|
|
||||||
//
|
|
||||||
// } else if (intent.getBooleanExtra("isNew", false)) {
|
|
||||||
// title = String.format("%s (new)", intent.getStringExtra("stringKey").replace("_", " "));
|
|
||||||
// } else {
|
|
||||||
// title = Algorithms.capitalizeFirstLetterAndLowercase(
|
|
||||||
// intent.getStringExtra("stringKey").replace("_", " "));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (getSupportActionBar() != null) {
|
|
||||||
// getSupportActionBar().setTitle(title);
|
|
||||||
// getSupportActionBar().setElevation(5.0f);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
EditProfileFragment editProfileFragment = new EditProfileFragment();
|
EditProfileFragment editProfileFragment = new EditProfileFragment();
|
||||||
editProfileFragment.setArguments(getIntent().getExtras());
|
editProfileFragment.setArguments(getIntent().getExtras());
|
||||||
getSupportFragmentManager().beginTransaction().add(android.R.id.content,
|
getSupportFragmentManager().beginTransaction().add(android.R.id.content,
|
||||||
editProfileFragment).commit();
|
editProfileFragment, "editProfileFragment").commit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
|
||||||
|
MenuItem m = menu.add(0, 0, 0, R.string.action_delete).setIcon(R.drawable.ic_action_delete_dark);
|
||||||
|
MenuItemCompat.setShowAsAction(m, MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||||
|
super.onCreateOptionsMenu(menu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
|
||||||
|
|
||||||
int itemId = item.getItemId();
|
int itemId = item.getItemId();
|
||||||
switch (itemId) {
|
switch (itemId) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
|
|
|
@ -3,14 +3,17 @@ package net.osmand.plus.profiles;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.GradientDrawable;
|
import android.graphics.drawable.GradientDrawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcel;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -23,9 +26,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.StateChangedListener;
|
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmAndAppCustomization;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
@ -36,8 +37,6 @@ import net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.ProfileTypeDial
|
||||||
import net.osmand.plus.profiles.SelectIconBottomSheetDialogFragment.IconIdListener;
|
import net.osmand.plus.profiles.SelectIconBottomSheetDialogFragment.IconIdListener;
|
||||||
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
|
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
|
||||||
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
||||||
import net.osmand.util.Algorithms;
|
|
||||||
import net.sf.junidecode.App;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
|
import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
|
||||||
|
|
||||||
|
@ -72,8 +71,10 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
String modeName = getArguments().getString("stringKey", "car");
|
String modeName = getArguments().getString("stringKey", "car");
|
||||||
isNew = getArguments().getBoolean("isNew", false);
|
isNew = getArguments().getBoolean("isNew", false);
|
||||||
isUserProfile = getArguments().getBoolean("isUserProfile", false);
|
isUserProfile = getArguments().getBoolean("isUserProfile", false);
|
||||||
|
|
||||||
profile = new TempApplicationProfile(
|
profile = new TempApplicationProfile(
|
||||||
ApplicationMode.valueOfStringKey(modeName, ApplicationMode.DEFAULT), isNew);
|
ApplicationMode.valueOfStringKey(modeName, ApplicationMode.DEFAULT), isNew, isUserProfile);
|
||||||
|
|
||||||
LOG.debug("Name: " + modeName + ", ");
|
LOG.debug("Name: " + modeName + ", ");
|
||||||
}
|
}
|
||||||
routingProfiles = getRoutingProfiles();
|
routingProfiles = getRoutingProfiles();
|
||||||
|
@ -291,9 +292,13 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean saveNewProfile(TempApplicationProfile profile, RoutingProfile selectedRoutingProfile) {
|
private boolean saveNewProfile(TempApplicationProfile profile, RoutingProfile selectedRoutingProfile) {
|
||||||
//todo check if profile exists
|
|
||||||
|
if (isUserProfile && !isNew) {
|
||||||
|
return updateProfile();
|
||||||
|
}
|
||||||
|
|
||||||
List<ApplicationMode> copyAllModes = new ArrayList<>(ApplicationMode.allPossibleValues());
|
List<ApplicationMode> copyAllModes = new ArrayList<>(ApplicationMode.allPossibleValues());
|
||||||
List<ApplicationMode> copyAllAvailableModes = new ArrayList<>(ApplicationMode.values(getMyApplication()));
|
// List<ApplicationMode> copyAllAvailableModes = new ArrayList<>(ApplicationMode.values(getMyApplication()));
|
||||||
Iterator<ApplicationMode> it = copyAllModes.iterator();
|
Iterator<ApplicationMode> it = copyAllModes.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
ApplicationMode am = it.next();
|
ApplicationMode am = it.next();
|
||||||
|
@ -304,14 +309,11 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String customStringKey = profile.stringKey;
|
||||||
|
if (isNew && profile.getParent() != null) {
|
||||||
|
customStringKey = profile.getParent().getStringKey() + "_" + profile.userProfileTitle.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
String customStringKey = profile.getParent().getStringKey() + "_" + profile.userProfileTitle.hashCode();
|
|
||||||
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
|
|
||||||
if (mode.getStringKey().equals(customStringKey)) {
|
|
||||||
//todo notify user that there is already profile with such name
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode
|
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode
|
||||||
.createCustomMode(profile.userProfileTitle, customStringKey)
|
.createCustomMode(profile.userProfileTitle, customStringKey)
|
||||||
.parent(profile.parent)
|
.parent(profile.parent)
|
||||||
|
@ -320,17 +322,18 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
switch (profile.parent.getStringKey()) {
|
switch (profile.parent.getStringKey()) {
|
||||||
case "car":
|
case "car":
|
||||||
case "aircraft":
|
case "aircraft":
|
||||||
builder.carLocation();
|
builder.setLocationAndBearingIcons(1);
|
||||||
break;
|
break;
|
||||||
case "bicicle":
|
case "bicycle":
|
||||||
builder.bicycleLocation();
|
builder.setLocationAndBearingIcons(2);
|
||||||
break;
|
break;
|
||||||
case "boat":
|
case "boat":
|
||||||
builder.nauticalLocation();
|
builder.setLocationAndBearingIcons(3);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.customReg();
|
ApplicationMode customMode = builder.customReg();
|
||||||
|
customMode.saveCustomProfileToSettings(getSettings());
|
||||||
|
|
||||||
//todo build profile, save and register:
|
//todo build profile, save and register:
|
||||||
|
|
||||||
|
@ -381,7 +384,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
|
|
||||||
private class TempApplicationProfile {
|
private class TempApplicationProfile {
|
||||||
int key = -1;
|
int key = -1;
|
||||||
String stringKey = "";
|
String stringKey;
|
||||||
String userProfileTitle = "";
|
String userProfileTitle = "";
|
||||||
ApplicationMode parent = null;
|
ApplicationMode parent = null;
|
||||||
int iconId = R.drawable.map_world_globe_dark;
|
int iconId = R.drawable.map_world_globe_dark;
|
||||||
|
@ -389,20 +392,21 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
int minDistanceForTurn = 50; //todo use default or what?
|
int minDistanceForTurn = 50; //todo use default or what?
|
||||||
RoutingProfile routingProfile = null;
|
RoutingProfile routingProfile = null;
|
||||||
|
|
||||||
TempApplicationProfile(ApplicationMode mode, boolean isNew) {
|
TempApplicationProfile(ApplicationMode mode, boolean isNew, boolean isUserProfile) {
|
||||||
if (isNew ) {
|
if (isNew ) {
|
||||||
stringKey = "new_" + mode.getStringKey();
|
stringKey = "new_" + mode.getStringKey();
|
||||||
parent = mode;
|
parent = mode;
|
||||||
} else if (isUserProfile) {
|
} else if (isUserProfile) {
|
||||||
stringKey = mode.getStringKey();
|
stringKey = mode.getStringKey();
|
||||||
parent = getParent();
|
parent = mode.getParent();
|
||||||
iconId = mode.getSmallIconDark();
|
iconId = mode.getSmallIconDark();
|
||||||
userProfileTitle = mode.getUserProfileTitle();
|
userProfileTitle = mode.getUserProfileName();
|
||||||
} else {
|
} else {
|
||||||
key = mode.getStringResource();
|
key = mode.getStringResource();
|
||||||
stringKey = mode.getStringKey();
|
stringKey = mode.getStringKey();
|
||||||
iconId = mode.getSmallIconDark();
|
iconId = mode.getSmallIconDark();
|
||||||
}
|
}
|
||||||
|
LOG.debug("Parent: " + getParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public RoutingProfile getRoutingProfile() {
|
public RoutingProfile getRoutingProfile() {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.osmand.plus.profiles;
|
package net.osmand.plus.profiles;
|
||||||
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.SwitchCompat;
|
import android.support.v7.widget.SwitchCompat;
|
||||||
|
@ -10,16 +9,13 @@ import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileViewHolder;
|
import net.osmand.plus.profiles.ProfileMenuAdapter.ProfileViewHolder;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
import net.sf.junidecode.App;
|
|
||||||
|
|
||||||
|
|
||||||
public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder> {
|
public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder> {
|
||||||
|
@ -63,7 +59,7 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
||||||
public void onBindViewHolder(@NonNull final ProfileViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull final ProfileViewHolder holder, int position) {
|
||||||
final ApplicationMode item = items.get(position);
|
final ApplicationMode item = items.get(position);
|
||||||
if (item.getParent() != null) {
|
if (item.getParent() != null) {
|
||||||
holder.title.setText(item.getUserProfileTitle());
|
holder.title.setText(item.getUserProfileName());
|
||||||
holder.descr.setText(String.format("Type: %s", Algorithms.capitalizeFirstLetterAndLowercase(item.getParent().getStringKey().replace("_", " "))));
|
holder.descr.setText(String.format("Type: %s", Algorithms.capitalizeFirstLetterAndLowercase(item.getParent().getStringKey().replace("_", " "))));
|
||||||
} else {
|
} else {
|
||||||
holder.title.setText(app.getResources().getString(item.getStringResource()));
|
holder.title.setText(app.getResources().getString(item.getStringResource()));
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
||||||
listener = new ProfileListener() {
|
listener = new ProfileListener() {
|
||||||
@Override
|
@Override
|
||||||
public void changeProfileStatus(ApplicationMode item, boolean isSelected) {
|
public void changeProfileStatus(ApplicationMode item, boolean isSelected) {
|
||||||
LOG.debug(getString(item.getStringResource()) + " - " + isSelected);
|
//LOG.debug(getString(item.getStringResource()) + " - " + isSelected);
|
||||||
StringBuilder vls = new StringBuilder(ApplicationMode.DEFAULT.getStringKey()+",");
|
StringBuilder vls = new StringBuilder(ApplicationMode.DEFAULT.getStringKey()+",");
|
||||||
ApplicationMode mode = null;
|
ApplicationMode mode = null;
|
||||||
for (ApplicationMode sam : allAppModes) {
|
for (ApplicationMode sam : allAppModes) {
|
||||||
|
@ -87,10 +87,8 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
||||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||||
intent.putExtra("stringKey", item.getStringKey());
|
intent.putExtra("stringKey", item.getStringKey());
|
||||||
intent.putExtra("isNew", false);
|
intent.putExtra("isNew", false);
|
||||||
if (!item.getUserProfileTitle().isEmpty()) {
|
if (!item.getUserProfileName().isEmpty()) {
|
||||||
intent.putExtra("isUserProfile", true);
|
intent.putExtra("isUserProfile", true);
|
||||||
} else {
|
|
||||||
intent.putExtra("isUserProfile", false);
|
|
||||||
}
|
}
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class RoutingOptionsHelper {
|
||||||
addRouteMenuAppModes(ApplicationMode.PEDESTRIAN, PermanentAppModeOptions.PEDESTRIAN.routingParameters);
|
addRouteMenuAppModes(ApplicationMode.PEDESTRIAN, PermanentAppModeOptions.PEDESTRIAN.routingParameters);
|
||||||
addRouteMenuAppModes(ApplicationMode.PUBLIC_TRANSPORT, PermanentAppModeOptions.PUBLIC_TRANSPORT.routingParameters);
|
addRouteMenuAppModes(ApplicationMode.PUBLIC_TRANSPORT, PermanentAppModeOptions.PUBLIC_TRANSPORT.routingParameters);
|
||||||
addRouteMenuAppModes(ApplicationMode.BOAT, PermanentAppModeOptions.BOAT.routingParameters);
|
addRouteMenuAppModes(ApplicationMode.BOAT, PermanentAppModeOptions.BOAT.routingParameters);
|
||||||
addRouteMenuAppModes(ApplicationMode.AIRCRAFT, PermanentAppModeOptions.AIRCAFT.routingParameters);
|
addRouteMenuAppModes(ApplicationMode.AIRCRAFT, PermanentAppModeOptions.AIRCRAFT.routingParameters);
|
||||||
// addRouteMenuAppModes(ApplicationMode.HIKING, PermanentAppModeOptions.HIKING.routingParameters);
|
// addRouteMenuAppModes(ApplicationMode.HIKING, PermanentAppModeOptions.HIKING.routingParameters);
|
||||||
// addRouteMenuAppModes(ApplicationMode.MOTORCYCLE, PermanentAppModeOptions.MOTORCYCLE.routingParameters);
|
// addRouteMenuAppModes(ApplicationMode.MOTORCYCLE, PermanentAppModeOptions.MOTORCYCLE.routingParameters);
|
||||||
// addRouteMenuAppModes(ApplicationMode.TRUCK, PermanentAppModeOptions.TRUCK.routingParameters);
|
// addRouteMenuAppModes(ApplicationMode.TRUCK, PermanentAppModeOptions.TRUCK.routingParameters);
|
||||||
|
@ -971,11 +971,11 @@ public class RoutingOptionsHelper {
|
||||||
PEDESTRIAN(MuteSoundRoutingParameter.KEY, GeneralRouter.USE_HEIGHT_OBSTACLES),
|
PEDESTRIAN(MuteSoundRoutingParameter.KEY, GeneralRouter.USE_HEIGHT_OBSTACLES),
|
||||||
PUBLIC_TRANSPORT(MuteSoundRoutingParameter.KEY),
|
PUBLIC_TRANSPORT(MuteSoundRoutingParameter.KEY),
|
||||||
BOAT(MuteSoundRoutingParameter.KEY),
|
BOAT(MuteSoundRoutingParameter.KEY),
|
||||||
AIRCAFT(MuteSoundRoutingParameter.KEY),
|
AIRCRAFT(MuteSoundRoutingParameter.KEY);
|
||||||
HIKING(MuteSoundRoutingParameter.KEY),
|
// HIKING(MuteSoundRoutingParameter.KEY),
|
||||||
MOTORCYCLE(MuteSoundRoutingParameter.KEY),
|
// MOTORCYCLE(MuteSoundRoutingParameter.KEY),
|
||||||
TRUCK(MuteSoundRoutingParameter.KEY),
|
// TRUCK(MuteSoundRoutingParameter.KEY),
|
||||||
TRAIN(MuteSoundRoutingParameter.KEY);
|
// TRAIN(MuteSoundRoutingParameter.KEY);
|
||||||
|
|
||||||
List<String> routingParameters;
|
List<String> routingParameters;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue