Improve place does not exist dialog

Signed-off-by: map-per <map-per@gmx.de>
This commit is contained in:
map-per
2025-09-30 18:53:50 +02:00
committed by jeanbaptisteC
parent 37a518cb9b
commit 633896854d
6 changed files with 22 additions and 20 deletions

View File

@@ -40,7 +40,6 @@ public class EditTextDialogFragment extends BaseMwmDialogFragment
private String mHint; private String mHint;
private TextInputEditText mEtInput; private TextInputEditText mEtInput;
private TextInputLayout mEtInputLayout; private TextInputLayout mEtInputLayout;
private Button mPositiveButton;
private Validator mInputValidator; private Validator mInputValidator;
private OnTextSaveListener mTextSaveListener; private OnTextSaveListener mTextSaveListener;
@@ -117,21 +116,20 @@ public class EditTextDialogFragment extends BaseMwmDialogFragment
AlertDialog editTextDialog = new MaterialAlertDialogBuilder(requireActivity(), R.style.MwmTheme_AlertDialog) AlertDialog editTextDialog = new MaterialAlertDialogBuilder(requireActivity(), R.style.MwmTheme_AlertDialog)
.setView(buildView()) .setView(buildView())
.setNegativeButton(negativeButtonText, null) .setNegativeButton(negativeButtonText, null)
.setPositiveButton(positiveButtonText, .setPositiveButton(positiveButtonText, null)
(dialog, which) -> {
final String result = mEtInput.getText().toString();
processInput(result);
dismiss();
})
.create(); .create();
// Wait till alert is shown to get mPositiveButton. // Set up onClick listener for mPositiveButton.
editTextDialog.setOnShowListener((dialog) -> { editTextDialog.setOnShowListener((dialog) -> {
mPositiveButton = editTextDialog.getButton(DialogInterface.BUTTON_POSITIVE); Button positiveButton = editTextDialog.getButton(DialogInterface.BUTTON_POSITIVE);
final FragmentActivity activity = getActivity();
if (activity == null) positiveButton.setOnClickListener(view -> {
return; final String result = mEtInput.getText().toString();
this.validateInput(activity, mInitialText); if (validateInput(requireActivity(), result)) {
processInput(result);
editTextDialog.dismiss();
}
});
}); });
// Setup validation on input edit. // Setup validation on input edit.
@@ -149,14 +147,16 @@ public class EditTextDialogFragment extends BaseMwmDialogFragment
return editTextDialog; return editTextDialog;
} }
private void validateInput(@NonNull FragmentActivity activity, @Nullable String input) private boolean validateInput(@NonNull FragmentActivity activity, @Nullable String input)
{ {
if (mPositiveButton != null && mInputValidator != null) if (mInputValidator != null)
{ {
final String maybeError = mInputValidator.validate(activity, input); final String maybeError = mInputValidator.validate(activity, input);
mPositiveButton.setEnabled(maybeError == null);
mEtInputLayout.getEditText().setError(maybeError); mEtInputLayout.getEditText().setError(maybeError);
mEtInputLayout.requestFocus();
return maybeError == null;
} }
return false;
} }
private void processInput(@Nullable String text) private void processInput(@Nullable String text)

View File

@@ -1007,7 +1007,7 @@ public class EditorFragment extends BaseMwmFragment implements View.OnClickListe
private void placeDoesntExist() private void placeDoesntExist()
{ {
EditTextDialogFragment dialogFragment = EditTextDialogFragment.show( EditTextDialogFragment dialogFragment = EditTextDialogFragment.show(
getString(R.string.editor_place_doesnt_exist), "", getString(R.string.editor_comment_hint), getString(R.string.editor_place_doesnt_exist), "", getString(R.string.editor_place_doesnt_exist_description),
getString(R.string.editor_report_problem_send_button), getString(R.string.cancel), this, getString(R.string.editor_report_problem_send_button), getString(R.string.cancel), this,
getDeleteCommentValidator()); getDeleteCommentValidator());
dialogFragment.setTextSaveListener(this::commitPlaceDoesntExists); dialogFragment.setTextSaveListener(this::commitPlaceDoesntExists);

View File

@@ -23,7 +23,8 @@
style="@style/MwmWidget.Editor.CustomTextInput" style="@style/MwmWidget.Editor.CustomTextInput"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="text|textCapSentences" android:inputType="textMultiLine"
android:gravity="top"
android:padding="@dimen/margin_half_double_plus" android:padding="@dimen/margin_half_double_plus"
android:maxLength="100" android:maxLength="100"
android:singleLine="true" /> android:singleLine="true" />

View File

@@ -535,12 +535,12 @@
<string name="placepage_more_button">More</string> <string name="placepage_more_button">More</string>
<string name="placepage_edit_bookmark_button">Edit Bookmark</string> <string name="placepage_edit_bookmark_button">Edit Bookmark</string>
<string name="placepage_personal_notes_hint">Personal notes (text or html)</string> <string name="placepage_personal_notes_hint">Personal notes (text or html)</string>
<string name="editor_comment_hint">Comment…</string>
<string name="editor_reset_edits_message">Discard all local changes?</string> <string name="editor_reset_edits_message">Discard all local changes?</string>
<string name="editor_reset_edits_button">Discard</string> <string name="editor_reset_edits_button">Discard</string>
<string name="editor_remove_place_message">Delete added place?</string> <string name="editor_remove_place_message">Delete added place?</string>
<string name="editor_remove_place_button">Delete</string> <string name="editor_remove_place_button">Delete</string>
<string name="editor_place_doesnt_exist">Place does not exist</string> <string name="editor_place_doesnt_exist">Place does not exist</string>
<string name="editor_place_doesnt_exist_description">Describe what the place looks like now to send an error note to the OpenStreetMap community</string>
<!-- Error message for "Place doesn't exist" dialog when comment is empty --> <!-- Error message for "Place doesn't exist" dialog when comment is empty -->
<string name="delete_place_empty_comment_error">Please indicate the reason for deleting the place</string> <string name="delete_place_empty_comment_error">Please indicate the reason for deleting the place</string>
<!-- Phone number error message --> <!-- Phone number error message -->

View File

@@ -42,7 +42,7 @@
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
<userDefinedRuntimeAttributes> <userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="styleName" value="regular14:blackSecondaryText"/> <userDefinedRuntimeAttribute type="string" keyPath="styleName" value="regular14:blackSecondaryText"/>
<userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="editor_detailed_description"/> <userDefinedRuntimeAttribute type="string" keyPath="localizedText" value="editor_place_doesnt_exist_description"/>
</userDefinedRuntimeAttributes> </userDefinedRuntimeAttributes>
</label> </label>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="npf-dH-f50"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="npf-dH-f50">

View File

@@ -730,6 +730,7 @@
"editor_remove_place_message" = "Delete added place?"; "editor_remove_place_message" = "Delete added place?";
"editor_remove_place_button" = "Delete"; "editor_remove_place_button" = "Delete";
"editor_place_doesnt_exist" = "Place does not exist"; "editor_place_doesnt_exist" = "Place does not exist";
"editor_place_doesnt_exist_description" = "Describe what the place looks like now to send an error note to the OpenStreetMap community";
"text_more_button" = "…more"; "text_more_button" = "…more";
/* Phone number error message */ /* Phone number error message */