diff --git a/OsmAnd/res/layout/profile_list_item.xml b/OsmAnd/res/layout/profile_list_item.xml index 98b252b1ba..39a7a43863 100644 --- a/OsmAnd/res/layout/profile_list_item.xml +++ b/OsmAnd/res/layout/profile_list_item.xml @@ -67,7 +67,12 @@ android:src="@drawable/ic_action_additional_option" android:tint="?attr/primary_icon_color" android:layout_gravity="center_vertical" - android:padding="@dimen/setting_profile_item_switch_margin"/> + android:paddingLeft="@dimen/setting_profile_item_switch_margin" + android:paddingRight="10dp" + android:paddingBottom="@dimen/setting_profile_item_switch_margin" + android:paddingTop="@dimen/setting_profile_item_switch_margin" + android:paddingStart="@dimen/setting_profile_item_switch_margin" + android:paddingEnd="10dp"/> it = values.iterator(); while (it.hasNext()) { ApplicationMode m = it.next(); - if (m.userProfileName == userModeTitle) { + if (m.userProfileName != null && m.userProfileName.equals(userModeTitle)) { it.remove(); } } diff --git a/OsmAnd/src/net/osmand/plus/profiles/EditProfileFragment.java b/OsmAnd/src/net/osmand/plus/profiles/EditProfileFragment.java index 45e33a5e9f..6efbacf3b5 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/EditProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/profiles/EditProfileFragment.java @@ -1,11 +1,9 @@ package net.osmand.plus.profiles; -import static net.osmand.plus.activities.SettingsBaseActivity.getRoutingStringPropertyDescription; import static net.osmand.plus.activities.SettingsNavigationActivity.INTENT_SKIP_DIALOG; import static net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.TYPE_APP_PROFILE; import android.app.Activity; -import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnDismissListener; import android.content.Intent; @@ -25,8 +23,6 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.ViewTreeObserver.OnGlobalLayoutListener; -import android.view.ViewTreeObserver.OnScrollChangedListener; -import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; @@ -45,7 +41,6 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.OsmandActionBarActivity; -import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.SettingsNavigationActivity; import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.ProfileTypeDialogListener; @@ -101,7 +96,6 @@ public class EditProfileFragment extends BaseOsmAndFragment { private Button cancelBtnSV; private Button saveButtonSV; - @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -112,6 +106,7 @@ public class EditProfileFragment extends BaseOsmAndFragment { isUserProfile = getArguments().getBoolean("isUserProfile", false); mode = ApplicationMode.valueOfStringKey(modeName, ApplicationMode.DEFAULT); profile = new TempApplicationProfile(mode, isNew, isUserProfile); + } routingProfiles = getRoutingProfiles(); } @@ -172,6 +167,7 @@ public class EditProfileFragment extends BaseOsmAndFragment { profileNameEt.setText(title); startIconId = profile.iconId; isDataChanged = false; + } else if (isNew) { isDataChanged = true; title = String @@ -321,6 +317,7 @@ public class EditProfileFragment extends BaseOsmAndFragment { if (actionBar != null) { actionBar.setTitle(s.toString()); profile.setUserProfileTitle(s.toString()); + LOG.debug("Typed name: " + s); } } } @@ -435,6 +432,7 @@ public class EditProfileFragment extends BaseOsmAndFragment { @Override public void onClick(View v) { if (saveNewProfile()) { + activateMode(mode); getActivity().onBackPressed(); } } @@ -444,6 +442,7 @@ public class EditProfileFragment extends BaseOsmAndFragment { @Override public void onClick(View v) { if (saveNewProfile()) { + activateMode(mode); getActivity().onBackPressed(); } } @@ -527,10 +526,6 @@ public class EditProfileFragment extends BaseOsmAndFragment { private boolean saveNewProfile() { - if (isUserProfile && !isNew) { - ApplicationMode.deleteCustomMode(profile.getUserProfileTitle(), getMyApplication()); - } - if (profile.getRoutingProfile() == null && getActivity() != null) { showSaveWarningDialog( "Select Routing Type", @@ -546,26 +541,35 @@ public class EditProfileFragment extends BaseOsmAndFragment { ); return false; } - for (ApplicationMode m : ApplicationMode.allPossibleValues()) { - if (m.getUserProfileName() != null && m.getUserProfileName() - .equals(profile.getUserProfileTitle()) - && getActivity() != null) { - AlertDialog.Builder bld = new AlertDialog.Builder(getActivity()); - bld.setTitle("Duplicate Name"); - bld.setMessage("There is already profile with such name"); - bld.setNegativeButton(R.string.shared_string_dismiss, null); - bld.show(); - bld.setOnDismissListener(new OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialog) { - profileNameEt.requestFocus(); + //check for duplicates + + for (ApplicationMode m : ApplicationMode.allPossibleValues()) { + if (m.getUserProfileName() != null && getActivity() != null) { + if (m.getUserProfileName().equals(profile.getUserProfileTitle())) { + if (isNew || !Algorithms.isEmpty(mode.getUserProfileName()) && !mode.getUserProfileName().equals(profile.getUserProfileTitle())) { + AlertDialog.Builder bld = new AlertDialog.Builder(getActivity()); + bld.setTitle("Duplicate Name"); + bld.setMessage("There is already profile with such name"); + bld.setNegativeButton(R.string.shared_string_dismiss, null); + bld.show(); + bld.setOnDismissListener(new OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + profileNameEt.requestFocus(); + + } + }); + return false; } - }); - return false; + } } } + if (isUserProfile && !isNew) { + ApplicationMode.deleteCustomMode(mode.getUserProfileName(), getMyApplication()); + } + String customStringKey = profile.stringKey; if (isNew && profile.getParent() != null) { customStringKey = diff --git a/OsmAnd/src/net/osmand/plus/profiles/ProfileBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/profiles/ProfileBottomSheetDialogFragment.java index e751353415..89ccbddd93 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/ProfileBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/profiles/ProfileBottomSheetDialogFragment.java @@ -108,6 +108,11 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment return view; } + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + } + private static boolean isNightMode(OsmandApplication ctx) { return !ctx.getSettings().isLightContent(); } @@ -135,8 +140,7 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment } @Override - public void onBindViewHolder(@NonNull final ItemViewHolder holder, int position) { - final int pos = holder.getAdapterPosition(); + public void onBindViewHolder(@NonNull final ItemViewHolder holder, final int position) { final ProfileDataObject item = items.get(position); holder.title.setText(item.getName()); if (item.isSelected()) { @@ -150,15 +154,15 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - listener.onSelectedType(pos); + listener.onSelectedType(position); holder.radioButton.setChecked(true); if (item instanceof RoutingProfile) { - items.get(pos).setSelected(true); + items.get(position).setSelected(true); items.get(previousSelection).setSelected(false); } notifyItemChanged(previousSelection); - previousSelection = pos; + previousSelection = position; } }); diff --git a/OsmAnd/src/net/osmand/plus/profiles/ProfileMenuAdapter.java b/OsmAnd/src/net/osmand/plus/profiles/ProfileMenuAdapter.java index 96d2d7aa9b..fdbaf9b725 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/ProfileMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/profiles/ProfileMenuAdapter.java @@ -95,16 +95,12 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter } } }); - - holder.profileOptions.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { listener.editProfile(item); } }); - - } @Override