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 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="reverse_all_points">Reverse all points</string>
<string name="release_3_9"> <string name="release_3_9">
• Added option to export and import all data including settings, resources, my places\n\n • 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" xmlns:tools="http://schemas.android.com/tools"
android:title="@string/osmand_settings"> android:title="@string/osmand_settings">
<net.osmand.plus.settings.preferences.ListPreferenceEx <Preference
android:icon="@drawable/ic_world_globe_dark"
android:key="default_application_mode_string" android:key="default_application_mode_string"
android:icon="@drawable/ic_world_globe_dark"
android:persistent="false"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:title="@string/settings_preset" /> 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.measurementtool.StartPlanRouteBottomSheet;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.dialogs.DismissRouteBottomSheetFragment; import net.osmand.plus.osmedit.dialogs.DismissRouteBottomSheetFragment;
import net.osmand.plus.profiles.ProfileDataUtils;
import net.osmand.plus.profiles.RoutingProfileDataObject; import net.osmand.plus.profiles.RoutingProfileDataObject;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routepreparationmenu.WaypointsFragment; 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_CHOSEN_PROFILE_TAG;
import static net.osmand.plus.ContextMenuAdapter.PROFILES_CONTROL_BUTTON_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.ContextMenuAdapter.PROFILES_NORMAL_PROFILE_TAG;
import static net.osmand.plus.settings.fragments.NavigationFragment.getRoutingProfiles;
public class MapActivityActions implements DialogProvider { public class MapActivityActions implements DialogProvider {
@ -737,7 +737,7 @@ public class MapActivityActions implements DialogProvider {
String modeDescription; String modeDescription;
Map<String, RoutingProfileDataObject> profilesObjects = getRoutingProfiles(app); Map<String, RoutingProfileDataObject> profilesObjects = ProfileDataUtils.getRoutingProfiles(app);
for (final ApplicationMode appMode : activeModes) { for (final ApplicationMode appMode : activeModes) {
if (appMode.isCustomProfile()) { if (appMode.isCustomProfile()) {
modeDescription = getProfileDescription(app, appMode, profilesObjects, getString(R.string.profile_type_user_string)); modeDescription = getProfileDescription(app, appMode, profilesObjects, getString(R.string.profile_type_user_string));
@ -1046,7 +1046,7 @@ public class MapActivityActions implements DialogProvider {
//switch profile button //switch profile button
ApplicationMode currentMode = app.getSettings().APPLICATION_MODE.get(); ApplicationMode currentMode = app.getSettings().APPLICATION_MODE.get();
String modeDescription; String modeDescription;
Map<String, RoutingProfileDataObject> profilesObjects = getRoutingProfiles(app); Map<String, RoutingProfileDataObject> profilesObjects = ProfileDataUtils.getRoutingProfiles(app);
if (currentMode.isCustomProfile()) { if (currentMode.isCustomProfile()) {
modeDescription = getProfileDescription(app, currentMode, profilesObjects, getString(R.string.profile_type_user_string)); modeDescription = getProfileDescription(app, currentMode, profilesObjects, getString(R.string.profile_type_user_string));
} else { } else {

View file

@ -15,6 +15,7 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.profiles.ProfileDataUtils;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; 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.download.IndexItem;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.widgets.style.CustomTypefaceSpan; import net.osmand.plus.widgets.style.CustomTypefaceSpan;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -221,7 +221,7 @@ public class PluginInstalledBottomSheetDialog extends MenuBottomSheetDialogFragm
final BottomSheetItemWithCompoundButton[] appModeItem = new BottomSheetItemWithCompoundButton[1]; final BottomSheetItemWithCompoundButton[] appModeItem = new BottomSheetItemWithCompoundButton[1];
appModeItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() appModeItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setChecked(ApplicationMode.values(app).contains(mode)) .setChecked(ApplicationMode.values(app).contains(mode))
.setDescription(BaseSettingsFragment.getAppModeDescription(app, mode)) .setDescription(ProfileDataUtils.getAppModeDescription(app, mode))
.setTitle(mode.toHumanString()) .setTitle(mode.toHumanString())
.setIcon(getActiveIcon(mode.getIconRes())) .setIcon(getActiveIcon(mode.getIconRes()))
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_switch_56dp) .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.settings.backend.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -105,7 +104,7 @@ public class ConfigureProfileMenuAdapter extends AbstractProfileMenuAdapter<Conf
holder.menuIcon.setVisibility(View.VISIBLE); holder.menuIcon.setVisibility(View.VISIBLE);
final ApplicationMode item = (ApplicationMode) obj; final ApplicationMode item = (ApplicationMode) obj;
holder.title.setText(item.toHumanString()); holder.title.setText(item.toHumanString());
holder.descr.setText(BaseSettingsFragment.getAppModeDescription(app, item)); holder.descr.setText(ProfileDataUtils.getAppModeDescription(app, item));
holder.initSwitcher = true; holder.initSwitcher = true;
holder.compoundButton.setChecked(selectedItems.contains(item)); 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.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import java.util.ArrayList; import java.util.ArrayList;
@ -241,7 +240,7 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
if (order == null) { if (order == null) {
order = mode.getOrder(); 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)); 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.ColorRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
public class ProfileDataObject implements Comparable<ProfileDataObject> { public class ProfileDataObject implements Comparable<ProfileDataObject> {
private String name; private String name;
@ -62,4 +63,5 @@ public class ProfileDataObject implements Comparable<ProfileDataObject> {
public int compareTo(@NonNull ProfileDataObject another) { public int compareTo(@NonNull ProfileDataObject another) {
return this.name.compareToIgnoreCase(another.name); 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); 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.activities.MapActivity;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; 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 net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
import java.util.ArrayList; import java.util.ArrayList;
@ -54,7 +54,8 @@ public class SelectMultipleProfilesBottomSheet extends BasePreferenceBottomSheet
private void refreshProfiles(OsmandApplication app) { private void refreshProfiles(OsmandApplication app) {
profiles.clear(); profiles.clear();
profiles.addAll(NavigationFragment.getBaseProfiles(app, true)); List<ApplicationMode> appModes = ApplicationMode.allPossibleValues();
profiles.addAll(ProfileDataUtils.getDataObjects(app, appModes));
for (ProfileDataObject profile : profiles) { for (ProfileDataObject profile : profiles) {
String key = profile.getStringKey(); String key = profile.getStringKey();
profile.setSelected(selectedProfiles.contains(key)); profile.setSelected(selectedProfiles.contains(key));

View file

@ -2,8 +2,12 @@ package net.osmand.plus.profiles;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Bundle; 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;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -15,6 +19,8 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager; 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.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; 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.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.fragments.MainSettingsFragment; import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.settings.fragments.NavigationFragment; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.fragments.ProfileAppearanceFragment;
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet; import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
import net.osmand.router.RoutingConfiguration; import net.osmand.router.RoutingConfiguration;
@ -42,35 +48,36 @@ import java.util.List;
import static net.osmand.plus.importfiles.ImportHelper.ImportType.ROUTING; 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 private static final Log LOG = PlatformUtil.getLog(SelectProfileBottomSheet.class);
.getLog(SelectProfileBottomSheetDialogFragment.class); public static final String TAG = "SelectProfileBottomSheet";
public static final String TAG = "SelectProfileBottomSheetDialogFragment";
public final static String DIALOG_TYPE = "dialog_type"; 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 SELECTED_KEY = "selected_base";
public final static String PROFILE_KEY_ARG = "profile_key_arg"; 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"; public final static String IS_PROFILE_IMPORTED_ARG = "is_profile_imported_arg";
String type; private DialogMode dialogMode;
private SelectProfileListener listener;
private final List<ProfileDataObject> profiles = new ArrayList<>(); private final List<ProfileDataObject> profiles = new ArrayList<>();
private String selectedItemKey; private String selectedItemKey;
public enum DialogMode {
BASE_PROFILE,
NAVIGATION_PROFILE,
DEFAULT_PROFILE
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
Bundle args = getArguments(); Bundle args = getArguments();
if (args != null && args.get(DIALOG_TYPE) != null) { 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); selectedItemKey = args.getString(SELECTED_KEY, null);
refreshProfiles(app); refreshProfiles(app);
} }
@ -96,7 +103,7 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
int space = (int) getResources().getDimension(R.dimen.empty_state_text_button_padding_top); int space = (int) getResources().getDimension(R.dimen.empty_state_text_button_padding_top);
bottomSpaceView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, space)); 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 TitleItem(getString(R.string.select_base_profile_dialog_title)));
items.add(new LongDescriptionItem(getString(R.string.select_base_profile_dialog_message))); items.add(new LongDescriptionItem(getString(R.string.select_base_profile_dialog_message)));
for (int i = 0; i < profiles.size(); i++) { for (int i = 0; i < profiles.size(); i++) {
@ -138,7 +145,7 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
.setCustomView(bottomSpaceView) .setCustomView(bottomSpaceView)
.create());*/ .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 TitleItem(getString(R.string.select_nav_profile_dialog_title)));
items.add(new LongDescriptionItem(getString(R.string.select_nav_profile_dialog_message))); items.add(new LongDescriptionItem(getString(R.string.select_nav_profile_dialog_message)));
for (int i = 0; i < profiles.size(); i++) { for (int i = 0; i < profiles.size(); i++) {
@ -175,10 +182,39 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
items.add(new BaseBottomSheetItem.Builder() items.add(new BaseBottomSheetItem.Builder()
.setCustomView(bottomSpaceView) .setCustomView(bottomSpaceView)
.create()); .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) { 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(); OsmandApplication app = requiredMyApplication();
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
@ -194,12 +230,12 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
tvTitle.setText(profile.getName()); tvTitle.setText(profile.getName());
tvDescription.setText(profile.getDescription()); tvDescription.setText(profile.getDescription());
boolean isSelected = profile.getStringKey().equals(selectedItemKey); boolean isSelected = setupSelected && profile.getStringKey().equals(selectedItemKey);
int iconColor; int iconColor;
if (type.equals(TYPE_BASE_APP_PROFILE)) { if (dialogMode == DialogMode.NAVIGATION_PROFILE) {
iconColor = profile.getIconColor(nightMode);
} else {
iconColor = isSelected ? activeColorResId : iconDefaultColorResId; iconColor = isSelected ? activeColorResId : iconDefaultColorResId;
} else {
iconColor = profile.getIconColor(nightMode);
} }
Drawable drawableIcon = app.getUIUtilities().getIcon(profile.getIconRes(), iconColor); Drawable drawableIcon = app.getUIUtilities().getIcon(profile.getIconRes(), iconColor);
@ -213,18 +249,46 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
.setOnClickListener(new OnClickListener() { .setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (listener == null) {
getListener();
}
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(PROFILE_KEY_ARG, profile.getStringKey()); args.putString(PROFILE_KEY_ARG, profile.getStringKey());
listener.onSelectedType(args); Fragment target = getTargetFragment();
if (target instanceof OnSelectProfileCallback) {
((OnSelectProfileCallback) target).onProfileSelected(args);
}
dismiss(); dismiss();
} }
}) })
.create()); .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) { private void addButtonItem(int titleId, int iconId, OnClickListener listener) {
OsmandApplication app = requiredMyApplication(); OsmandApplication app = requiredMyApplication();
Context themedCtx = UiUtilities.getThemedContext(app, nightMode); Context themedCtx = UiUtilities.getThemedContext(app, nightMode);
@ -233,7 +297,7 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
View buttonView = View.inflate(themedCtx, R.layout.bottom_sheet_item_preference_btn, null); View buttonView = View.inflate(themedCtx, R.layout.bottom_sheet_item_preference_btn, null);
TextView tvTitle = buttonView.findViewById(R.id.title); TextView tvTitle = buttonView.findViewById(R.id.title);
tvTitle.setText(app.getString(titleId)); tvTitle.setText(getString(titleId));
ImageView ivIcon = buttonView.findViewById(R.id.icon); ImageView ivIcon = buttonView.findViewById(R.id.icon);
ivIcon.setImageDrawable(app.getUIUtilities().getIcon(iconId, activeColorResId)); ivIcon.setImageDrawable(app.getUIUtilities().getIcon(iconId, activeColorResId));
@ -244,18 +308,6 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
.create()); .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() { private void refreshView() {
Activity activity = getActivity(); Activity activity = getActivity();
View mainView = getView(); View mainView = getView();
@ -275,28 +327,25 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
} }
} }
private void getListener() { private void refreshProfiles(OsmandApplication app) {
FragmentActivity activity = getActivity(); profiles.clear();
if (activity != null) { switch (dialogMode) {
FragmentManager fragmentManager = activity.getSupportFragmentManager(); case BASE_PROFILE:
NavigationFragment navigationFragment = (NavigationFragment) fragmentManager.findFragmentByTag(NavigationFragment.class.getName()); List<ApplicationMode> appModes = new ArrayList<>(ApplicationMode.allPossibleValues());
ProfileAppearanceFragment profileAppearanceFragment = (ProfileAppearanceFragment) fragmentManager.findFragmentByTag(ProfileAppearanceFragment.TAG); appModes.remove(ApplicationMode.DEFAULT);
MainSettingsFragment mainSettingsFragment = (MainSettingsFragment) fragmentManager.findFragmentByTag(MainSettingsFragment.TAG); profiles.addAll(ProfileDataUtils.getDataObjects(app, appModes));
break;
if (navigationFragment != null) { case NAVIGATION_PROFILE:
listener = navigationFragment.getNavProfileListener(); profiles.addAll(ProfileDataUtils.getSortedRoutingProfiles(app));
} else if (profileAppearanceFragment != null) { break;
listener = profileAppearanceFragment.getParentProfileListener();
} else if (mainSettingsFragment != null) { case DEFAULT_PROFILE:
listener = mainSettingsFragment.getParentProfileListener(); profiles.addAll(ProfileDataUtils.getDataObjects(app, ApplicationMode.values(app)));
} break;
} }
} }
public interface SelectProfileListener {
void onSelectedType(Bundle args);
}
@Nullable @Nullable
private MapActivity getMapActivity() { private MapActivity getMapActivity() {
Activity activity = getActivity(); Activity activity = getActivity();
@ -305,4 +354,23 @@ public class SelectProfileBottomSheetDialogFragment extends BasePreferenceBottom
} }
return null; 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.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -99,7 +98,7 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter<SelectP
holder.menuIcon.setVisibility(View.GONE); holder.menuIcon.setVisibility(View.GONE);
final ApplicationMode item = (ApplicationMode) obj; final ApplicationMode item = (ApplicationMode) obj;
holder.title.setText(item.toHumanString()); 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); int profileColorResId = item.getIconColorInfo().getColor(nightMode);
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(profileColorResId, selectedIconColorRes)); holder.icon.setImageDrawable(app.getUIUtilities().getIcon(profileColorResId, selectedIconColorRes));

View file

@ -425,6 +425,7 @@ public class OsmandSettings {
if (valueSaved) { if (valueSaved) {
currentMode = val; currentMode = val;
profilePreferences = getProfilePreferences(currentMode); profilePreferences = getProfilePreferences(currentMode);
LAST_USED_APPLICATION_MODE.set(currentMode.getStringKey());
fireEvent(oldMode); 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<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) { public final OsmandPreference<ApplicationMode> DEFAULT_APPLICATION_MODE = new CommonPreference<ApplicationMode>(this, "default_application_mode_string", ApplicationMode.DEFAULT) {
@Override @Override
protected ApplicationMode getValue(Object prefs, ApplicationMode defaultValue) { 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); 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.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import net.osmand.plus.profiles.ProfileDataUtils;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; 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.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
public class ResetProfilePrefsBottomSheet extends BasePreferenceBottomSheet { public class ResetProfilePrefsBottomSheet extends BasePreferenceBottomSheet {
@ -48,7 +48,7 @@ public class ResetProfilePrefsBottomSheet extends BasePreferenceBottomSheet {
.setChecked(true) .setChecked(true)
.setCompoundButtonColorId(profileColor) .setCompoundButtonColorId(profileColor)
.setButtonTintList(ColorStateList.valueOf(getResolvedColor(profileColor))) .setButtonTintList(ColorStateList.valueOf(getResolvedColor(profileColor)))
.setDescription(BaseSettingsFragment.getAppModeDescription(ctx, mode)) .setDescription(ProfileDataUtils.getAppModeDescription(ctx, mode))
.setIcon(getIcon(mode.getIconRes(), profileColor)) .setIcon(getIcon(mode.getIconRes(), profileColor))
.setTitle(mode.toHumanString()) .setTitle(mode.toHumanString())
.setBackground(new LayerDrawable(layers)) .setBackground(new LayerDrawable(layers))

View file

@ -2,7 +2,6 @@ package net.osmand.plus.settings.fragments;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -883,17 +882,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return listPreference; 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) { public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType) {
return showInstance(activity, screenType, null); return showInstance(activity, screenType, null);
} }

View file

@ -2,6 +2,7 @@ package net.osmand.plus.settings.fragments;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.os.Bundle;
import android.util.Pair; import android.util.Pair;
import android.widget.ImageView; 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;
import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment.OnSendAnalyticsPrefsUpdate; import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment.OnSendAnalyticsPrefsUpdate;
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet; 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.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx; 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 public class GlobalSettingsFragment extends BaseSettingsFragment
implements OnSendAnalyticsPrefsUpdate, OnPreferenceChanged { implements OnSendAnalyticsPrefsUpdate, OnPreferenceChanged, OnSelectProfileCallback {
public static final String TAG = GlobalSettingsFragment.class.getSimpleName(); public static final String TAG = GlobalSettingsFragment.class.getSimpleName();
@ -94,9 +101,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment
@Override @Override
public void onPreferenceChanged(String prefId) { public void onPreferenceChanged(String prefId) {
if (prefId.equals(settings.DEFAULT_APPLICATION_MODE.getId())) { if (prefId.equals(settings.PREFERRED_LOCALE.getId())) {
setupDefaultAppModePref();
} else if (prefId.equals(settings.PREFERRED_LOCALE.getId())) {
// recreate activity to update locale // recreate activity to update locale
Activity activity = getActivity(); Activity activity = getActivity();
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
@ -117,7 +122,13 @@ public class GlobalSettingsFragment extends BaseSettingsFragment
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
String prefId = preference.getKey(); 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(); FragmentManager fm = getFragmentManager();
if (fm != null) { if (fm != null) {
SpeedCamerasBottomSheet.showInstance(fm, this); SpeedCamerasBottomSheet.showInstance(fm, this);
@ -127,23 +138,20 @@ public class GlobalSettingsFragment extends BaseSettingsFragment
} }
private void setupDefaultAppModePref() { private void setupDefaultAppModePref() {
OsmandApplication app = getMyApplication(); Preference defaultApplicationMode = (Preference) findPreference(settings.DEFAULT_APPLICATION_MODE.getId());
if (app == null) { int iconColor = settings.getApplicationMode().getIconColorInfo().getColor(isNightMode());
return; 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]); defaultApplicationMode.setIcon(getIcon(iconId, iconColor));
String[] entries = new String[appModes.length]; defaultApplicationMode.setSummary(summary);
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);
} }
private void setupPreferredLocalePref() { 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); 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) { public static Pair<String[], String[]> getPreferredLocaleIdsAndValues(Context ctx) {
// See language list and statistics at: https://hosted.weblate.org/projects/osmand/main/ // See language list and statistics at: https://hosted.weblate.org/projects/osmand/main/
// Hardy maintenance 2016-05-29: // 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.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment; import net.osmand.plus.profiles.ProfileDataUtils;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener; 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.ApplicationMode;
import net.osmand.plus.settings.backend.backup.SettingsItem; import net.osmand.plus.settings.backend.backup.SettingsItem;
import net.osmand.plus.settings.backend.backup.SettingsItemType; import net.osmand.plus.settings.backend.backup.SettingsItemType;
@ -33,12 +35,10 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import static net.osmand.plus.importfiles.ImportHelper.ImportType.SETTINGS; import static net.osmand.plus.importfiles.ImportHelper.ImportType.SETTINGS;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE; import static net.osmand.plus.profiles.SelectProfileBottomSheet.IS_PROFILE_IMPORTED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.IS_PROFILE_IMPORTED_ARG; import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILE_KEY_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.PROFILE_KEY_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
public class MainSettingsFragment extends BaseSettingsFragment { public class MainSettingsFragment extends BaseSettingsFragment implements OnSelectProfileCallback{
public static final String TAG = MainSettingsFragment.class.getName(); public static final String TAG = MainSettingsFragment.class.getName();
@ -52,7 +52,6 @@ public class MainSettingsFragment extends BaseSettingsFragment {
private List<ApplicationMode> allAppModes; private List<ApplicationMode> allAppModes;
private Set<ApplicationMode> availableAppModes; private Set<ApplicationMode> availableAppModes;
private SelectProfileListener selectProfileListener = null;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -119,15 +118,9 @@ public class MainSettingsFragment extends BaseSettingsFragment {
ApplicationMode.valueOfStringKey(prefId, null)); ApplicationMode.valueOfStringKey(prefId, null));
return true; return true;
} else if (CREATE_PROFILE.equals(prefId)) { } 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) { if (getActivity() != null) {
getActivity().getSupportFragmentManager().beginTransaction() SelectProfileBottomSheet.showInstance(getActivity(),
.add(dialog, "select_base_profile").commitAllowingStateLoss(); DialogMode.BASE_PROFILE, this, null, false);
} }
} else if (IMPORT_PROFILE.equals(prefId)) { } else if (IMPORT_PROFILE.equals(prefId)) {
final MapActivity mapActivity = getMapActivity(); final MapActivity mapActivity = getMapActivity();
@ -162,7 +155,7 @@ public class MainSettingsFragment extends BaseSettingsFragment {
private void setupConfigureProfilePref() { private void setupConfigureProfilePref() {
ApplicationMode selectedMode = app.getSettings().APPLICATION_MODE.get(); ApplicationMode selectedMode = app.getSettings().APPLICATION_MODE.get();
String title = selectedMode.toHumanString(); String title = selectedMode.toHumanString();
String profileType = getAppModeDescription(getContext(), selectedMode); String profileType = ProfileDataUtils.getAppModeDescription(getContext(), selectedMode);
Preference configureProfile = findPreference(CONFIGURE_PROFILE); Preference configureProfile = findPreference(CONFIGURE_PROFILE);
configureProfile.setIcon(getAppProfilesIcon(selectedMode, true)); configureProfile.setIcon(getAppProfilesIcon(selectedMode, true));
configureProfile.setTitle(title); configureProfile.setTitle(title);
@ -200,7 +193,7 @@ public class MainSettingsFragment extends BaseSettingsFragment {
pref.setIcon(getAppProfilesIcon(applicationMode, isAppProfileEnabled)); pref.setIcon(getAppProfilesIcon(applicationMode, isAppProfileEnabled));
pref.setTitle(applicationMode.toHumanString()); pref.setTitle(applicationMode.toHumanString());
pref.setSummary(getAppModeDescription(getContext(), applicationMode)); pref.setSummary(ProfileDataUtils.getAppModeDescription(getContext(), applicationMode));
pref.setChecked(isAppProfileEnabled); pref.setChecked(isAppProfileEnabled);
pref.setLayoutResource(R.layout.preference_with_descr_dialog_and_switch); pref.setLayoutResource(R.layout.preference_with_descr_dialog_and_switch);
pref.setFragment(ConfigureProfileFragment.class.getName()); 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); : 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 @Override
public void onPause() { public void onPause() {
updateRouteInfoMenu(); updateRouteInfoMenu();
super.onPause(); 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 androidx.preference.SwitchPreferenceCompat;
import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.profiles.ProfileDataUtils;
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet; import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet;
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.DialogMode; import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.DialogMode;
import net.osmand.plus.settings.backend.ApplicationMode; 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.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.profiles.ProfileDataObject;
import net.osmand.plus.profiles.RoutingProfileDataObject; import net.osmand.plus.profiles.RoutingProfileDataObject;
import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources; 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.routing.RouteProvider;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import net.osmand.router.GeneralRouter;
import net.osmand.router.RoutingConfiguration;
import net.osmand.util.Algorithms; 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 java.util.Map;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE; import static net.osmand.plus.profiles.SelectProfileBottomSheet.IS_PROFILE_IMPORTED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.IS_PROFILE_IMPORTED_ARG; import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILE_KEY_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.routepreparationmenu.RouteOptionsBottomSheet.DIALOG_MODE_KEY; 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 TAG = NavigationFragment.class.getSimpleName();
public static final String NAVIGATION_TYPE = "navigation_type"; 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 Map<String, RoutingProfileDataObject> routingProfileDataObjects;
private Preference navigationType; private Preference navigationType;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
routingProfileDataObjects = getRoutingProfiles(app); routingProfileDataObjects = ProfileDataUtils.getRoutingProfiles(app);
setupOnBackPressedCallback(); setupOnBackPressedCallback();
} }
@ -134,38 +121,17 @@ public class NavigationFragment extends BaseSettingsFragment {
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals(NAVIGATION_TYPE)) { if (preference.getKey().equals(NAVIGATION_TYPE)) {
final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment(); String routingProfileKey =
Bundle bundle = new Bundle(); getSelectedAppMode() != null ? getSelectedAppMode().getRoutingProfile() : null;
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());
if (getActivity() != null) { if (getActivity() != null) {
getActivity().getSupportFragmentManager().beginTransaction() SelectProfileBottomSheet.showInstance(
.add(dialog, "select_nav_type").commitAllowingStateLoss(); getActivity(), SelectProfileBottomSheet.DialogMode.NAVIGATION_PROFILE,
this, routingProfileKey, false);
} }
} }
return 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) { void updateRoutingProfile(String profileKey) {
RoutingProfileDataObject selectedRoutingProfileDataObject = routingProfileDataObjects.get(profileKey); RoutingProfileDataObject selectedRoutingProfileDataObject = routingProfileDataObjects.get(profileKey);
if (profileKey == null || selectedRoutingProfileDataObject == null) { if (profileKey == null || selectedRoutingProfileDataObject == null) {
@ -193,112 +159,6 @@ public class NavigationFragment extends BaseSettingsFragment {
appMode.setRoutingProfile(profileKey); 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() { private void setupVehicleParametersPref() {
Preference vehicleParameters = findPreference("vehicle_parameters"); Preference vehicleParameters = findPreference("vehicle_parameters");
int iconRes = getSelectedAppMode().getIconRes(); int iconRes = getSelectedAppMode().getIconRes();
@ -311,4 +171,12 @@ public class NavigationFragment extends BaseSettingsFragment {
mapActivity.getMapRouteInfoMenu().updateMenu(); 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.NavigationIcon;
import net.osmand.plus.profiles.ProfileIconColors; import net.osmand.plus.profiles.ProfileIconColors;
import net.osmand.plus.profiles.ProfileIcons; 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.routing.RouteProvider;
import net.osmand.plus.widgets.FlowLayout; import net.osmand.plus.widgets.FlowLayout;
import net.osmand.plus.widgets.OsmandTextFieldBoxes; import net.osmand.plus.widgets.OsmandTextFieldBoxes;
@ -64,13 +66,10 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE; import static net.osmand.plus.profiles.SelectProfileBottomSheet.IS_PROFILE_IMPORTED_ARG;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.IS_PROFILE_IMPORTED_ARG; import static net.osmand.plus.profiles.SelectProfileBottomSheet.PROFILE_KEY_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;
public class ProfileAppearanceFragment extends BaseSettingsFragment { public class ProfileAppearanceFragment extends BaseSettingsFragment implements OnSelectProfileCallback {
private static final Log LOG = PlatformUtil.getLog(ProfileAppearanceFragment.class); 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_BASE_PROFILE_IMPORTED = "is_base_profile_imported";
private static final String IS_NEW_PROFILE_KEY = "is_new_profile_key"; private static final String IS_NEW_PROFILE_KEY = "is_new_profile_key";
private SelectProfileBottomSheetDialogFragment.SelectProfileListener parentProfileListener;
private SettingsHelper.SettingsExportListener exportListener; private SettingsHelper.SettingsExportListener exportListener;
private ProgressDialog progress; private ProgressDialog progress;
@ -400,18 +398,12 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
public void onClick(View v) { public void onClick(View v) {
if (isNewProfile) { if (isNewProfile) {
hideKeyboard(); hideKeyboard();
final SelectProfileBottomSheetDialogFragment fragment = new SelectProfileBottomSheetDialogFragment(); String selectedAppModeKey =
Bundle bundle = new Bundle(); changedProfile.parent != null ? changedProfile.parent.getStringKey() : null;
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);
if (getActivity() != null) { if (getActivity() != null) {
getActivity().getSupportFragmentManager().beginTransaction() SelectProfileBottomSheet.showInstance(
.add(fragment, "select_nav_type").commitAllowingStateLoss(); 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() { private SettingsHelper.SettingsExportListener getSettingsExportListener() {
if (exportListener == null) { if (exportListener == null) {
exportListener = new SettingsHelper.SettingsExportListener() { 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) { public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType, @Nullable String appMode, boolean imported) {
try { try {
Fragment fragment = Fragment.instantiate(activity, screenType.fragmentName); Fragment fragment = Fragment.instantiate(activity, screenType.fragmentName);