Add profile appearance draft with save changing

This commit is contained in:
Dima-1 2019-12-18 22:15:24 +02:00
parent 185ec7fe55
commit 0f5448795c
11 changed files with 224 additions and 148 deletions

View file

@ -239,7 +239,7 @@
android:tint="@color/settings_divider"/>
<net.osmand.plus.widgets.OsmandTextFieldBoxes
android:id="@+id/navigation_type_otfb"
android:id="@+id/master_profile_otfb"
android:layout_width="match_parent"
android:layout_height="60dp"
app:primaryColor="@color/active_color_primary_dark"
@ -247,7 +247,7 @@
app:labelText="@string/nav_type_hint">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/navigation_type_et"
android:id="@+id/master_profile_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"

View file

@ -25,15 +25,15 @@
android:tint="@color/settings_divider"/>
<net.osmand.plus.widgets.OsmandTextFieldBoxes
android:id="@+id/navigation_type_otfb"
android:id="@+id/master_profile_otfb"
android:layout_width="match_parent"
android:layout_height="60dp"
app:primaryColor="@color/active_color_primary_dark"
app:secondaryColor="?android:textColorSecondary"
app:labelText="@string/nav_type_hint">
app:labelText="@string/master_profile">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/navigation_type_et"
android:id="@+id/master_profile_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"

View file

@ -11,6 +11,8 @@
Thx - Hardy
-->
<string name="select_navigation_icon">Select navigation icon</string>
<string name="select_map_icon">Select map icon</string>
<string name="delete_profiles_descr">After you tap Apply, deleted profiles will be lost completely.</string>
<string name="master_profile">Master profile</string>
<string name="select_color">Select color</string>

View file

@ -52,12 +52,12 @@
<PreferenceCategory
android:key="select_map_icon"
android:layout="@layout/preference_category_with_descr"
android:title="@string/map_during_navigation" />
android:title="@string/select_map_icon" />
<Preference
android:key="map_icon_items"
android:layout="@layout/preference_with_descr"
android:title="@string/map_during_navigation"
android:title="@string/select_map_icon"
android:selectable="false"/>
<Preference
@ -67,12 +67,12 @@
<PreferenceCategory
android:key="select_nav_icon"
android:layout="@layout/preference_category_with_descr"
android:title="@string/map_during_navigation" />
android:title="@string/select_navigation_icon" />
<Preference
android:key="nav_icon_items"
android:layout="@layout/preference_with_descr"
android:title="@string/map_during_navigation"
android:title="@string/select_navigation_icon"
android:selectable="false"/>
</PreferenceScreen>

View file

@ -3,6 +3,7 @@ package net.osmand.plus;
import android.content.Context;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import com.google.gson.Gson;
@ -862,4 +863,79 @@ public class ApplicationMode {
return nightMode ? nightColor : dayColor;
}
}
public enum ProfileIcons {
CAR(R.drawable.ic_action_car_dark, R.string.app_mode_car, "ic_action_car_dark", false),
TAXI(R.drawable.ic_action_taxi, R.string.app_mode_taxi, "ic_action_taxi", false),
TRUCK(R.drawable.ic_action_truck_dark, R.string.app_mode_truck, "ic_action_truck_dark", false),
SHUTTLE_BUS(R.drawable.ic_action_shuttle_bus, R.string.app_mode_shuttle_bus, "ic_action_shuttle_bus", false),
BUS(R.drawable.ic_action_bus_dark, R.string.app_mode_bus, "ic_action_bus_dark", false),
SUBWAY(R.drawable.ic_action_subway, R.string.app_mode_subway, "ic_action_subway", false),
MOTORCYCLE(R.drawable.ic_action_motorcycle_dark, R.string.app_mode_motorcycle, "ic_action_motorcycle_dark", false),
BICYCLE(R.drawable.ic_action_bicycle_dark, R.string.app_mode_bicycle, "ic_action_bicycle_dark", false),
HORSE(R.drawable.ic_action_horse, R.string.app_mode_horse, "ic_action_horse", false),
PEDESTRIAN(R.drawable.ic_action_pedestrian_dark, R.string.app_mode_pedestrian, "ic_action_pedestrian_dark", false),
TREKKING(R.drawable.ic_action_trekking_dark, R.string.app_mode_hiking, "ic_action_trekking_dark", false),
SKIING(R.drawable.ic_action_skiing, R.string.app_mode_skiing, "ic_action_skiing", false),
SAIL_BOAT(R.drawable.ic_action_sail_boat_dark, R.string.app_mode_boat, "ic_action_sail_boat_dark", false),
AIRCRAFT(R.drawable.ic_action_aircraft, R.string.app_mode_aircraft, "ic_action_aircraft", false),
HELICOPTER(R.drawable.ic_action_helicopter, R.string.app_mode_helicopter, "ic_action_helicopter", false),
TRANSPORTER(R.drawable.ic_action_personal_transporter, R.string.app_mode_personal_transporter, "ic_action_personal_transporter", false),
MONOWHEEL(R.drawable.ic_action_monowheel, R.string.app_mode_monowheel, "ic_action_monowheel", false),
SCOOTER(R.drawable.ic_action_scooter, R.string.app_mode_scooter, "ic_action_scooter", false),
UFO(R.drawable.ic_action_ufo, R.string.app_mode_ufo, "ic_action_ufo", false),
OFFROAD(R.drawable.ic_action_offroad, R.string.app_mode_offroad, "ic_action_offroad", false),
CAMPERVAN(R.drawable.ic_action_campervan, R.string.app_mode_campervan, "ic_action_campervan", false),
CAMPER(R.drawable.ic_action_camper, R.string.app_mode_camper, "ic_action_camper", false),
PICKUP_TRUCK(R.drawable.ic_action_pickup_truck, R.string.app_mode_pickup_truck, "ic_action_pickup_truck", false),
WAGON(R.drawable.ic_action_wagon, R.string.app_mode_wagon, "ic_action_wagon", false),
UTV(R.drawable.ic_action_utv, R.string.app_mode_utv, "ic_action_utv", false);
@DrawableRes
private int resId;
@StringRes
private int titleId;
private String resStringId;
private boolean isSelected;
ProfileIcons(@DrawableRes int resId, @StringRes int titleId, @NonNull String resStringId, boolean isSelected) {
this.resId = resId;
this.titleId = titleId;
this.isSelected = isSelected;
this.resStringId = resStringId;
}
public static ArrayList<Integer> getIcons() {
ArrayList<Integer> list = new ArrayList<>();
for (ProfileIcons pi : values()) {
list.add(pi.resId);
}
return list;
}
public int getResId() {
return resId;
}
public int getTitleId() {
return titleId;
}
public String getResStringId() {
return resStringId;
}
public static String getResStringByResId(int resId) {
for (ProfileIcons pi : values()) {
if (pi.resId == resId) {
return pi.resStringId;
}
}
return CAR.getResStringId();
}
public boolean isSelected() {
return isSelected;
}
}
}

View file

@ -133,6 +133,7 @@ import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType;
import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.plus.settings.BaseSettingsFragment.SettingsScreenType;
import net.osmand.plus.settings.DataStorageFragment;
import net.osmand.plus.settings.ProfileAppearanceFragment;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapControlsLayer;
@ -676,6 +677,12 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return;
}
}
ProfileAppearanceFragment profileAppearanceFragment = getProfileAppearanceFragment();
if (profileAppearanceFragment != null) {
if (profileAppearanceFragment.isProfileAppearanceChanged(this)) {
return;
}
}
if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) {
if (mapContextMenu.getCurrentMenuState() != MenuState.HEADER_ONLY && !isLandscapeLayout()) {
mapContextMenu.openMenuHeaderOnly();
@ -2400,6 +2407,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return getFragment(EditProfileFragment.TAG);
}
public ProfileAppearanceFragment getProfileAppearanceFragment() {
return getFragment(ProfileAppearanceFragment.TAG);
}
public QuickActionListFragment getQuickActionListFragment() {
return getFragment(QuickActionListFragment.TAG);
}

View file

@ -164,8 +164,8 @@ public class EditProfileFragment extends BaseOsmAndFragment {
selectColorBtn = view.findViewById(R.id.select_icon_color_button);
profileNameEt = view.findViewById(R.id.profile_name_et);
profileNameTextBox = view.findViewById(R.id.profile_name_otfb);
navTypeEt = view.findViewById(R.id.navigation_type_et);
navTypeTextBox = view.findViewById(R.id.navigation_type_otfb);
navTypeEt = view.findViewById(R.id.master_profile_et);
navTypeTextBox = view.findViewById(R.id.master_profile_otfb);
selectNavTypeBtn = view.findViewById(R.id.select_nav_type_btn);
cancelBtn = view.findViewById(R.id.cancel_button);
saveButton = view.findViewById(R.id.save_profile_btn);

View file

@ -11,6 +11,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
@ -46,7 +47,6 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
private final List<ProfileDataObject> profiles = new ArrayList<>();
private List<IconResWithDescr> icons;
private String selectedItemKey;
private String selectedIconRes;
@ -64,7 +64,6 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
profiles.addAll(SettingsProfileFragment.getBaseProfiles(app));
} else if (type.equals(TYPE_ICON)) {
selectedIconRes = args.getString(SELECTED_ICON, "");
icons = getProfileIcons();
} else {
LOG.error("Check intent data!");
dismiss();
@ -178,10 +177,10 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
}
} else if (type.equals(TYPE_ICON)) {
items.add(new TitleItem(getString(R.string.select_icon_profile_dialog_title)));
for (final IconResWithDescr icon : icons) {
for (final ApplicationMode.ProfileIcons icon : ApplicationMode.ProfileIcons.values()) {
Drawable drawableIcon;
boolean isSelected = icon.resStringId.equals(selectedIconRes);
int iconRes = icon.resId;
boolean isSelected = icon.getResStringId().equals(selectedIconRes);
int iconRes = icon.getResId();
if (isSelected) {
drawableIcon = getMyApplication().getUIUtilities()
.getIcon(iconRes, nightMode
@ -193,11 +192,11 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
}
items.add(new BottomSheetItemWithCompoundButton.Builder()
.setChecked(icon.resStringId.equals(selectedIconRes))
.setChecked(icon.getResStringId().equals(selectedIconRes))
.setButtonTintList(isSelected
? ColorStateList.valueOf(getResolvedColor(getActiveColorId()))
: null)
.setTitle(getMyApplication().getString(icon.titleId))
.setTitle(getMyApplication().getString(icon.getTitleId()))
.setIcon(drawableIcon)
.setLayoutId(R.layout.bottom_sheet_item_with_radio_btn)
.setOnClickListener(new OnClickListener() {
@ -207,7 +206,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
getListener();
}
if (listener != null) {
listener.onSelectedType(icon.resId, icon.resStringId);
listener.onSelectedType(icon.getResId(), icon.getResStringId());
}
dismiss();
}
@ -218,7 +217,6 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
}
}
private void getListener() {
FragmentActivity activity = getActivity();
if (activity != null) {
@ -226,7 +224,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
EditProfileFragment editProfileFragment = (EditProfileFragment) fragmentManager.findFragmentByTag(EditProfileFragment.TAG);
SettingsProfileFragment settingsProfileFragment = (SettingsProfileFragment) fragmentManager.findFragmentByTag(SettingsProfileFragment.class.getName());
NavigationFragment navigationFragment = (NavigationFragment) fragmentManager.findFragmentByTag(NavigationFragment.class.getName());
ProfileAppearanceFragment profileAppearanceFragment = (ProfileAppearanceFragment) fragmentManager.findFragmentByTag(ProfileAppearanceFragment.class.getName());
ProfileAppearanceFragment profileAppearanceFragment = (ProfileAppearanceFragment) fragmentManager.findFragmentByTag(ProfileAppearanceFragment.TAG);
if (editProfileFragment != null) {
switch (type) {
@ -251,52 +249,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
}
}
private List<IconResWithDescr> getProfileIcons() {
List<IconResWithDescr> icons = new ArrayList<>();
icons.add(new IconResWithDescr(R.drawable.ic_action_car_dark, R.string.app_mode_car, "ic_action_car_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_taxi, R.string.app_mode_taxi, "ic_action_taxi", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_truck_dark, R.string.app_mode_truck, "ic_action_truck_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_shuttle_bus, R.string.app_mode_shuttle_bus, "ic_action_shuttle_bus", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_bus_dark, R.string.app_mode_bus, "ic_action_bus_dark",false));
icons.add(new IconResWithDescr(R.drawable.ic_action_subway, R.string.app_mode_subway, "ic_action_subway", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_motorcycle_dark, R.string.app_mode_motorcycle, "ic_action_motorcycle_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_bicycle_dark, R.string.app_mode_bicycle, "ic_action_bicycle_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_horse, R.string.app_mode_horse, "ic_action_horse", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_pedestrian_dark, R.string.app_mode_pedestrian,"ic_action_pedestrian_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_trekking_dark, R.string.app_mode_hiking, "ic_action_trekking_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_skiing, R.string.app_mode_skiing, "ic_action_skiing", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_sail_boat_dark, R.string.app_mode_boat, "ic_action_sail_boat_dark", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_aircraft, R.string.app_mode_aircraft, "ic_action_aircraft", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_helicopter, R.string.app_mode_helicopter, "ic_action_helicopter", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_personal_transporter, R.string.app_mode_personal_transporter, "ic_action_personal_transporter", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_monowheel, R.string.app_mode_monowheel, "ic_action_monowheel", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_scooter, R.string.app_mode_scooter, "ic_action_scooter", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_ufo, R.string.app_mode_ufo, "ic_action_ufo", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_offroad, R.string.app_mode_offroad, "ic_action_offroad", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_campervan, R.string.app_mode_campervan, "ic_action_campervan", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_camper, R.string.app_mode_camper, "ic_action_camper", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_pickup_truck, R.string.app_mode_pickup_truck, "ic_action_pickup_truck", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_wagon, R.string.app_mode_wagon, "ic_action_wagon", false));
icons.add(new IconResWithDescr(R.drawable.ic_action_utv, R.string.app_mode_utv, "ic_action_utv", false));
return icons;
}
public interface SelectProfileListener {
void onSelectedType(int pos, String stringRes);
}
private class IconResWithDescr {
private int resId;
private int titleId;
private String resStringId;
private boolean isSelected;
public IconResWithDescr(int resId, int titleId, String resStringId, boolean isSelected) {
this.resId = resId;
this.titleId = titleId;
this.isSelected = isSelected;
this.resStringId = resStringId;
}
}
}

View file

@ -98,7 +98,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, R.xml.turn_screen_on, R.layout.profile_preference_toolbar_with_switch),
DATA_STORAGE(DataStorageFragment.class.getName(), false, R.xml.data_storage, R.layout.global_preference_toolbar),
DIALOGS_AND_NOTIFICATIONS_SETTINGS(DialogsAndNotificationsSettingsFragment.class.getName(), false, R.xml.dialogs_and_notifications_preferences, R.layout.global_preferences_toolbar_with_switch),
PROFILE_APPEARANCE(ProfileAppearanceFragment.class.getName(), true, R.xml.profile_appearance, R.layout.profile_preference_toolbar);
PROFILE_APPEARANCE(ProfileAppearanceFragment.TAG, true, R.xml.profile_appearance, R.layout.profile_preference_toolbar);
public final String fragmentName;
public final boolean profileDependent;

View file

@ -245,9 +245,14 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
if (ctx == null) {
return;
}
Preference configureMap = findPreference(PROFILE_APPEARANCE);
configureMap.setIcon(getContentIcon(getSelectedAppMode().getIconRes()));
configureMap.setFragment(ProfileAppearanceFragment.class.getName());
if (!getSelectedAppMode().equals(ApplicationMode.DEFAULT)) {
configureMap.setIcon(getContentIcon(getSelectedAppMode().getIconRes()));
configureMap.setFragment(ProfileAppearanceFragment.TAG);
} else {
configureMap.setVisible(false);
}
}
private void setupExportProfilePref() {

View file

@ -3,12 +3,12 @@ package net.osmand.plus.settings;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.Editable;
import android.text.TextWatcher;
@ -23,11 +23,12 @@ import android.widget.ImageView;
import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
import net.osmand.plus.profiles.SettingsProfileFragment;
import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.widgets.FlowLayout;
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
import net.osmand.util.Algorithms;
@ -40,12 +41,16 @@ import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TY
public class ProfileAppearanceFragment extends BaseSettingsFragment {
public static final String TAG = ProfileAppearanceFragment.class.getName();
private static final String MASTER_PROFILE = "master_profile";
private static final String PROFILE_NAME = "profile_name";
private static final String SELECT_COLOR = "select_color";
private static final String SELECT_ICON = "select_icon";
private static final String COLOR_ITEMS = "color_items";
private static final String ICON_ITEMS = "icon_items";
private static final String SELECT_MAP_ICON = "select_map_icon";
private static final String SELECT_NAV_ICON = "select_nav_icon";
public static final String PROFILE_NAME_KEY = "profile_name_key";
public static final String PROFILE_ICON_RES_KEY = "profile_icon_res_key";
public static final String PROFILE_COLOR_KEY = "profile_color_key";
@ -54,8 +59,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
private EditText baseProfileName;
private ApplicationProfileObject profile;
private ApplicationProfileObject changedProfile;
private Button cancelButton;
private Button saveButton;
private EditText profileName;
private FlowLayout colorItems;
private FlowLayout iconItems;
@ -68,24 +71,30 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
restoreState(savedInstanceState);
} else {
profile = new ApplicationProfileObject();
profile.stringKey = getSelectedAppMode().getStringKey();
profile.parent = getSelectedAppMode().getParent();
profile.name = getSelectedAppMode().toHumanString(getContext());
profile.color = getSelectedAppMode().getIconColorInfo();
profile.iconRes = getSelectedAppMode().getIconRes();
profile.routingProfile = getSelectedAppMode().getRoutingProfile();
profile.routeService = getSelectedAppMode().getRouteService();
changedProfile = new ApplicationProfileObject();
changedProfile.stringKey = profile.stringKey;
changedProfile.parent = profile.parent;
changedProfile.name = profile.name;
changedProfile.color = profile.color;
changedProfile.iconRes = profile.iconRes;
changedProfile.routingProfile = profile.routingProfile;
changedProfile.routeService = profile.routeService;
}
}
@Override
protected void setupPreferences() {
PreferenceCategory selectColor = (PreferenceCategory) findPreference(SELECT_COLOR);
selectColor.setIconSpaceReserved(false);
PreferenceCategory selectIcon = (PreferenceCategory) findPreference(SELECT_ICON);
selectIcon.setIconSpaceReserved(false);
findPreference(SELECT_COLOR).setIconSpaceReserved(false);
findPreference(SELECT_ICON).setIconSpaceReserved(false);
findPreference(SELECT_MAP_ICON).setIconSpaceReserved(false);
findPreference(SELECT_NAV_ICON).setIconSpaceReserved(false);
}
@SuppressLint("InlinedApi")
@ -96,9 +105,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
FrameLayout frameLayout = view.findViewById(android.R.id.list_container);
View inflatedLayout = UiUtilities.getInflater(getContext(), isNightMode())
.inflate(R.layout.preference_cancel_save_button, frameLayout, false);
(frameLayout).addView(inflatedLayout);
cancelButton=inflatedLayout.findViewById(R.id.cancel_button);
saveButton=inflatedLayout.findViewById(R.id.save_profile_btn);
frameLayout.addView(inflatedLayout);
Button cancelButton = inflatedLayout.findViewById(R.id.cancel_button);
Button saveButton = inflatedLayout.findViewById(R.id.save_profile_btn);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -111,10 +120,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
@Override
public void onClick(View v) {
if (getActivity() != null) {
if (profile.equals(changedProfile)) {
if (isChanged()) {
saveNewProfile();
profile = changedProfile;
getActivity().onBackPressed();
} else {
}
}
}
@ -123,6 +132,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
return view;
}
private boolean isChanged() {
return !profile.equals(changedProfile);
}
@Override
protected void createToolbar(LayoutInflater inflater, View view) {
super.createToolbar(inflater, view);
@ -149,9 +162,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
changedProfile.color = (ApplicationMode.ProfileIconColors) savedInstanceState.getSerializable(PROFILE_COLOR_KEY);
String stringKey = savedInstanceState.getString(PROFILE_PARENT_KEY);
changedProfile.parent = ApplicationMode.valueOfStringKey(stringKey, null);
OsmandApplication app = getMyApplication();
if (changedProfile.parent == null) {
changedProfile.parent = app.getSettings().getApplicationMode();
changedProfile.parent = settings.getApplicationMode();
}
}
@ -163,8 +175,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
}
View profileButton = view.findViewById(R.id.profile_button);
if (profileButton != null) {
int iconColor = ContextCompat.getColor(getContext(), changedProfile.color.getColor(isNightMode()));
AndroidUtils.setBackground(profileButton, UiUtilities.tintDrawable(ContextCompat.getDrawable(getContext(),
int iconColor = ContextCompat.getColor(app, changedProfile.color.getColor(isNightMode()));
AndroidUtils.setBackground(profileButton, UiUtilities.tintDrawable(ContextCompat.getDrawable(app,
R.drawable.circle_background_light), UiUtilities.getColorWithAlpha(iconColor, 0.1f)));
ImageView profileIcon = view.findViewById(R.id.profile_icon);
if (profileIcon != null) {
@ -200,11 +212,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
}
});
} else if (MASTER_PROFILE.equals(preference.getKey())) {
baseProfileName = (EditText) holder.findViewById(R.id.navigation_type_et);
baseProfileName = (EditText) holder.findViewById(R.id.master_profile_et);
baseProfileName.setText(changedProfile.parent != null
? changedProfile.parent.toHumanString(getContext())
: getSelectedAppMode().toHumanString(getContext()));
OsmandTextFieldBoxes baseProfileNameHint = (OsmandTextFieldBoxes) holder.findViewById(R.id.navigation_type_otfb);
OsmandTextFieldBoxes baseProfileNameHint = (OsmandTextFieldBoxes) holder.findViewById(R.id.master_profile_otfb);
baseProfileNameHint.setLabelText(getString(R.string.master_profile));
FrameLayout selectNavTypeBtn = (FrameLayout) holder.findViewById(R.id.select_nav_type_btn);
selectNavTypeBtn.setOnClickListener(new View.OnClickListener() {
@ -230,14 +242,14 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
colorItems = (FlowLayout) holder.findViewById(R.id.color_items);
colorItems.removeAllViews();
for (ApplicationMode.ProfileIconColors color : ApplicationMode.ProfileIconColors.values()) {
View view = createColorView(color);
View view = createColorItemView(color);
colorItems.addView(view, new FlowLayout.LayoutParams(0, 0));
ImageView outlineCircle = view.findViewById(R.id.outlineCircle);
ImageView checkMark = view.findViewById(R.id.checkMark);
GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat.getDrawable(getContext(), R.drawable.circle_contour_bg_light);
GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat.getDrawable(app, R.drawable.circle_contour_bg_light);
if (gradientDrawable != null) {
gradientDrawable.setStroke(AndroidUtils.dpToPx(getContext(), 2),
UiUtilities.getColorWithAlpha(ContextCompat.getColor(getContext(), color.getColor(isNightMode())), 0.3f));
gradientDrawable.setStroke(AndroidUtils.dpToPx(app, 2),
UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, color.getColor(isNightMode())), 0.3f));
outlineCircle.setImageDrawable(gradientDrawable);
}
checkMark.setVisibility(View.GONE);
@ -247,34 +259,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
} else if (ICON_ITEMS.equals(preference.getKey())) {
iconItems = (FlowLayout) holder.findViewById(R.id.color_items);
iconItems.removeAllViews();
ArrayList<Integer> icons = new ArrayList<>();
icons.add(R.drawable.ic_action_car_dark);
icons.add(R.drawable.ic_action_taxi);
icons.add(R.drawable.ic_action_truck_dark);
icons.add(R.drawable.ic_action_shuttle_bus);
icons.add(R.drawable.ic_action_bus_dark);
icons.add(R.drawable.ic_action_subway);
icons.add(R.drawable.ic_action_motorcycle_dark);
icons.add(R.drawable.ic_action_bicycle_dark);
icons.add(R.drawable.ic_action_horse);
icons.add(R.drawable.ic_action_pedestrian_dark);
icons.add(R.drawable.ic_action_trekking_dark);
icons.add(R.drawable.ic_action_skiing);
icons.add(R.drawable.ic_action_sail_boat_dark);
icons.add(R.drawable.ic_action_aircraft);
icons.add(R.drawable.ic_action_helicopter);
icons.add(R.drawable.ic_action_personal_transporter);
icons.add(R.drawable.ic_action_monowheel);
icons.add(R.drawable.ic_action_scooter);
icons.add(R.drawable.ic_action_ufo);
icons.add(R.drawable.ic_action_offroad);
icons.add(R.drawable.ic_action_campervan);
icons.add(R.drawable.ic_action_camper);
icons.add(R.drawable.ic_action_pickup_truck);
icons.add(R.drawable.ic_action_wagon);
icons.add(R.drawable.ic_action_utv);
ArrayList<Integer> icons = ApplicationMode.ProfileIcons.getIcons();
for (int iconRes : icons) {
View view = createIconView(iconRes);
View view = createIconItemView(iconRes);
iconItems.addView(view, new FlowLayout.LayoutParams(0, 0));
ImageView outlineCircle = view.findViewById(R.id.outlineCircle);
outlineCircle.setVisibility(View.GONE);
@ -283,12 +270,12 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
}
}
private View createColorView(final ApplicationMode.ProfileIconColors colorRes) {
private View createColorItemView(final ApplicationMode.ProfileIconColors colorRes) {
FrameLayout colorView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode())
.inflate(R.layout.preference_circle_item, null, false);
ImageView coloredCircle = colorView.findViewById(R.id.bckgroundCircle);
coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light,
ContextCompat.getColor(getContext(), colorRes.getColor(isNightMode()))));
ContextCompat.getColor(app, colorRes.getColor(isNightMode()))));
coloredCircle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -315,14 +302,14 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
updateProfileButton();
}
private View createIconView(final int iconRes) {
private View createIconItemView(final int iconRes) {
FrameLayout iconView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode())
.inflate(R.layout.preference_circle_item, null, false);
ImageView checkMark = iconView.findViewById(R.id.checkMark);
checkMark.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.icon_color_default_light));
ImageView coloredCircle = iconView.findViewById(R.id.bckgroundCircle);
coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light,
UiUtilities.getColorWithAlpha(ContextCompat.getColor(getContext(), R.color.icon_color_default_light), 0.1f)));
UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f)));
coloredCircle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -343,22 +330,22 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
checkMark.setImageDrawable(app.getUIUtilities().getIcon(changedProfile.iconRes, R.color.icon_color_default_light));
ImageView coloredCircle = view.findViewById(R.id.bckgroundCircle);
coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light,
UiUtilities.getColorWithAlpha(ContextCompat.getColor(getContext(), R.color.icon_color_default_light), 0.1f)));
UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f)));
changedProfile.iconRes = iconRes;
updateProfileButton();
}
private void setIconNewColor(int iconRes) {
int changedProfileColor = ContextCompat.getColor(getContext(), changedProfile.color.getColor(
int changedProfileColor = ContextCompat.getColor(app, changedProfile.color.getColor(
app.getDaynightHelper().isNightModeForMapControls()));
View view = iconItems.findViewWithTag(iconRes);
ImageView coloredCircle = view.findViewById(R.id.bckgroundCircle);
coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light,
UiUtilities.getColorWithAlpha(ContextCompat.getColor(getContext(), changedProfile.color.getColor(isNightMode())), 0.1f)));
UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, changedProfile.color.getColor(isNightMode())), 0.1f)));
ImageView outlineCircle = view.findViewById(R.id.outlineCircle);
GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat.getDrawable(getContext(), R.drawable.circle_contour_bg_light);
GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat.getDrawable(app, R.drawable.circle_contour_bg_light);
if (gradientDrawable != null) {
gradientDrawable.setStroke(AndroidUtils.dpToPx(getContext(), 2), changedProfileColor);
gradientDrawable.setStroke(AndroidUtils.dpToPx(app, 2), changedProfileColor);
}
outlineCircle.setImageDrawable(gradientDrawable);
outlineCircle.setVisibility(View.VISIBLE);
@ -392,7 +379,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
}
void updateParentProfile(int pos) {
String key = SettingsProfileFragment.getBaseProfiles(getMyApplication()).get(pos).getStringKey();
setupBaseProfileView(key);
changedProfile.parent = ApplicationMode.valueOfStringKey(key, ApplicationMode.DEFAULT);
@ -406,8 +392,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
}
}
/* private boolean saveNewProfile() {
boolean isNew = true;
private boolean saveNewProfile() {
boolean isNew = false;
if (changedProfile.name.isEmpty()
|| changedProfile.name.replace(" ", "").length() < 1
|| profileName.getText().toString().replace(" ", "").length() < 1) {
@ -444,26 +430,16 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
ApplicationMode.ApplicationModeBuilder builder = ApplicationMode
.createCustomMode(changedProfile.parent, changedProfile.name.trim(), customStringKey)
.icon(app, profile.iconStringName);
if(profile.routingProfileDataObject.getStringKey().equals(
EditProfileFragment.RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) {
builder.setRouteService(RouteProvider.RouteService.STRAIGHT);
} else if(profile.routingProfileDataObject.getStringKey().equals(
EditProfileFragment.RoutingProfilesResources.BROUTER_MODE.name())) {
builder.setRouteService(RouteProvider.RouteService.BROUTER);
} else if (profile.routingProfileDataObject != null) {
builder.setRoutingProfile(profile.routingProfileDataObject.getStringKey());
}
builder.setColor(changedProfile.color);
mode = ApplicationMode.saveProfile(builder, getMyApplication());
.icon(app, ApplicationMode.ProfileIcons.getResStringByResId(changedProfile.iconRes))
.setRouteService(changedProfile.routeService)
.setRoutingProfile(changedProfile.routingProfile)
.setColor(changedProfile.color);
ApplicationMode mode = ApplicationMode.saveProfile(builder, getMyApplication());
if (!ApplicationMode.values(app).contains(mode)) {
ApplicationMode.changeProfileAvailability(mode, true, getMyApplication());
}
return true;
}*/
}
private void showSaveWarningDialog(String title, String message, Activity activity) {
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
@ -473,10 +449,63 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
bld.show();
}
public boolean isProfileAppearanceChanged(final MapActivity mapActivity) {
if (isChanged()) {
AlertDialog.Builder dismissDialog = new AlertDialog.Builder(mapActivity);
dismissDialog.setTitle(R.string.shared_string_dismiss);
dismissDialog.setMessage(R.string.exit_without_saving);
dismissDialog.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
changedProfile = profile;
mapActivity.onBackPressed();
}
});
dismissDialog.setNegativeButton(R.string.shared_string_cancel, null);
dismissDialog.show();
return true;
} else {
return false;
}
}
class ApplicationProfileObject {
String stringKey;
ApplicationMode parent = null;
String name;
ApplicationMode.ProfileIconColors color;
int iconRes;
String routingProfile;
RouteProvider.RouteService routeService;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ApplicationProfileObject that = (ApplicationProfileObject) o;
if (iconRes != that.iconRes) return false;
if (stringKey != null ? !stringKey.equals(that.stringKey) : that.stringKey != null)
return false;
if (parent != null ? !parent.equals(that.parent) : that.parent != null) return false;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (color != that.color) return false;
if (routingProfile != null ? !routingProfile.equals(that.routingProfile) : that.routingProfile != null)
return false;
return routeService == that.routeService;
}
@Override
public int hashCode() {
int result = stringKey != null ? stringKey.hashCode() : 0;
result = 31 * result + (parent != null ? parent.hashCode() : 0);
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (color != null ? color.hashCode() : 0);
result = 31 * result + iconRes;
result = 31 * result + (routingProfile != null ? routingProfile.hashCode() : 0);
result = 31 * result + (routeService != null ? routeService.hashCode() : 0);
return result;
}
}
}