Fix parts of edit poi
This commit is contained in:
parent
9feb3e0a4d
commit
21daf32a34
7 changed files with 319 additions and 366 deletions
|
@ -29,7 +29,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1">
|
||||
|
||||
<EditText
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/valueEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -1,5 +1,24 @@
|
|||
package net.osmand.plus.osmedit;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.StringMatcher;
|
||||
import net.osmand.osm.AbstractPoiType;
|
||||
import net.osmand.osm.MapPoiTypes;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiFilter;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.osm.edit.OSMSettings;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.osmedit.data.EditPoiData;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Point;
|
||||
|
@ -17,37 +36,16 @@ import android.view.ViewGroup;
|
|||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.StringMatcher;
|
||||
import net.osmand.osm.AbstractPoiType;
|
||||
import net.osmand.osm.MapPoiTypes;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiFilter;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.osm.edit.OSMSettings;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.osmedit.data.EditPoiData;
|
||||
import net.osmand.plus.osmedit.data.Tag;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class AdvancedDataFragment extends Fragment {
|
||||
private static final String TAG = "AdvancedDataFragment";
|
||||
private static final Log LOG = PlatformUtil.getLog(AdvancedDataFragment.class);
|
||||
|
||||
private TagAdapterLinearLayoutHack mAdapter;
|
||||
private EditPoiData.TagsChangedListener mTagsChangedListener;
|
||||
private boolean mIsUserInput = true;
|
||||
private Drawable deleteDrawable;
|
||||
|
||||
@Override
|
||||
|
@ -83,7 +81,7 @@ public class AdvancedDataFragment extends Fragment {
|
|||
addTagButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mAdapter.addTag(new Tag("", ""));
|
||||
mAdapter.addTagView("", "");
|
||||
}
|
||||
});
|
||||
return view;
|
||||
|
@ -92,14 +90,11 @@ public class AdvancedDataFragment extends Fragment {
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
// TODO read more about lifecycle
|
||||
mAdapter.updateViews();
|
||||
mTagsChangedListener = new EditPoiData.TagsChangedListener() {
|
||||
@Override
|
||||
public void onTagsChanged() {
|
||||
mIsUserInput = false;
|
||||
mAdapter.updateViews();
|
||||
mIsUserInput = true;
|
||||
}
|
||||
};
|
||||
getData().addListener(mTagsChangedListener);
|
||||
|
@ -156,20 +151,13 @@ public class AdvancedDataFragment extends Fragment {
|
|||
this.mapPoiTypes = mapPoiTypes;
|
||||
}
|
||||
|
||||
public void addTag(Tag tag) {
|
||||
editPoiData.tags.add(tag);
|
||||
if (mIsUserInput)
|
||||
editPoiData.notifyDatasetChanged(mTagsChangedListener);
|
||||
updateViews();
|
||||
}
|
||||
|
||||
public void updateViews() {
|
||||
linearLayout.removeAllViews();
|
||||
for (Tag tag : editPoiData.tags) {
|
||||
if (tag.tag.equals(OSMSettings.OSMTagKey.NAME.getValue())) {
|
||||
nameTextView.setText(tag.value);
|
||||
} else if (tag.tag.equals(EditPoiFragment.POI_TYPE_TAG)) {
|
||||
String subType = tag.value.trim().toLowerCase();
|
||||
for (Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
|
||||
if (tag.getKey().equals(OSMSettings.OSMTagKey.NAME.getValue())) {
|
||||
nameTextView.setText(tag.getValue());
|
||||
} else if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) {
|
||||
String subType = tag.getValue().trim().toLowerCase();
|
||||
if (allTranslatedSubTypes.get(subType) != null) {
|
||||
PoiType pt = allTranslatedSubTypes.get(subType);
|
||||
amenityTagTextView.setText(pt.getOsmTag());
|
||||
|
@ -179,30 +167,33 @@ public class AdvancedDataFragment extends Fragment {
|
|||
amenityTextView.setText(subType);
|
||||
}
|
||||
} else {
|
||||
View view = getView(tag);
|
||||
linearLayout.addView(view);
|
||||
addTagView(tag.getKey(), tag.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private View getView(final Tag tag) {
|
||||
public void addTagView(String tg, String vl) {
|
||||
View view = getView(tg, vl);
|
||||
linearLayout.addView(view);
|
||||
}
|
||||
|
||||
private View getView(String tg, String vl) {
|
||||
final View convertView = LayoutInflater.from(linearLayout.getContext())
|
||||
.inflate(R.layout.poi_tag_list_item, null, false);
|
||||
final AutoCompleteTextView tagEditText =
|
||||
(AutoCompleteTextView) convertView.findViewById(R.id.tagEditText);
|
||||
tagEditText.setText(tag.tag);
|
||||
final EditText valueEditText = (EditText) convertView.findViewById(R.id.valueEditText);
|
||||
tagEditText.setText(tg);
|
||||
final AutoCompleteTextView valueEditText =
|
||||
(AutoCompleteTextView) convertView.findViewById(R.id.valueEditText);
|
||||
ImageButton deleteItemImageButton =
|
||||
(ImageButton) convertView.findViewById(R.id.deleteItemImageButton);
|
||||
valueEditText.setText(tag.value);
|
||||
valueEditText.setText(vl);
|
||||
deleteItemImageButton.setImageDrawable(deleteDrawable);
|
||||
deleteItemImageButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
linearLayout.removeView((View) v.getParent());
|
||||
editPoiData.tags.remove(tag);
|
||||
if (mIsUserInput)
|
||||
editPoiData.notifyDatasetChanged(null);
|
||||
editPoiData.removeTag(tagEditText.toString());
|
||||
}
|
||||
});
|
||||
tagEditText.addTextChangedListener(new TextWatcher() {
|
||||
|
@ -216,29 +207,26 @@ public class AdvancedDataFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
editPoiData.tags.remove(tag);
|
||||
tag.tag = tagEditText.getText().toString();
|
||||
editPoiData.tags.add(tag);
|
||||
if (mIsUserInput)
|
||||
editPoiData.notifyDatasetChanged(mTagsChangedListener);
|
||||
if (!editPoiData.isInEdit()) {
|
||||
editPoiData.putTag(s.toString(), valueEditText.getText().toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
final Set<String> tagKeys = new HashSet<>();
|
||||
final Set<String> valueKeys = new HashSet<>();
|
||||
for (String s : allTypes.keySet()) {
|
||||
AbstractPoiType abstractPoiType = allTypes.get(s);
|
||||
addPoiToStringSet(abstractPoiType, tagKeys);
|
||||
addPoiToStringSet(abstractPoiType, tagKeys, valueKeys);
|
||||
}
|
||||
// addPoiToStringSet(mapPoiTypes.getOtherPoiCategory(), tagKeys);
|
||||
addPoiToStringSet(mapPoiTypes.getOtherMapCategory(), tagKeys);
|
||||
addPoiToStringSet(mapPoiTypes.getOtherMapCategory(), tagKeys, valueKeys);
|
||||
|
||||
ArrayAdapter<Object> adapter = new ArrayAdapter<>(linearLayout.getContext(),
|
||||
ArrayAdapter<Object> tagAdapter = new ArrayAdapter<>(linearLayout.getContext(),
|
||||
R.layout.list_textview, tagKeys.toArray());
|
||||
tagEditText.setAdapter(adapter);
|
||||
tagEditText.setAdapter(tagAdapter);
|
||||
tagEditText.setThreshold(1);
|
||||
tagEditText.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO: 8/29/15 Rewrite as dialog fragment
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final String[] tags = tagKeys.toArray(new String[tagKeys.size()]);
|
||||
builder.setItems(tags, new Dialog.OnClickListener() {
|
||||
|
@ -252,6 +240,7 @@ public class AdvancedDataFragment extends Fragment {
|
|||
builder.show();
|
||||
}
|
||||
});
|
||||
|
||||
valueEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
@ -263,18 +252,38 @@ public class AdvancedDataFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
editPoiData.tags.remove(tag);
|
||||
tag.value = valueEditText.getText().toString();
|
||||
editPoiData.tags.add(tag);
|
||||
if (mIsUserInput)
|
||||
editPoiData.notifyDatasetChanged(mTagsChangedListener);
|
||||
if (!editPoiData.isInEdit()) {
|
||||
editPoiData.putTag(tagEditText.getText().toString(), s.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
ArrayAdapter<Object> valueAdapter = new ArrayAdapter<>(linearLayout.getContext(),
|
||||
R.layout.list_textview, valueKeys.toArray());
|
||||
valueEditText.setAdapter(valueAdapter);
|
||||
valueEditText.setThreshold(1);
|
||||
valueEditText.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final String[] values = valueKeys.toArray(new String[tagKeys.size()]);
|
||||
builder.setItems(values, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
valueEditText.setText(values[which]);
|
||||
}
|
||||
|
||||
});
|
||||
builder.create();
|
||||
builder.show();
|
||||
}
|
||||
});
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
||||
private static void addPoiToStringSet(AbstractPoiType abstractPoiType, Set<String> stringSet) {
|
||||
private static void addPoiToStringSet(AbstractPoiType abstractPoiType, Set<String> stringSet,
|
||||
Set<String> values) {
|
||||
if (abstractPoiType instanceof PoiType) {
|
||||
PoiType poiType = (PoiType) abstractPoiType;
|
||||
if (poiType.getOsmTag() != null &&
|
||||
|
@ -283,22 +292,29 @@ public class AdvancedDataFragment extends Fragment {
|
|||
if (poiType.getOsmTag2() != null) {
|
||||
stringSet.add(poiType.getOsmTag2());
|
||||
}
|
||||
|
||||
}
|
||||
if (poiType.getOsmValue() != null) {
|
||||
values.add(poiType.getOsmValue());
|
||||
}
|
||||
if (poiType.getOsmValue2() != null) {
|
||||
values.add(poiType.getOsmValue2());
|
||||
}
|
||||
} else if (abstractPoiType instanceof PoiCategory) {
|
||||
PoiCategory poiCategory = (PoiCategory) abstractPoiType;
|
||||
for (PoiFilter filter : poiCategory.getPoiFilters()) {
|
||||
addPoiToStringSet(filter, stringSet);
|
||||
addPoiToStringSet(filter, stringSet, values);
|
||||
}
|
||||
for (PoiType poiType : poiCategory.getPoiTypes()) {
|
||||
addPoiToStringSet(poiType, stringSet);
|
||||
addPoiToStringSet(poiType, stringSet, values);
|
||||
}
|
||||
for (PoiType poiType : poiCategory.getPoiAdditionals()) {
|
||||
addPoiToStringSet(poiType, stringSet);
|
||||
addPoiToStringSet(poiType, stringSet, values);
|
||||
}
|
||||
} else if (abstractPoiType instanceof PoiFilter) {
|
||||
PoiFilter poiFilter = (PoiFilter) abstractPoiType;
|
||||
for (PoiType poiType : poiFilter.getPoiTypes()) {
|
||||
addPoiToStringSet(poiType, stringSet);
|
||||
addPoiToStringSet(poiType, stringSet, values);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("abstractPoiType can't be instance of class "
|
||||
|
|
|
@ -1,5 +1,23 @@
|
|||
package net.osmand.plus.osmedit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.osm.edit.OSMSettings;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.osmedit.data.EditPoiData;
|
||||
import net.osmand.plus.osmedit.dialogs.OpeningHoursDaysDialogFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.OpeningHoursHoursDialogFragment;
|
||||
import net.osmand.util.OpeningHoursParser;
|
||||
import net.osmand.util.OpeningHoursParser.BasicOpeningHourRule;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
@ -7,7 +25,6 @@ import android.os.Bundle;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Display;
|
||||
|
@ -21,25 +38,6 @@ import android.widget.ImageView;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.osm.edit.OSMSettings;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.osmedit.data.EditPoiData;
|
||||
import net.osmand.plus.osmedit.data.Tag;
|
||||
import net.osmand.plus.osmedit.dialogs.OpeningHoursDaysDialogFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.OpeningHoursHoursDialogFragment;
|
||||
import net.osmand.util.OpeningHoursParser;
|
||||
import net.osmand.util.OpeningHoursParser.BasicOpeningHourRule;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BasicDataFragment extends Fragment {
|
||||
private static final String TAG = "BasicDataFragment";
|
||||
private static final Log LOG = PlatformUtil.getLog(BasicDataFragment.class);
|
||||
|
@ -49,8 +47,7 @@ public class BasicDataFragment extends Fragment {
|
|||
private EditText phoneEditText;
|
||||
private EditText webSiteEditText;
|
||||
private EditText descriptionEditText;
|
||||
private EditPoiData.TagsChangedListener mTagsChangedListener;
|
||||
private boolean mIsUserInput = true;
|
||||
private List<EditPoiData.TagsChangedListener> listeners = new LinkedList<EditPoiData.TagsChangedListener>();
|
||||
OpeningHoursAdapter mOpeningHoursAdapter;
|
||||
|
||||
@Nullable
|
||||
|
@ -91,26 +88,20 @@ public class BasicDataFragment extends Fragment {
|
|||
iconsCache.getPaintedContentIcon(R.drawable.ic_action_time, iconColor));
|
||||
|
||||
streetEditText = (EditText) view.findViewById(R.id.streetEditText);
|
||||
streetEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
|
||||
OSMSettings.OSMTagKey.ADDR_STREET.getValue()));
|
||||
houseNumberEditText = (EditText) view.findViewById(R.id.houseNumberEditText);
|
||||
houseNumberEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
|
||||
OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue()));
|
||||
phoneEditText = (EditText) view.findViewById(R.id.phoneEditText);
|
||||
phoneEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
|
||||
OSMSettings.OSMTagKey.PHONE.getValue()));
|
||||
webSiteEditText = (EditText) view.findViewById(R.id.webSiteEditText);
|
||||
webSiteEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
|
||||
OSMSettings.OSMTagKey.WEBSITE.getValue()));
|
||||
descriptionEditText = (EditText) view.findViewById(R.id.descriptionEditText);
|
||||
descriptionEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
|
||||
OSMSettings.OSMTagKey.DESCRIPTION.getValue()));
|
||||
addTextWatcher(OSMSettings.OSMTagKey.ADDR_STREET.getValue(), streetEditText);
|
||||
addTextWatcher(OSMSettings.OSMTagKey.WEBSITE.getValue(), webSiteEditText);
|
||||
addTextWatcher(OSMSettings.OSMTagKey.PHONE.getValue(), phoneEditText);
|
||||
addTextWatcher(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue(), houseNumberEditText);
|
||||
addTextWatcher(OSMSettings.OSMTagKey.DESCRIPTION.getValue(), descriptionEditText);
|
||||
Button addOpeningHoursButton = (Button) view.findViewById(R.id.addOpeningHoursButton);
|
||||
addOpeningHoursButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
BasicOpeningHourRule rule = new BasicOpeningHourRule();
|
||||
// TODO: 8/27/15 Figure out some better defauls or leave it as it is
|
||||
rule.setStartTime(9 * 60);
|
||||
rule.setEndTime(18 * 60);
|
||||
OpeningHoursDaysDialogFragment fragment = OpeningHoursDaysDialogFragment.createInstance(rule, -1);
|
||||
|
@ -141,39 +132,57 @@ public class BasicDataFragment extends Fragment {
|
|||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mTagsChangedListener = new EditPoiData.TagsChangedListener() {
|
||||
@Override
|
||||
public void onTagsChanged() {
|
||||
TagMapProcessor tagMapProcessor = new TagMapProcessor();
|
||||
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.ADDR_STREET.getValue(),
|
||||
new EditTextTagFilter(streetEditText));
|
||||
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue(),
|
||||
new EditTextTagFilter(houseNumberEditText));
|
||||
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.PHONE.getValue(),
|
||||
new EditTextTagFilter(phoneEditText));
|
||||
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.WEBSITE.getValue(),
|
||||
new EditTextTagFilter(webSiteEditText));
|
||||
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.DESCRIPTION.getValue(),
|
||||
new EditTextTagFilter(descriptionEditText));
|
||||
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.OPENING_HOURS.getValue(),
|
||||
new OpenHoursTagFilter(mOpeningHoursAdapter));
|
||||
for(EditPoiData.TagsChangedListener tl : listeners) {
|
||||
getData().addListener(tl);
|
||||
}
|
||||
getData().notifyToUpdateUI();
|
||||
|
||||
// FIXME opening hours
|
||||
// @Override
|
||||
// public void process( String openingHoursString ) {
|
||||
// parseOpenedHoursHandleErrors(openingHoursString);
|
||||
// if (openingHours == null) {
|
||||
// openingHours = new OpeningHoursParser.OpeningHours();
|
||||
// }
|
||||
// LOG.debug("openingHours=" + openingHours);
|
||||
// adapter.replaceOpeningHours(openingHours);
|
||||
// adapter.updateViews();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onUntriggered() {
|
||||
// adapter.replaceOpeningHours(new OpeningHoursParser.OpeningHours());
|
||||
// adapter.updateViews();
|
||||
// }
|
||||
}
|
||||
|
||||
mIsUserInput = false;
|
||||
for (Tag tag : getData().tags) {
|
||||
tagMapProcessor.process(tag);
|
||||
}
|
||||
tagMapProcessor.clearEmptyFields();
|
||||
mIsUserInput = true;
|
||||
protected void addTextWatcher(final String tag, EditText e) {
|
||||
e.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
};
|
||||
mTagsChangedListener.onTagsChanged();
|
||||
getData().addListener(mTagsChangedListener);
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (!getData().isInEdit()) {
|
||||
getData().putTag(tag, s.toString());
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
getData().deleteListener(mTagsChangedListener);
|
||||
for(EditPoiData.TagsChangedListener tl : listeners) {
|
||||
getData().deleteListener(tl);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -187,80 +196,10 @@ public class BasicDataFragment extends Fragment {
|
|||
mOpeningHoursAdapter.setOpeningHoursRule(item, position);
|
||||
}
|
||||
|
||||
private static class TagMapProcessor {
|
||||
private final Map<String, TagFilter> mFilters = new HashMap<>();
|
||||
|
||||
|
||||
public void addFilter(String tag, TagFilter filter) {
|
||||
mFilters.put(tag, filter);
|
||||
}
|
||||
|
||||
public void process(Tag tag) {
|
||||
if (mFilters.containsKey(tag.tag)) {
|
||||
final TagFilter filter = mFilters.get(tag.tag);
|
||||
filter.process(tag);
|
||||
mFilters.remove(tag.tag);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearEmptyFields() {
|
||||
for (String tag : mFilters.keySet()) {
|
||||
mFilters.get(tag).onUntriggered();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private interface TagFilter {
|
||||
void process(Tag tag);
|
||||
|
||||
void onUntriggered();
|
||||
}
|
||||
|
||||
private static class EditTextTagFilter implements TagFilter {
|
||||
private final EditText editText;
|
||||
|
||||
private EditTextTagFilter(EditText editText) {
|
||||
this.editText = editText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(Tag tag) {
|
||||
editText.setText(tag.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUntriggered() {
|
||||
editText.setText(null);
|
||||
}
|
||||
}
|
||||
|
||||
private static class OpenHoursTagFilter implements TagFilter {
|
||||
private final OpeningHoursAdapter adapter;
|
||||
|
||||
private OpenHoursTagFilter(OpeningHoursAdapter adapter) {
|
||||
this.adapter = adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(Tag tag) {
|
||||
String openingHoursString = tag.value;
|
||||
LOG.debug("openingHoursString=" + openingHoursString);
|
||||
OpeningHoursParser.OpeningHours openingHours =
|
||||
parseOpenedHoursHandleErrors(openingHoursString);
|
||||
if (openingHours == null) {
|
||||
openingHours = new OpeningHoursParser.OpeningHours();
|
||||
// TODO show error message
|
||||
}
|
||||
LOG.debug("openingHours=" + openingHours);
|
||||
adapter.replaceOpeningHours(openingHours);
|
||||
adapter.updateViews();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUntriggered() {
|
||||
adapter.replaceOpeningHours(new OpeningHoursParser.OpeningHours());
|
||||
adapter.updateViews();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private EditPoiFragment getEditPoiFragment() {
|
||||
return (EditPoiFragment) getParentFragment();
|
||||
|
@ -480,37 +419,7 @@ public class BasicDataFragment extends Fragment {
|
|||
return basic;
|
||||
}
|
||||
|
||||
private class MyOnFocusChangeListener implements TextWatcher {
|
||||
private final EditPoiData data;
|
||||
private final String tagName;
|
||||
|
||||
public MyOnFocusChangeListener(EditPoiData data,
|
||||
String tagName) {
|
||||
this.data = data;
|
||||
this.tagName = tagName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (mIsUserInput) {
|
||||
String string = s.toString();
|
||||
if (!TextUtils.isEmpty(string)) {
|
||||
Tag tag = new Tag(tagName, string);
|
||||
data.tags.remove(tag);
|
||||
data.tags.add(tag);
|
||||
data.notifyDatasetChanged(mTagsChangedListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class OpeningHoursAdapter {
|
||||
private OpeningHoursParser.OpeningHours openingHours;
|
||||
|
@ -547,12 +456,9 @@ public class BasicDataFragment extends Fragment {
|
|||
for (int i = 0; i < openingHours.getRules().size(); i++) {
|
||||
linearLayout.addView(getView(i));
|
||||
}
|
||||
if (mIsUserInput) {
|
||||
Tag openHours = new Tag(OSMSettings.OSMTagKey.OPENING_HOURS.getValue(),
|
||||
if (!data.isInEdit()) {
|
||||
data.putTag(OSMSettings.OSMTagKey.OPENING_HOURS.getValue(),
|
||||
openingHours.toStringNoMonths());
|
||||
data.tags.remove(openHours);
|
||||
data.tags.add(openHours);
|
||||
data.notifyDatasetChanged(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,30 @@
|
|||
package net.osmand.plus.osmedit;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.osm.edit.EntityInfo;
|
||||
import net.osmand.osm.edit.Node;
|
||||
import net.osmand.osm.edit.OSMSettings;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.osmedit.data.EditPoiData;
|
||||
import net.osmand.plus.osmedit.dialogs.DeletePoiDialogFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
|
@ -41,32 +66,6 @@ import android.widget.ImageButton;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.osm.edit.EntityInfo;
|
||||
import net.osmand.osm.edit.Node;
|
||||
import net.osmand.osm.edit.OSMSettings;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.osmedit.data.EditPoiData;
|
||||
import net.osmand.plus.osmedit.data.Tag;
|
||||
import net.osmand.plus.osmedit.dialogs.DeletePoiDialogFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
|
||||
public class EditPoiFragment extends DialogFragment {
|
||||
public static final String TAG = "EditPoiFragment";
|
||||
private static final Log LOG = PlatformUtil.getLog(EditPoiFragment.class);
|
||||
|
@ -75,7 +74,7 @@ public class EditPoiFragment extends DialogFragment {
|
|||
private static final String KEY_AMENITY = "key_amenity";
|
||||
private static final String TAGS_LIST = "tags_list";
|
||||
|
||||
private final EditPoiData editPoiData = new EditPoiData();
|
||||
private EditPoiData editPoiData;
|
||||
private ViewPager viewPager;
|
||||
private boolean isLocalEdit;
|
||||
private boolean mIsUserInput = true;
|
||||
|
@ -83,7 +82,7 @@ public class EditPoiFragment extends DialogFragment {
|
|||
private AutoCompleteTextView poiTypeEditText;
|
||||
private Node node;
|
||||
private Map<String, PoiType> allTranslatedSubTypes;
|
||||
public static final String POI_TYPE_TAG = "poi_type_tag";
|
||||
|
||||
private OpenstreetmapUtil mOpenstreetmapUtil;
|
||||
private TextInputLayout poiTypeTextInputLayout;
|
||||
|
||||
|
@ -102,9 +101,10 @@ public class EditPoiFragment extends DialogFragment {
|
|||
}
|
||||
|
||||
node = (Node) getArguments().getSerializable(KEY_AMENITY_NODE);
|
||||
allTranslatedSubTypes = getMyApplication().getPoiTypes()
|
||||
.getAllTranslatedNames();
|
||||
editPoiData.amenity = (Amenity) getArguments().getSerializable(KEY_AMENITY);
|
||||
allTranslatedSubTypes = getMyApplication().getPoiTypes().getAllTranslatedNames();
|
||||
|
||||
Amenity amenity = (Amenity) getArguments().getSerializable(KEY_AMENITY);
|
||||
editPoiData = new EditPoiData(amenity, node, allTranslatedSubTypes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -127,36 +127,8 @@ public class EditPoiFragment extends DialogFragment {
|
|||
boolean isLightTheme = settings.OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
editPoiData.tags = (LinkedHashSet<Tag>) savedInstanceState.getSerializable(TAGS_LIST);
|
||||
} else {
|
||||
editPoiData.tags = new LinkedHashSet<>();
|
||||
|
||||
tryAddTag(OSMSettings.OSMTagKey.ADDR_STREET.getValue(),
|
||||
node.getTag(OSMSettings.OSMTagKey.ADDR_STREET));
|
||||
tryAddTag(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue(),
|
||||
node.getTag(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER));
|
||||
tryAddTag(OSMSettings.OSMTagKey.PHONE.getValue(),
|
||||
editPoiData.amenity.getPhone());
|
||||
tryAddTag(OSMSettings.OSMTagKey.WEBSITE.getValue(),
|
||||
editPoiData.amenity.getSite());
|
||||
for (String tag : node.getTagKeySet()) {
|
||||
tryAddTag(tag, node.getTag(tag));
|
||||
}
|
||||
String subType = editPoiData.amenity.getSubType();
|
||||
String key;
|
||||
String value;
|
||||
if (allTranslatedSubTypes.get(subType) != null) {
|
||||
PoiType pt = allTranslatedSubTypes.get(subType);
|
||||
key = pt.getOsmTag();
|
||||
value = pt.getOsmValue();
|
||||
} else {
|
||||
key = editPoiData.amenity.getType().getDefaultTag();
|
||||
value = subType;
|
||||
}
|
||||
final Tag tag = new Tag(key, value);
|
||||
editPoiData.tags.remove(tag);
|
||||
tag.tag = POI_TYPE_TAG;
|
||||
editPoiData.tags.add(tag);
|
||||
Map<String, String> mp =(Map<String, String>) savedInstanceState.getSerializable(TAGS_LIST);
|
||||
editPoiData.updateTags(mp);
|
||||
}
|
||||
|
||||
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
|
||||
|
@ -230,11 +202,8 @@ public class EditPoiFragment extends DialogFragment {
|
|||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
final Tag tag = new Tag(OSMSettings.OSMTagKey.NAME.getValue(), s.toString());
|
||||
if (mIsUserInput) {
|
||||
getEditPoiData().tags.remove(tag);
|
||||
getEditPoiData().tags.add(tag);
|
||||
getEditPoiData().notifyDatasetChanged(mTagsChangedListener);
|
||||
if (!getEditPoiData().isInEdit()) {
|
||||
getEditPoiData().putTag(OSMSettings.OSMTagKey.NAME.getValue(), s.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -252,11 +221,8 @@ public class EditPoiFragment extends DialogFragment {
|
|||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
final Tag tag = new Tag(POI_TYPE_TAG, s.toString());
|
||||
if (mIsUserInput) {
|
||||
getEditPoiData().tags.remove(tag);
|
||||
getEditPoiData().tags.add(tag);
|
||||
getEditPoiData().notifyDatasetChanged(mTagsChangedListener);
|
||||
if (!getEditPoiData().isInEdit()) {
|
||||
getEditPoiData().putTag(EditPoiData.POI_TYPE_TAG, s.toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -294,24 +260,24 @@ public class EditPoiFragment extends DialogFragment {
|
|||
return;
|
||||
}
|
||||
OsmPoint.Action action = node.getId() == -1 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
|
||||
for (Tag tag : editPoiData.tags) {
|
||||
if (tag.tag.equals(POI_TYPE_TAG)) {
|
||||
final PoiType poiType = allTranslatedSubTypes.get(tag.value.trim().toLowerCase());
|
||||
for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
|
||||
if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) {
|
||||
final PoiType poiType = allTranslatedSubTypes.get(tag.getValue().trim().toLowerCase());
|
||||
if (poiType != null) {
|
||||
node.putTag(poiType.getOsmTag(), poiType.getOsmValue());
|
||||
if (poiType.getOsmTag2() != null) {
|
||||
node.putTag(poiType.getOsmTag2(), poiType.getOsmValue2());
|
||||
}
|
||||
} else {
|
||||
node.putTag(editPoiData.amenity.getType().getDefaultTag(), tag.value);
|
||||
node.putTag(editPoiData.amenity.getType().getDefaultTag(), tag.getValue());
|
||||
}
|
||||
// } else if (tag.tag.equals(OSMSettings.OSMTagKey.DESCRIPTION.getValue())) {
|
||||
// description = tag.value;
|
||||
} else {
|
||||
if (tag.value.length() > 0) {
|
||||
node.putTag(tag.tag, tag.value);
|
||||
if (tag.getKey().length() > 0) {
|
||||
node.putTag(tag.getKey(), tag.getValue());
|
||||
} else {
|
||||
node.removeTag(tag.tag);
|
||||
node.removeTag(tag.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -369,15 +335,10 @@ public class EditPoiFragment extends DialogFragment {
|
|||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putSerializable(TAGS_LIST, editPoiData.tags);
|
||||
outState.putSerializable(TAGS_LIST, (Serializable) editPoiData.getTagValues());
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private void tryAddTag(String key, String value) {
|
||||
if (!Algorithms.isEmpty(value)) {
|
||||
editPoiData.tags.add(new Tag(key, value));
|
||||
}
|
||||
}
|
||||
|
||||
public static EditPoiFragment createAddPoiInstance(double latitude, double longitude,
|
||||
OsmandApplication application) {
|
||||
|
@ -407,7 +368,6 @@ public class EditPoiFragment extends DialogFragment {
|
|||
poiTypeEditText.setText(subCategory);
|
||||
}
|
||||
|
||||
// TODO: 8/28/15 Move to some king of helper class
|
||||
public static void commitNode(final OsmPoint.Action action,
|
||||
final Node n,
|
||||
final EntityInfo info,
|
||||
|
|
|
@ -1,19 +1,120 @@
|
|||
package net.osmand.plus.osmedit.data;
|
||||
|
||||
import net.osmand.data.Amenity;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.osm.edit.Node;
|
||||
import net.osmand.osm.edit.OSMSettings;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
public class EditPoiData {
|
||||
private Set<TagsChangedListener> mListeners = new HashSet<>();
|
||||
public LinkedHashSet<Tag> tags;
|
||||
public Amenity amenity;
|
||||
private LinkedHashMap<String, String > tagValues = new LinkedHashMap<String, String>();
|
||||
private boolean isInEdit = false;
|
||||
public final Amenity amenity;
|
||||
public static final String POI_TYPE_TAG = "poi_type_tag";
|
||||
|
||||
public EditPoiData(Amenity amenity, Node node, Map<String, PoiType> allTranslatedSubTypes) {
|
||||
this.amenity = amenity;
|
||||
initTags(node, allTranslatedSubTypes);
|
||||
}
|
||||
|
||||
public void notifyDatasetChanged(TagsChangedListener listenerToSkip) {
|
||||
|
||||
public void updateTags(Map<String, String> mp) {
|
||||
this.tagValues.clear();
|
||||
this.tagValues.putAll(mp);
|
||||
}
|
||||
private void tryAddTag(String key, String value) {
|
||||
if (!Algorithms.isEmpty(value)) {
|
||||
tagValues.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void initTags(Node node, Map<String, PoiType> allTranslatedSubTypes) {
|
||||
|
||||
tryAddTag(OSMSettings.OSMTagKey.ADDR_STREET.getValue(),
|
||||
node.getTag(OSMSettings.OSMTagKey.ADDR_STREET));
|
||||
tryAddTag(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue(),
|
||||
node.getTag(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER));
|
||||
tryAddTag(OSMSettings.OSMTagKey.PHONE.getValue(),
|
||||
amenity.getPhone());
|
||||
tryAddTag(OSMSettings.OSMTagKey.WEBSITE.getValue(),
|
||||
amenity.getSite());
|
||||
for (String tag : node.getTagKeySet()) {
|
||||
tryAddTag(tag, node.getTag(tag));
|
||||
}
|
||||
String subType = amenity.getSubType();
|
||||
String key;
|
||||
String value;
|
||||
if (allTranslatedSubTypes.get(subType) != null) {
|
||||
PoiType pt = allTranslatedSubTypes.get(subType);
|
||||
key = pt.getOsmTag();
|
||||
value = pt.getOsmValue();
|
||||
} else {
|
||||
key = amenity.getType().getDefaultTag();
|
||||
value = subType;
|
||||
}
|
||||
tagValues.remove(key);
|
||||
tagValues.put(POI_TYPE_TAG, value);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> getTagValues() {
|
||||
return Collections.unmodifiableMap(tagValues);
|
||||
}
|
||||
|
||||
|
||||
public void putTag(String tag, String value) {
|
||||
if(isInEdit) {
|
||||
throw new IllegalStateException("Can't modify in edit mode");
|
||||
}
|
||||
try {
|
||||
isInEdit = true;
|
||||
tagValues.put(tag, value);
|
||||
notifyDatasetChanged();
|
||||
} finally {
|
||||
isInEdit = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void notifyToUpdateUI() {
|
||||
if(isInEdit) {
|
||||
throw new IllegalStateException("Can't modify in edit mode");
|
||||
}
|
||||
try {
|
||||
isInEdit = true;
|
||||
notifyDatasetChanged();
|
||||
} finally {
|
||||
isInEdit = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeTag(String tag) {
|
||||
if(isInEdit) {
|
||||
throw new IllegalStateException("Can't modify in edit mode");
|
||||
}
|
||||
try {
|
||||
isInEdit = true;
|
||||
tagValues.remove(tag);
|
||||
notifyDatasetChanged();
|
||||
} finally {
|
||||
isInEdit = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInEdit() {
|
||||
return isInEdit;
|
||||
}
|
||||
|
||||
|
||||
private void notifyDatasetChanged() {
|
||||
for (TagsChangedListener listener : mListeners) {
|
||||
if (listener != listenerToSkip) listener.onTagsChanged();
|
||||
listener.onTagsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,6 +127,12 @@ public class EditPoiData {
|
|||
}
|
||||
|
||||
public interface TagsChangedListener {
|
||||
|
||||
void onTagsChanged();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
package net.osmand.plus.osmedit.data;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Tag implements Serializable {
|
||||
private static final Log LOG = PlatformUtil.getLog(Tag.class);
|
||||
public String tag;
|
||||
public String value;
|
||||
|
||||
public Tag(String tag, String value) {
|
||||
this.tag = tag;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Tag tag1 = (Tag) o;
|
||||
return tag.equals(tag1.tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return tag.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Tag{" +
|
||||
"tag='" + tag + '\'' +
|
||||
", value='" + value + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -831,6 +831,9 @@ public class VoiceRouter {
|
|||
}
|
||||
|
||||
private void makeSound(){
|
||||
if(isMute()) {
|
||||
return;
|
||||
}
|
||||
SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
|
||||
int soundClick = -1;
|
||||
boolean success = true;
|
||||
|
|
Loading…
Reference in a new issue