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:src="@drawable/ic_action_additional_option"
|
||||||
android:tint="?attr/primary_icon_color"
|
android:tint="?attr/primary_icon_color"
|
||||||
android:layout_gravity="center_vertical"
|
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.support.v7.widget.SwitchCompat
|
||||||
android:id="@+id/profile_switch"
|
android:id="@+id/profile_switch"
|
||||||
|
@ -76,8 +81,10 @@
|
||||||
android:layout_gravity="center_vertical|end"
|
android:layout_gravity="center_vertical|end"
|
||||||
android:paddingRight="16dp"
|
android:paddingRight="16dp"
|
||||||
android:paddingEnd="16dp"
|
android:paddingEnd="16dp"
|
||||||
android:paddingLeft="4dp"
|
android:paddingTop="@dimen/setting_profile_item_switch_margin"
|
||||||
android:paddingStart="4dp"
|
android:paddingBottom="@dimen/setting_profile_item_switch_margin"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingStart="16dp"
|
||||||
android:background="@null"
|
android:background="@null"
|
||||||
android:clickable="false"
|
android:clickable="false"
|
||||||
android:focusable="false"
|
android:focusable="false"
|
||||||
|
|
|
@ -527,7 +527,7 @@ public class ApplicationMode {
|
||||||
Iterator<ApplicationMode> it = values.iterator();
|
Iterator<ApplicationMode> it = values.iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
ApplicationMode m = it.next();
|
ApplicationMode m = it.next();
|
||||||
if (m.userProfileName == userModeTitle) {
|
if (m.userProfileName != null && m.userProfileName.equals(userModeTitle)) {
|
||||||
it.remove();
|
it.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package net.osmand.plus.profiles;
|
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.activities.SettingsNavigationActivity.INTENT_SKIP_DIALOG;
|
||||||
import static net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.TYPE_APP_PROFILE;
|
import static net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.TYPE_APP_PROFILE;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnDismissListener;
|
import android.content.DialogInterface.OnDismissListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -25,8 +23,6 @@ import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||||
import android.view.ViewTreeObserver.OnScrollChangedListener;
|
|
||||||
import android.view.inputmethod.InputMethodManager;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
|
@ -45,7 +41,6 @@ import net.osmand.plus.OsmandApplication;
|
||||||
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.activities.OsmandActionBarActivity;
|
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||||
import net.osmand.plus.activities.SettingsBaseActivity;
|
|
||||||
import net.osmand.plus.activities.SettingsNavigationActivity;
|
import net.osmand.plus.activities.SettingsNavigationActivity;
|
||||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||||
import net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.ProfileTypeDialogListener;
|
import net.osmand.plus.profiles.ProfileBottomSheetDialogFragment.ProfileTypeDialogListener;
|
||||||
|
@ -101,7 +96,6 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
private Button cancelBtnSV;
|
private Button cancelBtnSV;
|
||||||
private Button saveButtonSV;
|
private Button saveButtonSV;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -112,6 +106,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
isUserProfile = getArguments().getBoolean("isUserProfile", false);
|
isUserProfile = getArguments().getBoolean("isUserProfile", false);
|
||||||
mode = ApplicationMode.valueOfStringKey(modeName, ApplicationMode.DEFAULT);
|
mode = ApplicationMode.valueOfStringKey(modeName, ApplicationMode.DEFAULT);
|
||||||
profile = new TempApplicationProfile(mode, isNew, isUserProfile);
|
profile = new TempApplicationProfile(mode, isNew, isUserProfile);
|
||||||
|
|
||||||
}
|
}
|
||||||
routingProfiles = getRoutingProfiles();
|
routingProfiles = getRoutingProfiles();
|
||||||
}
|
}
|
||||||
|
@ -172,6 +167,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
profileNameEt.setText(title);
|
profileNameEt.setText(title);
|
||||||
startIconId = profile.iconId;
|
startIconId = profile.iconId;
|
||||||
isDataChanged = false;
|
isDataChanged = false;
|
||||||
|
|
||||||
} else if (isNew) {
|
} else if (isNew) {
|
||||||
isDataChanged = true;
|
isDataChanged = true;
|
||||||
title = String
|
title = String
|
||||||
|
@ -321,6 +317,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.setTitle(s.toString());
|
actionBar.setTitle(s.toString());
|
||||||
profile.setUserProfileTitle(s.toString());
|
profile.setUserProfileTitle(s.toString());
|
||||||
|
LOG.debug("Typed name: " + s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -435,6 +432,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (saveNewProfile()) {
|
if (saveNewProfile()) {
|
||||||
|
activateMode(mode);
|
||||||
getActivity().onBackPressed();
|
getActivity().onBackPressed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -444,6 +442,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (saveNewProfile()) {
|
if (saveNewProfile()) {
|
||||||
|
activateMode(mode);
|
||||||
getActivity().onBackPressed();
|
getActivity().onBackPressed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -527,10 +526,6 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
|
|
||||||
private boolean saveNewProfile() {
|
private boolean saveNewProfile() {
|
||||||
|
|
||||||
if (isUserProfile && !isNew) {
|
|
||||||
ApplicationMode.deleteCustomMode(profile.getUserProfileTitle(), getMyApplication());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (profile.getRoutingProfile() == null && getActivity() != null) {
|
if (profile.getRoutingProfile() == null && getActivity() != null) {
|
||||||
showSaveWarningDialog(
|
showSaveWarningDialog(
|
||||||
"Select Routing Type",
|
"Select Routing Type",
|
||||||
|
@ -546,26 +541,35 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
||||||
);
|
);
|
||||||
return false;
|
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;
|
String customStringKey = profile.stringKey;
|
||||||
if (isNew && profile.getParent() != null) {
|
if (isNew && profile.getParent() != null) {
|
||||||
customStringKey =
|
customStringKey =
|
||||||
|
|
|
@ -108,6 +108,11 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isNightMode(OsmandApplication ctx) {
|
private static boolean isNightMode(OsmandApplication ctx) {
|
||||||
return !ctx.getSettings().isLightContent();
|
return !ctx.getSettings().isLightContent();
|
||||||
}
|
}
|
||||||
|
@ -135,8 +140,7 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull final ItemViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull final ItemViewHolder holder, final int position) {
|
||||||
final int pos = holder.getAdapterPosition();
|
|
||||||
final ProfileDataObject item = items.get(position);
|
final ProfileDataObject item = items.get(position);
|
||||||
holder.title.setText(item.getName());
|
holder.title.setText(item.getName());
|
||||||
if (item.isSelected()) {
|
if (item.isSelected()) {
|
||||||
|
@ -150,15 +154,15 @@ public class ProfileBottomSheetDialogFragment extends BottomSheetDialogFragment
|
||||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
listener.onSelectedType(pos);
|
listener.onSelectedType(position);
|
||||||
holder.radioButton.setChecked(true);
|
holder.radioButton.setChecked(true);
|
||||||
|
|
||||||
if (item instanceof RoutingProfile) {
|
if (item instanceof RoutingProfile) {
|
||||||
items.get(pos).setSelected(true);
|
items.get(position).setSelected(true);
|
||||||
items.get(previousSelection).setSelected(false);
|
items.get(previousSelection).setSelected(false);
|
||||||
}
|
}
|
||||||
notifyItemChanged(previousSelection);
|
notifyItemChanged(previousSelection);
|
||||||
previousSelection = pos;
|
previousSelection = position;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -95,16 +95,12 @@ public class ProfileMenuAdapter extends RecyclerView.Adapter<ProfileViewHolder>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
holder.profileOptions.setOnClickListener(new OnClickListener() {
|
holder.profileOptions.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
listener.editProfile(item);
|
listener.editProfile(item);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue