Fix issue with saving duplicates and overwriting existing profiles with same name
UI fixes
This commit is contained in:
parent
998e04181c
commit
b2f84d502e
5 changed files with 49 additions and 38 deletions
|
@ -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"/>
|
||||
|
||||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/profile_switch"
|
||||
|
@ -76,8 +81,10 @@
|
|||
android:layout_gravity="center_vertical|end"
|
||||
android:paddingRight="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingStart="4dp"
|
||||
android:paddingTop="@dimen/setting_profile_item_switch_margin"
|
||||
android:paddingBottom="@dimen/setting_profile_item_switch_margin"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingStart="16dp"
|
||||
android:background="@null"
|
||||
android:clickable="false"
|
||||
android:focusable="false"
|
||||
|
|
|
@ -527,7 +527,7 @@ public class ApplicationMode {
|
|||
Iterator<ApplicationMode> it = values.iterator();
|
||||
while (it.hasNext()) {
|
||||
ApplicationMode m = it.next();
|
||||
if (m.userProfileName == userModeTitle) {
|
||||
if (m.userProfileName != null && m.userProfileName.equals(userModeTitle)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -95,16 +95,12 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
holder.profileOptions.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
listener.editProfile(item);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue