Merge pull request #10431 from osmandapp/UseLastProfileByDefault

Use last profile by default
This commit is contained in:
Vitaliy 2020-12-21 10:56:22 +02:00 committed by GitHub
commit ecb5354b5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 411 additions and 346 deletions

View file

@ -11,6 +11,8 @@
Thx - Hardy
-->
<string name="shared_string_last_used">Last used</string>
<string name="profile_by_default_description">Select the profile, that will be used on application start.</string>
<string name="reverse_all_points">Reverse all points</string>
<string name="release_3_9">
• Added option to export and import all data including settings, resources, my places\n\n

View file

@ -4,9 +4,10 @@
xmlns:tools="http://schemas.android.com/tools"
android:title="@string/osmand_settings">
<net.osmand.plus.settings.preferences.ListPreferenceEx
android:icon="@drawable/ic_world_globe_dark"
<Preference
android:key="default_application_mode_string"
android:icon="@drawable/ic_world_globe_dark"
android:persistent="false"
android:layout="@layout/preference_with_descr"
android:title="@string/settings_preset" />

View file

@ -63,6 +63,7 @@ import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.measurementtool.StartPlanRouteBottomSheet;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.dialogs.DismissRouteBottomSheetFragment;
import net.osmand.plus.profiles.ProfileDataUtils;
import net.osmand.plus.profiles.RoutingProfileDataObject;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routepreparationmenu.WaypointsFragment;
@ -121,7 +122,6 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_S
import static net.osmand.plus.ContextMenuAdapter.PROFILES_CHOSEN_PROFILE_TAG;
import static net.osmand.plus.ContextMenuAdapter.PROFILES_CONTROL_BUTTON_TAG;
import static net.osmand.plus.ContextMenuAdapter.PROFILES_NORMAL_PROFILE_TAG;
import static net.osmand.plus.settings.fragments.NavigationFragment.getRoutingProfiles;
public class MapActivityActions implements DialogProvider {
@ -737,7 +737,7 @@ public class MapActivityActions implements DialogProvider {
String modeDescription;
Map<String, RoutingProfileDataObject> profilesObjects = getRoutingProfiles(app);
Map<String, RoutingProfileDataObject> profilesObjects = ProfileDataUtils.getRoutingProfiles(app);
for (final ApplicationMode appMode : activeModes) {
if (appMode.isCustomProfile()) {
modeDescription = getProfileDescription(app, appMode, profilesObjects, getString(R.string.profile_type_user_string));
@ -1046,7 +1046,7 @@ public class MapActivityActions implements DialogProvider {
//switch profile button
ApplicationMode currentMode = app.getSettings().APPLICATION_MODE.get();
String modeDescription;
Map<String, RoutingProfileDataObject> profilesObjects = getRoutingProfiles(app);
Map<String, RoutingProfileDataObject> profilesObjects = ProfileDataUtils.getRoutingProfiles(app);
if (currentMode.isCustomProfile()) {
modeDescription = getProfileDescription(app, currentMode, profilesObjects, getString(R.string.profile_type_user_string));
} else {

View file

@ -15,6 +15,7 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.profiles.ProfileDataUtils;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -33,7 +34,6 @@ import net.osmand.plus.download.DownloadValidationManager;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
import org.apache.commons.logging.Log;
@ -221,7 +221,7 @@ public class PluginInstalledBottomSheetDialog extends MenuBottomSheetDialogFragm
final BottomSheetItemWithCompoundButton[] appModeItem = new BottomSheetItemWithCompoundButton[1];
appModeItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setChecked(ApplicationMode.values(app).contains(mode))
.setDescription(BaseSettingsFragment.getAppModeDescription(app, mode))
.setDescription(ProfileDataUtils.getAppModeDescription(app, mode))
.setTitle(mode.toHumanString())
.setIcon(getActiveIcon(mode.getIconRes()))
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_switch_56dp)

View file

@ -16,7 +16,6 @@ import net.osmand.PlatformUtil;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -105,7 +104,7 @@ public class ConfigureProfileMenuAdapter extends AbstractProfileMenuAdapter<Conf
holder.menuIcon.setVisibility(View.VISIBLE);
final ApplicationMode item = (ApplicationMode) obj;
holder.title.setText(item.toHumanString());
holder.descr.setText(BaseSettingsFragment.getAppModeDescription(app, item));
holder.descr.setText(ProfileDataUtils.getAppModeDescription(app, item));
holder.initSwitcher = true;
holder.compoundButton.setChecked(selectedItems.contains(item));

View file

@ -31,7 +31,6 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import java.util.ArrayList;
@ -241,7 +240,7 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
if (order == null) {
order = mode.getOrder();
}
profiles.add(new EditProfileDataObject(modeKey, mode.toHumanString(), BaseSettingsFragment.getAppModeDescription(getContext(), mode),
profiles.add(new EditProfileDataObject(modeKey, mode.toHumanString(), ProfileDataUtils.getAppModeDescription(getContext(), mode),
mode.getIconRes(), false, mode.isCustomProfile(), deleted, mode.getIconColorInfo(), order));
}
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.profiles;
import androidx.annotation.ColorRes;
import androidx.annotation.NonNull;
public class ProfileDataObject implements Comparable<ProfileDataObject> {
private String name;
@ -62,4 +63,5 @@ public class ProfileDataObject implements Comparable<ProfileDataObject> {
public int compareTo(@NonNull ProfileDataObject another) {
return this.name.compareToIgnoreCase(another.name);
}
}

View file

@ -0,0 +1,136 @@
package net.osmand.plus.profiles;
import android.content.Context;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.router.GeneralRouter;
import net.osmand.router.RoutingConfiguration;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ProfileDataUtils {
public static final String OSMAND_NAVIGATION = "osmand_navigation";
public static List<ProfileDataObject> getDataObjects(OsmandApplication app,
List<ApplicationMode> appModes) {
List<ProfileDataObject> profiles = new ArrayList<>();
for (ApplicationMode mode : appModes) {
String description = mode.getDescription();
if (Algorithms.isEmpty(description)) {
description = getAppModeDescription(app, mode);
}
profiles.add(new ProfileDataObject(mode.toHumanString(), description,
mode.getStringKey(), mode.getIconRes(), false, mode.getIconColorInfo()));
}
return profiles;
}
public static String getAppModeDescription(Context ctx, ApplicationMode mode) {
String description;
if (mode.isCustomProfile()) {
description = ctx.getString(R.string.profile_type_user_string);
} else {
description = ctx.getString(R.string.profile_type_osmand_string);
}
return description;
}
public static List<RoutingProfileDataObject> getSortedRoutingProfiles(OsmandApplication app) {
List<RoutingProfileDataObject> result = new ArrayList<>();
Map<String, List<RoutingProfileDataObject>> routingProfilesByFileNames = getRoutingProfilesByFileNames(app);
List<String> fileNames = new ArrayList<>(routingProfilesByFileNames.keySet());
Collections.sort(fileNames, new Comparator<String>() {
@Override
public int compare(String s, String t1) {
return s.equals(OSMAND_NAVIGATION) ? -1 : t1.equals(OSMAND_NAVIGATION) ? 1 : s.compareToIgnoreCase(t1);
}
});
for (String fileName : fileNames) {
List<RoutingProfileDataObject> routingProfilesFromFile = routingProfilesByFileNames.get(fileName);
if (routingProfilesFromFile != null) {
Collections.sort(routingProfilesFromFile);
result.addAll(routingProfilesFromFile);
}
}
return result;
}
public static Map<String, List<RoutingProfileDataObject>> getRoutingProfilesByFileNames(OsmandApplication app) {
Map<String, List<RoutingProfileDataObject>> result = new HashMap<>();
for (final RoutingProfileDataObject profile : getRoutingProfiles(app).values()) {
String fileName = profile.getFileName() != null ? profile.getFileName() : OSMAND_NAVIGATION;
if (result.containsKey(fileName)) {
result.get(fileName).add(profile);
} else {
result.put(fileName, new ArrayList<RoutingProfileDataObject>() {
{ add(profile); }
});
}
}
return result;
}
public static Map<String, RoutingProfileDataObject> getRoutingProfiles(OsmandApplication context) {
Map<String, RoutingProfileDataObject> profilesObjects = new HashMap<>();
profilesObjects.put(RoutingProfileDataObject.RoutingProfilesResources.STRAIGHT_LINE_MODE.name(), new RoutingProfileDataObject(
RoutingProfileDataObject.RoutingProfilesResources.STRAIGHT_LINE_MODE.name(),
context.getString(RoutingProfileDataObject.RoutingProfilesResources.STRAIGHT_LINE_MODE.getStringRes()),
context.getString(R.string.special_routing_type),
RoutingProfileDataObject.RoutingProfilesResources.STRAIGHT_LINE_MODE.getIconRes(),
false, null));
profilesObjects.put(RoutingProfileDataObject.RoutingProfilesResources.DIRECT_TO_MODE.name(), new RoutingProfileDataObject(
RoutingProfileDataObject.RoutingProfilesResources.DIRECT_TO_MODE.name(),
context.getString(RoutingProfileDataObject.RoutingProfilesResources.DIRECT_TO_MODE.getStringRes()),
context.getString(R.string.special_routing_type),
RoutingProfileDataObject.RoutingProfilesResources.DIRECT_TO_MODE.getIconRes(),
false, null));
if (context.getBRouterService() != null) {
profilesObjects.put(RoutingProfileDataObject.RoutingProfilesResources.BROUTER_MODE.name(), new RoutingProfileDataObject(
RoutingProfileDataObject.RoutingProfilesResources.BROUTER_MODE.name(),
context.getString(RoutingProfileDataObject.RoutingProfilesResources.BROUTER_MODE.getStringRes()),
context.getString(R.string.third_party_routing_type),
RoutingProfileDataObject.RoutingProfilesResources.BROUTER_MODE.getIconRes(),
false, null));
}
List<String> disabledRouterNames = OsmandPlugin.getDisabledRouterNames();
for (RoutingConfiguration.Builder builder : context.getAllRoutingConfigs()) {
collectRoutingProfilesFromConfig(context, builder, profilesObjects, disabledRouterNames);
}
return profilesObjects;
}
private static void collectRoutingProfilesFromConfig(OsmandApplication app, RoutingConfiguration.Builder builder,
Map<String, RoutingProfileDataObject> profilesObjects, List<String> disabledRouterNames) {
for (Map.Entry<String, GeneralRouter> entry : builder.getAllRouters().entrySet()) {
String routerKey = entry.getKey();
GeneralRouter router = entry.getValue();
if (!routerKey.equals("geocoding") && !disabledRouterNames.contains(router.getFilename())) {
int iconRes = R.drawable.ic_action_gdirections_dark;
String name = router.getProfileName();
String description = app.getString(R.string.osmand_default_routing);
String fileName = router.getFilename();
if (!Algorithms.isEmpty(fileName)) {
description = fileName;
} else if (RoutingProfileDataObject.RoutingProfilesResources.isRpValue(name.toUpperCase())) {
iconRes = RoutingProfileDataObject.RoutingProfilesResources.valueOf(name.toUpperCase()).getIconRes();
name = app.getString(RoutingProfileDataObject.RoutingProfilesResources.valueOf(name.toUpperCase()).getStringRes());
}
profilesObjects.put(routerKey, new RoutingProfileDataObject(routerKey, name, description,
iconRes, false, fileName));
}
}
}
}

View file

@ -59,4 +59,5 @@ public class RoutingProfileDataObject extends ProfileDataObject {
return rpValues.contains(value);
}
}
}

View file

@ -19,7 +19,7 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.fragments.NavigationFragment;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
import java.util.ArrayList;
@ -54,7 +54,8 @@ public class SelectMultipleProfilesBottomSheet extends BasePreferenceBottomSheet
private void refreshProfiles(OsmandApplication app) {
profiles.clear();
profiles.addAll(NavigationFragment.getBaseProfiles(app, true));
List<ApplicationMode> appModes = ApplicationMode.allPossibleValues();
profiles.addAll(ProfileDataUtils.getDataObjects(app, appModes));
for (ProfileDataObject profile : profiles) {
String key = profile.getStringKey();
profile.setSelected(selectedProfiles.contains(key));

View file

@ -2,8 +2,12 @@ package net.osmand.plus.profiles;
import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
@ -15,6 +19,8 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
@ -28,10 +34,10 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.SimpleDividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.fragments.MainSettingsFragment;
import net.osmand.plus.settings.fragments.NavigationFragment;
import net.osmand.plus.settings.fragments.ProfileAppearanceFragment;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
import net.osmand.router.RoutingConfiguration;
@ -42,35 +48,36 @@ import java.util.List;
import static net.osmand.plus.importfiles.ImportHelper.ImportType.ROUTING;
public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottomSheet {
public class SelectProfileBottomSheet extends BasePreferenceBottomSheet {
private static final Log LOG = PlatformUtil
.getLog(SelectProfileBottomSheetDialogFragment.class);
public static final String TAG = "SelectProfileBottomSheetDialogFragment";
private static final Log LOG = PlatformUtil.getLog(SelectProfileBottomSheet.class);
public static final String TAG = "SelectProfileBottomSheet";
public final static String DIALOG_TYPE = "dialog_type";
public final static String TYPE_BASE_APP_PROFILE = "base_profiles";
public final static String TYPE_NAV_PROFILE = "routing_profiles";
public final static String SELECTED_KEY = "selected_base";
public final static String PROFILE_KEY_ARG = "profile_key_arg";
public final static String USE_LAST_PROFILE_ARG = "use_last_profile_arg";
public final static String IS_PROFILE_IMPORTED_ARG = "is_profile_imported_arg";
String type;
private SelectProfileListener listener;
private DialogMode dialogMode;
private final List<ProfileDataObject> profiles = new ArrayList<>();
private String selectedItemKey;
public enum DialogMode {
BASE_PROFILE,
NAVIGATION_PROFILE,
DEFAULT_PROFILE
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OsmandApplication app = getMyApplication();
Bundle args = getArguments();
if (args != null && args.get(DIALOG_TYPE) != null) {
type = args.getString(DIALOG_TYPE);
String dialogModeName = args.getString(DIALOG_TYPE);
dialogMode = DialogMode.valueOf(dialogModeName);
selectedItemKey = args.getString(SELECTED_KEY, null);
refreshProfiles(app);
}
@ -91,12 +98,12 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
@Override
public void createMenuItems(Bundle savedInstanceState) {
OsmandApplication app = requiredMyApplication();
View bottomSpaceView = new View(app);
int space = (int) getResources().getDimension(R.dimen.empty_state_text_button_padding_top);
bottomSpaceView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, space));
if (type.equals(TYPE_BASE_APP_PROFILE)) {
if (dialogMode == DialogMode.BASE_PROFILE) {
items.add(new TitleItem(getString(R.string.select_base_profile_dialog_title)));
items.add(new LongDescriptionItem(getString(R.string.select_base_profile_dialog_message)));
for (int i = 0; i < profiles.size(); i++) {
@ -138,7 +145,7 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
.setCustomView(bottomSpaceView)
.create());*/
} else if (type.equals(TYPE_NAV_PROFILE)) {
} else if (dialogMode == DialogMode.NAVIGATION_PROFILE) {
items.add(new TitleItem(getString(R.string.select_nav_profile_dialog_title)));
items.add(new LongDescriptionItem(getString(R.string.select_nav_profile_dialog_message)));
for (int i = 0; i < profiles.size(); i++) {
@ -146,11 +153,11 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
boolean showBottomDivider = false;
if (i < profiles.size() - 1) {
RoutingProfileDataObject nextProfile = (RoutingProfileDataObject) profiles.get(i + 1);
if (profile.getFileName() == null) {
showBottomDivider = nextProfile.getFileName() != null;
} else {
showBottomDivider = !profile.getFileName().equals(nextProfile.getFileName());
}
if (profile.getFileName() == null) {
showBottomDivider = nextProfile.getFileName() != null;
} else {
showBottomDivider = !profile.getFileName().equals(nextProfile.getFileName());
}
}
addProfileItem(profile, showBottomDivider);
}
@ -175,15 +182,44 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(bottomSpaceView)
.create());
} else if (dialogMode == DialogMode.DEFAULT_PROFILE) {
items.add(new TitleItem(getString(R.string.settings_preset)));
items.add(new LongDescriptionItem(getString(R.string.profile_by_default_description)));
boolean useLastAppModeByDefault = app.getSettings().USE_LAST_APPLICATION_MODE_BY_DEFAULT.get();
addCheckableItem(R.string.shared_string_last_used, useLastAppModeByDefault, new OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
args.putBoolean(USE_LAST_PROFILE_ARG, true);
Fragment target = getTargetFragment();
if (target instanceof OnSelectProfileCallback) {
((OnSelectProfileCallback) target).onProfileSelected(args);
}
dismiss();
}
});
items.add(new SimpleDividerItem(app));
for (int i = 0; i < profiles.size(); i++) {
ProfileDataObject profile = profiles.get(i);
addProfileItem(profile, false, !useLastAppModeByDefault);
}
}
}
private void addProfileItem(final ProfileDataObject profile, boolean showBottomDivider) {
addProfileItem(profile, showBottomDivider, true);
}
private void addProfileItem(final ProfileDataObject profile,
boolean showBottomDivider,
boolean setupSelected) {
OsmandApplication app = requiredMyApplication();
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
int iconDefaultColorResId = nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light;
View itemView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.bottom_sheet_item_with_descr_and_radio_btn, null);
TextView tvTitle = itemView.findViewById(R.id.title);
TextView tvDescription = itemView.findViewById(R.id.description);
@ -193,13 +229,13 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
tvTitle.setText(profile.getName());
tvDescription.setText(profile.getDescription());
boolean isSelected = profile.getStringKey().equals(selectedItemKey);
boolean isSelected = setupSelected && profile.getStringKey().equals(selectedItemKey);
int iconColor;
if (type.equals(TYPE_BASE_APP_PROFILE)) {
iconColor = profile.getIconColor(nightMode);
} else {
if (dialogMode == DialogMode.NAVIGATION_PROFILE) {
iconColor = isSelected ? activeColorResId : iconDefaultColorResId;
} else {
iconColor = profile.getIconColor(nightMode);
}
Drawable drawableIcon = app.getUIUtilities().getIcon(profile.getIconRes(), iconColor);
@ -213,28 +249,56 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (listener == null) {
getListener();
}
Bundle args = new Bundle();
args.putString(PROFILE_KEY_ARG, profile.getStringKey());
listener.onSelectedType(args);
Fragment target = getTargetFragment();
if (target instanceof OnSelectProfileCallback) {
((OnSelectProfileCallback) target).onProfileSelected(args);
}
dismiss();
}
})
.create());
}
private void addCheckableItem(int titleId,
boolean isSelected,
OnClickListener listener) {
OsmandApplication app = requiredMyApplication();
View itemView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.bottom_sheet_item_with_descr_and_radio_btn, null);
itemView.findViewById(R.id.icon).setVisibility(View.GONE);
itemView.findViewById(R.id.description).setVisibility(View.GONE);
itemView.findViewById(R.id.divider_bottom).setVisibility(View.GONE);
Typeface typeface = FontCache.getRobotoMedium(app);
String title = getString(titleId);
SpannableString spannable = UiUtilities.createCustomFontSpannable(typeface, title, title, title);
int activeColor = ContextCompat.getColor(app, getActiveColorId());
ForegroundColorSpan colorSpan = new ForegroundColorSpan(activeColor);
spannable.setSpan(colorSpan, 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
((TextView) itemView.findViewById(R.id.title)).setText(spannable);
CompoundButton compoundButton = itemView.findViewById(R.id.compound_button);
compoundButton.setChecked(isSelected);
UiUtilities.setupCompoundButton(compoundButton, nightMode, UiUtilities.CompoundButtonType.GLOBAL);
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(itemView)
.setOnClickListener(listener)
.create());
}
private void addButtonItem(int titleId, int iconId, OnClickListener listener) {
OsmandApplication app = requiredMyApplication();
Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
int activeColorResId = AndroidUtils.resolveAttribute(themedCtx, R.attr.active_color_basic);
View buttonView = View.inflate(themedCtx, R.layout.bottom_sheet_item_preference_btn, null);
TextView tvTitle = buttonView.findViewById(R.id.title);
tvTitle.setText(app.getString(titleId));
tvTitle.setText(getString(titleId));
ImageView ivIcon = buttonView.findViewById(R.id.icon);
ivIcon.setImageDrawable(app.getUIUtilities().getIcon(iconId, activeColorResId));
@ -244,18 +308,6 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
.create());
}
private void refreshProfiles(OsmandApplication app) {
profiles.clear();
if (type.equals(TYPE_NAV_PROFILE)) {
profiles.addAll(NavigationFragment.getSortedRoutingProfiles(app));
} else if (type.equals(TYPE_BASE_APP_PROFILE)) {
profiles.addAll(NavigationFragment.getBaseProfiles(app));
} else {
LOG.error("Check data type!");
dismiss();
}
}
private void refreshView() {
Activity activity = getActivity();
View mainView = getView();
@ -275,28 +327,25 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
}
}
private void getListener() {
FragmentActivity activity = getActivity();
if (activity != null) {
FragmentManager fragmentManager = activity.getSupportFragmentManager();
NavigationFragment navigationFragment = (NavigationFragment) fragmentManager.findFragmentByTag(NavigationFragment.class.getName());
ProfileAppearanceFragment profileAppearanceFragment = (ProfileAppearanceFragment) fragmentManager.findFragmentByTag(ProfileAppearanceFragment.TAG);
MainSettingsFragment mainSettingsFragment = (MainSettingsFragment) fragmentManager.findFragmentByTag(MainSettingsFragment.TAG);
private void refreshProfiles(OsmandApplication app) {
profiles.clear();
switch (dialogMode) {
case BASE_PROFILE:
List<ApplicationMode> appModes = new ArrayList<>(ApplicationMode.allPossibleValues());
appModes.remove(ApplicationMode.DEFAULT);
profiles.addAll(ProfileDataUtils.getDataObjects(app, appModes));
break;
if (navigationFragment != null) {
listener = navigationFragment.getNavProfileListener();
} else if (profileAppearanceFragment != null) {
listener = profileAppearanceFragment.getParentProfileListener();
} else if (mainSettingsFragment != null) {
listener = mainSettingsFragment.getParentProfileListener();
}
case NAVIGATION_PROFILE:
profiles.addAll(ProfileDataUtils.getSortedRoutingProfiles(app));
break;
case DEFAULT_PROFILE:
profiles.addAll(ProfileDataUtils.getDataObjects(app, ApplicationMode.values(app)));
break;
}
}
public interface SelectProfileListener {
void onSelectedType(Bundle args);
}
@Nullable
private MapActivity getMapActivity() {
Activity activity = getActivity();
@ -305,4 +354,23 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
}
return null;
}
public static void showInstance(@NonNull FragmentActivity activity,
@NonNull DialogMode dialogMode,
@Nullable Fragment target,
String selectedItemKey,
boolean usedOnMap) {
SelectProfileBottomSheet fragment = new SelectProfileBottomSheet();
Bundle args = new Bundle();
args.putString(DIALOG_TYPE, dialogMode.name());
args.putString(SELECTED_KEY, selectedItemKey);
fragment.setArguments(args);
fragment.setUsedOnMap(usedOnMap);
fragment.setTargetFragment(target, 0);
fragment.show(activity.getSupportFragmentManager(), TAG);
}
public interface OnSelectProfileCallback {
void onProfileSelected(Bundle args);
}
}

View file

@ -19,7 +19,6 @@ import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -99,7 +98,7 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter<SelectP
holder.menuIcon.setVisibility(View.GONE);
final ApplicationMode item = (ApplicationMode) obj;
holder.title.setText(item.toHumanString());
holder.descr.setText(BaseSettingsFragment.getAppModeDescription(app, item));
holder.descr.setText(ProfileDataUtils.getAppModeDescription(app, item));
int profileColorResId = item.getIconColorInfo().getColor(nightMode);
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(profileColorResId, selectedIconColorRes));

View file

@ -425,6 +425,7 @@ public class OsmandSettings {
if (valueSaved) {
currentMode = val;
profilePreferences = getProfilePreferences(currentMode);
LAST_USED_APPLICATION_MODE.set(currentMode.getStringKey());
fireEvent(oldMode);
}
@ -735,11 +736,20 @@ public class OsmandSettings {
public final OsmandPreference<String> LAST_FAV_CATEGORY_ENTERED = new StringPreference(this, "last_fav_category", "").makeGlobal();
public final OsmandPreference<Boolean> USE_LAST_APPLICATION_MODE_BY_DEFAULT = new BooleanPreference(this, "use_last_application_mode_by_default", false).makeGlobal().makeShared();
public final OsmandPreference<String> LAST_USED_APPLICATION_MODE = new StringPreference(this, "last_used_application_mode", ApplicationMode.DEFAULT.getStringKey()).makeGlobal().makeShared();
public final OsmandPreference<ApplicationMode> DEFAULT_APPLICATION_MODE = new CommonPreference<ApplicationMode>(this, "default_application_mode_string", ApplicationMode.DEFAULT) {
@Override
protected ApplicationMode getValue(Object prefs, ApplicationMode defaultValue) {
String key = settingsAPI.getString(prefs, getId(), defaultValue.getStringKey());
String key;
if (USE_LAST_APPLICATION_MODE_BY_DEFAULT.get()) {
key = LAST_USED_APPLICATION_MODE.get();
} else {
key = settingsAPI.getString(prefs, getId(), defaultValue.getStringKey());
}
return ApplicationMode.valueOfStringKey(key, defaultValue);
}

View file

@ -12,6 +12,7 @@ import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import net.osmand.plus.profiles.ProfileDataUtils;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@ -19,7 +20,6 @@ import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
public class ResetProfilePrefsBottomSheet extends BasePreferenceBottomSheet {
@ -48,7 +48,7 @@ public class ResetProfilePrefsBottomSheet extends BasePreferenceBottomSheet {
.setChecked(true)
.setCompoundButtonColorId(profileColor)
.setButtonTintList(ColorStateList.valueOf(getResolvedColor(profileColor)))
.setDescription(BaseSettingsFragment.getAppModeDescription(ctx, mode))
.setDescription(ProfileDataUtils.getAppModeDescription(ctx, mode))
.setIcon(getIcon(mode.getIconRes(), profileColor))
.setTitle(mode.toHumanString())
.setBackground(new LayerDrawable(layers))

View file

@ -2,7 +2,6 @@ package net.osmand.plus.settings.fragments;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
@ -883,17 +882,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return listPreference;
}
public static String getAppModeDescription(Context ctx, ApplicationMode mode) {
String description;
if (mode.isCustomProfile()) {
description = ctx.getString(R.string.profile_type_user_string);
} else {
description = ctx.getString(R.string.profile_type_osmand_string);
}
return description;
}
public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType) {
return showInstance(activity, screenType, null);
}

View file

@ -2,6 +2,7 @@ package net.osmand.plus.settings.fragments;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Pair;
import android.widget.ImageView;
@ -16,14 +17,20 @@ import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment;
import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment.OnSendAnalyticsPrefsUpdate;
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet;
import net.osmand.plus.profiles.SelectProfileBottomSheet;
import net.osmand.plus.profiles.SelectProfileBottomSheet.DialogMode;
import net.osmand.plus.profiles.SelectProfileBottomSheet.OnSelectProfileCallback;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILE_KEY_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheet.USE_LAST_PROFILE_ARG;
public class GlobalSettingsFragment extends BaseSettingsFragment
implements OnSendAnalyticsPrefsUpdate, OnPreferenceChanged {
implements OnSendAnalyticsPrefsUpdate, OnPreferenceChanged, OnSelectProfileCallback {
public static final String TAG = GlobalSettingsFragment.class.getSimpleName();
@ -94,9 +101,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment
@Override
public void onPreferenceChanged(String prefId) {
if (prefId.equals(settings.DEFAULT_APPLICATION_MODE.getId())) {
setupDefaultAppModePref();
} else if (prefId.equals(settings.PREFERRED_LOCALE.getId())) {
if (prefId.equals(settings.PREFERRED_LOCALE.getId())) {
// recreate activity to update locale
Activity activity = getActivity();
OsmandApplication app = getMyApplication();
@ -117,7 +122,13 @@ public class GlobalSettingsFragment extends BaseSettingsFragment
@Override
public boolean onPreferenceClick(Preference preference) {
String prefId = preference.getKey();
if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(prefId) && !settings.SPEED_CAMERAS_UNINSTALLED.get()) {
if (prefId.equals(settings.DEFAULT_APPLICATION_MODE.getId())) {
if (getActivity() != null) {
String defaultModeKey = settings.DEFAULT_APPLICATION_MODE.get().getStringKey();
SelectProfileBottomSheet.showInstance(getActivity(),
DialogMode.DEFAULT_PROFILE, this, defaultModeKey, false);
}
} else if (settings.SPEED_CAMERAS_UNINSTALLED.getId().equals(prefId) && !settings.SPEED_CAMERAS_UNINSTALLED.get()) {
FragmentManager fm = getFragmentManager();
if (fm != null) {
SpeedCamerasBottomSheet.showInstance(fm, this);
@ -127,23 +138,20 @@ public class GlobalSettingsFragment extends BaseSettingsFragment
}
private void setupDefaultAppModePref() {
OsmandApplication app = getMyApplication();
if (app == null) {
return;
Preference defaultApplicationMode = (Preference) findPreference(settings.DEFAULT_APPLICATION_MODE.getId());
int iconColor = settings.getApplicationMode().getIconColorInfo().getColor(isNightMode());
String summary;
int iconId;
if (settings.USE_LAST_APPLICATION_MODE_BY_DEFAULT.get()) {
summary = getString(R.string.shared_string_last_used);
iconId = R.drawable.ic_action_manage_profiles;
} else {
ApplicationMode appMode = settings.DEFAULT_APPLICATION_MODE.get();
summary = appMode.toHumanString();
iconId = appMode.getIconRes();
}
ApplicationMode[] appModes = ApplicationMode.values(app).toArray(new ApplicationMode[0]);
String[] entries = new String[appModes.length];
String[] entryValues = new String[appModes.length];
for (int i = 0; i < entries.length; i++) {
entries[i] = appModes[i].toHumanString();
entryValues[i] = appModes[i].getStringKey();
}
ListPreferenceEx defaultApplicationMode = (ListPreferenceEx) findPreference(settings.DEFAULT_APPLICATION_MODE.getId());
defaultApplicationMode.setIcon(getIcon(settings.DEFAULT_APPLICATION_MODE.get().getIconRes(),
settings.getApplicationMode().getIconColorInfo().getColor(isNightMode())));
defaultApplicationMode.setEntries(entries);
defaultApplicationMode.setEntryValues(entryValues);
defaultApplicationMode.setIcon(getIcon(iconId, iconColor));
defaultApplicationMode.setSummary(summary);
}
private void setupPreferredLocalePref() {
@ -219,6 +227,18 @@ public class GlobalSettingsFragment extends BaseSettingsFragment
uninstallSpeedCameras.setTitle(uninstalled ? R.string.speed_cameras_removed_descr : R.string.uninstall_speed_cameras);
}
@Override
public void onProfileSelected(Bundle args) {
if (args.getBoolean(USE_LAST_PROFILE_ARG)) {
settings.USE_LAST_APPLICATION_MODE_BY_DEFAULT.set(true);
} else {
settings.USE_LAST_APPLICATION_MODE_BY_DEFAULT.set(false);
String value = args.getString(PROFILE_KEY_ARG);
settings.setPreference(settings.DEFAULT_APPLICATION_MODE.getId(), value);
}
setupDefaultAppModePref();
}
public static Pair<String[], String[]> getPreferredLocaleIdsAndValues(Context ctx) {
// See language list and statistics at: https://hosted.weblate.org/projects/osmand/main/
// Hardy maintenance 2016-05-29:

View file

@ -20,8 +20,10 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener;
import net.osmand.plus.profiles.ProfileDataUtils;
import net.osmand.plus.profiles.SelectProfileBottomSheet;
import net.osmand.plus.profiles.SelectProfileBottomSheet.DialogMode;
import net.osmand.plus.profiles.SelectProfileBottomSheet.OnSelectProfileCallback;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.backup.SettingsItem;
import net.osmand.plus.settings.backend.backup.SettingsItemType;
@ -33,12 +35,10 @@ import java.util.List;
import java.util.Set;
import static net.osmand.plus.importfiles.ImportHelper.ImportType.SETTINGS;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.IS_PROFILE_IMPORTED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.PROFILE_KEY_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
import static net.osmand.plus.profiles.SelectProfileBottomSheet.IS_PROFILE_IMPORTED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILE_KEY_ARG;
public class MainSettingsFragment extends BaseSettingsFragment {
public class MainSettingsFragment extends BaseSettingsFragment implements OnSelectProfileCallback{
public static final String TAG = MainSettingsFragment.class.getName();
@ -52,7 +52,6 @@ public class MainSettingsFragment extends BaseSettingsFragment {
private List<ApplicationMode> allAppModes;
private Set<ApplicationMode> availableAppModes;
private SelectProfileListener selectProfileListener = null;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -119,15 +118,9 @@ public class MainSettingsFragment extends BaseSettingsFragment {
ApplicationMode.valueOfStringKey(prefId, null));
return true;
} else if (CREATE_PROFILE.equals(prefId)) {
final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
Bundle bundle = new Bundle();
bundle.putString(DIALOG_TYPE, TYPE_BASE_APP_PROFILE);
dialog.setArguments(bundle);
dialog.setUsedOnMap(false);
dialog.setAppMode(getSelectedAppMode());
if (getActivity() != null) {
getActivity().getSupportFragmentManager().beginTransaction()
.add(dialog, "select_base_profile").commitAllowingStateLoss();
SelectProfileBottomSheet.showInstance(getActivity(),
DialogMode.BASE_PROFILE, this, null, false);
}
} else if (IMPORT_PROFILE.equals(prefId)) {
final MapActivity mapActivity = getMapActivity();
@ -162,7 +155,7 @@ public class MainSettingsFragment extends BaseSettingsFragment {
private void setupConfigureProfilePref() {
ApplicationMode selectedMode = app.getSettings().APPLICATION_MODE.get();
String title = selectedMode.toHumanString();
String profileType = getAppModeDescription(getContext(), selectedMode);
String profileType = ProfileDataUtils.getAppModeDescription(getContext(), selectedMode);
Preference configureProfile = findPreference(CONFIGURE_PROFILE);
configureProfile.setIcon(getAppProfilesIcon(selectedMode, true));
configureProfile.setTitle(title);
@ -200,7 +193,7 @@ public class MainSettingsFragment extends BaseSettingsFragment {
pref.setIcon(getAppProfilesIcon(applicationMode, isAppProfileEnabled));
pref.setTitle(applicationMode.toHumanString());
pref.setSummary(getAppModeDescription(getContext(), applicationMode));
pref.setSummary(ProfileDataUtils.getAppModeDescription(getContext(), applicationMode));
pref.setChecked(isAppProfileEnabled);
pref.setLayoutResource(R.layout.preference_with_descr_dialog_and_switch);
pref.setFragment(ConfigureProfileFragment.class.getName());
@ -222,30 +215,23 @@ public class MainSettingsFragment extends BaseSettingsFragment {
: getIcon(iconResId, isNightMode() ? R.color.icon_color_secondary_dark : R.color.icon_color_secondary_light);
}
public SelectProfileListener getParentProfileListener() {
if (selectProfileListener == null) {
selectProfileListener = new SelectProfileListener() {
@Override
public void onSelectedType(Bundle args) {
FragmentActivity activity = getActivity();
if (activity != null) {
FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (fragmentManager != null) {
String profileKey = args.getString(PROFILE_KEY_ARG);
boolean imported = args.getBoolean(IS_PROFILE_IMPORTED_ARG);
ProfileAppearanceFragment.showInstance(activity, SettingsScreenType.PROFILE_APPEARANCE,
profileKey, imported);
}
}
}
};
}
return selectProfileListener;
}
@Override
public void onPause() {
updateRouteInfoMenu();
super.onPause();
}
@Override
public void onProfileSelected(Bundle args) {
FragmentActivity activity = getActivity();
if (activity != null) {
FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (fragmentManager != null) {
String profileKey = args.getString(PROFILE_KEY_ARG);
boolean imported = args.getBoolean(IS_PROFILE_IMPORTED_ARG);
ProfileAppearanceFragment.showInstance(activity, SettingsScreenType.PROFILE_APPEARANCE,
profileKey, imported);
}
}
}
}

View file

@ -10,51 +10,38 @@ import androidx.preference.Preference;
import androidx.preference.SwitchPreferenceCompat;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.profiles.ProfileDataUtils;
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet;
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.DialogMode;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.profiles.ProfileDataObject;
import net.osmand.plus.profiles.RoutingProfileDataObject;
import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
import net.osmand.plus.profiles.SelectProfileBottomSheet;
import net.osmand.plus.profiles.SelectProfileBottomSheet.OnSelectProfileCallback;
import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import net.osmand.router.GeneralRouter;
import net.osmand.router.RoutingConfiguration;
import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.IS_PROFILE_IMPORTED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.PROFILE_KEY_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE;
import static net.osmand.plus.profiles.SelectProfileBottomSheet.IS_PROFILE_IMPORTED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILE_KEY_ARG;
import static net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.DIALOG_MODE_KEY;
public class NavigationFragment extends BaseSettingsFragment {
public class NavigationFragment extends BaseSettingsFragment implements OnSelectProfileCallback {
public static final String TAG = NavigationFragment.class.getSimpleName();
public static final String NAVIGATION_TYPE = "navigation_type";
public static final String OSMAND_NAVIGATION = "osmand_navigation";
private SelectProfileBottomSheetDialogFragment.SelectProfileListener navTypeListener;
private Map<String, RoutingProfileDataObject> routingProfileDataObjects;
private Preference navigationType;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
routingProfileDataObjects = getRoutingProfiles(app);
routingProfileDataObjects = ProfileDataUtils.getRoutingProfiles(app);
setupOnBackPressedCallback();
}
@ -134,38 +121,17 @@ public class NavigationFragment extends BaseSettingsFragment {
@Override
public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals(NAVIGATION_TYPE)) {
final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
Bundle bundle = new Bundle();
if (getSelectedAppMode() != null) {
bundle.putString(SELECTED_KEY, getSelectedAppMode().getRoutingProfile());
}
bundle.putString(DIALOG_TYPE, TYPE_NAV_PROFILE);
dialog.setArguments(bundle);
dialog.setUsedOnMap(false);
dialog.setAppMode(getSelectedAppMode());
String routingProfileKey =
getSelectedAppMode() != null ? getSelectedAppMode().getRoutingProfile() : null;
if (getActivity() != null) {
getActivity().getSupportFragmentManager().beginTransaction()
.add(dialog, "select_nav_type").commitAllowingStateLoss();
SelectProfileBottomSheet.showInstance(
getActivity(), SelectProfileBottomSheet.DialogMode.NAVIGATION_PROFILE,
this, routingProfileKey, false);
}
}
return false;
}
public SelectProfileBottomSheetDialogFragment.SelectProfileListener getNavProfileListener() {
if (navTypeListener == null) {
navTypeListener = new SelectProfileBottomSheetDialogFragment.SelectProfileListener() {
@Override
public void onSelectedType(Bundle args) {
if (args.getBoolean(IS_PROFILE_IMPORTED_ARG)) {
routingProfileDataObjects = getRoutingProfiles(app);
}
updateRoutingProfile(args.getString(PROFILE_KEY_ARG));
}
};
}
return navTypeListener;
}
void updateRoutingProfile(String profileKey) {
RoutingProfileDataObject selectedRoutingProfileDataObject = routingProfileDataObjects.get(profileKey);
if (profileKey == null || selectedRoutingProfileDataObject == null) {
@ -193,112 +159,6 @@ public class NavigationFragment extends BaseSettingsFragment {
appMode.setRoutingProfile(profileKey);
}
public static List<RoutingProfileDataObject> getSortedRoutingProfiles(OsmandApplication app) {
List<RoutingProfileDataObject> result = new ArrayList<>();
Map<String, List<RoutingProfileDataObject>> routingProfilesByFileNames = getRoutingProfilesByFileNames(app);
List<String> fileNames = new ArrayList<>(routingProfilesByFileNames.keySet());
Collections.sort(fileNames, new Comparator<String>() {
@Override
public int compare(String s, String t1) {
return s.equals(OSMAND_NAVIGATION) ? -1 : t1.equals(OSMAND_NAVIGATION) ? 1 : s.compareToIgnoreCase(t1);
}
});
for (String fileName : fileNames) {
List<RoutingProfileDataObject> routingProfilesFromFile = routingProfilesByFileNames.get(fileName);
if (routingProfilesFromFile != null) {
Collections.sort(routingProfilesFromFile);
result.addAll(routingProfilesFromFile);
}
}
return result;
}
public static Map<String, List<RoutingProfileDataObject>> getRoutingProfilesByFileNames(OsmandApplication app) {
Map<String, List<RoutingProfileDataObject>> result = new HashMap<>();
for (final RoutingProfileDataObject profile : getRoutingProfiles(app).values()) {
String fileName = profile.getFileName() != null ? profile.getFileName() : OSMAND_NAVIGATION;
if (result.containsKey(fileName)) {
result.get(fileName).add(profile);
} else {
result.put(fileName, new ArrayList<RoutingProfileDataObject>() {
{ add(profile); }
});
}
}
return result;
}
public static Map<String, RoutingProfileDataObject> getRoutingProfiles(OsmandApplication context) {
Map<String, RoutingProfileDataObject> profilesObjects = new HashMap<>();
profilesObjects.put(RoutingProfilesResources.STRAIGHT_LINE_MODE.name(), new RoutingProfileDataObject(
RoutingProfilesResources.STRAIGHT_LINE_MODE.name(),
context.getString(RoutingProfilesResources.STRAIGHT_LINE_MODE.getStringRes()),
context.getString(R.string.special_routing_type),
RoutingProfilesResources.STRAIGHT_LINE_MODE.getIconRes(),
false, null));
profilesObjects.put(RoutingProfilesResources.DIRECT_TO_MODE.name(), new RoutingProfileDataObject(
RoutingProfilesResources.DIRECT_TO_MODE.name(),
context.getString(RoutingProfilesResources.DIRECT_TO_MODE.getStringRes()),
context.getString(R.string.special_routing_type),
RoutingProfilesResources.DIRECT_TO_MODE.getIconRes(),
false, null));
if (context.getBRouterService() != null) {
profilesObjects.put(RoutingProfilesResources.BROUTER_MODE.name(), new RoutingProfileDataObject(
RoutingProfilesResources.BROUTER_MODE.name(),
context.getString(RoutingProfilesResources.BROUTER_MODE.getStringRes()),
context.getString(R.string.third_party_routing_type),
RoutingProfilesResources.BROUTER_MODE.getIconRes(),
false, null));
}
List<String> disabledRouterNames = OsmandPlugin.getDisabledRouterNames();
for (RoutingConfiguration.Builder builder : context.getAllRoutingConfigs()) {
collectRoutingProfilesFromConfig(context, builder, profilesObjects, disabledRouterNames);
}
return profilesObjects;
}
private static void collectRoutingProfilesFromConfig(OsmandApplication app, RoutingConfiguration.Builder builder,
Map<String, RoutingProfileDataObject> profilesObjects, List<String> disabledRouterNames) {
for (Map.Entry<String, GeneralRouter> entry : builder.getAllRouters().entrySet()) {
String routerKey = entry.getKey();
GeneralRouter router = entry.getValue();
if (!routerKey.equals("geocoding") && !disabledRouterNames.contains(router.getFilename())) {
int iconRes = R.drawable.ic_action_gdirections_dark;
String name = router.getProfileName();
String description = app.getString(R.string.osmand_default_routing);
String fileName = router.getFilename();
if (!Algorithms.isEmpty(fileName)) {
description = fileName;
} else if (RoutingProfilesResources.isRpValue(name.toUpperCase())) {
iconRes = RoutingProfilesResources.valueOf(name.toUpperCase()).getIconRes();
name = app.getString(RoutingProfilesResources.valueOf(name.toUpperCase()).getStringRes());
}
profilesObjects.put(routerKey, new RoutingProfileDataObject(routerKey, name, description,
iconRes, false, fileName));
}
}
}
public static List<ProfileDataObject> getBaseProfiles(OsmandApplication app) {
return getBaseProfiles(app, false);
}
public static List<ProfileDataObject> getBaseProfiles(OsmandApplication app, boolean includeBrowseMap) {
List<ProfileDataObject> profiles = new ArrayList<>();
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
if (mode != ApplicationMode.DEFAULT || includeBrowseMap) {
String description = mode.getDescription();
if (Algorithms.isEmpty(description)) {
description = getAppModeDescription(app, mode);
}
profiles.add(new ProfileDataObject(mode.toHumanString(), description,
mode.getStringKey(), mode.getIconRes(), false, mode.getIconColorInfo()));
}
}
return profiles;
}
private void setupVehicleParametersPref() {
Preference vehicleParameters = findPreference("vehicle_parameters");
int iconRes = getSelectedAppMode().getIconRes();
@ -311,4 +171,12 @@ public class NavigationFragment extends BaseSettingsFragment {
mapActivity.getMapRouteInfoMenu().updateMenu();
}
}
@Override
public void onProfileSelected(Bundle args) {
if (args.getBoolean(IS_PROFILE_IMPORTED_ARG)) {
routingProfileDataObjects = ProfileDataUtils.getRoutingProfiles(app);
}
updateRoutingProfile(args.getString(PROFILE_KEY_ARG));
}
}

View file

@ -51,7 +51,9 @@ import net.osmand.plus.profiles.LocationIcon;
import net.osmand.plus.profiles.NavigationIcon;
import net.osmand.plus.profiles.ProfileIconColors;
import net.osmand.plus.profiles.ProfileIcons;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
import net.osmand.plus.profiles.SelectProfileBottomSheet;
import net.osmand.plus.profiles.SelectProfileBottomSheet.DialogMode;
import net.osmand.plus.profiles.SelectProfileBottomSheet.OnSelectProfileCallback;
import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.widgets.FlowLayout;
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
@ -64,13 +66,10 @@ import java.util.ArrayList;
import java.util.Collections;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.IS_PROFILE_IMPORTED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.PROFILE_KEY_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
import static net.osmand.plus.profiles.SelectProfileBottomSheet.IS_PROFILE_IMPORTED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILE_KEY_ARG;
public class ProfileAppearanceFragment extends BaseSettingsFragment {
public class ProfileAppearanceFragment extends BaseSettingsFragment implements OnSelectProfileCallback {
private static final Log LOG = PlatformUtil.getLog(ProfileAppearanceFragment.class);
@ -98,7 +97,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
private static final String IS_BASE_PROFILE_IMPORTED = "is_base_profile_imported";
private static final String IS_NEW_PROFILE_KEY = "is_new_profile_key";
private SelectProfileBottomSheetDialogFragment.SelectProfileListener parentProfileListener;
private SettingsHelper.SettingsExportListener exportListener;
private ProgressDialog progress;
@ -400,18 +398,12 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
public void onClick(View v) {
if (isNewProfile) {
hideKeyboard();
final SelectProfileBottomSheetDialogFragment fragment = new SelectProfileBottomSheetDialogFragment();
Bundle bundle = new Bundle();
fragment.setUsedOnMap(false);
fragment.setAppMode(getSelectedAppMode());
if (changedProfile.parent != null) {
bundle.putString(SELECTED_KEY, changedProfile.parent.getStringKey());
}
bundle.putString(DIALOG_TYPE, TYPE_BASE_APP_PROFILE);
fragment.setArguments(bundle);
String selectedAppModeKey =
changedProfile.parent != null ? changedProfile.parent.getStringKey() : null;
if (getActivity() != null) {
getActivity().getSupportFragmentManager().beginTransaction()
.add(fragment, "select_nav_type").commitAllowingStateLoss();
SelectProfileBottomSheet.showInstance(
getActivity(), DialogMode.BASE_PROFILE, ProfileAppearanceFragment.this,
selectedAppModeKey, false);
}
}
}
@ -709,20 +701,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
}
}
public SelectProfileBottomSheetDialogFragment.SelectProfileListener getParentProfileListener() {
if (parentProfileListener == null) {
parentProfileListener = new SelectProfileBottomSheetDialogFragment.SelectProfileListener() {
@Override
public void onSelectedType(Bundle args) {
String profileKey = args.getString(PROFILE_KEY_ARG);
boolean imported = args.getBoolean(IS_PROFILE_IMPORTED_ARG);
updateParentProfile(profileKey, imported);
}
};
}
return parentProfileListener;
}
private SettingsHelper.SettingsExportListener getSettingsExportListener() {
if (exportListener == null) {
exportListener = new SettingsHelper.SettingsExportListener() {
@ -953,6 +931,13 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
}
}
@Override
public void onProfileSelected(Bundle args) {
String profileKey = args.getString(PROFILE_KEY_ARG);
boolean imported = args.getBoolean(IS_PROFILE_IMPORTED_ARG);
updateParentProfile(profileKey, imported);
}
public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType, @Nullable String appMode, boolean imported) {
try {
Fragment fragment = Fragment.instantiate(activity, screenType.fragmentName);