saving and edit new profile - work in progress
This commit is contained in:
parent
885729c6e8
commit
d13b160b4f
10 changed files with 281 additions and 155 deletions
|
@ -1066,7 +1066,7 @@
|
|||
android:name=".profiles.SettingsProfileActivity"/>
|
||||
|
||||
|
||||
<activity android:name=".profiles.SelectedProfileActivity"
|
||||
<activity android:name=".profiles.EditProfileActivity"
|
||||
android:label="Application profiles"
|
||||
/>
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public class ApplicationMode {
|
|||
//
|
||||
// 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();
|
||||
|
||||
String profile = "profile: ";
|
||||
static {
|
||||
ApplicationMode[] exceptDefault = new ApplicationMode[]{CAR, PEDESTRIAN, BICYCLE, BOAT, PUBLIC_TRANSPORT};
|
||||
ApplicationMode[] exceptPedestrianAndDefault = new ApplicationMode[]{CAR, BICYCLE, BOAT, PUBLIC_TRANSPORT};
|
||||
|
@ -104,8 +104,6 @@ public class ApplicationMode {
|
|||
|
||||
|
||||
public static class ApplicationModeBuilder {
|
||||
|
||||
|
||||
private ApplicationMode applicationMode;
|
||||
|
||||
public ApplicationMode reg() {
|
||||
|
@ -125,6 +123,29 @@ public class ApplicationMode {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
public ApplicationModeBuilder parent(ApplicationMode parent) {
|
||||
applicationMode.parent = parent;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type - id of set of icons for different navigation styles:
|
||||
* 1 - car, 2 - bicicle, 3 - nautical, any other - default
|
||||
*/
|
||||
public ApplicationModeBuilder setLocationAndBearingIcons(int type) {
|
||||
switch (type) {
|
||||
case 1:
|
||||
return this.carLocation();
|
||||
case 2:
|
||||
return this.bicycleLocation();
|
||||
case 3:
|
||||
return this.nauticalLocation();
|
||||
default:
|
||||
return this.defLocation();
|
||||
}
|
||||
}
|
||||
|
||||
public ApplicationModeBuilder carLocation() {
|
||||
applicationMode.bearingIconDay = R.drawable.map_car_bearing;
|
||||
applicationMode.bearingIconNight = R.drawable.map_car_bearing_night;
|
||||
|
@ -137,11 +158,6 @@ public class ApplicationMode {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ApplicationModeBuilder parent(ApplicationMode parent) {
|
||||
applicationMode.parent = parent;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApplicationModeBuilder bicycleLocation() {
|
||||
applicationMode.bearingIconDay = R.drawable.map_bicycle_bearing;
|
||||
applicationMode.bearingIconNight = R.drawable.map_bicycle_bearing_night;
|
||||
|
@ -191,8 +207,15 @@ public class ApplicationMode {
|
|||
applicationMode.offRouteDistance = offRouteDistance;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ApplicationModeBuilder userProfileTitle(String userProfileTitle) {
|
||||
applicationMode.userProfileTitle = userProfileTitle;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static ApplicationModeBuilder create(int key, String stringKey) {
|
||||
ApplicationModeBuilder builder = new ApplicationModeBuilder();
|
||||
builder.applicationMode = new ApplicationMode(key, stringKey);
|
||||
|
@ -200,7 +223,7 @@ public class ApplicationMode {
|
|||
}
|
||||
|
||||
public static ApplicationModeBuilder createCustomMode(String userProfileTitle, String stringKey) {
|
||||
return create(-1, stringKey);
|
||||
return create(-1, stringKey).userProfileTitle(userProfileTitle);
|
||||
}
|
||||
|
||||
private ApplicationMode(int key, String stringKey) {
|
||||
|
@ -410,18 +433,6 @@ public class ApplicationMode {
|
|||
return offRouteDistance;
|
||||
}
|
||||
|
||||
public void setUserProfileTitle(String userProfileTitle) {
|
||||
this.userProfileTitle = userProfileTitle;
|
||||
}
|
||||
|
||||
public void setMapIconId(int mapIconId) {
|
||||
this.mapIconId = mapIconId;
|
||||
}
|
||||
|
||||
public void setSmallIconDark(int smallIconDark) {
|
||||
this.smallIconDark = smallIconDark;
|
||||
}
|
||||
|
||||
public boolean isDerivedRoutingFrom(ApplicationMode mode) {
|
||||
return this == mode || getParent() == mode;
|
||||
}
|
||||
|
|
|
@ -842,6 +842,8 @@ public class OsmandSettings {
|
|||
|
||||
public final OsmandPreference<String> AVAILABLE_APP_MODES = new StringPreference("available_application_modes", "car,bicycle,pedestrian,public_transport,").makeGlobal().cache();
|
||||
|
||||
// public final OsmandPreference<List<String>> CUSTOM_APP_MODES = new ListStringPreference()
|
||||
|
||||
public final OsmandPreference<String> LAST_FAV_CATEGORY_ENTERED = new StringPreference("last_fav_category", "").makeGlobal();
|
||||
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ import net.osmand.plus.mapmarkers.PlanRouteFragment;
|
|||
import net.osmand.plus.measurementtool.MeasurementEditingContext;
|
||||
import net.osmand.plus.measurementtool.MeasurementToolFragment;
|
||||
import net.osmand.plus.measurementtool.NewGpxData;
|
||||
import net.osmand.plus.profiles.SelectedProfileFragment;
|
||||
import net.osmand.plus.profiles.EditProfileFragment;
|
||||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
import net.osmand.plus.routepreparationmenu.ChooseRouteFragment;
|
||||
|
@ -777,14 +777,14 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
}
|
||||
setIntent(null);
|
||||
}
|
||||
if (intent.hasExtra(SelectedProfileFragment.OPEN_CONFIG_ON_MAP)) {
|
||||
switch (intent.getStringExtra(SelectedProfileFragment.OPEN_CONFIG_ON_MAP)) {
|
||||
case SelectedProfileFragment.MAP_CONFIG:
|
||||
if (intent.hasExtra(EditProfileFragment.OPEN_CONFIG_ON_MAP)) {
|
||||
switch (intent.getStringExtra(EditProfileFragment.OPEN_CONFIG_ON_MAP)) {
|
||||
case EditProfileFragment.MAP_CONFIG:
|
||||
LOG.debug("open map config");
|
||||
this.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_MAP, null);
|
||||
break;
|
||||
|
||||
case SelectedProfileFragment.SCREEN_CONFIG:
|
||||
case EditProfileFragment.SCREEN_CONFIG:
|
||||
LOG.debug("open screen config");
|
||||
this.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN, null);
|
||||
break;
|
||||
|
|
57
OsmAnd/src/net/osmand/plus/profiles/EditProfileActivity.java
Normal file
57
OsmAnd/src/net/osmand/plus/profiles/EditProfileActivity.java
Normal file
|
@ -0,0 +1,57 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import android.view.MenuItem;
|
||||
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
public class EditProfileActivity extends OsmandActionBarActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
getMyApplication().applyTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
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) {
|
||||
EditProfileFragment editProfileFragment = new EditProfileFragment();
|
||||
editProfileFragment.setArguments(getIntent().getExtras());
|
||||
getSupportFragmentManager().beginTransaction().add(android.R.id.content,
|
||||
editProfileFragment).commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
switch (itemId) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.profiles;
|
|||
import android.content.Intent;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
@ -19,8 +20,12 @@ import android.widget.FrameLayout;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmAndAppCustomization;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -31,12 +36,14 @@ import net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.ProfileTypeDial
|
|||
import net.osmand.plus.profiles.SelectIconBottomSheetDialogFragment.IconIdListener;
|
||||
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
|
||||
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.sf.junidecode.App;
|
||||
import org.apache.commons.logging.Log;
|
||||
import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
|
||||
|
||||
public class SelectedProfileFragment extends BaseOsmAndFragment {
|
||||
public class EditProfileFragment extends BaseOsmAndFragment {
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(SelectedProfileFragment.class);
|
||||
private static final Log LOG = PlatformUtil.getLog(EditProfileFragment.class);
|
||||
|
||||
public static final String OPEN_CONFIG_ON_MAP = "openConfigOnMap";
|
||||
public static final String MAP_CONFIG = "openMapConfigMenu";
|
||||
|
@ -44,16 +51,14 @@ 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;
|
||||
TempApplicationProfile profile = null;
|
||||
ArrayList<RoutingProfile> routingProfiles;
|
||||
OsmandApplication app;
|
||||
RoutingProfile selectedRoutingProfile = null;
|
||||
float defSpeed = 0f;
|
||||
|
||||
private boolean isNew = false;
|
||||
private boolean isUserProfile = false;
|
||||
private boolean isDataChanged = false;
|
||||
|
||||
private ProfileTypeDialogListener profileTypeDialogListener = null;
|
||||
|
@ -65,12 +70,11 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
|
|||
app = getMyApplication();
|
||||
if (getArguments() != null) {
|
||||
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);
|
||||
}
|
||||
isNew = getArguments().getBoolean("isNew", false);
|
||||
isUserProfile = getArguments().getBoolean("isUserProfile", false);
|
||||
profile = new TempApplicationProfile(
|
||||
ApplicationMode.valueOfStringKey(modeName, ApplicationMode.DEFAULT), isNew);
|
||||
LOG.debug("Name: " + modeName + ", ");
|
||||
}
|
||||
routingProfiles = getRoutingProfiles();
|
||||
}
|
||||
|
@ -99,44 +103,63 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
|
|||
profileIconBtn.setBackgroundResource(R.drawable.rounded_background_3dp);
|
||||
GradientDrawable selectIconBtnBackground = (GradientDrawable) profileIconBtn
|
||||
.getBackground();
|
||||
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
|
||||
.setPrimaryColor(ContextCompat.getColor(app, R.color.color_dialog_buttons_dark));
|
||||
navTypeTextBox
|
||||
.setPrimaryColor(ContextCompat.getColor(app, R.color.color_dialog_buttons_dark));
|
||||
selectIconBtnBackground
|
||||
.setColor(app.getResources().getColor(R.color.text_field_box_dark));
|
||||
profileNameTextBox.setPrimaryColor(ContextCompat.getColor(app, R.color.color_dialog_buttons_dark));
|
||||
navTypeTextBox.setPrimaryColor(ContextCompat.getColor(app, R.color.color_dialog_buttons_dark));
|
||||
selectIconBtnBackground.setColor(app.getResources().getColor(R.color.text_field_box_dark));
|
||||
} else {
|
||||
selectIconBtnBackground
|
||||
.setColor(app.getResources().getColor(R.color.text_field_box_light));
|
||||
selectIconBtnBackground.setColor(app.getResources().getColor(R.color.text_field_box_light));
|
||||
}
|
||||
|
||||
String title = "New Profile";
|
||||
int startIconId = R.drawable.map_world_globe_dark;
|
||||
LOG.debug("isUserProfile = " + isUserProfile);
|
||||
LOG.debug("isNew = " + isNew);
|
||||
if (isUserProfile && !isNew) {
|
||||
title = profile.getUserProfileTitle();
|
||||
profileNameEt.setText(title);
|
||||
startIconId = profile.iconId;
|
||||
} else if (isNew) {
|
||||
title = String.format("%s (new)", getResources().getString(profile.parent.getStringResource()));
|
||||
profileNameEt.setText(title);
|
||||
startIconId = profile.getParent().getSmallIconDark();
|
||||
} else if (profile.getKey() != -1){
|
||||
title = getResources().getString(profile.getKey());
|
||||
profileNameEt.setText(profile.getKey());
|
||||
startIconId = profile.getIconId();
|
||||
}
|
||||
|
||||
profileNameEt.clearFocus();
|
||||
|
||||
if (getActivity() != null && ((EditProfileActivity) getActivity()).getSupportActionBar() != null) {
|
||||
((EditProfileActivity) getActivity()).getSupportActionBar().setTitle(title);
|
||||
((EditProfileActivity) getActivity()).getSupportActionBar().setElevation(5.0f);
|
||||
}
|
||||
|
||||
profileIcon.setImageDrawable(app.getUIUtilities().getIcon(startIconId,
|
||||
isNightMode ? R.color.active_buttons_and_links_dark
|
||||
: R.color.active_buttons_and_links_light));
|
||||
|
||||
profileTypeDialogListener = new ProfileTypeDialogListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
selectedRoutingProfile = routingProfiles.get(pos);
|
||||
navTypeEt.setText(selectedRoutingProfile.getName());
|
||||
profile.setRoutingProfile(selectedRoutingProfile);
|
||||
}
|
||||
};
|
||||
|
||||
iconIdListener = new IconIdListener() {
|
||||
@Override
|
||||
public void selectedIconId(int iconRes) {
|
||||
profile.setMapIconId(iconRes);
|
||||
profile.setSmallIconDark(iconRes);
|
||||
profile.setIconId(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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -157,6 +180,7 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
|
|||
ActionBar actionBar = ((OsmandActionBarActivity) getActivity()).getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle(s.toString());
|
||||
profile.setUserProfileTitle(s.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,13 +200,10 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
|
|||
.commitAllowingStateLoss();
|
||||
}
|
||||
|
||||
|
||||
// navTypeEt.setText("Car");
|
||||
// navTypeEt.setCursorVisible(false);
|
||||
// navTypeEt.setTextIsSelectable(false);
|
||||
// navTypeEt.clearFocus();
|
||||
navTypeEt.setCursorVisible(false);
|
||||
navTypeEt.setTextIsSelectable(false);
|
||||
navTypeEt.clearFocus();
|
||||
navTypeEt.requestFocus(ExtendedEditText.FOCUS_UP);
|
||||
// LOG.debug("click on text");
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -193,7 +214,7 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
|
|||
final SelectIconBottomSheetDialogFragment iconSelectDialog = new SelectIconBottomSheetDialogFragment();
|
||||
iconSelectDialog.setIconIdListener(iconIdListener);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("selectedIcon", profile.getSmallIconDark());
|
||||
bundle.putInt("selectedIcon", profile.getIconId());
|
||||
iconSelectDialog.setArguments(bundle);
|
||||
if (getActivity() != null) {
|
||||
getActivity().getSupportFragmentManager().beginTransaction()
|
||||
|
@ -260,11 +281,8 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
|
|||
saveButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String title = profileNameTextBox.getEditText().getText().toString();
|
||||
if (ApplicationMode.allPossibleValues().contains(profile)) {
|
||||
updateProfile();
|
||||
} else {
|
||||
saveNewProfile(title, parent, selectedRoutingProfile, defSpeed);
|
||||
if (saveNewProfile(profile, selectedRoutingProfile)) {
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -272,30 +290,56 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
private boolean saveNewProfile(
|
||||
String userProfileTitle,
|
||||
ApplicationMode profile,
|
||||
RoutingProfile selectedRoutingProfile,
|
||||
float defSpeed) {
|
||||
private boolean saveNewProfile(TempApplicationProfile profile, RoutingProfile selectedRoutingProfile) {
|
||||
//todo check if profile exists
|
||||
List<ApplicationMode> copyAllModes = new ArrayList<>(ApplicationMode.allPossibleValues());
|
||||
List<ApplicationMode> copyAllAvailableModes = new ArrayList<>(ApplicationMode.values(getMyApplication()));
|
||||
Iterator<ApplicationMode> it = copyAllModes.iterator();
|
||||
while (it.hasNext()) {
|
||||
ApplicationMode am = it.next();
|
||||
if (am.getStringKey().equals(profile.stringKey)) {
|
||||
if (ApplicationMode.values(getMyApplication()).contains(am)) {
|
||||
//todo unregister mode from available
|
||||
}
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String customStringKey = profile.getParent().getStringKey() + "_" + 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
|
||||
.createCustomMode(profile.userProfileTitle, customStringKey)
|
||||
.parent(profile.parent)
|
||||
.icon(profile.iconId, profile.iconId);
|
||||
|
||||
switch (profile.parent.getStringKey()) {
|
||||
case "car":
|
||||
case "aircraft":
|
||||
builder.carLocation();
|
||||
break;
|
||||
case "bicicle":
|
||||
builder.bicycleLocation();
|
||||
break;
|
||||
case "boat":
|
||||
builder.nauticalLocation();
|
||||
break;
|
||||
}
|
||||
|
||||
builder.customReg();
|
||||
|
||||
ApplicationMode.createCustomMode(userProfileTitle, customStringKey);
|
||||
//todo build profile, save and register:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateProfile() {
|
||||
|
||||
private boolean updateProfile() {
|
||||
//todo implement update;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -333,4 +377,72 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
return routingProfiles;
|
||||
}
|
||||
|
||||
|
||||
private class TempApplicationProfile {
|
||||
int key = -1;
|
||||
String stringKey = "";
|
||||
String userProfileTitle = "";
|
||||
ApplicationMode parent = null;
|
||||
int iconId = R.drawable.map_world_globe_dark;
|
||||
float defaultSpeed = 10f; //todo use default or what?
|
||||
int minDistanceForTurn = 50; //todo use default or what?
|
||||
RoutingProfile routingProfile = null;
|
||||
|
||||
TempApplicationProfile(ApplicationMode mode, boolean isNew) {
|
||||
if (isNew ) {
|
||||
stringKey = "new_" + mode.getStringKey();
|
||||
parent = mode;
|
||||
} else if (isUserProfile) {
|
||||
stringKey = mode.getStringKey();
|
||||
parent = getParent();
|
||||
iconId = mode.getSmallIconDark();
|
||||
userProfileTitle = mode.getUserProfileTitle();
|
||||
} else {
|
||||
key = mode.getStringResource();
|
||||
stringKey = mode.getStringKey();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||
import net.osmand.plus.dashboard.DashBaseFragment;
|
||||
|
||||
public class IconSelectBottomSheetDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -63,7 +63,8 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
|||
public void onBindViewHolder(@NonNull final ProfileViewHolder holder, int position) {
|
||||
final ApplicationMode item = items.get(position);
|
||||
if (item.getParent() != null) {
|
||||
holder.descr.setText(String.format("Type: %s", item.getParent().getStringKey()));
|
||||
holder.title.setText(item.getUserProfileTitle());
|
||||
holder.descr.setText(String.format("Type: %s", Algorithms.capitalizeFirstLetterAndLowercase(item.getParent().getStringKey().replace("_", " "))));
|
||||
} else {
|
||||
holder.title.setText(app.getResources().getString(item.getStringResource()));
|
||||
holder.descr.setText(String.format("Type: %s", Algorithms.capitalizeFirstLetterAndLowercase(item.getStringKey().replace("_", " "))));
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
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 {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
getMyApplication().applyTheme(this);
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.single_fragment_layout);
|
||||
Intent intent = getIntent();
|
||||
if (intent.getExtras() != null) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
SelectedProfileFragment selectedProfileFragment = new SelectedProfileFragment();
|
||||
selectedProfileFragment.setArguments(getIntent().getExtras());
|
||||
getSupportFragmentManager().beginTransaction().add(android.R.id.content, selectedProfileFragment).commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int itemId = item.getItemId();
|
||||
switch (itemId) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ 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;
|
||||
import android.support.annotation.NonNull;
|
||||
|
@ -85,9 +84,14 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
|
||||
@Override
|
||||
public void editProfile(ApplicationMode item) {
|
||||
Intent intent = new Intent(getActivity(), SelectedProfileActivity.class);
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
intent.putExtra("stringKey", item.getStringKey());
|
||||
intent.putExtra("isNew", false);
|
||||
if (!item.getUserProfileTitle().isEmpty()) {
|
||||
intent.putExtra("isUserProfile", true);
|
||||
} else {
|
||||
intent.putExtra("isUserProfile", false);
|
||||
}
|
||||
startActivity(intent);
|
||||
}
|
||||
};
|
||||
|
@ -96,8 +100,9 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public void onSelectedType(int pos) {
|
||||
LOG.debug("Base profile: " + baseProfiles.get(pos).getName());
|
||||
Intent intent = new Intent(getActivity(), SelectedProfileActivity.class);
|
||||
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
|
||||
intent.putExtra("isNew", true);
|
||||
intent.putExtra("isUserProfile", true);
|
||||
intent.putExtra("stringKey", baseProfiles.get(pos).getStringKey());
|
||||
startActivity(intent);
|
||||
}
|
||||
|
@ -132,6 +137,15 @@ public class SettingsProfileFragment extends BaseOsmAndFragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
allAppModes = ApplicationMode.allPossibleValues();
|
||||
allAppModes.remove(ApplicationMode.DEFAULT);
|
||||
|
||||
adapter.updateItemsList(allAppModes);
|
||||
}
|
||||
|
||||
private ArrayList<BaseProfile> getBaseProfiles() {
|
||||
ArrayList<BaseProfile> profiles = new ArrayList<>();
|
||||
for (ApplicationMode mode : ApplicationMode.getDefaultValues()) {
|
||||
|
|
Loading…
Reference in a new issue