fix value check logic and add length filters to edtiTexts in simple and advanced edit poi fragments

This commit is contained in:
madwasp79 2019-03-25 10:23:16 +02:00
parent 25656e83a8
commit 7f84c18eac
3 changed files with 26 additions and 4 deletions

View file

@ -1,10 +1,13 @@
package net.osmand.plus.osmedit;
import static net.osmand.plus.osmedit.EditPoiDialogFragment.AMENITY_TEXT_LENGTH;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
@ -205,6 +208,9 @@ public class AdvancedEditPoiFragment extends BaseOsmAndFragment
});
final AutoCompleteTextView valueEditText =
(AutoCompleteTextView) convertView.findViewById(R.id.valueEditText);
valueEditText.setFilters(new InputFilter[] {
new InputFilter.LengthFilter(AMENITY_TEXT_LENGTH)
});
tagEditText.setText(tg);
tagEditText.setAdapter(tagAdapter);
tagEditText.setThreshold(1);

View file

@ -1,5 +1,7 @@
package net.osmand.plus.osmedit;
import static net.osmand.plus.osmedit.EditPoiDialogFragment.AMENITY_TEXT_LENGTH;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@ -7,6 +9,9 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputFilter.LengthFilter;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.TypedValue;
@ -78,6 +83,9 @@ public class BasicEditPoiFragment extends BaseOsmAndFragment
openingHoursImageView.setImageDrawable(
getPaintedContentIcon(R.drawable.ic_action_time, iconColor));
InputFilter[] lengthLimit = new InputFilter[] {
new InputFilter.LengthFilter(AMENITY_TEXT_LENGTH)
};
streetEditText = (EditText) view.findViewById(R.id.streetEditText);
houseNumberEditText = (EditText) view.findViewById(R.id.houseNumberEditText);
phoneEditText = (EditText) view.findViewById(R.id.phoneEditText);
@ -88,6 +96,11 @@ public class BasicEditPoiFragment extends BaseOsmAndFragment
addTextWatcher(OSMSettings.OSMTagKey.PHONE.getValue(), phoneEditText);
addTextWatcher(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue(), houseNumberEditText);
addTextWatcher(OSMSettings.OSMTagKey.DESCRIPTION.getValue(), descriptionEditText);
streetEditText.setFilters(lengthLimit);
houseNumberEditText.setFilters(lengthLimit);
phoneEditText.setFilters(lengthLimit);
webSiteEditText.setFilters(lengthLimit);
descriptionEditText.setFilters(lengthLimit);
Button addOpeningHoursButton = (Button) view.findViewById(R.id.addOpeningHoursButton);
addOpeningHoursButton.setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -48,6 +48,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Map.Entry;
import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
@ -108,6 +109,8 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
private TextInputLayout poiTypeTextInputLayout;
private View view;
public static final int AMENITY_TEXT_LENGTH= 255;
@Override
public void onAttach(Context activity) {
super.onAttach(activity);
@ -438,9 +441,9 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment {
}
private String isTextLengthInRange() {
for (String s: editPoiData.getChangedTags()) {
if (editPoiData.getTag(s).length() > 255) {
return s;
for (Entry<String, String> s: editPoiData.getTagValues().entrySet()) {
if (s.getValue().length() > AMENITY_TEXT_LENGTH) {
return s.getKey();
}
}
return "";